All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee
@ 2013-03-04 19:33 Paulo Borges
  2013-03-04 19:33 ` [PATCH 01/13] dundee: Rename dundee BlueZ 4 support Paulo Borges
                   ` (15 more replies)
  0 siblings, 16 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-04 19:33 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1364 bytes --]

This series implements support for BlueZ 5 to dundee. It uses the
org.bluez.Profile1 API to register an external profile.

While the interface between BlueZ and dundee has changed, the interfaces
"org.ofono.dundee.Device" and "org.ofono.dundee.Manager" remains
unchanged.

Paulo Borges (13):
  dundee: Rename dundee BlueZ 4 support
  dundee: Start BlueZ 5 support
  bluez5: Add DUN_UUID
  dundee: Initial GDBusClient for BlueZ 5
  dundee: Add mechanism to store bluetooth devices
  dundee: Add tracking of bluetooth devices
  dundee: Listen to devices property changes
  dundee: Add dundee device driver skeleton
  dundee: Register/unregister dundee device
  dundee: Add BlueZ Profile handler
  dundee: Add support for driver connect
  dundee: Add dundee disconnect function
  dundee: Handle Profile connect and disconnect

 Makefile.am        |   16 +-
 dundee/bluetooth.c |  297 -----------------------------------
 dundee/bluez4.c    |  297 +++++++++++++++++++++++++++++++++++
 dundee/bluez5.c    |  445 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 dundee/device.c    |   14 +-
 dundee/dundee.h    |    5 +
 plugins/bluez5.h   |    1 +
 7 files changed, 769 insertions(+), 306 deletions(-)
 delete mode 100644 dundee/bluetooth.c
 create mode 100644 dundee/bluez4.c
 create mode 100644 dundee/bluez5.c

-- 
1.7.9.5


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

* [PATCH 01/13] dundee: Rename dundee BlueZ 4 support
  2013-03-04 19:33 [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Paulo Borges
@ 2013-03-04 19:33 ` Paulo Borges
  2013-03-04 19:33 ` [PATCH 02/13] dundee: Start BlueZ 5 support Paulo Borges
                   ` (14 subsequent siblings)
  15 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-04 19:33 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 14474 bytes --]

The BlueZ 4 support file for dundee has now been renamed to
bluez4.c to make it easier to add a BlueZ 5 support file.
---
 Makefile.am        |    2 +-
 dundee/bluetooth.c |  297 ----------------------------------------------------
 dundee/bluez4.c    |  297 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 298 insertions(+), 298 deletions(-)
 delete mode 100644 dundee/bluetooth.c
 create mode 100644 dundee/bluez4.c

diff --git a/Makefile.am b/Makefile.am
index 557f499..ed35988 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -763,7 +763,7 @@ sbin_PROGRAMS += dundee/dundee
 dundee_dundee_SOURCES = $(gdbus_sources) $(gatchat_sources) $(btio_sources) \
 			src/log.c src/dbus.c plugins/bluez4.c \
 			dundee/dundee.h dundee/main.c dundee/dbus.c \
-			dundee/manager.c dundee/device.c dundee/bluetooth.c
+			dundee/manager.c dundee/device.c dundee/bluez4.c
 
 dundee_dundee_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ -ldl
 
diff --git a/dundee/bluetooth.c b/dundee/bluetooth.c
deleted file mode 100644
index 58355d3..0000000
--- a/dundee/bluetooth.c
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- *  oFono - Open Source Telephony
- *
- *  Copyright (C) 2008-2012  Intel Corporation. All rights reserved.
- *  Copyright (C) 2012  BMW Car IT GmbH. All rights reserved.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License version 2 as
- *  published by the Free Software Foundation.
- *
- *  This program 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 General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/socket.h>
-
-#include <glib.h>
-
-#include "plugins/bluez4.h"
-
-#include "dundee.h"
-
-static GHashTable *bluetooth_hash;
-
-struct bluetooth_device {
-	struct dundee_device *device;
-
-	char *path;
-	char *address;
-	char *name;
-
-	int fd;
-
-	DBusPendingCall *call;
-};
-
-static void bt_disconnect(struct dundee_device *device,
-				dundee_device_disconnect_cb_t cb, void *data)
-{
-	struct bluetooth_device *bt = dundee_device_get_data(device);
-
-	DBG("%p", bt);
-
-	shutdown(bt->fd, SHUT_RDWR);
-
-	CALLBACK_WITH_SUCCESS(cb, data);
-}
-
-static void bt_connect_reply(DBusPendingCall *call, gpointer user_data)
-{
-	struct cb_data *cbd = user_data;
-	dundee_device_connect_cb_t cb = cbd->cb;
-	struct bluetooth_device *bt = cbd->user;
-	DBusMessage *reply;
-	DBusError derr;
-	int fd;
-
-	DBG("%p", bt);
-
-	reply = dbus_pending_call_steal_reply(call);
-
-	bt->call = NULL;
-
-	dbus_error_init(&derr);
-	if (dbus_set_error_from_message(&derr, reply)) {
-		DBG("Connection to bt serial returned with error: %s, %s",
-						derr.name, derr.message);
-
-		dbus_error_free(&derr);
-
-		CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
-		goto done;
-	}
-
-	dbus_message_get_args(reply, NULL, DBUS_TYPE_UNIX_FD, &fd,
-			DBUS_TYPE_INVALID);
-
-	DBG("%p fd %d", bt, fd);
-
-	if (fd < 0) {
-		CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
-		goto done;
-	}
-
-	bt->fd = fd;
-
-	CALLBACK_WITH_SUCCESS(cb, fd, cbd->data);
-
-done:
-	dbus_message_unref(reply);
-	g_free(cbd);
-}
-
-static void bt_connect(struct dundee_device *device,
-			dundee_device_connect_cb_t cb, void *data)
-{
-	struct bluetooth_device *bt = dundee_device_get_data(device);
-	struct cb_data *cbd = cb_data_new(cb, data);
-	char *profile = "dun";
-	int status;
-
-	DBG("%p", bt);
-
-	cbd->user = bt;
-
-	status = bluetooth_send_with_reply(bt->path,
-					BLUEZ_SERIAL_INTERFACE, "ConnectFD",
-					&bt->call, bt_connect_reply,
-					cbd, NULL, DBUS_TIMEOUT,
-					DBUS_TYPE_STRING, &profile,
-					DBUS_TYPE_INVALID);
-	if (status == 0)
-		return;
-
-	g_free(cbd);
-
-	CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
-}
-
-struct dundee_device_driver bluetooth_driver = {
-	.name = "bluetooth",
-	.connect = bt_connect,
-	.disconnect = bt_disconnect,
-};
-
-static int bt_probe(const char *path, const char *dev_addr,
-				const char *adapter_addr, const char *alias)
-{
-	struct bluetooth_device *bt;
-	struct dundee_device *device;
-	char buf[256];
-
-	DBG("");
-
-	/* We already have this device in our hash, ignore */
-	if (g_hash_table_lookup(bluetooth_hash, path) != NULL)
-		return -EALREADY;
-
-	ofono_info("Using device: %s, devaddr: %s, adapter: %s",
-			path, dev_addr, adapter_addr);
-
-	strcpy(buf, "dun/");
-	bluetooth_create_path(dev_addr, adapter_addr, buf + 4, sizeof(buf) - 4);
-
-	bt = g_try_new0(struct bluetooth_device, 1);
-	if (bt == NULL)
-		return -ENOMEM;
-
-	DBG("%p", bt);
-
-	device = dundee_device_create(&bluetooth_driver);
-	if (device == NULL)
-		goto free;
-
-	dundee_device_set_data(device, bt);
-
-	bt->path = g_strdup(path);
-	if (bt->path == NULL)
-		goto free;
-
-	bt->address = g_strdup(dev_addr);
-	if (bt->address == NULL)
-		goto free;
-
-	bt->name = g_strdup(alias);
-	if (bt->name == NULL)
-		goto free;
-
-	dundee_device_set_name(device, bt->name);
-
-	if (dundee_device_register(device) < 0) {
-		g_free(device);
-		goto free;
-	}
-
-	bt->device = device;
-	g_hash_table_insert(bluetooth_hash, g_strdup(path), bt);
-
-	return 0;
-
-free:
-	g_free(bt->path);
-	g_free(bt->address);
-	g_free(bt->name);
-	g_free(bt);
-
-	return -ENOMEM;
-}
-
-static void destroy_device(gpointer user)
-{
-	struct bluetooth_device *bt = user;
-
-	DBG("%p", bt);
-
-	if (bt->call != NULL)
-		dbus_pending_call_cancel(bt->call);
-
-	g_free(bt->path);
-	g_free(bt->address);
-
-	g_free(bt);
-}
-
-static gboolean bt_remove_device(gpointer key, gpointer value,
-					gpointer user_data)
-{
-	struct bluetooth_device *bt = value;
-	const char *path = key;
-	const char *prefix = user_data;
-
-	DBG("%p", bt);
-
-	if (prefix && g_str_has_prefix(path, prefix) == FALSE)
-		return FALSE;
-
-	dundee_device_unregister(bt->device);
-
-	return TRUE;
-}
-
-static void bt_remove(const char *prefix)
-{
-	DBG("%s", prefix);
-
-	if (bluetooth_hash == NULL)
-		return;
-
-	g_hash_table_foreach_remove(bluetooth_hash, bt_remove_device,
-							(gpointer) prefix);
-}
-
-static void bt_set_alias(const char *path, const char *alias)
-{
-	struct bluetooth_device *bt;
-
-	DBG("");
-
-	if (path == NULL || alias == NULL)
-		return;
-
-	bt = g_hash_table_lookup(bluetooth_hash, path);
-	if (bt == NULL)
-		return;
-
-	g_free(bt->name);
-	bt->name = g_strdup(alias);
-
-	dundee_device_set_name(bt->device, bt->name);
-}
-
-static struct bluetooth_profile dun_profile = {
-	.name		= "dun_dt",
-	.probe		= bt_probe,
-	.remove		= bt_remove,
-	.set_alias	= bt_set_alias,
-};
-
-int __dundee_bluetooth_init(void)
-{
-	int err;
-
-	DBG("");
-
-	err = bluetooth_register_uuid(DUN_GW_UUID, &dun_profile);
-	if (err < 0)
-		return err;
-
-	bluetooth_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
-						g_free, destroy_device);
-
-	return 0;
-}
-
-void  __dundee_bluetooth_cleanup(void)
-{
-	DBG("");
-
-	bluetooth_unregister_uuid(DUN_GW_UUID);
-	g_hash_table_destroy(bluetooth_hash);
-}
diff --git a/dundee/bluez4.c b/dundee/bluez4.c
new file mode 100644
index 0000000..58355d3
--- /dev/null
+++ b/dundee/bluez4.c
@@ -0,0 +1,297 @@
+/*
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2008-2012  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2012  BMW Car IT GmbH. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/socket.h>
+
+#include <glib.h>
+
+#include "plugins/bluez4.h"
+
+#include "dundee.h"
+
+static GHashTable *bluetooth_hash;
+
+struct bluetooth_device {
+	struct dundee_device *device;
+
+	char *path;
+	char *address;
+	char *name;
+
+	int fd;
+
+	DBusPendingCall *call;
+};
+
+static void bt_disconnect(struct dundee_device *device,
+				dundee_device_disconnect_cb_t cb, void *data)
+{
+	struct bluetooth_device *bt = dundee_device_get_data(device);
+
+	DBG("%p", bt);
+
+	shutdown(bt->fd, SHUT_RDWR);
+
+	CALLBACK_WITH_SUCCESS(cb, data);
+}
+
+static void bt_connect_reply(DBusPendingCall *call, gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	dundee_device_connect_cb_t cb = cbd->cb;
+	struct bluetooth_device *bt = cbd->user;
+	DBusMessage *reply;
+	DBusError derr;
+	int fd;
+
+	DBG("%p", bt);
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	bt->call = NULL;
+
+	dbus_error_init(&derr);
+	if (dbus_set_error_from_message(&derr, reply)) {
+		DBG("Connection to bt serial returned with error: %s, %s",
+						derr.name, derr.message);
+
+		dbus_error_free(&derr);
+
+		CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+		goto done;
+	}
+
+	dbus_message_get_args(reply, NULL, DBUS_TYPE_UNIX_FD, &fd,
+			DBUS_TYPE_INVALID);
+
+	DBG("%p fd %d", bt, fd);
+
+	if (fd < 0) {
+		CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+		goto done;
+	}
+
+	bt->fd = fd;
+
+	CALLBACK_WITH_SUCCESS(cb, fd, cbd->data);
+
+done:
+	dbus_message_unref(reply);
+	g_free(cbd);
+}
+
+static void bt_connect(struct dundee_device *device,
+			dundee_device_connect_cb_t cb, void *data)
+{
+	struct bluetooth_device *bt = dundee_device_get_data(device);
+	struct cb_data *cbd = cb_data_new(cb, data);
+	char *profile = "dun";
+	int status;
+
+	DBG("%p", bt);
+
+	cbd->user = bt;
+
+	status = bluetooth_send_with_reply(bt->path,
+					BLUEZ_SERIAL_INTERFACE, "ConnectFD",
+					&bt->call, bt_connect_reply,
+					cbd, NULL, DBUS_TIMEOUT,
+					DBUS_TYPE_STRING, &profile,
+					DBUS_TYPE_INVALID);
+	if (status == 0)
+		return;
+
+	g_free(cbd);
+
+	CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+}
+
+struct dundee_device_driver bluetooth_driver = {
+	.name = "bluetooth",
+	.connect = bt_connect,
+	.disconnect = bt_disconnect,
+};
+
+static int bt_probe(const char *path, const char *dev_addr,
+				const char *adapter_addr, const char *alias)
+{
+	struct bluetooth_device *bt;
+	struct dundee_device *device;
+	char buf[256];
+
+	DBG("");
+
+	/* We already have this device in our hash, ignore */
+	if (g_hash_table_lookup(bluetooth_hash, path) != NULL)
+		return -EALREADY;
+
+	ofono_info("Using device: %s, devaddr: %s, adapter: %s",
+			path, dev_addr, adapter_addr);
+
+	strcpy(buf, "dun/");
+	bluetooth_create_path(dev_addr, adapter_addr, buf + 4, sizeof(buf) - 4);
+
+	bt = g_try_new0(struct bluetooth_device, 1);
+	if (bt == NULL)
+		return -ENOMEM;
+
+	DBG("%p", bt);
+
+	device = dundee_device_create(&bluetooth_driver);
+	if (device == NULL)
+		goto free;
+
+	dundee_device_set_data(device, bt);
+
+	bt->path = g_strdup(path);
+	if (bt->path == NULL)
+		goto free;
+
+	bt->address = g_strdup(dev_addr);
+	if (bt->address == NULL)
+		goto free;
+
+	bt->name = g_strdup(alias);
+	if (bt->name == NULL)
+		goto free;
+
+	dundee_device_set_name(device, bt->name);
+
+	if (dundee_device_register(device) < 0) {
+		g_free(device);
+		goto free;
+	}
+
+	bt->device = device;
+	g_hash_table_insert(bluetooth_hash, g_strdup(path), bt);
+
+	return 0;
+
+free:
+	g_free(bt->path);
+	g_free(bt->address);
+	g_free(bt->name);
+	g_free(bt);
+
+	return -ENOMEM;
+}
+
+static void destroy_device(gpointer user)
+{
+	struct bluetooth_device *bt = user;
+
+	DBG("%p", bt);
+
+	if (bt->call != NULL)
+		dbus_pending_call_cancel(bt->call);
+
+	g_free(bt->path);
+	g_free(bt->address);
+
+	g_free(bt);
+}
+
+static gboolean bt_remove_device(gpointer key, gpointer value,
+					gpointer user_data)
+{
+	struct bluetooth_device *bt = value;
+	const char *path = key;
+	const char *prefix = user_data;
+
+	DBG("%p", bt);
+
+	if (prefix && g_str_has_prefix(path, prefix) == FALSE)
+		return FALSE;
+
+	dundee_device_unregister(bt->device);
+
+	return TRUE;
+}
+
+static void bt_remove(const char *prefix)
+{
+	DBG("%s", prefix);
+
+	if (bluetooth_hash == NULL)
+		return;
+
+	g_hash_table_foreach_remove(bluetooth_hash, bt_remove_device,
+							(gpointer) prefix);
+}
+
+static void bt_set_alias(const char *path, const char *alias)
+{
+	struct bluetooth_device *bt;
+
+	DBG("");
+
+	if (path == NULL || alias == NULL)
+		return;
+
+	bt = g_hash_table_lookup(bluetooth_hash, path);
+	if (bt == NULL)
+		return;
+
+	g_free(bt->name);
+	bt->name = g_strdup(alias);
+
+	dundee_device_set_name(bt->device, bt->name);
+}
+
+static struct bluetooth_profile dun_profile = {
+	.name		= "dun_dt",
+	.probe		= bt_probe,
+	.remove		= bt_remove,
+	.set_alias	= bt_set_alias,
+};
+
+int __dundee_bluetooth_init(void)
+{
+	int err;
+
+	DBG("");
+
+	err = bluetooth_register_uuid(DUN_GW_UUID, &dun_profile);
+	if (err < 0)
+		return err;
+
+	bluetooth_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+						g_free, destroy_device);
+
+	return 0;
+}
+
+void  __dundee_bluetooth_cleanup(void)
+{
+	DBG("");
+
+	bluetooth_unregister_uuid(DUN_GW_UUID);
+	g_hash_table_destroy(bluetooth_hash);
+}
-- 
1.7.9.5


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

* [PATCH 02/13] dundee: Start BlueZ 5 support
  2013-03-04 19:33 [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Paulo Borges
  2013-03-04 19:33 ` [PATCH 01/13] dundee: Rename dundee BlueZ 4 support Paulo Borges
@ 2013-03-04 19:33 ` Paulo Borges
  2013-03-11 17:01   ` Daniel Wagner
  2013-03-04 19:33 ` [PATCH 03/13] bluez5: Add DUN_UUID Paulo Borges
                   ` (13 subsequent siblings)
  15 siblings, 1 reply; 55+ messages in thread
From: Paulo Borges @ 2013-03-04 19:33 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2532 bytes --]

This patch adds the BlueZ 5 support file for dundee.
---
 Makefile.am     |   16 ++++++++++------
 dundee/bluez5.c |   37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 6 deletions(-)
 create mode 100644 dundee/bluez5.c

diff --git a/Makefile.am b/Makefile.am
index ed35988..1748d06 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -756,24 +756,28 @@ endif
 endif
 
 if BLUETOOTH
-if BLUEZ4
 if DUNDEE
 sbin_PROGRAMS += dundee/dundee
 
-dundee_dundee_SOURCES = $(gdbus_sources) $(gatchat_sources) $(btio_sources) \
-			src/log.c src/dbus.c plugins/bluez4.c \
-			dundee/dundee.h dundee/main.c dundee/dbus.c \
-			dundee/manager.c dundee/device.c dundee/bluez4.c
+dundee_common_sources = $(gdbus_sources) $(gatchat_sources) \
+			src/log.c src/dbus.c dundee/dundee.h dundee/main.c \
+			dundee/dbus.c dundee/manager.c dundee/device.c
 
 dundee_dundee_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ -ldl
 
 if DATAFILES
 dist_dbusconf_DATA += dundee/dundee.conf
-
 if SYSTEMD
 systemdunit_DATA += dundee/dundee.service
 endif
 endif
+
+if BLUEZ4
+dundee_dundee_SOURCES = $(dundee_common_sources) $(btio_sources) \
+			plugins/bluez4.c dundee/bluez4.c
+else
+dundee_dundee_SOURCES = $(dundee_common_sources) plugins/bluez5.c \
+			dundee/bluez5.c
 endif
 endif
 endif
diff --git a/dundee/bluez5.c b/dundee/bluez5.c
new file mode 100644
index 0000000..6685b4c
--- /dev/null
+++ b/dundee/bluez5.c
@@ -0,0 +1,37 @@
+/*
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2013  Instituto Nokia de Tecnologia - INdT
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "dundee.h"
+
+int __dundee_bluetooth_init(void)
+{
+	DBG("");
+
+	return 0;
+}
+
+void __dundee_bluetooth_cleanup(void)
+{
+	DBG("");
+}
-- 
1.7.9.5


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

* [PATCH 03/13] bluez5: Add DUN_UUID
  2013-03-04 19:33 [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Paulo Borges
  2013-03-04 19:33 ` [PATCH 01/13] dundee: Rename dundee BlueZ 4 support Paulo Borges
  2013-03-04 19:33 ` [PATCH 02/13] dundee: Start BlueZ 5 support Paulo Borges
@ 2013-03-04 19:33 ` Paulo Borges
  2013-03-04 19:33 ` [PATCH 04/13] dundee: Initial GDBusClient for BlueZ 5 Paulo Borges
                   ` (12 subsequent siblings)
  15 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-04 19:33 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 533 bytes --]

---
 plugins/bluez5.h |    1 +
 1 file changed, 1 insertion(+)

diff --git a/plugins/bluez5.h b/plugins/bluez5.h
index f7f3d7e..09654b7 100644
--- a/plugins/bluez5.h
+++ b/plugins/bluez5.h
@@ -25,6 +25,7 @@
 #define BLUEZ_DEVICE_INTERFACE		BLUEZ_SERVICE ".Device1"
 #define BLUEZ_ERROR_INTERFACE		BLUEZ_SERVICE ".Error"
 
+#define DUN_UUID	"00001103-0000-1000-8000-00805f9b34fb"
 #define HFP_HS_UUID	"0000111e-0000-1000-8000-00805f9b34fb"
 #define HFP_AG_UUID	"0000111f-0000-1000-8000-00805f9b34fb"
 
-- 
1.7.9.5


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

* [PATCH 04/13] dundee: Initial GDBusClient for BlueZ 5
  2013-03-04 19:33 [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Paulo Borges
                   ` (2 preceding siblings ...)
  2013-03-04 19:33 ` [PATCH 03/13] bluez5: Add DUN_UUID Paulo Borges
@ 2013-03-04 19:33 ` Paulo Borges
  2013-03-11 17:08   ` Daniel Wagner
  2013-03-04 19:33 ` [PATCH 05/13] dundee: Add mechanism to store bluetooth devices Paulo Borges
                   ` (11 subsequent siblings)
  15 siblings, 1 reply; 55+ messages in thread
From: Paulo Borges @ 2013-03-04 19:33 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2628 bytes --]

This patch adds the callbacks to track additions and removals of
BlueZ related interfaces and property changes in these interfaces.
---
 dundee/bluez5.c |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 dundee/dundee.h |    2 ++
 2 files changed, 62 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index 6685b4c..40df700 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -22,16 +22,76 @@
 #include <config.h>
 #endif
 
+#include <stdint.h>
+#include <sys/socket.h>
+#include <gdbus.h>
+
 #include "dundee.h"
+#include "plugins/bluez5.h"
+
+#define DUN_DT_PROFILE_PATH   "/bluetooth/profile/dun_dt"
+
+static GDBusClient *bluez;
+
+static void proxy_added(GDBusProxy *proxy, void *user_data)
+{
+	const char *path = g_dbus_proxy_get_path(proxy);
+	const char *interface = g_dbus_proxy_get_interface(proxy);
+
+	if (g_str_equal(BLUEZ_DEVICE_INTERFACE, interface) == FALSE)
+		return;
+
+	DBG("%s %s", path, interface);
+}
+
+static void proxy_removed(GDBusProxy *proxy, void *user_data)
+{
+	const char *path = g_dbus_proxy_get_path(proxy);
+	const char *interface = g_dbus_proxy_get_interface(proxy);
+
+	if (g_str_equal(BLUEZ_DEVICE_INTERFACE, interface) == FALSE)
+		return;
+
+	DBG("%s %s", path, interface);
+}
+
+static void property_changed(GDBusProxy *proxy, const char *name,
+					DBusMessageIter *iter, void *user_data)
+{
+	const char *path = g_dbus_proxy_get_path(proxy);
+	const char *interface = g_dbus_proxy_get_interface(proxy);
+
+	if (g_str_equal(BLUEZ_DEVICE_INTERFACE, interface) == FALSE)
+		return;
+
+	DBG("%s %s.%s", path, interface, name);
+}
+
+static void connect_handler(DBusConnection *conn, void *user_data)
+{
+	DBG("");
+
+	bt_register_profile_with_role(conn, DUN_UUID, DUN_VERSION_1_2,
+				"dun_dt", DUN_DT_PROFILE_PATH, "client");
+}
 
 int __dundee_bluetooth_init(void)
 {
+	DBusConnection *conn = ofono_dbus_get_connection();
+
 	DBG("");
 
+	bluez = g_dbus_client_new(conn, BLUEZ_SERVICE, BLUEZ_MANAGER_PATH);
+	g_dbus_client_set_connect_watch(bluez, connect_handler, NULL);
+	g_dbus_client_set_proxy_handlers(bluez, proxy_added, proxy_removed,
+						property_changed, NULL);
+
 	return 0;
 }
 
 void __dundee_bluetooth_cleanup(void)
 {
 	DBG("");
+
+	g_dbus_client_unref(bluez);
 }
diff --git a/dundee/dundee.h b/dundee/dundee.h
index db932b6..daf78a5 100644
--- a/dundee/dundee.h
+++ b/dundee/dundee.h
@@ -26,6 +26,8 @@
 
 #include <ofono/types.h>
 
+#define DUN_VERSION_1_2 0x0102
+
 void __dundee_exit(void);
 
 enum dundee_error_type {
-- 
1.7.9.5


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

* [PATCH 05/13] dundee: Add mechanism to store bluetooth devices
  2013-03-04 19:33 [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Paulo Borges
                   ` (3 preceding siblings ...)
  2013-03-04 19:33 ` [PATCH 04/13] dundee: Initial GDBusClient for BlueZ 5 Paulo Borges
@ 2013-03-04 19:33 ` Paulo Borges
  2013-03-04 19:33 ` [PATCH 06/13] dundee: Add tracking of " Paulo Borges
                   ` (10 subsequent siblings)
  15 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-04 19:33 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1354 bytes --]

This patch adds a hash that will store every known bluetooth
device that implements DUN service.
---
 dundee/bluez5.c |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index 40df700..970f3a2 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -32,6 +32,25 @@
 #define DUN_DT_PROFILE_PATH   "/bluetooth/profile/dun_dt"
 
 static GDBusClient *bluez;
+static GHashTable *registered_devices;
+
+struct bluetooth_device {
+	char *path;
+	char *address;
+	char *name;
+};
+
+static void bluetooth_device_destroy(gpointer user_data)
+{
+	struct bluetooth_device *bt_device = user_data;
+
+	DBG("%s", bt_device->path);
+
+	g_free(bt_device->path);
+	g_free(bt_device->address);
+	g_free(bt_device->name);
+	g_free(bt_device);
+}
 
 static void proxy_added(GDBusProxy *proxy, void *user_data)
 {
@@ -86,6 +105,9 @@ int __dundee_bluetooth_init(void)
 	g_dbus_client_set_proxy_handlers(bluez, proxy_added, proxy_removed,
 						property_changed, NULL);
 
+	registered_devices = g_hash_table_new_full(g_str_hash, g_str_equal,
+					g_free, bluetooth_device_destroy);
+
 	return 0;
 }
 
@@ -94,4 +116,5 @@ void __dundee_bluetooth_cleanup(void)
 	DBG("");
 
 	g_dbus_client_unref(bluez);
+	g_hash_table_destroy(registered_devices);
 }
-- 
1.7.9.5


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

* [PATCH 06/13] dundee: Add tracking of bluetooth devices
  2013-03-04 19:33 [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Paulo Borges
                   ` (4 preceding siblings ...)
  2013-03-04 19:33 ` [PATCH 05/13] dundee: Add mechanism to store bluetooth devices Paulo Borges
@ 2013-03-04 19:33 ` Paulo Borges
  2013-03-04 19:33 ` [PATCH 07/13] dundee: Listen to devices property changes Paulo Borges
                   ` (9 subsequent siblings)
  15 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-04 19:33 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3212 bytes --]

This patch tracks the GDBusProxy for Bluetooth devices in order to
be able to get their properties and register them when they
implement DUN.
---
 dundee/bluez5.c |   90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index 970f3a2..8d8e656 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -52,15 +52,103 @@ static void bluetooth_device_destroy(gpointer user_data)
 	g_free(bt_device);
 }
 
+static struct bluetooth_device *bluetooth_device_create(const char *path,
+					const char *address, const char *alias)
+{
+	struct bluetooth_device *tmp;
+
+	DBG("%s %s %s", path, address, alias);
+
+	tmp = g_try_new0(struct bluetooth_device, 1);
+	if (tmp == NULL)
+		return NULL;
+
+	tmp->path = g_strdup(path);
+	tmp->address = g_strdup(address);
+	tmp->name = g_strdup(alias);
+
+	return tmp;
+}
+
+static void bluetooth_device_register(GDBusProxy *proxy)
+{
+	const char *path = g_dbus_proxy_get_path(proxy);
+	const char *alias, *address;
+	struct bluetooth_device *bt_device;
+	DBusMessageIter iter;
+
+	DBG("%s", path);
+
+	if (g_hash_table_lookup(registered_devices, path) != NULL)
+		return;
+
+	if (g_dbus_proxy_get_property(proxy, "Address", &iter) == FALSE)
+		return;
+
+	dbus_message_iter_get_basic(&iter, &address);
+
+	if (g_dbus_proxy_get_property(proxy, "Alias", &iter) == FALSE)
+		return;
+
+	dbus_message_iter_get_basic(&iter, &alias);
+
+	bt_device = bluetooth_device_create(path, address, alias);
+	if (bt_device == NULL) {
+		ofono_error("register bluetooth device failed");
+		return;
+	}
+
+	g_hash_table_insert(registered_devices, g_strdup(path), bt_device);
+}
+
+static void bluetooth_device_unregister(const char *path)
+{
+	DBG("");
+
+	g_hash_table_remove(registered_devices, path);
+}
+
+static gboolean has_dun_uuid(DBusMessageIter *array)
+{
+	DBusMessageIter value;
+
+	if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
+		return FALSE;
+
+	dbus_message_iter_recurse(array, &value);
+
+	while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
+		const char *uuid;
+
+		dbus_message_iter_get_basic(&value, &uuid);
+
+		if (g_str_equal(uuid, DUN_UUID) == TRUE)
+			return TRUE;
+
+		dbus_message_iter_next(&value);
+	}
+
+	return FALSE;
+}
+
 static void proxy_added(GDBusProxy *proxy, void *user_data)
 {
 	const char *path = g_dbus_proxy_get_path(proxy);
 	const char *interface = g_dbus_proxy_get_interface(proxy);
+	DBusMessageIter iter;
 
 	if (g_str_equal(BLUEZ_DEVICE_INTERFACE, interface) == FALSE)
 		return;
 
+	if (g_dbus_proxy_get_property(proxy, "UUIDs", &iter) == FALSE)
+		return;
+
 	DBG("%s %s", path, interface);
+
+	if (has_dun_uuid(&iter) == FALSE)
+		return;
+
+	bluetooth_device_register(proxy);
 }
 
 static void proxy_removed(GDBusProxy *proxy, void *user_data)
@@ -72,6 +160,8 @@ static void proxy_removed(GDBusProxy *proxy, void *user_data)
 		return;
 
 	DBG("%s %s", path, interface);
+
+	bluetooth_device_unregister(path);
 }
 
 static void property_changed(GDBusProxy *proxy, const char *name,
-- 
1.7.9.5


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

* [PATCH 07/13] dundee: Listen to devices property changes
  2013-03-04 19:33 [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Paulo Borges
                   ` (5 preceding siblings ...)
  2013-03-04 19:33 ` [PATCH 06/13] dundee: Add tracking of " Paulo Borges
@ 2013-03-04 19:33 ` Paulo Borges
  2013-03-11 17:17   ` Daniel Wagner
  2013-03-04 19:33 ` [PATCH 08/13] dundee: Add dundee device driver skeleton Paulo Borges
                   ` (8 subsequent siblings)
  15 siblings, 1 reply; 55+ messages in thread
From: Paulo Borges @ 2013-03-04 19:33 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1464 bytes --]

When a bluetooth device property change and this property is Alias
or UUIDs, we need to refresh our representation of this device.
---
 dundee/bluez5.c |   26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index 8d8e656..623201f 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -169,11 +169,35 @@ static void property_changed(GDBusProxy *proxy, const char *name,
 {
 	const char *path = g_dbus_proxy_get_path(proxy);
 	const char *interface = g_dbus_proxy_get_interface(proxy);
+	const char *alias;
+	struct bluetooth_device *bt_device;
+	gboolean uuid;
 
 	if (g_str_equal(BLUEZ_DEVICE_INTERFACE, interface) == FALSE)
 		return;
 
-	DBG("%s %s.%s", path, interface, name);
+	bt_device = g_hash_table_lookup(registered_devices, path);
+
+	if (g_str_equal(name, "Alias") == TRUE) {
+		if (bt_device == NULL)
+			return;
+
+		dbus_message_iter_get_basic(iter, &alias);
+
+		DBG("%s alias changed: %s", path, alias);
+
+		bt_device->name = g_strdup(alias);
+	} else if (g_str_equal(name, "UUIDs") == TRUE) {
+		DBG("%s uuids changed", path);
+
+		uuid = has_dun_uuid(iter);
+
+		if (bt_device != NULL && uuid == FALSE)
+			bluetooth_device_unregister(path);
+
+		else if (bt_device == NULL && uuid == TRUE)
+			bluetooth_device_register(proxy);
+	}
 }
 
 static void connect_handler(DBusConnection *conn, void *user_data)
-- 
1.7.9.5


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

* [PATCH 08/13] dundee: Add dundee device driver skeleton
  2013-03-04 19:33 [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Paulo Borges
                   ` (6 preceding siblings ...)
  2013-03-04 19:33 ` [PATCH 07/13] dundee: Listen to devices property changes Paulo Borges
@ 2013-03-04 19:33 ` Paulo Borges
  2013-03-04 19:33 ` [PATCH 09/13] dundee: Register/unregister dundee device Paulo Borges
                   ` (7 subsequent siblings)
  15 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-04 19:33 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1029 bytes --]

This patch adds the functions to be called when the dundee will
connect or disconnect with a Bluetooth device.
---
 dundee/bluez5.c |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index 623201f..19111e7 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -52,6 +52,24 @@ static void bluetooth_device_destroy(gpointer user_data)
 	g_free(bt_device);
 }
 
+static void bluetooth_device_connect(struct dundee_device *device,
+			dundee_device_connect_cb_t cb, void *data)
+{
+	DBG("");
+}
+
+static void bluetooth_device_disconnect(struct dundee_device *device,
+				dundee_device_disconnect_cb_t cb, void *data)
+{
+	DBG("");
+}
+
+struct dundee_device_driver bluetooth_driver = {
+	.name = "bluetooth",
+	.connect = bluetooth_device_connect,
+	.disconnect = bluetooth_device_disconnect,
+};
+
 static struct bluetooth_device *bluetooth_device_create(const char *path,
 					const char *address, const char *alias)
 {
-- 
1.7.9.5


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

* [PATCH 09/13] dundee: Register/unregister dundee device
  2013-03-04 19:33 [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Paulo Borges
                   ` (7 preceding siblings ...)
  2013-03-04 19:33 ` [PATCH 08/13] dundee: Add dundee device driver skeleton Paulo Borges
@ 2013-03-04 19:33 ` Paulo Borges
  2013-03-04 19:37 ` [PATCH 10/13] dundee: Add BlueZ Profile handler Paulo Borges
                   ` (6 subsequent siblings)
  15 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-04 19:33 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1716 bytes --]

This patch adds the dundee device struct to the our Bluetooth
device representation.
---
 dundee/bluez5.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index 19111e7..12f0cf0 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -35,6 +35,8 @@ static GDBusClient *bluez;
 static GHashTable *registered_devices;
 
 struct bluetooth_device {
+	struct dundee_device *device;
+
 	char *path;
 	char *address;
 	char *name;
@@ -46,6 +48,9 @@ static void bluetooth_device_destroy(gpointer user_data)
 
 	DBG("%s", bt_device->path);
 
+	if (bt_device->device != NULL)
+		dundee_device_unregister(bt_device->device);
+
 	g_free(bt_device->path);
 	g_free(bt_device->address);
 	g_free(bt_device->name);
@@ -93,6 +98,7 @@ static void bluetooth_device_register(GDBusProxy *proxy)
 	const char *path = g_dbus_proxy_get_path(proxy);
 	const char *alias, *address;
 	struct bluetooth_device *bt_device;
+	struct dundee_device *device;
 	DBusMessageIter iter;
 
 	DBG("%s", path);
@@ -116,7 +122,26 @@ static void bluetooth_device_register(GDBusProxy *proxy)
 		return;
 	}
 
+	device = dundee_device_create(&bluetooth_driver);
+	if (device == NULL)
+		goto free;
+
+	dundee_device_set_data(device, bt_device);
+	dundee_device_set_name(device, bt_device->name);
+
+	if (dundee_device_register(device) < 0) {
+		g_free(device);
+		goto free;
+	}
+
+	bt_device->device = device;
 	g_hash_table_insert(registered_devices, g_strdup(path), bt_device);
+
+	return;
+
+free:
+	bluetooth_device_destroy(bt_device);
+	return;
 }
 
 static void bluetooth_device_unregister(const char *path)
-- 
1.7.9.5


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

* [PATCH 10/13] dundee: Add BlueZ Profile handler
  2013-03-04 19:33 [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Paulo Borges
                   ` (8 preceding siblings ...)
  2013-03-04 19:33 ` [PATCH 09/13] dundee: Register/unregister dundee device Paulo Borges
@ 2013-03-04 19:37 ` Paulo Borges
  2013-03-04 19:38 ` [PATCH 11/13] dundee: Add support for driver connect Paulo Borges
                   ` (5 subsequent siblings)
  15 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-04 19:37 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3191 bytes --]

This patch declares the external dundee Profile handler. It
contains the initial implementation of the D-Bus Profile1
interface and methods responsible for handling Bluetooth
connections.
---
 dundee/bluez5.c |   68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index 12f0cf0..becff32 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -25,6 +25,7 @@
 #include <stdint.h>
 #include <sys/socket.h>
 #include <gdbus.h>
+#include <errno.h>
 
 #include "dundee.h"
 #include "plugins/bluez5.h"
@@ -42,6 +43,59 @@ struct bluetooth_device {
 	char *name;
 };
 
+static DBusMessage *profile_new_connection(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	DBG("");
+
+	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+						".NotImplemented",
+						"Implementation not provided");
+}
+
+static DBusMessage *profile_release(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	DBG("");
+
+	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+						".NotImplemented",
+						"Implementation not provided");
+}
+
+static DBusMessage *profile_cancel(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	DBG("");
+
+	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+						".NotImplemented",
+						"Implementation not provided");
+}
+
+static DBusMessage *profile_disconnection(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	DBG("");
+
+	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+						".NotImplemented",
+						"Implementation not provided");
+}
+
+static const GDBusMethodTable profile_methods[] = {
+	{ GDBUS_ASYNC_METHOD("NewConnection",
+				GDBUS_ARGS({ "device", "o"}, { "fd", "h"},
+						{ "fd_properties", "a{sv}" }),
+				NULL, profile_new_connection) },
+	{ GDBUS_METHOD("Release", NULL, NULL, profile_release) },
+	{ GDBUS_METHOD("Cancel", NULL, NULL, profile_cancel) },
+	{ GDBUS_METHOD("RequestDisconnection",
+				GDBUS_ARGS({"device", "o"}), NULL,
+				profile_disconnection) },
+	{ }
+};
+
 static void bluetooth_device_destroy(gpointer user_data)
 {
 	struct bluetooth_device *bt_device = user_data;
@@ -257,6 +311,15 @@ int __dundee_bluetooth_init(void)
 
 	DBG("");
 
+	if (!g_dbus_register_interface(conn, DUN_DT_PROFILE_PATH,
+					BLUEZ_PROFILE_INTERFACE,
+					profile_methods, NULL,
+					NULL, NULL, NULL)) {
+		ofono_error("Register Profile interface failed: %s",
+						DUN_DT_PROFILE_PATH);
+		return -EIO;
+	}
+
 	bluez = g_dbus_client_new(conn, BLUEZ_SERVICE, BLUEZ_MANAGER_PATH);
 	g_dbus_client_set_connect_watch(bluez, connect_handler, NULL);
 	g_dbus_client_set_proxy_handlers(bluez, proxy_added, proxy_removed,
@@ -270,8 +333,13 @@ int __dundee_bluetooth_init(void)
 
 void __dundee_bluetooth_cleanup(void)
 {
+	DBusConnection *conn = ofono_dbus_get_connection();
+
 	DBG("");
 
+	g_dbus_unregister_interface(conn, DUN_DT_PROFILE_PATH,
+						BLUEZ_PROFILE_INTERFACE);
+
 	g_dbus_client_unref(bluez);
 	g_hash_table_destroy(registered_devices);
 }
-- 
1.7.9.5


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

* [PATCH 11/13] dundee: Add support for driver connect
  2013-03-04 19:33 [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Paulo Borges
                   ` (9 preceding siblings ...)
  2013-03-04 19:37 ` [PATCH 10/13] dundee: Add BlueZ Profile handler Paulo Borges
@ 2013-03-04 19:38 ` Paulo Borges
  2013-03-04 19:38 ` [PATCH 12/13] dundee: Add dundee disconnect function Paulo Borges
                   ` (4 subsequent siblings)
  15 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-04 19:38 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 916 bytes --]

This patch glues together the dundee driver interface with the
D-Bus Profile1 interface.

When the dundee driver requests a connection, it will call the
Device1's ConnectProfile.
---
 dundee/bluez5.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index becff32..31bdfea 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -114,7 +114,12 @@ static void bluetooth_device_destroy(gpointer user_data)
 static void bluetooth_device_connect(struct dundee_device *device,
 			dundee_device_connect_cb_t cb, void *data)
 {
-	DBG("");
+	struct bluetooth_device *bt_device = dundee_device_get_data(device);
+
+	DBG("%s", bt_device->path);
+
+	bt_connect_profile(ofono_dbus_get_connection(), bt_device->path,
+						DUN_DT_UUID, NULL, NULL);
 }
 
 static void bluetooth_device_disconnect(struct dundee_device *device,
-- 
1.7.9.5


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

* [PATCH 12/13] dundee: Add dundee disconnect function
  2013-03-04 19:33 [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Paulo Borges
                   ` (10 preceding siblings ...)
  2013-03-04 19:38 ` [PATCH 11/13] dundee: Add support for driver connect Paulo Borges
@ 2013-03-04 19:38 ` Paulo Borges
  2013-03-04 19:39 ` [PATCH 13/13] dundee: Handle Profile connect and disconnect Paulo Borges
                   ` (3 subsequent siblings)
  15 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-04 19:38 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1645 bytes --]

---
 dundee/device.c |   14 +++++++++++---
 dundee/dundee.h |    3 +++
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/dundee/device.c b/dundee/device.c
index e5f6424..2d84aaa 100644
--- a/dundee/device.c
+++ b/dundee/device.c
@@ -270,11 +270,13 @@ err:
 	device->pending = NULL;
 }
 
-static void disconnect_callback(const struct dundee_error *error, void *data)
+void dundee_device_disconnect(const struct dundee_error *error,
+						struct dundee_device *device)
 {
-	struct dundee_device *device = data;
+	if (device == NULL)
+		return;
 
-	DBG("%p", device);
+	DBG("%s", device->path);
 
 	g_at_chat_unref(device->chat);
 	device->chat = NULL;
@@ -295,6 +297,12 @@ out:
 	device->pending = NULL;
 }
 
+static void disconnect_callback(const struct dundee_error *error, void *data)
+{
+	struct dundee_device *device = data;
+	dundee_device_disconnect(error, device);
+}
+
 static gboolean ppp_connect_timeout(gpointer user_data)
 {
 	struct dundee_device *device = user_data;
diff --git a/dundee/dundee.h b/dundee/dundee.h
index daf78a5..1889d84 100644
--- a/dundee/dundee.h
+++ b/dundee/dundee.h
@@ -130,6 +130,9 @@ struct dundee_device *dundee_device_create(struct dundee_device_driver *d);
 int dundee_device_register(struct dundee_device *device);
 void dundee_device_unregister(struct dundee_device *device);
 
+void dundee_device_disconnect(const struct dundee_error *error,
+						struct dundee_device *device);
+
 void dundee_device_set_data(struct dundee_device *device, void *data);
 void *dundee_device_get_data(struct dundee_device *device);
 
-- 
1.7.9.5


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

* [PATCH 13/13] dundee: Handle Profile connect and disconnect
  2013-03-04 19:33 [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Paulo Borges
                   ` (11 preceding siblings ...)
  2013-03-04 19:38 ` [PATCH 12/13] dundee: Add dundee disconnect function Paulo Borges
@ 2013-03-04 19:39 ` Paulo Borges
  2013-03-11 17:23 ` [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Daniel Wagner
                   ` (2 subsequent siblings)
  15 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-04 19:39 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 4647 bytes --]

---
 dundee/bluez5.c |  115 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 105 insertions(+), 10 deletions(-)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index 31bdfea..a92cbae 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -41,16 +41,63 @@ struct bluetooth_device {
 	char *path;
 	char *address;
 	char *name;
+
+	struct cb_data *connect_cbd;
+
+	int fd;
 };
 
 static DBusMessage *profile_new_connection(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
-	DBG("");
+	struct bluetooth_device *bt_device;
+	dundee_device_connect_cb_t cb;
+	DBusMessageIter iter;
+	const char *path;
+	int fd;
 
-	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
-						".NotImplemented",
-						"Implementation not provided");
+	if (dbus_message_iter_init(msg, &iter) == FALSE)
+		goto error;
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
+		goto error;
+
+	dbus_message_iter_get_basic(&iter, &path);
+
+	bt_device = g_hash_table_lookup(registered_devices, path);
+	if (bt_device == NULL)
+		goto error;
+
+	cb = bt_device->connect_cbd->cb;
+
+	dbus_message_iter_next(&iter);
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UNIX_FD)
+		goto call_failure;
+
+	dbus_message_iter_get_basic(&iter, &fd);
+	if (fd < 0)
+		goto call_failure;
+
+	DBG("%s %d", bt_device->path, fd);
+
+	bt_device->fd = fd;
+
+	CALLBACK_WITH_SUCCESS(cb, fd, bt_device->connect_cbd->data);
+
+	g_free(bt_device->connect_cbd);
+	bt_device->connect_cbd = NULL;
+
+	return dbus_message_new_method_return(msg);
+
+call_failure:
+	CALLBACK_WITH_FAILURE(cb, -1, bt_device->connect_cbd->data);
+
+	g_free(bt_device->connect_cbd);
+	bt_device->connect_cbd = NULL;
+
+error:
+	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE ".Rejected",
+					"Invalid arguments in method call");
 }
 
 static DBusMessage *profile_release(DBusConnection *conn,
@@ -76,11 +123,31 @@ static DBusMessage *profile_cancel(DBusConnection *conn,
 static DBusMessage *profile_disconnection(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
-	DBG("");
+	struct bluetooth_device *bt_device;
+	DBusMessageIter iter;
+	const char *path;
 
-	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
-						".NotImplemented",
-						"Implementation not provided");
+	if (dbus_message_iter_init(msg, &iter) == FALSE)
+		goto error;
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
+		goto error;
+
+	dbus_message_iter_get_basic(&iter, &path);
+
+	bt_device = g_hash_table_lookup(registered_devices, path);
+	if (bt_device == NULL)
+		goto error;
+
+	DBG("%s", bt_device->path);
+
+	CALLBACK_WITH_SUCCESS(dundee_device_disconnect, bt_device->device);
+
+	return dbus_message_new_method_return(msg);
+
+error:
+	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE ".Rejected",
+					"Invalid arguments in method call");
 }
 
 static const GDBusMethodTable profile_methods[] = {
@@ -105,27 +172,55 @@ static void bluetooth_device_destroy(gpointer user_data)
 	if (bt_device->device != NULL)
 		dundee_device_unregister(bt_device->device);
 
+	if (bt_device->connect_cbd != NULL)
+		g_free(bt_device->connect_cbd);
+
 	g_free(bt_device->path);
 	g_free(bt_device->address);
 	g_free(bt_device->name);
 	g_free(bt_device);
 }
 
+static void bluetooth_device_connect_callback(gboolean success,
+							gpointer user_data)
+{
+	struct bluetooth_device *bt_device = user_data;
+
+	if (success) {
+		DBG("Success");
+		return;
+	}
+
+	DBG("ConnectProfile() returned an error");
+
+	g_free(bt_device->connect_cbd);
+	bt_device->connect_cbd = NULL;
+}
+
 static void bluetooth_device_connect(struct dundee_device *device,
 			dundee_device_connect_cb_t cb, void *data)
 {
 	struct bluetooth_device *bt_device = dundee_device_get_data(device);
+	struct cb_data *cbd = cb_data_new(cb, data);
 
 	DBG("%s", bt_device->path);
 
+	cbd->user = bt_device;
+	bt_device->connect_cbd = cbd;
+
 	bt_connect_profile(ofono_dbus_get_connection(), bt_device->path,
-						DUN_DT_UUID, NULL, NULL);
+		DUN_UUID, bluetooth_device_connect_callback, bt_device);
 }
 
 static void bluetooth_device_disconnect(struct dundee_device *device,
 				dundee_device_disconnect_cb_t cb, void *data)
 {
-	DBG("");
+	struct bluetooth_device *bt_device = dundee_device_get_data(device);
+
+	DBG("%s", bt_device->path);
+
+	shutdown(bt_device->fd, SHUT_RDWR);
+	CALLBACK_WITH_SUCCESS(cb, data);
 }
 
 struct dundee_device_driver bluetooth_driver = {
-- 
1.7.9.5


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

* Re: [PATCH 02/13] dundee: Start BlueZ 5 support
  2013-03-04 19:33 ` [PATCH 02/13] dundee: Start BlueZ 5 support Paulo Borges
@ 2013-03-11 17:01   ` Daniel Wagner
  0 siblings, 0 replies; 55+ messages in thread
From: Daniel Wagner @ 2013-03-11 17:01 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1392 bytes --]

Hi Paulo,

I guess, I am in charge to review your patches. Let's start then :)

Just a nitpick in this one.

On 03/04/2013 08:33 PM, Paulo Borges wrote:
> This patch adds the BlueZ 5 support file for dundee.
> ---
>   Makefile.am     |   16 ++++++++++------
>   dundee/bluez5.c |   37 +++++++++++++++++++++++++++++++++++++
>   2 files changed, 47 insertions(+), 6 deletions(-)
>   create mode 100644 dundee/bluez5.c
>
> diff --git a/Makefile.am b/Makefile.am
> index ed35988..1748d06 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -756,24 +756,28 @@ endif
>   endif
>
>   if BLUETOOTH
> -if BLUEZ4
>   if DUNDEE
>   sbin_PROGRAMS += dundee/dundee
>
> -dundee_dundee_SOURCES = $(gdbus_sources) $(gatchat_sources) $(btio_sources) \
> -			src/log.c src/dbus.c plugins/bluez4.c \
> -			dundee/dundee.h dundee/main.c dundee/dbus.c \
> -			dundee/manager.c dundee/device.c dundee/bluez4.c
> +dundee_common_sources = $(gdbus_sources) $(gatchat_sources) \
> +			src/log.c src/dbus.c dundee/dundee.h dundee/main.c \
> +			dundee/dbus.c dundee/manager.c dundee/device.c
>
>   dundee_dundee_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ -ldl
>
>   if DATAFILES
>   dist_dbusconf_DATA += dundee/dundee.conf
> -
>   if SYSTEMD
>   systemdunit_DATA += dundee/dundee.service
>   endif
>   endif

The line removal seems not necessary.

cheers,
daniel

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

* Re: [PATCH 04/13] dundee: Initial GDBusClient for BlueZ 5
  2013-03-04 19:33 ` [PATCH 04/13] dundee: Initial GDBusClient for BlueZ 5 Paulo Borges
@ 2013-03-11 17:08   ` Daniel Wagner
  0 siblings, 0 replies; 55+ messages in thread
From: Daniel Wagner @ 2013-03-11 17:08 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1194 bytes --]

Hi Paulo,

On 03/04/2013 08:33 PM, Paulo Borges wrote:
> This patch adds the callbacks to track additions and removals of
> BlueZ related interfaces and property changes in these interfaces.
> ---
>   dundee/bluez5.c |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
>   dundee/dundee.h |    2 ++
>   2 files changed, 62 insertions(+)
>
> diff --git a/dundee/bluez5.c b/dundee/bluez5.c
> index 6685b4c..40df700 100644
> --- a/dundee/bluez5.c
> +++ b/dundee/bluez5.c
> @@ -22,16 +22,76 @@
>   #include <config.h>
>   #endif
>
> +#include <stdint.h>
> +#include <sys/socket.h>
> +#include <gdbus.h>
> +
>   #include "dundee.h"
> +#include "plugins/bluez5.h"
> +
> +#define DUN_DT_PROFILE_PATH   "/bluetooth/profile/dun_dt"
> +
> +static GDBusClient *bluez;
> +
> +static void proxy_added(GDBusProxy *proxy, void *user_data)
> +{
> +	const char *path = g_dbus_proxy_get_path(proxy);
> +	const char *interface = g_dbus_proxy_get_interface(proxy);
> +
> +	if (g_str_equal(BLUEZ_DEVICE_INTERFACE, interface) == FALSE)
> +		return;

In oFono, just use let the '== FALSE' part away. The same applies for 
the rest of the series.


cheers,
daniel

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

* Re: [PATCH 07/13] dundee: Listen to devices property changes
  2013-03-04 19:33 ` [PATCH 07/13] dundee: Listen to devices property changes Paulo Borges
@ 2013-03-11 17:17   ` Daniel Wagner
  2013-03-12  9:56     ` Daniel Wagner
  0 siblings, 1 reply; 55+ messages in thread
From: Daniel Wagner @ 2013-03-11 17:17 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1790 bytes --]

Hi Paulo,

On 03/04/2013 08:33 PM, Paulo Borges wrote:
> When a bluetooth device property change and this property is Alias
> or UUIDs, we need to refresh our representation of this device.
> ---
>   dundee/bluez5.c |   26 +++++++++++++++++++++++++-
>   1 file changed, 25 insertions(+), 1 deletion(-)
>
> diff --git a/dundee/bluez5.c b/dundee/bluez5.c
> index 8d8e656..623201f 100644
> --- a/dundee/bluez5.c
> +++ b/dundee/bluez5.c
> @@ -169,11 +169,35 @@ static void property_changed(GDBusProxy *proxy, const char *name,
>   {
>   	const char *path = g_dbus_proxy_get_path(proxy);
>   	const char *interface = g_dbus_proxy_get_interface(proxy);
> +	const char *alias;
> +	struct bluetooth_device *bt_device;
> +	gboolean uuid;
>
>   	if (g_str_equal(BLUEZ_DEVICE_INTERFACE, interface) == FALSE)
>   		return;
>
> -	DBG("%s %s.%s", path, interface, name);
> +	bt_device = g_hash_table_lookup(registered_devices, path);
> +
> +	if (g_str_equal(name, "Alias") == TRUE) {
> +		if (bt_device == NULL)
> +			return;
> +
> +		dbus_message_iter_get_basic(iter, &alias);
> +
> +		DBG("%s alias changed: %s", path, alias);
> +
> +		bt_device->name = g_strdup(alias);
> +	} else if (g_str_equal(name, "UUIDs") == TRUE) {
> +		DBG("%s uuids changed", path);
> +
> +		uuid = has_dun_uuid(iter);
> +
> +		if (bt_device != NULL && uuid == FALSE)
> +			bluetooth_device_unregister(path);
> +
> +		else if (bt_device == NULL && uuid == TRUE)
> +			bluetooth_device_register(proxy);
> +	}

I find this a bit hard to read. What about

	if (uuid)
		if (bt_device != NULL)
			bluetooth_device_unregister(path);
	else
		if (bt_device == NULL)
			bluetooth_device_regster(path);

? I am not sure if Denis or Marcel approves this :)

cheers,
daniel


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

* Re: [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee
  2013-03-04 19:33 [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Paulo Borges
                   ` (12 preceding siblings ...)
  2013-03-04 19:39 ` [PATCH 13/13] dundee: Handle Profile connect and disconnect Paulo Borges
@ 2013-03-11 17:23 ` Daniel Wagner
  2013-03-11 20:41   ` Paulo Borges
  2013-03-14 13:32 ` [PATCH v2 " Paulo Borges
  2013-03-20 22:26 ` [PATCH v3 " Paulo Borges
  15 siblings, 1 reply; 55+ messages in thread
From: Daniel Wagner @ 2013-03-11 17:23 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 478 bytes --]

Hi Paulo,

On 03/04/2013 08:33 PM, Paulo Borges wrote:
> This series implements support for BlueZ 5 to dundee. It uses the
> org.bluez.Profile1 API to register an external profile.
>
> While the interface between BlueZ and dundee has changed, the interfaces
> "org.ofono.dundee.Device" and "org.ofono.dundee.Manager" remains
> unchanged.

Thanks for your patches. They look pretty good to me. Let's see if Denis 
or Marcel have something to say.

cheer,
daniel


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

* Re: [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee
  2013-03-11 17:23 ` [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Daniel Wagner
@ 2013-03-11 20:41   ` Paulo Borges
  0 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-11 20:41 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 341 bytes --]

Hi Daniel,

On Mon, Mar 11, 2013 at 2:23 PM, Daniel Wagner <wagi@monom.org> wrote:

> Hi Paulo,
>
> Thanks for your patches. They look pretty good to me. Let's see if Denis
> or Marcel have something to say.
>
> cheer,
> daniel
>

Thank you for reviewing my patches! I'll fix the mentioned points and send
a v2 soon.

Paulo

[-- Attachment #2: attachment.html --]
[-- Type: text/html, Size: 623 bytes --]

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

* Re: [PATCH 07/13] dundee: Listen to devices property changes
  2013-03-11 17:17   ` Daniel Wagner
@ 2013-03-12  9:56     ` Daniel Wagner
  0 siblings, 0 replies; 55+ messages in thread
From: Daniel Wagner @ 2013-03-12  9:56 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 570 bytes --]

>> +        uuid = has_dun_uuid(iter);
>> +
>> +        if (bt_device != NULL && uuid == FALSE)
>> +            bluetooth_device_unregister(path);
>> +
>> +        else if (bt_device == NULL && uuid == TRUE)
>> +            bluetooth_device_register(proxy);
>> +    }
>
> I find this a bit hard to read. What about
>
>      if (uuid)
>          if (bt_device != NULL)
>              bluetooth_device_unregister(path);
>      else
>          if (bt_device == NULL)
>              bluetooth_device_regster(path);

Obviously, some braces are needed :)


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

* [PATCH v2 00/13] Add support for BlueZ 5 Profile1 API to dundee
  2013-03-04 19:33 [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Paulo Borges
                   ` (13 preceding siblings ...)
  2013-03-11 17:23 ` [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Daniel Wagner
@ 2013-03-14 13:32 ` Paulo Borges
  2013-03-14 13:32   ` [PATCH v2 01/13] dundee: Rename dundee BlueZ 4 support Paulo Borges
                     ` (13 more replies)
  2013-03-20 22:26 ` [PATCH v3 " Paulo Borges
  15 siblings, 14 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-14 13:32 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1362 bytes --]

This series implements support for BlueZ 5 to dundee. It uses the
org.bluez.Profile1 API to register an external profile.

While the interface between BlueZ and dundee has changed, the interfaces
"org.ofono.dundee.Device" and "org.ofono.dundee.Manager" remains
unchanged.

Paulo Borges (13):
  dundee: Rename dundee BlueZ 4 support
  dundee: Start BlueZ 5 support
  bluez5: Add DUN_UUID
  dundee: Initial GDBusClient for BlueZ 5
  dundee: Add mechanism to store bluetooth devices
  dundee: Add tracking of bluetooth devices
  dundee: Listen to devices property changes
  dundee: Add dundee device driver skeleton
  dundee: Register/unregister dundee device
  dundee: Add BlueZ Profile handler
  dundee: Add support for driver connect
  dundee: Add dundee disconnect function
  dundee: Handle Profile connect and disconnect

 Makefile.am        |   15 +-
 dundee/bluetooth.c |  297 ----------------------------------
 dundee/bluez4.c    |  297 ++++++++++++++++++++++++++++++++++
 dundee/bluez5.c    |  447 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 dundee/device.c    |   14 +-
 dundee/dundee.h    |    5 +
 plugins/bluez5.h   |    1 +
 7 files changed, 771 insertions(+), 305 deletions(-)
 delete mode 100644 dundee/bluetooth.c
 create mode 100644 dundee/bluez4.c
 create mode 100644 dundee/bluez5.c

-- 
1.7.9.5


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

* [PATCH v2 01/13] dundee: Rename dundee BlueZ 4 support
  2013-03-14 13:32 ` [PATCH v2 " Paulo Borges
@ 2013-03-14 13:32   ` Paulo Borges
  2013-03-14 13:32   ` [PATCH v2 02/13] dundee: Start BlueZ 5 support Paulo Borges
                     ` (12 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-14 13:32 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 14474 bytes --]

The BlueZ 4 support file for dundee has now been renamed to
bluez4.c to make it easier to add a BlueZ 5 support file.
---
 Makefile.am        |    2 +-
 dundee/bluetooth.c |  297 ----------------------------------------------------
 dundee/bluez4.c    |  297 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 298 insertions(+), 298 deletions(-)
 delete mode 100644 dundee/bluetooth.c
 create mode 100644 dundee/bluez4.c

diff --git a/Makefile.am b/Makefile.am
index 3b998af..3a7a8dc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -763,7 +763,7 @@ sbin_PROGRAMS += dundee/dundee
 dundee_dundee_SOURCES = $(gdbus_sources) $(gatchat_sources) $(btio_sources) \
 			src/log.c src/dbus.c plugins/bluez4.c \
 			dundee/dundee.h dundee/main.c dundee/dbus.c \
-			dundee/manager.c dundee/device.c dundee/bluetooth.c
+			dundee/manager.c dundee/device.c dundee/bluez4.c
 
 dundee_dundee_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ -ldl
 
diff --git a/dundee/bluetooth.c b/dundee/bluetooth.c
deleted file mode 100644
index 58355d3..0000000
--- a/dundee/bluetooth.c
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- *  oFono - Open Source Telephony
- *
- *  Copyright (C) 2008-2012  Intel Corporation. All rights reserved.
- *  Copyright (C) 2012  BMW Car IT GmbH. All rights reserved.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License version 2 as
- *  published by the Free Software Foundation.
- *
- *  This program 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 General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/socket.h>
-
-#include <glib.h>
-
-#include "plugins/bluez4.h"
-
-#include "dundee.h"
-
-static GHashTable *bluetooth_hash;
-
-struct bluetooth_device {
-	struct dundee_device *device;
-
-	char *path;
-	char *address;
-	char *name;
-
-	int fd;
-
-	DBusPendingCall *call;
-};
-
-static void bt_disconnect(struct dundee_device *device,
-				dundee_device_disconnect_cb_t cb, void *data)
-{
-	struct bluetooth_device *bt = dundee_device_get_data(device);
-
-	DBG("%p", bt);
-
-	shutdown(bt->fd, SHUT_RDWR);
-
-	CALLBACK_WITH_SUCCESS(cb, data);
-}
-
-static void bt_connect_reply(DBusPendingCall *call, gpointer user_data)
-{
-	struct cb_data *cbd = user_data;
-	dundee_device_connect_cb_t cb = cbd->cb;
-	struct bluetooth_device *bt = cbd->user;
-	DBusMessage *reply;
-	DBusError derr;
-	int fd;
-
-	DBG("%p", bt);
-
-	reply = dbus_pending_call_steal_reply(call);
-
-	bt->call = NULL;
-
-	dbus_error_init(&derr);
-	if (dbus_set_error_from_message(&derr, reply)) {
-		DBG("Connection to bt serial returned with error: %s, %s",
-						derr.name, derr.message);
-
-		dbus_error_free(&derr);
-
-		CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
-		goto done;
-	}
-
-	dbus_message_get_args(reply, NULL, DBUS_TYPE_UNIX_FD, &fd,
-			DBUS_TYPE_INVALID);
-
-	DBG("%p fd %d", bt, fd);
-
-	if (fd < 0) {
-		CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
-		goto done;
-	}
-
-	bt->fd = fd;
-
-	CALLBACK_WITH_SUCCESS(cb, fd, cbd->data);
-
-done:
-	dbus_message_unref(reply);
-	g_free(cbd);
-}
-
-static void bt_connect(struct dundee_device *device,
-			dundee_device_connect_cb_t cb, void *data)
-{
-	struct bluetooth_device *bt = dundee_device_get_data(device);
-	struct cb_data *cbd = cb_data_new(cb, data);
-	char *profile = "dun";
-	int status;
-
-	DBG("%p", bt);
-
-	cbd->user = bt;
-
-	status = bluetooth_send_with_reply(bt->path,
-					BLUEZ_SERIAL_INTERFACE, "ConnectFD",
-					&bt->call, bt_connect_reply,
-					cbd, NULL, DBUS_TIMEOUT,
-					DBUS_TYPE_STRING, &profile,
-					DBUS_TYPE_INVALID);
-	if (status == 0)
-		return;
-
-	g_free(cbd);
-
-	CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
-}
-
-struct dundee_device_driver bluetooth_driver = {
-	.name = "bluetooth",
-	.connect = bt_connect,
-	.disconnect = bt_disconnect,
-};
-
-static int bt_probe(const char *path, const char *dev_addr,
-				const char *adapter_addr, const char *alias)
-{
-	struct bluetooth_device *bt;
-	struct dundee_device *device;
-	char buf[256];
-
-	DBG("");
-
-	/* We already have this device in our hash, ignore */
-	if (g_hash_table_lookup(bluetooth_hash, path) != NULL)
-		return -EALREADY;
-
-	ofono_info("Using device: %s, devaddr: %s, adapter: %s",
-			path, dev_addr, adapter_addr);
-
-	strcpy(buf, "dun/");
-	bluetooth_create_path(dev_addr, adapter_addr, buf + 4, sizeof(buf) - 4);
-
-	bt = g_try_new0(struct bluetooth_device, 1);
-	if (bt == NULL)
-		return -ENOMEM;
-
-	DBG("%p", bt);
-
-	device = dundee_device_create(&bluetooth_driver);
-	if (device == NULL)
-		goto free;
-
-	dundee_device_set_data(device, bt);
-
-	bt->path = g_strdup(path);
-	if (bt->path == NULL)
-		goto free;
-
-	bt->address = g_strdup(dev_addr);
-	if (bt->address == NULL)
-		goto free;
-
-	bt->name = g_strdup(alias);
-	if (bt->name == NULL)
-		goto free;
-
-	dundee_device_set_name(device, bt->name);
-
-	if (dundee_device_register(device) < 0) {
-		g_free(device);
-		goto free;
-	}
-
-	bt->device = device;
-	g_hash_table_insert(bluetooth_hash, g_strdup(path), bt);
-
-	return 0;
-
-free:
-	g_free(bt->path);
-	g_free(bt->address);
-	g_free(bt->name);
-	g_free(bt);
-
-	return -ENOMEM;
-}
-
-static void destroy_device(gpointer user)
-{
-	struct bluetooth_device *bt = user;
-
-	DBG("%p", bt);
-
-	if (bt->call != NULL)
-		dbus_pending_call_cancel(bt->call);
-
-	g_free(bt->path);
-	g_free(bt->address);
-
-	g_free(bt);
-}
-
-static gboolean bt_remove_device(gpointer key, gpointer value,
-					gpointer user_data)
-{
-	struct bluetooth_device *bt = value;
-	const char *path = key;
-	const char *prefix = user_data;
-
-	DBG("%p", bt);
-
-	if (prefix && g_str_has_prefix(path, prefix) == FALSE)
-		return FALSE;
-
-	dundee_device_unregister(bt->device);
-
-	return TRUE;
-}
-
-static void bt_remove(const char *prefix)
-{
-	DBG("%s", prefix);
-
-	if (bluetooth_hash == NULL)
-		return;
-
-	g_hash_table_foreach_remove(bluetooth_hash, bt_remove_device,
-							(gpointer) prefix);
-}
-
-static void bt_set_alias(const char *path, const char *alias)
-{
-	struct bluetooth_device *bt;
-
-	DBG("");
-
-	if (path == NULL || alias == NULL)
-		return;
-
-	bt = g_hash_table_lookup(bluetooth_hash, path);
-	if (bt == NULL)
-		return;
-
-	g_free(bt->name);
-	bt->name = g_strdup(alias);
-
-	dundee_device_set_name(bt->device, bt->name);
-}
-
-static struct bluetooth_profile dun_profile = {
-	.name		= "dun_dt",
-	.probe		= bt_probe,
-	.remove		= bt_remove,
-	.set_alias	= bt_set_alias,
-};
-
-int __dundee_bluetooth_init(void)
-{
-	int err;
-
-	DBG("");
-
-	err = bluetooth_register_uuid(DUN_GW_UUID, &dun_profile);
-	if (err < 0)
-		return err;
-
-	bluetooth_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
-						g_free, destroy_device);
-
-	return 0;
-}
-
-void  __dundee_bluetooth_cleanup(void)
-{
-	DBG("");
-
-	bluetooth_unregister_uuid(DUN_GW_UUID);
-	g_hash_table_destroy(bluetooth_hash);
-}
diff --git a/dundee/bluez4.c b/dundee/bluez4.c
new file mode 100644
index 0000000..58355d3
--- /dev/null
+++ b/dundee/bluez4.c
@@ -0,0 +1,297 @@
+/*
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2008-2012  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2012  BMW Car IT GmbH. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/socket.h>
+
+#include <glib.h>
+
+#include "plugins/bluez4.h"
+
+#include "dundee.h"
+
+static GHashTable *bluetooth_hash;
+
+struct bluetooth_device {
+	struct dundee_device *device;
+
+	char *path;
+	char *address;
+	char *name;
+
+	int fd;
+
+	DBusPendingCall *call;
+};
+
+static void bt_disconnect(struct dundee_device *device,
+				dundee_device_disconnect_cb_t cb, void *data)
+{
+	struct bluetooth_device *bt = dundee_device_get_data(device);
+
+	DBG("%p", bt);
+
+	shutdown(bt->fd, SHUT_RDWR);
+
+	CALLBACK_WITH_SUCCESS(cb, data);
+}
+
+static void bt_connect_reply(DBusPendingCall *call, gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	dundee_device_connect_cb_t cb = cbd->cb;
+	struct bluetooth_device *bt = cbd->user;
+	DBusMessage *reply;
+	DBusError derr;
+	int fd;
+
+	DBG("%p", bt);
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	bt->call = NULL;
+
+	dbus_error_init(&derr);
+	if (dbus_set_error_from_message(&derr, reply)) {
+		DBG("Connection to bt serial returned with error: %s, %s",
+						derr.name, derr.message);
+
+		dbus_error_free(&derr);
+
+		CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+		goto done;
+	}
+
+	dbus_message_get_args(reply, NULL, DBUS_TYPE_UNIX_FD, &fd,
+			DBUS_TYPE_INVALID);
+
+	DBG("%p fd %d", bt, fd);
+
+	if (fd < 0) {
+		CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+		goto done;
+	}
+
+	bt->fd = fd;
+
+	CALLBACK_WITH_SUCCESS(cb, fd, cbd->data);
+
+done:
+	dbus_message_unref(reply);
+	g_free(cbd);
+}
+
+static void bt_connect(struct dundee_device *device,
+			dundee_device_connect_cb_t cb, void *data)
+{
+	struct bluetooth_device *bt = dundee_device_get_data(device);
+	struct cb_data *cbd = cb_data_new(cb, data);
+	char *profile = "dun";
+	int status;
+
+	DBG("%p", bt);
+
+	cbd->user = bt;
+
+	status = bluetooth_send_with_reply(bt->path,
+					BLUEZ_SERIAL_INTERFACE, "ConnectFD",
+					&bt->call, bt_connect_reply,
+					cbd, NULL, DBUS_TIMEOUT,
+					DBUS_TYPE_STRING, &profile,
+					DBUS_TYPE_INVALID);
+	if (status == 0)
+		return;
+
+	g_free(cbd);
+
+	CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+}
+
+struct dundee_device_driver bluetooth_driver = {
+	.name = "bluetooth",
+	.connect = bt_connect,
+	.disconnect = bt_disconnect,
+};
+
+static int bt_probe(const char *path, const char *dev_addr,
+				const char *adapter_addr, const char *alias)
+{
+	struct bluetooth_device *bt;
+	struct dundee_device *device;
+	char buf[256];
+
+	DBG("");
+
+	/* We already have this device in our hash, ignore */
+	if (g_hash_table_lookup(bluetooth_hash, path) != NULL)
+		return -EALREADY;
+
+	ofono_info("Using device: %s, devaddr: %s, adapter: %s",
+			path, dev_addr, adapter_addr);
+
+	strcpy(buf, "dun/");
+	bluetooth_create_path(dev_addr, adapter_addr, buf + 4, sizeof(buf) - 4);
+
+	bt = g_try_new0(struct bluetooth_device, 1);
+	if (bt == NULL)
+		return -ENOMEM;
+
+	DBG("%p", bt);
+
+	device = dundee_device_create(&bluetooth_driver);
+	if (device == NULL)
+		goto free;
+
+	dundee_device_set_data(device, bt);
+
+	bt->path = g_strdup(path);
+	if (bt->path == NULL)
+		goto free;
+
+	bt->address = g_strdup(dev_addr);
+	if (bt->address == NULL)
+		goto free;
+
+	bt->name = g_strdup(alias);
+	if (bt->name == NULL)
+		goto free;
+
+	dundee_device_set_name(device, bt->name);
+
+	if (dundee_device_register(device) < 0) {
+		g_free(device);
+		goto free;
+	}
+
+	bt->device = device;
+	g_hash_table_insert(bluetooth_hash, g_strdup(path), bt);
+
+	return 0;
+
+free:
+	g_free(bt->path);
+	g_free(bt->address);
+	g_free(bt->name);
+	g_free(bt);
+
+	return -ENOMEM;
+}
+
+static void destroy_device(gpointer user)
+{
+	struct bluetooth_device *bt = user;
+
+	DBG("%p", bt);
+
+	if (bt->call != NULL)
+		dbus_pending_call_cancel(bt->call);
+
+	g_free(bt->path);
+	g_free(bt->address);
+
+	g_free(bt);
+}
+
+static gboolean bt_remove_device(gpointer key, gpointer value,
+					gpointer user_data)
+{
+	struct bluetooth_device *bt = value;
+	const char *path = key;
+	const char *prefix = user_data;
+
+	DBG("%p", bt);
+
+	if (prefix && g_str_has_prefix(path, prefix) == FALSE)
+		return FALSE;
+
+	dundee_device_unregister(bt->device);
+
+	return TRUE;
+}
+
+static void bt_remove(const char *prefix)
+{
+	DBG("%s", prefix);
+
+	if (bluetooth_hash == NULL)
+		return;
+
+	g_hash_table_foreach_remove(bluetooth_hash, bt_remove_device,
+							(gpointer) prefix);
+}
+
+static void bt_set_alias(const char *path, const char *alias)
+{
+	struct bluetooth_device *bt;
+
+	DBG("");
+
+	if (path == NULL || alias == NULL)
+		return;
+
+	bt = g_hash_table_lookup(bluetooth_hash, path);
+	if (bt == NULL)
+		return;
+
+	g_free(bt->name);
+	bt->name = g_strdup(alias);
+
+	dundee_device_set_name(bt->device, bt->name);
+}
+
+static struct bluetooth_profile dun_profile = {
+	.name		= "dun_dt",
+	.probe		= bt_probe,
+	.remove		= bt_remove,
+	.set_alias	= bt_set_alias,
+};
+
+int __dundee_bluetooth_init(void)
+{
+	int err;
+
+	DBG("");
+
+	err = bluetooth_register_uuid(DUN_GW_UUID, &dun_profile);
+	if (err < 0)
+		return err;
+
+	bluetooth_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+						g_free, destroy_device);
+
+	return 0;
+}
+
+void  __dundee_bluetooth_cleanup(void)
+{
+	DBG("");
+
+	bluetooth_unregister_uuid(DUN_GW_UUID);
+	g_hash_table_destroy(bluetooth_hash);
+}
-- 
1.7.9.5


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

* [PATCH v2 02/13] dundee: Start BlueZ 5 support
  2013-03-14 13:32 ` [PATCH v2 " Paulo Borges
  2013-03-14 13:32   ` [PATCH v2 01/13] dundee: Rename dundee BlueZ 4 support Paulo Borges
@ 2013-03-14 13:32   ` Paulo Borges
  2013-03-14 13:32   ` [PATCH v2 03/13] bluez5: Add DUN_UUID Paulo Borges
                     ` (11 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-14 13:32 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2490 bytes --]

This patch adds the BlueZ 5 support file for dundee.
---
 Makefile.am     |   15 ++++++++++-----
 dundee/bluez5.c |   37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 5 deletions(-)
 create mode 100644 dundee/bluez5.c

diff --git a/Makefile.am b/Makefile.am
index 3a7a8dc..44cf7d7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -756,14 +756,12 @@ endif
 endif
 
 if BLUETOOTH
-if BLUEZ4
 if DUNDEE
 sbin_PROGRAMS += dundee/dundee
 
-dundee_dundee_SOURCES = $(gdbus_sources) $(gatchat_sources) $(btio_sources) \
-			src/log.c src/dbus.c plugins/bluez4.c \
-			dundee/dundee.h dundee/main.c dundee/dbus.c \
-			dundee/manager.c dundee/device.c dundee/bluez4.c
+dundee_common_sources = $(gdbus_sources) $(gatchat_sources) \
+			src/log.c src/dbus.c dundee/dundee.h dundee/main.c \
+			dundee/dbus.c dundee/manager.c dundee/device.c
 
 dundee_dundee_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ -ldl
 
@@ -774,6 +772,13 @@ if SYSTEMD
 systemdunit_DATA += dundee/dundee.service
 endif
 endif
+
+if BLUEZ4
+dundee_dundee_SOURCES = $(dundee_common_sources) $(btio_sources) \
+			plugins/bluez4.c dundee/bluez4.c
+else
+dundee_dundee_SOURCES = $(dundee_common_sources) plugins/bluez5.c \
+			dundee/bluez5.c
 endif
 endif
 endif
diff --git a/dundee/bluez5.c b/dundee/bluez5.c
new file mode 100644
index 0000000..6685b4c
--- /dev/null
+++ b/dundee/bluez5.c
@@ -0,0 +1,37 @@
+/*
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2013  Instituto Nokia de Tecnologia - INdT
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "dundee.h"
+
+int __dundee_bluetooth_init(void)
+{
+	DBG("");
+
+	return 0;
+}
+
+void __dundee_bluetooth_cleanup(void)
+{
+	DBG("");
+}
-- 
1.7.9.5


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

* [PATCH v2 03/13] bluez5: Add DUN_UUID
  2013-03-14 13:32 ` [PATCH v2 " Paulo Borges
  2013-03-14 13:32   ` [PATCH v2 01/13] dundee: Rename dundee BlueZ 4 support Paulo Borges
  2013-03-14 13:32   ` [PATCH v2 02/13] dundee: Start BlueZ 5 support Paulo Borges
@ 2013-03-14 13:32   ` Paulo Borges
  2013-03-14 13:32   ` [PATCH v2 04/13] dundee: Initial GDBusClient for BlueZ 5 Paulo Borges
                     ` (10 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-14 13:32 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 533 bytes --]

---
 plugins/bluez5.h |    1 +
 1 file changed, 1 insertion(+)

diff --git a/plugins/bluez5.h b/plugins/bluez5.h
index 573a54c..898a010 100644
--- a/plugins/bluez5.h
+++ b/plugins/bluez5.h
@@ -25,6 +25,7 @@
 #define BLUEZ_DEVICE_INTERFACE		BLUEZ_SERVICE ".Device1"
 #define BLUEZ_ERROR_INTERFACE		BLUEZ_SERVICE ".Error"
 
+#define DUN_UUID	"00001103-0000-1000-8000-00805f9b34fb"
 #define HFP_HS_UUID	"0000111e-0000-1000-8000-00805f9b34fb"
 #define HFP_AG_UUID	"0000111f-0000-1000-8000-00805f9b34fb"
 
-- 
1.7.9.5


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

* [PATCH v2 04/13] dundee: Initial GDBusClient for BlueZ 5
  2013-03-14 13:32 ` [PATCH v2 " Paulo Borges
                     ` (2 preceding siblings ...)
  2013-03-14 13:32   ` [PATCH v2 03/13] bluez5: Add DUN_UUID Paulo Borges
@ 2013-03-14 13:32   ` Paulo Borges
  2013-03-14 13:32   ` [PATCH v2 05/13] dundee: Add mechanism to store bluetooth devices Paulo Borges
                     ` (9 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-14 13:32 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2604 bytes --]

This patch adds the callbacks to track additions and removals of
BlueZ related interfaces and property changes in these interfaces.
---
 dundee/bluez5.c |   60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 dundee/dundee.h |    2 ++
 2 files changed, 62 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index 6685b4c..1b2c8e1 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -22,16 +22,76 @@
 #include <config.h>
 #endif
 
+#include <stdint.h>
+#include <sys/socket.h>
+#include <gdbus.h>
+
 #include "dundee.h"
+#include "plugins/bluez5.h"
+
+#define DUN_DT_PROFILE_PATH   "/bluetooth/profile/dun_dt"
+
+static GDBusClient *bluez;
+
+static void proxy_added(GDBusProxy *proxy, void *user_data)
+{
+	const char *path = g_dbus_proxy_get_path(proxy);
+	const char *interface = g_dbus_proxy_get_interface(proxy);
+
+	if (!g_str_equal(BLUEZ_DEVICE_INTERFACE, interface))
+		return;
+
+	DBG("%s %s", path, interface);
+}
+
+static void proxy_removed(GDBusProxy *proxy, void *user_data)
+{
+	const char *path = g_dbus_proxy_get_path(proxy);
+	const char *interface = g_dbus_proxy_get_interface(proxy);
+
+	if (!g_str_equal(BLUEZ_DEVICE_INTERFACE, interface))
+		return;
+
+	DBG("%s %s", path, interface);
+}
+
+static void property_changed(GDBusProxy *proxy, const char *name,
+					DBusMessageIter *iter, void *user_data)
+{
+	const char *path = g_dbus_proxy_get_path(proxy);
+	const char *interface = g_dbus_proxy_get_interface(proxy);
+
+	if (!g_str_equal(BLUEZ_DEVICE_INTERFACE, interface))
+		return;
+
+	DBG("%s %s.%s", path, interface, name);
+}
+
+static void connect_handler(DBusConnection *conn, void *user_data)
+{
+	DBG("");
+
+	bt_register_profile_with_role(conn, DUN_UUID, DUN_VERSION_1_2,
+				"dun_dt", DUN_DT_PROFILE_PATH, "client");
+}
 
 int __dundee_bluetooth_init(void)
 {
+	DBusConnection *conn = ofono_dbus_get_connection();
+
 	DBG("");
 
+	bluez = g_dbus_client_new(conn, BLUEZ_SERVICE, BLUEZ_MANAGER_PATH);
+	g_dbus_client_set_connect_watch(bluez, connect_handler, NULL);
+	g_dbus_client_set_proxy_handlers(bluez, proxy_added, proxy_removed,
+						property_changed, NULL);
+
 	return 0;
 }
 
 void __dundee_bluetooth_cleanup(void)
 {
 	DBG("");
+
+	g_dbus_client_unref(bluez);
 }
diff --git a/dundee/dundee.h b/dundee/dundee.h
index db932b6..daf78a5 100644
--- a/dundee/dundee.h
+++ b/dundee/dundee.h
@@ -26,6 +26,8 @@
 
 #include <ofono/types.h>
 
+#define DUN_VERSION_1_2 0x0102
+
 void __dundee_exit(void);
 
 enum dundee_error_type {
-- 
1.7.9.5


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

* [PATCH v2 05/13] dundee: Add mechanism to store bluetooth devices
  2013-03-14 13:32 ` [PATCH v2 " Paulo Borges
                     ` (3 preceding siblings ...)
  2013-03-14 13:32   ` [PATCH v2 04/13] dundee: Initial GDBusClient for BlueZ 5 Paulo Borges
@ 2013-03-14 13:32   ` Paulo Borges
  2013-03-14 13:32   ` [PATCH v2 06/13] dundee: Add tracking of " Paulo Borges
                     ` (8 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-14 13:32 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1354 bytes --]

This patch adds a hash that will store every known bluetooth
device that implements DUN service.
---
 dundee/bluez5.c |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index 1b2c8e1..f2c9fed 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -32,6 +32,25 @@
 #define DUN_DT_PROFILE_PATH   "/bluetooth/profile/dun_dt"
 
 static GDBusClient *bluez;
+static GHashTable *registered_devices;
+
+struct bluetooth_device {
+	char *path;
+	char *address;
+	char *name;
+};
+
+static void bluetooth_device_destroy(gpointer user_data)
+{
+	struct bluetooth_device *bt_device = user_data;
+
+	DBG("%s", bt_device->path);
+
+	g_free(bt_device->path);
+	g_free(bt_device->address);
+	g_free(bt_device->name);
+	g_free(bt_device);
+}
 
 static void proxy_added(GDBusProxy *proxy, void *user_data)
 {
@@ -86,6 +105,9 @@ int __dundee_bluetooth_init(void)
 	g_dbus_client_set_proxy_handlers(bluez, proxy_added, proxy_removed,
 						property_changed, NULL);
 
+	registered_devices = g_hash_table_new_full(g_str_hash, g_str_equal,
+					g_free, bluetooth_device_destroy);
+
 	return 0;
 }
 
@@ -94,4 +116,5 @@ void __dundee_bluetooth_cleanup(void)
 	DBG("");
 
 	g_dbus_client_unref(bluez);
+	g_hash_table_destroy(registered_devices);
 }
-- 
1.7.9.5


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

* [PATCH v2 06/13] dundee: Add tracking of bluetooth devices
  2013-03-14 13:32 ` [PATCH v2 " Paulo Borges
                     ` (4 preceding siblings ...)
  2013-03-14 13:32   ` [PATCH v2 05/13] dundee: Add mechanism to store bluetooth devices Paulo Borges
@ 2013-03-14 13:32   ` Paulo Borges
  2013-03-14 13:32   ` [PATCH v2 07/13] dundee: Listen to devices property changes Paulo Borges
                     ` (7 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-14 13:32 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3164 bytes --]

This patch tracks the GDBusProxy for Bluetooth devices in order to
be able to get their properties and register them when they
implement DUN.
---
 dundee/bluez5.c |   90 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index f2c9fed..ca44656 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -52,15 +52,103 @@ static void bluetooth_device_destroy(gpointer user_data)
 	g_free(bt_device);
 }
 
+static struct bluetooth_device *bluetooth_device_create(const char *path,
+					const char *address, const char *alias)
+{
+	struct bluetooth_device *tmp;
+
+	DBG("%s %s %s", path, address, alias);
+
+	tmp = g_try_new0(struct bluetooth_device, 1);
+	if (tmp == NULL)
+		return NULL;
+
+	tmp->path = g_strdup(path);
+	tmp->address = g_strdup(address);
+	tmp->name = g_strdup(alias);
+
+	return tmp;
+}
+
+static void bluetooth_device_register(GDBusProxy *proxy)
+{
+	const char *path = g_dbus_proxy_get_path(proxy);
+	const char *alias, *address;
+	struct bluetooth_device *bt_device;
+	DBusMessageIter iter;
+
+	DBG("%s", path);
+
+	if (g_hash_table_lookup(registered_devices, path) != NULL)
+		return;
+
+	if (!g_dbus_proxy_get_property(proxy, "Address", &iter))
+		return;
+
+	dbus_message_iter_get_basic(&iter, &address);
+
+	if (!g_dbus_proxy_get_property(proxy, "Alias", &iter))
+		return;
+
+	dbus_message_iter_get_basic(&iter, &alias);
+
+	bt_device = bluetooth_device_create(path, address, alias);
+	if (bt_device == NULL) {
+		ofono_error("register bluetooth device failed");
+		return;
+	}
+
+	g_hash_table_insert(registered_devices, g_strdup(path), bt_device);
+}
+
+static void bluetooth_device_unregister(const char *path)
+{
+	DBG("");
+
+	g_hash_table_remove(registered_devices, path);
+}
+
+static gboolean has_dun_uuid(DBusMessageIter *array)
+{
+	DBusMessageIter value;
+
+	if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
+		return FALSE;
+
+	dbus_message_iter_recurse(array, &value);
+
+	while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
+		const char *uuid;
+
+		dbus_message_iter_get_basic(&value, &uuid);
+
+		if (g_str_equal(uuid, DUN_UUID))
+			return TRUE;
+
+		dbus_message_iter_next(&value);
+	}
+
+	return FALSE;
+}
+
 static void proxy_added(GDBusProxy *proxy, void *user_data)
 {
 	const char *path = g_dbus_proxy_get_path(proxy);
 	const char *interface = g_dbus_proxy_get_interface(proxy);
+	DBusMessageIter iter;
 
 	if (!g_str_equal(BLUEZ_DEVICE_INTERFACE, interface))
 		return;
 
+	if (!g_dbus_proxy_get_property(proxy, "UUIDs", &iter))
+		return;
+
 	DBG("%s %s", path, interface);
+
+	if (!has_dun_uuid(&iter))
+		return;
+
+	bluetooth_device_register(proxy);
 }
 
 static void proxy_removed(GDBusProxy *proxy, void *user_data)
@@ -72,6 +160,8 @@ static void proxy_removed(GDBusProxy *proxy, void *user_data)
 		return;
 
 	DBG("%s %s", path, interface);
+
+	bluetooth_device_unregister(path);
 }
 
 static void property_changed(GDBusProxy *proxy, const char *name,
-- 
1.7.9.5


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

* [PATCH v2 07/13] dundee: Listen to devices property changes
  2013-03-14 13:32 ` [PATCH v2 " Paulo Borges
                     ` (5 preceding siblings ...)
  2013-03-14 13:32   ` [PATCH v2 06/13] dundee: Add tracking of " Paulo Borges
@ 2013-03-14 13:32   ` Paulo Borges
  2013-03-19 21:10     ` Daniel Wagner
  2013-03-14 13:32   ` [PATCH v2 08/13] dundee: Add dundee device driver skeleton Paulo Borges
                     ` (6 subsequent siblings)
  13 siblings, 1 reply; 55+ messages in thread
From: Paulo Borges @ 2013-03-14 13:32 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1440 bytes --]

When a bluetooth device property change and this property is Alias
or UUIDs, we need to refresh our representation of this device.
---
 dundee/bluez5.c |   28 +++++++++++++++++++++++++++-
 1 file changed, 27 insertions(+), 1 deletion(-)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index ca44656..d48aadf 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -169,11 +169,37 @@ static void property_changed(GDBusProxy *proxy, const char *name,
 {
 	const char *path = g_dbus_proxy_get_path(proxy);
 	const char *interface = g_dbus_proxy_get_interface(proxy);
+	const char *alias;
+	struct bluetooth_device *bt_device;
+	gboolean uuid;
 
 	if (!g_str_equal(BLUEZ_DEVICE_INTERFACE, interface))
 		return;
 
-	DBG("%s %s.%s", path, interface, name);
+	bt_device = g_hash_table_lookup(registered_devices, path);
+
+	if (g_str_equal(name, "Alias")) {
+		if (bt_device == NULL)
+			return;
+
+		dbus_message_iter_get_basic(iter, &alias);
+
+		DBG("%s alias changed: %s", path, alias);
+
+		bt_device->name = g_strdup(alias);
+	} else if (g_str_equal(name, "UUIDs")) {
+		DBG("%s uuids changed", path);
+
+		uuid = has_dun_uuid(iter);
+
+		if (uuid) {
+			if (bt_device == NULL)
+				bluetooth_device_register(proxy);
+		} else {
+			if (bt_device != NULL)
+				bluetooth_device_unregister(path);
+		}
+	}
 }
 
 static void connect_handler(DBusConnection *conn, void *user_data)
-- 
1.7.9.5


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

* [PATCH v2 08/13] dundee: Add dundee device driver skeleton
  2013-03-14 13:32 ` [PATCH v2 " Paulo Borges
                     ` (6 preceding siblings ...)
  2013-03-14 13:32   ` [PATCH v2 07/13] dundee: Listen to devices property changes Paulo Borges
@ 2013-03-14 13:32   ` Paulo Borges
  2013-03-14 13:32   ` [PATCH v2 09/13] dundee: Register/unregister dundee device Paulo Borges
                     ` (5 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-14 13:32 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1029 bytes --]

This patch adds the functions to be called when the dundee will
connect or disconnect with a Bluetooth device.
---
 dundee/bluez5.c |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index d48aadf..9568fde 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -52,6 +52,24 @@ static void bluetooth_device_destroy(gpointer user_data)
 	g_free(bt_device);
 }
 
+static void bluetooth_device_connect(struct dundee_device *device,
+			dundee_device_connect_cb_t cb, void *data)
+{
+	DBG("");
+}
+
+static void bluetooth_device_disconnect(struct dundee_device *device,
+				dundee_device_disconnect_cb_t cb, void *data)
+{
+	DBG("");
+}
+
+struct dundee_device_driver bluetooth_driver = {
+	.name = "bluetooth",
+	.connect = bluetooth_device_connect,
+	.disconnect = bluetooth_device_disconnect,
+};
+
 static struct bluetooth_device *bluetooth_device_create(const char *path,
 					const char *address, const char *alias)
 {
-- 
1.7.9.5


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

* [PATCH v2 09/13] dundee: Register/unregister dundee device
  2013-03-14 13:32 ` [PATCH v2 " Paulo Borges
                     ` (7 preceding siblings ...)
  2013-03-14 13:32   ` [PATCH v2 08/13] dundee: Add dundee device driver skeleton Paulo Borges
@ 2013-03-14 13:32   ` Paulo Borges
  2013-03-14 13:32   ` [PATCH v2 10/13] dundee: Add BlueZ Profile handler Paulo Borges
                     ` (4 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-14 13:32 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1716 bytes --]

This patch adds the dundee device struct to the our Bluetooth
device representation.
---
 dundee/bluez5.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index 9568fde..b4f6918 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -35,6 +35,8 @@ static GDBusClient *bluez;
 static GHashTable *registered_devices;
 
 struct bluetooth_device {
+	struct dundee_device *device;
+
 	char *path;
 	char *address;
 	char *name;
@@ -46,6 +48,9 @@ static void bluetooth_device_destroy(gpointer user_data)
 
 	DBG("%s", bt_device->path);
 
+	if (bt_device->device != NULL)
+		dundee_device_unregister(bt_device->device);
+
 	g_free(bt_device->path);
 	g_free(bt_device->address);
 	g_free(bt_device->name);
@@ -93,6 +98,7 @@ static void bluetooth_device_register(GDBusProxy *proxy)
 	const char *path = g_dbus_proxy_get_path(proxy);
 	const char *alias, *address;
 	struct bluetooth_device *bt_device;
+	struct dundee_device *device;
 	DBusMessageIter iter;
 
 	DBG("%s", path);
@@ -116,7 +122,26 @@ static void bluetooth_device_register(GDBusProxy *proxy)
 		return;
 	}
 
+	device = dundee_device_create(&bluetooth_driver);
+	if (device == NULL)
+		goto free;
+
+	dundee_device_set_data(device, bt_device);
+	dundee_device_set_name(device, bt_device->name);
+
+	if (dundee_device_register(device) < 0) {
+		g_free(device);
+		goto free;
+	}
+
+	bt_device->device = device;
 	g_hash_table_insert(registered_devices, g_strdup(path), bt_device);
+
+	return;
+
+free:
+	bluetooth_device_destroy(bt_device);
+	return;
 }
 
 static void bluetooth_device_unregister(const char *path)
-- 
1.7.9.5


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

* [PATCH v2 10/13] dundee: Add BlueZ Profile handler
  2013-03-14 13:32 ` [PATCH v2 " Paulo Borges
                     ` (8 preceding siblings ...)
  2013-03-14 13:32   ` [PATCH v2 09/13] dundee: Register/unregister dundee device Paulo Borges
@ 2013-03-14 13:32   ` Paulo Borges
  2013-03-14 13:32   ` [PATCH v2 11/13] dundee: Add support for driver connect Paulo Borges
                     ` (3 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-14 13:32 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3191 bytes --]

This patch declares the external dundee Profile handler. It
contains the initial implementation of the D-Bus Profile1
interface and methods responsible for handling Bluetooth
connections.
---
 dundee/bluez5.c |   68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index b4f6918..82bb7aa 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -25,6 +25,7 @@
 #include <stdint.h>
 #include <sys/socket.h>
 #include <gdbus.h>
+#include <errno.h>
 
 #include "dundee.h"
 #include "plugins/bluez5.h"
@@ -42,6 +43,59 @@ struct bluetooth_device {
 	char *name;
 };
 
+static DBusMessage *profile_new_connection(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	DBG("");
+
+	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+						".NotImplemented",
+						"Implementation not provided");
+}
+
+static DBusMessage *profile_release(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	DBG("");
+
+	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+						".NotImplemented",
+						"Implementation not provided");
+}
+
+static DBusMessage *profile_cancel(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	DBG("");
+
+	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+						".NotImplemented",
+						"Implementation not provided");
+}
+
+static DBusMessage *profile_disconnection(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	DBG("");
+
+	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+						".NotImplemented",
+						"Implementation not provided");
+}
+
+static const GDBusMethodTable profile_methods[] = {
+	{ GDBUS_ASYNC_METHOD("NewConnection",
+				GDBUS_ARGS({ "device", "o"}, { "fd", "h"},
+						{ "fd_properties", "a{sv}" }),
+				NULL, profile_new_connection) },
+	{ GDBUS_METHOD("Release", NULL, NULL, profile_release) },
+	{ GDBUS_METHOD("Cancel", NULL, NULL, profile_cancel) },
+	{ GDBUS_METHOD("RequestDisconnection",
+				GDBUS_ARGS({"device", "o"}), NULL,
+				profile_disconnection) },
+	{ }
+};
+
 static void bluetooth_device_destroy(gpointer user_data)
 {
 	struct bluetooth_device *bt_device = user_data;
@@ -259,6 +313,15 @@ int __dundee_bluetooth_init(void)
 
 	DBG("");
 
+	if (!g_dbus_register_interface(conn, DUN_DT_PROFILE_PATH,
+					BLUEZ_PROFILE_INTERFACE,
+					profile_methods, NULL,
+					NULL, NULL, NULL)) {
+		ofono_error("Register Profile interface failed: %s",
+						DUN_DT_PROFILE_PATH);
+		return -EIO;
+	}
+
 	bluez = g_dbus_client_new(conn, BLUEZ_SERVICE, BLUEZ_MANAGER_PATH);
 	g_dbus_client_set_connect_watch(bluez, connect_handler, NULL);
 	g_dbus_client_set_proxy_handlers(bluez, proxy_added, proxy_removed,
@@ -272,8 +335,13 @@ int __dundee_bluetooth_init(void)
 
 void __dundee_bluetooth_cleanup(void)
 {
+	DBusConnection *conn = ofono_dbus_get_connection();
+
 	DBG("");
 
+	g_dbus_unregister_interface(conn, DUN_DT_PROFILE_PATH,
+						BLUEZ_PROFILE_INTERFACE);
+
 	g_dbus_client_unref(bluez);
 	g_hash_table_destroy(registered_devices);
 }
-- 
1.7.9.5


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

* [PATCH v2 11/13] dundee: Add support for driver connect
  2013-03-14 13:32 ` [PATCH v2 " Paulo Borges
                     ` (9 preceding siblings ...)
  2013-03-14 13:32   ` [PATCH v2 10/13] dundee: Add BlueZ Profile handler Paulo Borges
@ 2013-03-14 13:32   ` Paulo Borges
  2013-03-18  8:38     ` Daniel Wagner
  2013-03-14 13:32   ` [PATCH v2 12/13] dundee: Add dundee disconnect function Paulo Borges
                     ` (2 subsequent siblings)
  13 siblings, 1 reply; 55+ messages in thread
From: Paulo Borges @ 2013-03-14 13:32 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 916 bytes --]

This patch glues together the dundee driver interface with the
D-Bus Profile1 interface.

When the dundee driver requests a connection, it will call the
Device1's ConnectProfile.
---
 dundee/bluez5.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index 82bb7aa..2d10e5a 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -114,7 +114,12 @@ static void bluetooth_device_destroy(gpointer user_data)
 static void bluetooth_device_connect(struct dundee_device *device,
 			dundee_device_connect_cb_t cb, void *data)
 {
-	DBG("");
+	struct bluetooth_device *bt_device = dundee_device_get_data(device);
+
+	DBG("%s", bt_device->path);
+
+	bt_connect_profile(ofono_dbus_get_connection(), bt_device->path,
+						DUN_DT_UUID, NULL, NULL);
 }
 
 static void bluetooth_device_disconnect(struct dundee_device *device,
-- 
1.7.9.5


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

* [PATCH v2 12/13] dundee: Add dundee disconnect function
  2013-03-14 13:32 ` [PATCH v2 " Paulo Borges
                     ` (10 preceding siblings ...)
  2013-03-14 13:32   ` [PATCH v2 11/13] dundee: Add support for driver connect Paulo Borges
@ 2013-03-14 13:32   ` Paulo Borges
  2013-03-14 13:32   ` [PATCH v2 13/13] dundee: Handle Profile connect and disconnect Paulo Borges
  2013-03-18  9:55   ` [PATCH v2 00/13] Add support for BlueZ 5 Profile1 API to dundee Daniel Wagner
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-14 13:32 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1645 bytes --]

---
 dundee/device.c |   14 +++++++++++---
 dundee/dundee.h |    3 +++
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/dundee/device.c b/dundee/device.c
index e5f6424..2d84aaa 100644
--- a/dundee/device.c
+++ b/dundee/device.c
@@ -270,11 +270,13 @@ err:
 	device->pending = NULL;
 }
 
-static void disconnect_callback(const struct dundee_error *error, void *data)
+void dundee_device_disconnect(const struct dundee_error *error,
+						struct dundee_device *device)
 {
-	struct dundee_device *device = data;
+	if (device == NULL)
+		return;
 
-	DBG("%p", device);
+	DBG("%s", device->path);
 
 	g_at_chat_unref(device->chat);
 	device->chat = NULL;
@@ -295,6 +297,12 @@ out:
 	device->pending = NULL;
 }
 
+static void disconnect_callback(const struct dundee_error *error, void *data)
+{
+	struct dundee_device *device = data;
+	dundee_device_disconnect(error, device);
+}
+
 static gboolean ppp_connect_timeout(gpointer user_data)
 {
 	struct dundee_device *device = user_data;
diff --git a/dundee/dundee.h b/dundee/dundee.h
index daf78a5..1889d84 100644
--- a/dundee/dundee.h
+++ b/dundee/dundee.h
@@ -130,6 +130,9 @@ struct dundee_device *dundee_device_create(struct dundee_device_driver *d);
 int dundee_device_register(struct dundee_device *device);
 void dundee_device_unregister(struct dundee_device *device);
 
+void dundee_device_disconnect(const struct dundee_error *error,
+						struct dundee_device *device);
+
 void dundee_device_set_data(struct dundee_device *device, void *data);
 void *dundee_device_get_data(struct dundee_device *device);
 
-- 
1.7.9.5


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

* [PATCH v2 13/13] dundee: Handle Profile connect and disconnect
  2013-03-14 13:32 ` [PATCH v2 " Paulo Borges
                     ` (11 preceding siblings ...)
  2013-03-14 13:32   ` [PATCH v2 12/13] dundee: Add dundee disconnect function Paulo Borges
@ 2013-03-14 13:32   ` Paulo Borges
  2013-03-18  9:55   ` [PATCH v2 00/13] Add support for BlueZ 5 Profile1 API to dundee Daniel Wagner
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-14 13:32 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 4631 bytes --]

---
 dundee/bluez5.c |  115 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 105 insertions(+), 10 deletions(-)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index 2d10e5a..d859eae 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -41,16 +41,63 @@ struct bluetooth_device {
 	char *path;
 	char *address;
 	char *name;
+
+	struct cb_data *connect_cbd;
+
+	int fd;
 };
 
 static DBusMessage *profile_new_connection(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
-	DBG("");
+	struct bluetooth_device *bt_device;
+	dundee_device_connect_cb_t cb;
+	DBusMessageIter iter;
+	const char *path;
+	int fd;
 
-	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
-						".NotImplemented",
-						"Implementation not provided");
+	if (!dbus_message_iter_init(msg, &iter))
+		goto error;
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
+		goto error;
+
+	dbus_message_iter_get_basic(&iter, &path);
+
+	bt_device = g_hash_table_lookup(registered_devices, path);
+	if (bt_device == NULL)
+		goto error;
+
+	cb = bt_device->connect_cbd->cb;
+
+	dbus_message_iter_next(&iter);
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UNIX_FD)
+		goto call_failure;
+
+	dbus_message_iter_get_basic(&iter, &fd);
+	if (fd < 0)
+		goto call_failure;
+
+	DBG("%s %d", bt_device->path, fd);
+
+	bt_device->fd = fd;
+
+	CALLBACK_WITH_SUCCESS(cb, fd, bt_device->connect_cbd->data);
+
+	g_free(bt_device->connect_cbd);
+	bt_device->connect_cbd = NULL;
+
+	return dbus_message_new_method_return(msg);
+
+call_failure:
+	CALLBACK_WITH_FAILURE(cb, -1, bt_device->connect_cbd->data);
+
+	g_free(bt_device->connect_cbd);
+	bt_device->connect_cbd = NULL;
+
+error:
+	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE ".Rejected",
+					"Invalid arguments in method call");
 }
 
 static DBusMessage *profile_release(DBusConnection *conn,
@@ -76,11 +123,31 @@ static DBusMessage *profile_cancel(DBusConnection *conn,
 static DBusMessage *profile_disconnection(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
-	DBG("");
+	struct bluetooth_device *bt_device;
+	DBusMessageIter iter;
+	const char *path;
 
-	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
-						".NotImplemented",
-						"Implementation not provided");
+	if (!dbus_message_iter_init(msg, &iter))
+		goto error;
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
+		goto error;
+
+	dbus_message_iter_get_basic(&iter, &path);
+
+	bt_device = g_hash_table_lookup(registered_devices, path);
+	if (bt_device == NULL)
+		goto error;
+
+	DBG("%s", bt_device->path);
+
+	CALLBACK_WITH_SUCCESS(dundee_device_disconnect, bt_device->device);
+
+	return dbus_message_new_method_return(msg);
+
+error:
+	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE ".Rejected",
+					"Invalid arguments in method call");
 }
 
 static const GDBusMethodTable profile_methods[] = {
@@ -105,27 +172,55 @@ static void bluetooth_device_destroy(gpointer user_data)
 	if (bt_device->device != NULL)
 		dundee_device_unregister(bt_device->device);
 
+	if (bt_device->connect_cbd != NULL)
+		g_free(bt_device->connect_cbd);
+
 	g_free(bt_device->path);
 	g_free(bt_device->address);
 	g_free(bt_device->name);
 	g_free(bt_device);
 }
 
+static void bluetooth_device_connect_callback(gboolean success,
+							gpointer user_data)
+{
+	struct bluetooth_device *bt_device = user_data;
+
+	if (success) {
+		DBG("Success");
+		return;
+	}
+
+	DBG("ConnectProfile() returned an error");
+
+	g_free(bt_device->connect_cbd);
+	bt_device->connect_cbd = NULL;
+}
+
 static void bluetooth_device_connect(struct dundee_device *device,
 			dundee_device_connect_cb_t cb, void *data)
 {
 	struct bluetooth_device *bt_device = dundee_device_get_data(device);
+	struct cb_data *cbd = cb_data_new(cb, data);
 
 	DBG("%s", bt_device->path);
 
+	cbd->user = bt_device;
+	bt_device->connect_cbd = cbd;
+
 	bt_connect_profile(ofono_dbus_get_connection(), bt_device->path,
-						DUN_DT_UUID, NULL, NULL);
+		DUN_UUID, bluetooth_device_connect_callback, bt_device);
 }
 
 static void bluetooth_device_disconnect(struct dundee_device *device,
 				dundee_device_disconnect_cb_t cb, void *data)
 {
-	DBG("");
+	struct bluetooth_device *bt_device = dundee_device_get_data(device);
+
+	DBG("%s", bt_device->path);
+
+	shutdown(bt_device->fd, SHUT_RDWR);
+	CALLBACK_WITH_SUCCESS(cb, data);
 }
 
 struct dundee_device_driver bluetooth_driver = {
-- 
1.7.9.5


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

* Re: [PATCH v2 11/13] dundee: Add support for driver connect
  2013-03-14 13:32   ` [PATCH v2 11/13] dundee: Add support for driver connect Paulo Borges
@ 2013-03-18  8:38     ` Daniel Wagner
  0 siblings, 0 replies; 55+ messages in thread
From: Daniel Wagner @ 2013-03-18  8:38 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1627 bytes --]

Hi Paulo,

The series breaks to compile at this patch.

On 03/14/2013 02:32 PM, Paulo Borges wrote:
> This patch glues together the dundee driver interface with the
> D-Bus Profile1 interface.
> 
> When the dundee driver requests a connection, it will call the
> Device1's ConnectProfile.
> ---
>   dundee/bluez5.c |    7 ++++++-
>   1 file changed, 6 insertions(+), 1 deletion(-)
> 
> diff --git a/dundee/bluez5.c b/dundee/bluez5.c
> index 82bb7aa..2d10e5a 100644
> --- a/dundee/bluez5.c
> +++ b/dundee/bluez5.c
> @@ -114,7 +114,12 @@ static void bluetooth_device_destroy(gpointer user_data)
>   static void bluetooth_device_connect(struct dundee_device *device,
>   			dundee_device_connect_cb_t cb, void *data)
>   {
> -	DBG("");
> +	struct bluetooth_device *bt_device = dundee_device_get_data(device);
> +
> +	DBG("%s", bt_device->path);
> +
> +	bt_connect_profile(ofono_dbus_get_connection(), bt_device->path,
> +						DUN_DT_UUID, NULL, NULL);
>   }
>   
>   static void bluetooth_device_disconnect(struct dundee_device *device,
> 

HEAD is now at 1198ace dundee: Add support for driver connect
make --no-print-directory all-am
  CC       dundee/bluez5.o
dundee/bluez5.c: In function ‘bluetooth_device_connect’:
dundee/bluez5.c:122:7: error: ‘DUN_DT_UUID’ undeclared (first use in this function)
dundee/bluez5.c:122:7: note: each undeclared identifier is reported only once for each function it appears in
make[1]: *** [dundee/bluez5.o] Error 1
make: *** [all] Error 2
Broke on 1198aceb147e2839a86b5f5c1cf65556d3d8fa2d


Should that be DUN_UUID?


cheers,
daniel

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

* Re: [PATCH v2 00/13] Add support for BlueZ 5 Profile1 API to dundee
  2013-03-14 13:32 ` [PATCH v2 " Paulo Borges
                     ` (12 preceding siblings ...)
  2013-03-14 13:32   ` [PATCH v2 13/13] dundee: Handle Profile connect and disconnect Paulo Borges
@ 2013-03-18  9:55   ` Daniel Wagner
  2013-03-19 17:11     ` Vinicius Costa Gomes
  13 siblings, 1 reply; 55+ messages in thread
From: Daniel Wagner @ 2013-03-18  9:55 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 7369 bytes --]

Hi Paulo,

I have tested this version and it seems to work. I say 'seems' because I was not able
keep open the connection. All phones I have tested open the connection and close
them right after. I am not sure if just my setup is broken. Testing against bluez4
gave the same behaviour. So I don't think your patches are causing this.

If Denis or Marcel do not speak up now, I'll apply them (fixing the compile glitch on
on patch #13, no need to resend the series.)

cheers,
daniel


dundee[1081]: dundee/device.c:set_property_active() 0x1e78960 path /device0
dundee[1081]: dundee/bluez5.c:bluetooth_device_connect() /org/bluez/hci0/dev_A0_4E_04_F6_F5_05
dundee[1081]: plugins/bluez5.c:device_send_message() Bluetooth: sending ConnectProfile for 00001103-0000-1000-8000-00805f9b34fb on /org/bluez/hci0/dev_A0_4E_04_F6_F5_05
dundee[1081]: dundee/bluez5.c:profile_new_connection() /org/bluez/hci0/dev_A0_4E_04_F6_F5_05 8
dundee[1081]: dundee/device.c:connect_callback() 0x1e78960
dundee[1081]: dundee/device.c:debug() Control: > ATD*99#\r
dundee[1081]: dundee/bluez5.c:bluetooth_device_connect_callback() Success
dundee[1081]: dundee/device.c:debug() Control: < ATD*99#\r
dundee[1081]: dundee/device.c:debug() Control: < \r\nCONNECT\r\n
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_generate_event: current state 0:INITIAL
dundee[1081]: dundee/device.c:debug() PPP: event: 0 (Up), action: 2, new_state: 2 (CLOSED)
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_generate_event: current state 2:CLOSED
dundee[1081]: dundee/device.c:debug() PPP: event: 2 (Open), action: 1026, new_state: 6 (REQSENT)
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_initialize_restart_count: current state 2:CLOSED
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_send_configure_request: current state 2:CLOSED
dundee[1081]: dundee/device.c:debug() PPP: gatchat/gatppp.c:ppp_enter_phase() 1
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_process_configure_request: current state 6:REQSENT
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_generate_event: current state 6:REQSENT
dundee[1081]: dundee/device.c:debug() PPP: event: 7 (RCR-), action: 4006, new_state: 6 (REQSENT)
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_send_configure_nak: current state 6:REQSENT
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_process_configure_ack: current state 6:REQSENT
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_generate_event: current state 6:REQSENT
dundee[1081]: dundee/device.c:debug() PPP: event: 8 (RCA), action: 27, new_state: 7 (ACKRCVD)
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_initialize_restart_count: current state 6:REQSENT
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_process_configure_request: current state 7:ACKRCVD
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_generate_event: current state 7:ACKRCVD
dundee[1081]: dundee/device.c:debug() PPP: event: 6 (RCR+), action: 2109, new_state: 9 (OPENED)
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_send_configure_ack: current state 7:ACKRCVD
dundee[1081]: dundee/device.c:debug() PPP: gatchat/gatppp.c:ppp_enter_phase() 2
dundee[1081]: dundee/device.c:debug() PPP: gatchat/gatppp.c:ppp_enter_phase() 3
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_generate_event: current state 0:INITIAL
dundee[1081]: dundee/device.c:debug() PPP: event: 2 (Open), action: 401, new_state: 1 (STARTING)
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_generate_event: current state 1:STARTING
dundee[1081]: dundee/device.c:debug() PPP: event: 0 (Up), action: 1026, new_state: 6 (REQSENT)
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_initialize_restart_count: current state 1:STARTING
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_send_configure_request: current state 1:STARTING
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_process_configure_request: current state 6:REQSENT
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_generate_event: current state 6:REQSENT
dundee[1081]: dundee/device.c:debug() PPP: event: 6 (RCR+), action: 2008, new_state: 8 (ACKSENT)
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_send_configure_ack: current state 6:REQSENT
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_process_configure_reject: current state 8:ACKSENT
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_generate_event: current state 8:ACKSENT
dundee[1081]: dundee/device.c:debug() PPP: event: 9 (RCN), action: 1028, new_state: 8 (ACKSENT)
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_initialize_restart_count: current state 8:ACKSENT
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_send_configure_request: current state 8:ACKSENT
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_process_configure_nak: current state 8:ACKSENT
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_generate_event: current state 8:ACKSENT
dundee[1081]: dundee/device.c:debug() PPP: event: 9 (RCN), action: 1028, new_state: 8 (ACKSENT)
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_initialize_restart_count: current state 8:ACKSENT
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_send_configure_request: current state 8:ACKSENT
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_process_configure_ack: current state 8:ACKSENT
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_generate_event: current state 8:ACKSENT
dundee[1081]: dundee/device.c:debug() PPP: event: 8 (RCA), action: 129, new_state: 9 (OPENED)
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_initialize_restart_count: current state 8:ACKSENT
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_generate_event: current state 9:OPENED
dundee[1081]: dundee/device.c:debug() PPP: event: 3 (Close), action: 8224, new_state: 4 (CLOSING)
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_initialize_restart_count: current state 9:OPENED
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_send_terminate_request: current state 9:OPENED
dundee[1081]: dundee/device.c:debug() PPP: ipcp: pppcp_generate_event: current state 9:OPENED
dundee[1081]: dundee/device.c:debug() PPP: event: 1 (Down), action: 201, new_state: 1 (STARTING)
dundee[1081]: dundee/device.c:debug() PPP: gatchat/gatppp.c:ppp_enter_phase() 5
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_process_terminate_ack: current state 4:CLOSING
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_generate_event: current state 4:CLOSING
dundee[1081]: dundee/device.c:debug() PPP: event: 11 (RTA), action: 802, new_state: 2 (CLOSED)
dundee[1081]: dundee/device.c:debug() PPP: lcp: pppcp_this_layer_finished: current state 2:CLOSED
dundee[1081]: dundee/device.c:debug() PPP: gatchat/gatppp.c:ppp_enter_phase() 0
dundee[1081]: dundee/device.c:debug() PPP: gatchat/gatppp.c:ppp_dead() 
dundee[1081]: dundee/device.c:ppp_disconnect() 0x1e78960
dundee[1081]: dundee/device.c:ppp_disconnect() PPP Link down: 3
dundee[1081]: dundee/bluez5.c:bluetooth_device_disconnect() /org/bluez/hci0/dev_A0_4E_04_F6_F5_05
dundee[1081]: dundee/device.c:dundee_device_disconnect() /device0
dundee[1081]: dundee/bluez5.c:bluetooth_device_disconnect() /org/bluez/hci0/dev_A0_4E_04_F6_F5_05
dundee[1081]: dundee/device.c:dundee_device_disconnect() /device0


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

* Re: [PATCH v2 00/13] Add support for BlueZ 5 Profile1 API to dundee
  2013-03-18  9:55   ` [PATCH v2 00/13] Add support for BlueZ 5 Profile1 API to dundee Daniel Wagner
@ 2013-03-19 17:11     ` Vinicius Costa Gomes
  0 siblings, 0 replies; 55+ messages in thread
From: Vinicius Costa Gomes @ 2013-03-19 17:11 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 539 bytes --]

Hi Daniel,

On 10:55 Mon 18 Mar, Daniel Wagner wrote:
> Hi Paulo,
> 
> I have tested this version and it seems to work. I say 'seems' because I was not able
> keep open the connection. All phones I have tested open the connection and close
> them right after. I am not sure if just my setup is broken. Testing against bluez4
> gave the same behaviour. So I don't think your patches are causing this.

Just for information, I did some field testing this weekend and I got it to work
fine with my N9.


Cheers,
-- 
Vinicius

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

* Re: [PATCH v2 07/13] dundee: Listen to devices property changes
  2013-03-14 13:32   ` [PATCH v2 07/13] dundee: Listen to devices property changes Paulo Borges
@ 2013-03-19 21:10     ` Daniel Wagner
  0 siblings, 0 replies; 55+ messages in thread
From: Daniel Wagner @ 2013-03-19 21:10 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2335 bytes --]

Hi Paulo,

I talked to Denis and he pointed out that this property_changed() 
function looks suspicious.

On 03/14/2013 02:32 PM, Paulo Borges wrote:
> When a bluetooth device property change and this property is Alias
> or UUIDs, we need to refresh our representation of this device.
> ---
>   dundee/bluez5.c |   28 +++++++++++++++++++++++++++-
>   1 file changed, 27 insertions(+), 1 deletion(-)
>
> diff --git a/dundee/bluez5.c b/dundee/bluez5.c
> index ca44656..d48aadf 100644
> --- a/dundee/bluez5.c
> +++ b/dundee/bluez5.c
> @@ -169,11 +169,37 @@ static void property_changed(GDBusProxy *proxy, const char *name,
>   {
>   	const char *path = g_dbus_proxy_get_path(proxy);
>   	const char *interface = g_dbus_proxy_get_interface(proxy);
> +	const char *alias;
> +	struct bluetooth_device *bt_device;
> +	gboolean uuid;
>
>   	if (!g_str_equal(BLUEZ_DEVICE_INTERFACE, interface))
>   		return;
>
> -	DBG("%s %s.%s", path, interface, name);
> +	bt_device = g_hash_table_lookup(registered_devices, path);
> +
> +	if (g_str_equal(name, "Alias")) {
> +		if (bt_device == NULL)
> +			return;
> +
> +		dbus_message_iter_get_basic(iter, &alias);
> +
> +		DBG("%s alias changed: %s", path, alias);
> +
> +		bt_device->name = g_strdup(alias);
> +	} else if (g_str_equal(name, "UUIDs")) {
> +		DBG("%s uuids changed", path);
> +
> +		uuid = has_dun_uuid(iter);
> +
> +		if (uuid) {
> +			if (bt_device == NULL)
> +				bluetooth_device_register(proxy);
> +		} else {
> +			if (bt_device != NULL)
> +				bluetooth_device_unregister(path);
> +		}
> +	}

So first thing, the nesting is should be avoided. Sorry, that's my bad.

	if (uuid && bt_device == NULL) register

	if (!uuid && bt_device) unregister

is what is an the ofono style.

>   }
>
>   static void connect_handler(DBusConnection *conn, void *user_data)
>

The next thing is why don't you use g_dbus_proxy_set_property_watch() 
for the property change. Then it might also be worth to split out the
the property handling into individual function. So one for Alias change
and one for UUID change.

See how Alias is handled in plugins/hfp_hf_bluez5.c

And there is the question came up, why it is necessary to handle UUID 
changes. Is this because a phone can enable/disable tethering?

cheers,
daniel


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

* [PATCH v3 00/13] Add support for BlueZ 5 Profile1 API to dundee
  2013-03-04 19:33 [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Paulo Borges
                   ` (14 preceding siblings ...)
  2013-03-14 13:32 ` [PATCH v2 " Paulo Borges
@ 2013-03-20 22:26 ` Paulo Borges
  2013-03-20 22:26   ` [PATCH v3 01/13] dundee: Rename dundee BlueZ 4 support Paulo Borges
                     ` (13 more replies)
  15 siblings, 14 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-20 22:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1366 bytes --]

This series implements support for BlueZ 5 to dundee. It uses the
org.bluez.Profile1 API to register an external profile.

While the interface between BlueZ and dundee has changed, the interfaces
"org.ofono.dundee.Device" and "org.ofono.dundee.Manager" remains
unchanged.

Paulo Borges (13):
  dundee: Rename dundee BlueZ 4 support
  dundee: Start BlueZ 5 support
  bluez5: Add DUN_UUID
  dundee: Initial GDBusClient for BlueZ 5
  dundee: Add mechanism to store bluetooth devices
  dundee: Add tracking of bluetooth devices
  dundee: Listen to devices property changes
  dundee: Add dundee device driver skeleton
  dundee: Register/unregister dundee device
  dundee: Add BlueZ Profile handler
  dundee: Add support for driver connect
  dundee: Add dundee disconnect function
  dundee: Handle Profile connect and disconnect

 Makefile.am        |   15 +-
 dundee/bluetooth.c |  297 ------------------------------------
 dundee/bluez4.c    |  297 ++++++++++++++++++++++++++++++++++++
 dundee/bluez5.c    |  422 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 dundee/device.c    |   14 +-
 dundee/dundee.h    |    5 +
 plugins/bluez5.h   |    1 +
 7 files changed, 746 insertions(+), 305 deletions(-)
 delete mode 100644 dundee/bluetooth.c
 create mode 100644 dundee/bluez4.c
 create mode 100644 dundee/bluez5.c

-- 
1.7.9.5


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

* [PATCH v3 01/13] dundee: Rename dundee BlueZ 4 support
  2013-03-20 22:26 ` [PATCH v3 " Paulo Borges
@ 2013-03-20 22:26   ` Paulo Borges
  2013-03-20 22:26   ` [PATCH v3 02/13] dundee: Start BlueZ 5 support Paulo Borges
                     ` (12 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-20 22:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 14474 bytes --]

The BlueZ 4 support file for dundee has now been renamed to
bluez4.c to make it easier to add a BlueZ 5 support file.
---
 Makefile.am        |    2 +-
 dundee/bluetooth.c |  297 ----------------------------------------------------
 dundee/bluez4.c    |  297 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 298 insertions(+), 298 deletions(-)
 delete mode 100644 dundee/bluetooth.c
 create mode 100644 dundee/bluez4.c

diff --git a/Makefile.am b/Makefile.am
index 3b998af..3a7a8dc 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -763,7 +763,7 @@ sbin_PROGRAMS += dundee/dundee
 dundee_dundee_SOURCES = $(gdbus_sources) $(gatchat_sources) $(btio_sources) \
 			src/log.c src/dbus.c plugins/bluez4.c \
 			dundee/dundee.h dundee/main.c dundee/dbus.c \
-			dundee/manager.c dundee/device.c dundee/bluetooth.c
+			dundee/manager.c dundee/device.c dundee/bluez4.c
 
 dundee_dundee_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ -ldl
 
diff --git a/dundee/bluetooth.c b/dundee/bluetooth.c
deleted file mode 100644
index 58355d3..0000000
--- a/dundee/bluetooth.c
+++ /dev/null
@@ -1,297 +0,0 @@
-/*
- *  oFono - Open Source Telephony
- *
- *  Copyright (C) 2008-2012  Intel Corporation. All rights reserved.
- *  Copyright (C) 2012  BMW Car IT GmbH. All rights reserved.
- *
- *  This program is free software; you can redistribute it and/or modify
- *  it under the terms of the GNU General Public License version 2 as
- *  published by the Free Software Foundation.
- *
- *  This program 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 General Public License for more details.
- *
- *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-#ifdef HAVE_CONFIG_H
-#include <config.h>
-#endif
-
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <fcntl.h>
-#include <string.h>
-#include <errno.h>
-#include <sys/socket.h>
-
-#include <glib.h>
-
-#include "plugins/bluez4.h"
-
-#include "dundee.h"
-
-static GHashTable *bluetooth_hash;
-
-struct bluetooth_device {
-	struct dundee_device *device;
-
-	char *path;
-	char *address;
-	char *name;
-
-	int fd;
-
-	DBusPendingCall *call;
-};
-
-static void bt_disconnect(struct dundee_device *device,
-				dundee_device_disconnect_cb_t cb, void *data)
-{
-	struct bluetooth_device *bt = dundee_device_get_data(device);
-
-	DBG("%p", bt);
-
-	shutdown(bt->fd, SHUT_RDWR);
-
-	CALLBACK_WITH_SUCCESS(cb, data);
-}
-
-static void bt_connect_reply(DBusPendingCall *call, gpointer user_data)
-{
-	struct cb_data *cbd = user_data;
-	dundee_device_connect_cb_t cb = cbd->cb;
-	struct bluetooth_device *bt = cbd->user;
-	DBusMessage *reply;
-	DBusError derr;
-	int fd;
-
-	DBG("%p", bt);
-
-	reply = dbus_pending_call_steal_reply(call);
-
-	bt->call = NULL;
-
-	dbus_error_init(&derr);
-	if (dbus_set_error_from_message(&derr, reply)) {
-		DBG("Connection to bt serial returned with error: %s, %s",
-						derr.name, derr.message);
-
-		dbus_error_free(&derr);
-
-		CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
-		goto done;
-	}
-
-	dbus_message_get_args(reply, NULL, DBUS_TYPE_UNIX_FD, &fd,
-			DBUS_TYPE_INVALID);
-
-	DBG("%p fd %d", bt, fd);
-
-	if (fd < 0) {
-		CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
-		goto done;
-	}
-
-	bt->fd = fd;
-
-	CALLBACK_WITH_SUCCESS(cb, fd, cbd->data);
-
-done:
-	dbus_message_unref(reply);
-	g_free(cbd);
-}
-
-static void bt_connect(struct dundee_device *device,
-			dundee_device_connect_cb_t cb, void *data)
-{
-	struct bluetooth_device *bt = dundee_device_get_data(device);
-	struct cb_data *cbd = cb_data_new(cb, data);
-	char *profile = "dun";
-	int status;
-
-	DBG("%p", bt);
-
-	cbd->user = bt;
-
-	status = bluetooth_send_with_reply(bt->path,
-					BLUEZ_SERIAL_INTERFACE, "ConnectFD",
-					&bt->call, bt_connect_reply,
-					cbd, NULL, DBUS_TIMEOUT,
-					DBUS_TYPE_STRING, &profile,
-					DBUS_TYPE_INVALID);
-	if (status == 0)
-		return;
-
-	g_free(cbd);
-
-	CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
-}
-
-struct dundee_device_driver bluetooth_driver = {
-	.name = "bluetooth",
-	.connect = bt_connect,
-	.disconnect = bt_disconnect,
-};
-
-static int bt_probe(const char *path, const char *dev_addr,
-				const char *adapter_addr, const char *alias)
-{
-	struct bluetooth_device *bt;
-	struct dundee_device *device;
-	char buf[256];
-
-	DBG("");
-
-	/* We already have this device in our hash, ignore */
-	if (g_hash_table_lookup(bluetooth_hash, path) != NULL)
-		return -EALREADY;
-
-	ofono_info("Using device: %s, devaddr: %s, adapter: %s",
-			path, dev_addr, adapter_addr);
-
-	strcpy(buf, "dun/");
-	bluetooth_create_path(dev_addr, adapter_addr, buf + 4, sizeof(buf) - 4);
-
-	bt = g_try_new0(struct bluetooth_device, 1);
-	if (bt == NULL)
-		return -ENOMEM;
-
-	DBG("%p", bt);
-
-	device = dundee_device_create(&bluetooth_driver);
-	if (device == NULL)
-		goto free;
-
-	dundee_device_set_data(device, bt);
-
-	bt->path = g_strdup(path);
-	if (bt->path == NULL)
-		goto free;
-
-	bt->address = g_strdup(dev_addr);
-	if (bt->address == NULL)
-		goto free;
-
-	bt->name = g_strdup(alias);
-	if (bt->name == NULL)
-		goto free;
-
-	dundee_device_set_name(device, bt->name);
-
-	if (dundee_device_register(device) < 0) {
-		g_free(device);
-		goto free;
-	}
-
-	bt->device = device;
-	g_hash_table_insert(bluetooth_hash, g_strdup(path), bt);
-
-	return 0;
-
-free:
-	g_free(bt->path);
-	g_free(bt->address);
-	g_free(bt->name);
-	g_free(bt);
-
-	return -ENOMEM;
-}
-
-static void destroy_device(gpointer user)
-{
-	struct bluetooth_device *bt = user;
-
-	DBG("%p", bt);
-
-	if (bt->call != NULL)
-		dbus_pending_call_cancel(bt->call);
-
-	g_free(bt->path);
-	g_free(bt->address);
-
-	g_free(bt);
-}
-
-static gboolean bt_remove_device(gpointer key, gpointer value,
-					gpointer user_data)
-{
-	struct bluetooth_device *bt = value;
-	const char *path = key;
-	const char *prefix = user_data;
-
-	DBG("%p", bt);
-
-	if (prefix && g_str_has_prefix(path, prefix) == FALSE)
-		return FALSE;
-
-	dundee_device_unregister(bt->device);
-
-	return TRUE;
-}
-
-static void bt_remove(const char *prefix)
-{
-	DBG("%s", prefix);
-
-	if (bluetooth_hash == NULL)
-		return;
-
-	g_hash_table_foreach_remove(bluetooth_hash, bt_remove_device,
-							(gpointer) prefix);
-}
-
-static void bt_set_alias(const char *path, const char *alias)
-{
-	struct bluetooth_device *bt;
-
-	DBG("");
-
-	if (path == NULL || alias == NULL)
-		return;
-
-	bt = g_hash_table_lookup(bluetooth_hash, path);
-	if (bt == NULL)
-		return;
-
-	g_free(bt->name);
-	bt->name = g_strdup(alias);
-
-	dundee_device_set_name(bt->device, bt->name);
-}
-
-static struct bluetooth_profile dun_profile = {
-	.name		= "dun_dt",
-	.probe		= bt_probe,
-	.remove		= bt_remove,
-	.set_alias	= bt_set_alias,
-};
-
-int __dundee_bluetooth_init(void)
-{
-	int err;
-
-	DBG("");
-
-	err = bluetooth_register_uuid(DUN_GW_UUID, &dun_profile);
-	if (err < 0)
-		return err;
-
-	bluetooth_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
-						g_free, destroy_device);
-
-	return 0;
-}
-
-void  __dundee_bluetooth_cleanup(void)
-{
-	DBG("");
-
-	bluetooth_unregister_uuid(DUN_GW_UUID);
-	g_hash_table_destroy(bluetooth_hash);
-}
diff --git a/dundee/bluez4.c b/dundee/bluez4.c
new file mode 100644
index 0000000..58355d3
--- /dev/null
+++ b/dundee/bluez4.c
@@ -0,0 +1,297 @@
+/*
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2008-2012  Intel Corporation. All rights reserved.
+ *  Copyright (C) 2012  BMW Car IT GmbH. All rights reserved.
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <string.h>
+#include <errno.h>
+#include <sys/socket.h>
+
+#include <glib.h>
+
+#include "plugins/bluez4.h"
+
+#include "dundee.h"
+
+static GHashTable *bluetooth_hash;
+
+struct bluetooth_device {
+	struct dundee_device *device;
+
+	char *path;
+	char *address;
+	char *name;
+
+	int fd;
+
+	DBusPendingCall *call;
+};
+
+static void bt_disconnect(struct dundee_device *device,
+				dundee_device_disconnect_cb_t cb, void *data)
+{
+	struct bluetooth_device *bt = dundee_device_get_data(device);
+
+	DBG("%p", bt);
+
+	shutdown(bt->fd, SHUT_RDWR);
+
+	CALLBACK_WITH_SUCCESS(cb, data);
+}
+
+static void bt_connect_reply(DBusPendingCall *call, gpointer user_data)
+{
+	struct cb_data *cbd = user_data;
+	dundee_device_connect_cb_t cb = cbd->cb;
+	struct bluetooth_device *bt = cbd->user;
+	DBusMessage *reply;
+	DBusError derr;
+	int fd;
+
+	DBG("%p", bt);
+
+	reply = dbus_pending_call_steal_reply(call);
+
+	bt->call = NULL;
+
+	dbus_error_init(&derr);
+	if (dbus_set_error_from_message(&derr, reply)) {
+		DBG("Connection to bt serial returned with error: %s, %s",
+						derr.name, derr.message);
+
+		dbus_error_free(&derr);
+
+		CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+		goto done;
+	}
+
+	dbus_message_get_args(reply, NULL, DBUS_TYPE_UNIX_FD, &fd,
+			DBUS_TYPE_INVALID);
+
+	DBG("%p fd %d", bt, fd);
+
+	if (fd < 0) {
+		CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+		goto done;
+	}
+
+	bt->fd = fd;
+
+	CALLBACK_WITH_SUCCESS(cb, fd, cbd->data);
+
+done:
+	dbus_message_unref(reply);
+	g_free(cbd);
+}
+
+static void bt_connect(struct dundee_device *device,
+			dundee_device_connect_cb_t cb, void *data)
+{
+	struct bluetooth_device *bt = dundee_device_get_data(device);
+	struct cb_data *cbd = cb_data_new(cb, data);
+	char *profile = "dun";
+	int status;
+
+	DBG("%p", bt);
+
+	cbd->user = bt;
+
+	status = bluetooth_send_with_reply(bt->path,
+					BLUEZ_SERIAL_INTERFACE, "ConnectFD",
+					&bt->call, bt_connect_reply,
+					cbd, NULL, DBUS_TIMEOUT,
+					DBUS_TYPE_STRING, &profile,
+					DBUS_TYPE_INVALID);
+	if (status == 0)
+		return;
+
+	g_free(cbd);
+
+	CALLBACK_WITH_FAILURE(cb, -1, cbd->data);
+}
+
+struct dundee_device_driver bluetooth_driver = {
+	.name = "bluetooth",
+	.connect = bt_connect,
+	.disconnect = bt_disconnect,
+};
+
+static int bt_probe(const char *path, const char *dev_addr,
+				const char *adapter_addr, const char *alias)
+{
+	struct bluetooth_device *bt;
+	struct dundee_device *device;
+	char buf[256];
+
+	DBG("");
+
+	/* We already have this device in our hash, ignore */
+	if (g_hash_table_lookup(bluetooth_hash, path) != NULL)
+		return -EALREADY;
+
+	ofono_info("Using device: %s, devaddr: %s, adapter: %s",
+			path, dev_addr, adapter_addr);
+
+	strcpy(buf, "dun/");
+	bluetooth_create_path(dev_addr, adapter_addr, buf + 4, sizeof(buf) - 4);
+
+	bt = g_try_new0(struct bluetooth_device, 1);
+	if (bt == NULL)
+		return -ENOMEM;
+
+	DBG("%p", bt);
+
+	device = dundee_device_create(&bluetooth_driver);
+	if (device == NULL)
+		goto free;
+
+	dundee_device_set_data(device, bt);
+
+	bt->path = g_strdup(path);
+	if (bt->path == NULL)
+		goto free;
+
+	bt->address = g_strdup(dev_addr);
+	if (bt->address == NULL)
+		goto free;
+
+	bt->name = g_strdup(alias);
+	if (bt->name == NULL)
+		goto free;
+
+	dundee_device_set_name(device, bt->name);
+
+	if (dundee_device_register(device) < 0) {
+		g_free(device);
+		goto free;
+	}
+
+	bt->device = device;
+	g_hash_table_insert(bluetooth_hash, g_strdup(path), bt);
+
+	return 0;
+
+free:
+	g_free(bt->path);
+	g_free(bt->address);
+	g_free(bt->name);
+	g_free(bt);
+
+	return -ENOMEM;
+}
+
+static void destroy_device(gpointer user)
+{
+	struct bluetooth_device *bt = user;
+
+	DBG("%p", bt);
+
+	if (bt->call != NULL)
+		dbus_pending_call_cancel(bt->call);
+
+	g_free(bt->path);
+	g_free(bt->address);
+
+	g_free(bt);
+}
+
+static gboolean bt_remove_device(gpointer key, gpointer value,
+					gpointer user_data)
+{
+	struct bluetooth_device *bt = value;
+	const char *path = key;
+	const char *prefix = user_data;
+
+	DBG("%p", bt);
+
+	if (prefix && g_str_has_prefix(path, prefix) == FALSE)
+		return FALSE;
+
+	dundee_device_unregister(bt->device);
+
+	return TRUE;
+}
+
+static void bt_remove(const char *prefix)
+{
+	DBG("%s", prefix);
+
+	if (bluetooth_hash == NULL)
+		return;
+
+	g_hash_table_foreach_remove(bluetooth_hash, bt_remove_device,
+							(gpointer) prefix);
+}
+
+static void bt_set_alias(const char *path, const char *alias)
+{
+	struct bluetooth_device *bt;
+
+	DBG("");
+
+	if (path == NULL || alias == NULL)
+		return;
+
+	bt = g_hash_table_lookup(bluetooth_hash, path);
+	if (bt == NULL)
+		return;
+
+	g_free(bt->name);
+	bt->name = g_strdup(alias);
+
+	dundee_device_set_name(bt->device, bt->name);
+}
+
+static struct bluetooth_profile dun_profile = {
+	.name		= "dun_dt",
+	.probe		= bt_probe,
+	.remove		= bt_remove,
+	.set_alias	= bt_set_alias,
+};
+
+int __dundee_bluetooth_init(void)
+{
+	int err;
+
+	DBG("");
+
+	err = bluetooth_register_uuid(DUN_GW_UUID, &dun_profile);
+	if (err < 0)
+		return err;
+
+	bluetooth_hash = g_hash_table_new_full(g_str_hash, g_str_equal,
+						g_free, destroy_device);
+
+	return 0;
+}
+
+void  __dundee_bluetooth_cleanup(void)
+{
+	DBG("");
+
+	bluetooth_unregister_uuid(DUN_GW_UUID);
+	g_hash_table_destroy(bluetooth_hash);
+}
-- 
1.7.9.5


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

* [PATCH v3 02/13] dundee: Start BlueZ 5 support
  2013-03-20 22:26 ` [PATCH v3 " Paulo Borges
  2013-03-20 22:26   ` [PATCH v3 01/13] dundee: Rename dundee BlueZ 4 support Paulo Borges
@ 2013-03-20 22:26   ` Paulo Borges
  2013-03-20 22:26   ` [PATCH v3 03/13] bluez5: Add DUN_UUID Paulo Borges
                     ` (11 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-20 22:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 2490 bytes --]

This patch adds the BlueZ 5 support file for dundee.
---
 Makefile.am     |   15 ++++++++++-----
 dundee/bluez5.c |   37 +++++++++++++++++++++++++++++++++++++
 2 files changed, 47 insertions(+), 5 deletions(-)
 create mode 100644 dundee/bluez5.c

diff --git a/Makefile.am b/Makefile.am
index 3a7a8dc..44cf7d7 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -756,14 +756,12 @@ endif
 endif
 
 if BLUETOOTH
-if BLUEZ4
 if DUNDEE
 sbin_PROGRAMS += dundee/dundee
 
-dundee_dundee_SOURCES = $(gdbus_sources) $(gatchat_sources) $(btio_sources) \
-			src/log.c src/dbus.c plugins/bluez4.c \
-			dundee/dundee.h dundee/main.c dundee/dbus.c \
-			dundee/manager.c dundee/device.c dundee/bluez4.c
+dundee_common_sources = $(gdbus_sources) $(gatchat_sources) \
+			src/log.c src/dbus.c dundee/dundee.h dundee/main.c \
+			dundee/dbus.c dundee/manager.c dundee/device.c
 
 dundee_dundee_LDADD = $(builtin_libadd) @GLIB_LIBS@ @DBUS_LIBS@ -ldl
 
@@ -774,6 +772,13 @@ if SYSTEMD
 systemdunit_DATA += dundee/dundee.service
 endif
 endif
+
+if BLUEZ4
+dundee_dundee_SOURCES = $(dundee_common_sources) $(btio_sources) \
+			plugins/bluez4.c dundee/bluez4.c
+else
+dundee_dundee_SOURCES = $(dundee_common_sources) plugins/bluez5.c \
+			dundee/bluez5.c
 endif
 endif
 endif
diff --git a/dundee/bluez5.c b/dundee/bluez5.c
new file mode 100644
index 0000000..6685b4c
--- /dev/null
+++ b/dundee/bluez5.c
@@ -0,0 +1,37 @@
+/*
+ *  oFono - Open Source Telephony
+ *
+ *  Copyright (C) 2013  Instituto Nokia de Tecnologia - INdT
+ *
+ *  This program is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License version 2 as
+ *  published by the Free Software Foundation.
+ *
+ *  This program 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 General Public License for more details.
+ *
+ *  You should have received a copy of the GNU General Public License
+ *  along with this program; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ */
+
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#include "dundee.h"
+
+int __dundee_bluetooth_init(void)
+{
+	DBG("");
+
+	return 0;
+}
+
+void __dundee_bluetooth_cleanup(void)
+{
+	DBG("");
+}
-- 
1.7.9.5


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

* [PATCH v3 03/13] bluez5: Add DUN_UUID
  2013-03-20 22:26 ` [PATCH v3 " Paulo Borges
  2013-03-20 22:26   ` [PATCH v3 01/13] dundee: Rename dundee BlueZ 4 support Paulo Borges
  2013-03-20 22:26   ` [PATCH v3 02/13] dundee: Start BlueZ 5 support Paulo Borges
@ 2013-03-20 22:26   ` Paulo Borges
  2013-03-20 22:26   ` [PATCH v3 04/13] dundee: Initial GDBusClient for BlueZ 5 Paulo Borges
                     ` (10 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-20 22:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 533 bytes --]

---
 plugins/bluez5.h |    1 +
 1 file changed, 1 insertion(+)

diff --git a/plugins/bluez5.h b/plugins/bluez5.h
index 573a54c..898a010 100644
--- a/plugins/bluez5.h
+++ b/plugins/bluez5.h
@@ -25,6 +25,7 @@
 #define BLUEZ_DEVICE_INTERFACE		BLUEZ_SERVICE ".Device1"
 #define BLUEZ_ERROR_INTERFACE		BLUEZ_SERVICE ".Error"
 
+#define DUN_UUID	"00001103-0000-1000-8000-00805f9b34fb"
 #define HFP_HS_UUID	"0000111e-0000-1000-8000-00805f9b34fb"
 #define HFP_AG_UUID	"0000111f-0000-1000-8000-00805f9b34fb"
 
-- 
1.7.9.5


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

* [PATCH v3 04/13] dundee: Initial GDBusClient for BlueZ 5
  2013-03-20 22:26 ` [PATCH v3 " Paulo Borges
                     ` (2 preceding siblings ...)
  2013-03-20 22:26   ` [PATCH v3 03/13] bluez5: Add DUN_UUID Paulo Borges
@ 2013-03-20 22:26   ` Paulo Borges
  2013-03-20 22:26   ` [PATCH v3 05/13] dundee: Add mechanism to store bluetooth devices Paulo Borges
                     ` (9 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-20 22:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1844 bytes --]

This patch adds callbacks to track additions of BlueZ related
interfaces.
---
 dundee/bluez5.c |   36 ++++++++++++++++++++++++++++++++++++
 dundee/dundee.h |    2 ++
 2 files changed, 38 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index 6685b4c..4ab7904 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -22,16 +22,52 @@
 #include <config.h>
 #endif
 
+#include <stdint.h>
+#include <sys/socket.h>
+#include <gdbus.h>
+
 #include "dundee.h"
+#include "plugins/bluez5.h"
+
+#define DUN_DT_PROFILE_PATH   "/bluetooth/profile/dun_dt"
+
+static GDBusClient *bluez;
+
+static void proxy_added(GDBusProxy *proxy, void *user_data)
+{
+	const char *path = g_dbus_proxy_get_path(proxy);
+	const char *interface = g_dbus_proxy_get_interface(proxy);
+
+	if (!g_str_equal(BLUEZ_DEVICE_INTERFACE, interface))
+		return;
+
+	DBG("%s %s", path, interface);
+}
+
+static void connect_handler(DBusConnection *conn, void *user_data)
+{
+	DBG("");
+
+	bt_register_profile_with_role(conn, DUN_UUID, DUN_VERSION_1_2,
+				"dun_dt", DUN_DT_PROFILE_PATH, "client");
+}
 
 int __dundee_bluetooth_init(void)
 {
+	DBusConnection *conn = ofono_dbus_get_connection();
+
 	DBG("");
 
+	bluez = g_dbus_client_new(conn, BLUEZ_SERVICE, BLUEZ_MANAGER_PATH);
+	g_dbus_client_set_connect_watch(bluez, connect_handler, NULL);
+	g_dbus_client_set_proxy_handlers(bluez, proxy_added, NULL, NULL, NULL);
+
 	return 0;
 }
 
 void __dundee_bluetooth_cleanup(void)
 {
 	DBG("");
+
+	g_dbus_client_unref(bluez);
 }
diff --git a/dundee/dundee.h b/dundee/dundee.h
index db932b6..daf78a5 100644
--- a/dundee/dundee.h
+++ b/dundee/dundee.h
@@ -26,6 +26,8 @@
 
 #include <ofono/types.h>
 
+#define DUN_VERSION_1_2 0x0102
+
 void __dundee_exit(void);
 
 enum dundee_error_type {
-- 
1.7.9.5


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

* [PATCH v3 05/13] dundee: Add mechanism to store bluetooth devices
  2013-03-20 22:26 ` [PATCH v3 " Paulo Borges
                     ` (3 preceding siblings ...)
  2013-03-20 22:26   ` [PATCH v3 04/13] dundee: Initial GDBusClient for BlueZ 5 Paulo Borges
@ 2013-03-20 22:26   ` Paulo Borges
  2013-03-20 22:26   ` [PATCH v3 06/13] dundee: Add tracking of " Paulo Borges
                     ` (8 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-20 22:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1389 bytes --]

This patch adds a hash that will store every known bluetooth
device that implements DUN service.
---
 dundee/bluez5.c |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index 4ab7904..7a9e0fe 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -32,6 +32,25 @@
 #define DUN_DT_PROFILE_PATH   "/bluetooth/profile/dun_dt"
 
 static GDBusClient *bluez;
+static GHashTable *registered_devices;
+
+struct bluetooth_device {
+	char *path;
+	char *address;
+	char *name;
+};
+
+static void bluetooth_device_destroy(gpointer user_data)
+{
+	struct bluetooth_device *bt_device = user_data;
+
+	DBG("%s", bt_device->path);
+
+	g_free(bt_device->path);
+	g_free(bt_device->address);
+	g_free(bt_device->name);
+	g_free(bt_device);
+}
 
 static void proxy_added(GDBusProxy *proxy, void *user_data)
 {
@@ -62,6 +81,9 @@ int __dundee_bluetooth_init(void)
 	g_dbus_client_set_connect_watch(bluez, connect_handler, NULL);
 	g_dbus_client_set_proxy_handlers(bluez, proxy_added, NULL, NULL, NULL);
 
+	registered_devices = g_hash_table_new_full(g_str_hash, g_str_equal,
+					g_free, bluetooth_device_destroy);
+
 	return 0;
 }
 
@@ -70,4 +92,5 @@ void __dundee_bluetooth_cleanup(void)
 	DBG("");
 
 	g_dbus_client_unref(bluez);
+	g_hash_table_destroy(registered_devices);
 }
-- 
1.7.9.5


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

* [PATCH v3 06/13] dundee: Add tracking of bluetooth devices
  2013-03-20 22:26 ` [PATCH v3 " Paulo Borges
                     ` (4 preceding siblings ...)
  2013-03-20 22:26   ` [PATCH v3 05/13] dundee: Add mechanism to store bluetooth devices Paulo Borges
@ 2013-03-20 22:26   ` Paulo Borges
  2013-03-20 22:26   ` [PATCH v3 07/13] dundee: Listen to devices property changes Paulo Borges
                     ` (7 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-20 22:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3349 bytes --]

This patch tracks the GDBusProxy for Bluetooth devices in order to
be able to get their properties.
---
 dundee/bluez5.c |  102 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 102 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index 7a9e0fe..3688753 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -52,15 +52,117 @@ static void bluetooth_device_destroy(gpointer user_data)
 	g_free(bt_device);
 }
 
+static struct bluetooth_device *bluetooth_device_create(const char *path,
+					const char *address, const char *alias)
+{
+	struct bluetooth_device *bt_device;
+
+	DBG("%s %s %s", path, address, alias);
+
+	bt_device = g_try_new0(struct bluetooth_device, 1);
+	if (bt_device == NULL)
+		return NULL;
+
+	bt_device->path = g_strdup(path);
+	bt_device->address = g_strdup(address);
+	bt_device->name = g_strdup(alias);
+
+	return bt_device;
+}
+
+static struct bluetooth_device *bluetooth_device_register(GDBusProxy *proxy)
+{
+	const char *path = g_dbus_proxy_get_path(proxy);
+	const char *alias, *address;
+	struct bluetooth_device *bt_device;
+	DBusMessageIter iter;
+
+	DBG("%s", path);
+
+	if (g_hash_table_lookup(registered_devices, path) != NULL)
+		return NULL;
+
+	if (!g_dbus_proxy_get_property(proxy, "Address", &iter))
+		return NULL;
+
+	dbus_message_iter_get_basic(&iter, &address);
+
+	if (!g_dbus_proxy_get_property(proxy, "Alias", &iter))
+		return NULL;
+
+	dbus_message_iter_get_basic(&iter, &alias);
+
+	bt_device = bluetooth_device_create(path, address, alias);
+	if (bt_device == NULL) {
+		ofono_error("Register bluetooth device failed");
+		return NULL;
+	}
+
+	g_hash_table_insert(registered_devices, g_strdup(path), bt_device);
+
+	return bt_device;
+}
+
+static void bluetooth_device_unregister(const char *path)
+{
+	DBG("");
+
+	g_hash_table_remove(registered_devices, path);
+}
+
+static gboolean has_dun_uuid(DBusMessageIter *array)
+{
+	DBusMessageIter value;
+
+	if (dbus_message_iter_get_arg_type(array) != DBUS_TYPE_ARRAY)
+		return FALSE;
+
+	dbus_message_iter_recurse(array, &value);
+
+	while (dbus_message_iter_get_arg_type(&value) == DBUS_TYPE_STRING) {
+		const char *uuid;
+
+		dbus_message_iter_get_basic(&value, &uuid);
+
+		if (g_str_equal(uuid, DUN_UUID))
+			return TRUE;
+
+		dbus_message_iter_next(&value);
+	}
+
+	return FALSE;
+}
+
+static void bluetooth_device_removed(GDBusProxy *proxy, void *user_data)
+{
+	struct bluetooth_device *bt_device = user_data;
+
+	DBG("%s", bt_device->path);
+
+	bluetooth_device_unregister(bt_device->path);
+}
+
 static void proxy_added(GDBusProxy *proxy, void *user_data)
 {
 	const char *path = g_dbus_proxy_get_path(proxy);
 	const char *interface = g_dbus_proxy_get_interface(proxy);
+	struct bluetooth_device *bt_device;
+	DBusMessageIter iter;
 
 	if (!g_str_equal(BLUEZ_DEVICE_INTERFACE, interface))
 		return;
 
+	if (!g_dbus_proxy_get_property(proxy, "UUIDs", &iter))
+		return;
+
 	DBG("%s %s", path, interface);
+
+	if (!has_dun_uuid(&iter))
+		return;
+
+	bt_device = bluetooth_device_register(proxy);
+	g_dbus_proxy_set_removed_watch(proxy, bluetooth_device_removed,
+								bt_device);
 }
 
 static void connect_handler(DBusConnection *conn, void *user_data)
-- 
1.7.9.5


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

* [PATCH v3 07/13] dundee: Listen to devices property changes
  2013-03-20 22:26 ` [PATCH v3 " Paulo Borges
                     ` (5 preceding siblings ...)
  2013-03-20 22:26   ` [PATCH v3 06/13] dundee: Add tracking of " Paulo Borges
@ 2013-03-20 22:26   ` Paulo Borges
  2013-03-20 22:26   ` [PATCH v3 08/13] dundee: Add dundee device driver skeleton Paulo Borges
                     ` (6 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-20 22:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1221 bytes --]

When a bluetooth device property change and this property is Alias,
we need to refresh our representation of this device.
---
 dundee/bluez5.c |   15 +++++++++++++++
 1 file changed, 15 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index 3688753..f0c51df 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -133,6 +133,20 @@ static gboolean has_dun_uuid(DBusMessageIter *array)
 	return FALSE;
 }
 
+static void alias_changed(GDBusProxy *proxy, const char *name,
+					DBusMessageIter *iter, void *user_data)
+{
+	const char *alias;
+	struct bluetooth_device *bt_device = user_data;
+
+	if (!g_str_equal("Alias", name))
+		return;
+
+	dbus_message_iter_get_basic(iter, &alias);
+
+	bt_device->name = g_strdup(alias);
+}
+
 static void bluetooth_device_removed(GDBusProxy *proxy, void *user_data)
 {
 	struct bluetooth_device *bt_device = user_data;
@@ -161,6 +175,7 @@ static void proxy_added(GDBusProxy *proxy, void *user_data)
 		return;
 
 	bt_device = bluetooth_device_register(proxy);
+	g_dbus_proxy_set_property_watch(proxy, alias_changed, bt_device);
 	g_dbus_proxy_set_removed_watch(proxy, bluetooth_device_removed,
 								bt_device);
 }
-- 
1.7.9.5


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

* [PATCH v3 08/13] dundee: Add dundee device driver skeleton
  2013-03-20 22:26 ` [PATCH v3 " Paulo Borges
                     ` (6 preceding siblings ...)
  2013-03-20 22:26   ` [PATCH v3 07/13] dundee: Listen to devices property changes Paulo Borges
@ 2013-03-20 22:26   ` Paulo Borges
  2013-03-20 22:26   ` [PATCH v3 09/13] dundee: Register/unregister dundee device Paulo Borges
                     ` (5 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-20 22:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1029 bytes --]

This patch adds the functions to be called when the dundee will
connect or disconnect with a Bluetooth device.
---
 dundee/bluez5.c |   18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index f0c51df..c78c445 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -52,6 +52,24 @@ static void bluetooth_device_destroy(gpointer user_data)
 	g_free(bt_device);
 }
 
+static void bluetooth_device_connect(struct dundee_device *device,
+			dundee_device_connect_cb_t cb, void *data)
+{
+	DBG("");
+}
+
+static void bluetooth_device_disconnect(struct dundee_device *device,
+				dundee_device_disconnect_cb_t cb, void *data)
+{
+	DBG("");
+}
+
+struct dundee_device_driver bluetooth_driver = {
+	.name = "bluetooth",
+	.connect = bluetooth_device_connect,
+	.disconnect = bluetooth_device_disconnect,
+};
+
 static struct bluetooth_device *bluetooth_device_create(const char *path,
 					const char *address, const char *alias)
 {
-- 
1.7.9.5


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

* [PATCH v3 09/13] dundee: Register/unregister dundee device
  2013-03-20 22:26 ` [PATCH v3 " Paulo Borges
                     ` (7 preceding siblings ...)
  2013-03-20 22:26   ` [PATCH v3 08/13] dundee: Add dundee device driver skeleton Paulo Borges
@ 2013-03-20 22:26   ` Paulo Borges
  2013-03-20 22:26   ` [PATCH v3 10/13] dundee: Add BlueZ Profile handler Paulo Borges
                     ` (4 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-20 22:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1774 bytes --]

This patch adds the dundee device struct to the our Bluetooth
device representation.
---
 dundee/bluez5.c |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index c78c445..504e2e0 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -35,6 +35,8 @@ static GDBusClient *bluez;
 static GHashTable *registered_devices;
 
 struct bluetooth_device {
+	struct dundee_device *device;
+
 	char *path;
 	char *address;
 	char *name;
@@ -46,6 +48,9 @@ static void bluetooth_device_destroy(gpointer user_data)
 
 	DBG("%s", bt_device->path);
 
+	if (bt_device->device != NULL)
+		dundee_device_unregister(bt_device->device);
+
 	g_free(bt_device->path);
 	g_free(bt_device->address);
 	g_free(bt_device->name);
@@ -93,6 +98,7 @@ static struct bluetooth_device *bluetooth_device_register(GDBusProxy *proxy)
 	const char *path = g_dbus_proxy_get_path(proxy);
 	const char *alias, *address;
 	struct bluetooth_device *bt_device;
+	struct dundee_device *device;
 	DBusMessageIter iter;
 
 	DBG("%s", path);
@@ -116,9 +122,26 @@ static struct bluetooth_device *bluetooth_device_register(GDBusProxy *proxy)
 		return NULL;
 	}
 
+	device = dundee_device_create(&bluetooth_driver);
+	if (device == NULL)
+		goto free;
+
+	dundee_device_set_data(device, bt_device);
+	dundee_device_set_name(device, bt_device->name);
+
+	if (dundee_device_register(device) < 0) {
+		g_free(device);
+		goto free;
+	}
+
+	bt_device->device = device;
 	g_hash_table_insert(registered_devices, g_strdup(path), bt_device);
 
 	return bt_device;
+
+free:
+	bluetooth_device_destroy(bt_device);
+	return NULL;
 }
 
 static void bluetooth_device_unregister(const char *path)
-- 
1.7.9.5


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

* [PATCH v3 10/13] dundee: Add BlueZ Profile handler
  2013-03-20 22:26 ` [PATCH v3 " Paulo Borges
                     ` (8 preceding siblings ...)
  2013-03-20 22:26   ` [PATCH v3 09/13] dundee: Register/unregister dundee device Paulo Borges
@ 2013-03-20 22:26   ` Paulo Borges
  2013-03-20 22:26   ` [PATCH v3 11/13] dundee: Add support for driver connect Paulo Borges
                     ` (3 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-20 22:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 3195 bytes --]

This patch declares the external dundee Profile handler. It
contains the initial implementation of the D-Bus Profile1
interface and methods responsible for handling Bluetooth
connections.
---
 dundee/bluez5.c |   68 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index 504e2e0..fdf015d 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -25,6 +25,7 @@
 #include <stdint.h>
 #include <sys/socket.h>
 #include <gdbus.h>
+#include <errno.h>
 
 #include "dundee.h"
 #include "plugins/bluez5.h"
@@ -42,6 +43,59 @@ struct bluetooth_device {
 	char *name;
 };
 
+static DBusMessage *profile_new_connection(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	DBG("");
+
+	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+						".NotImplemented",
+						"Implementation not provided");
+}
+
+static DBusMessage *profile_release(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	DBG("");
+
+	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+						".NotImplemented",
+						"Implementation not provided");
+}
+
+static DBusMessage *profile_cancel(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	DBG("");
+
+	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+						".NotImplemented",
+						"Implementation not provided");
+}
+
+static DBusMessage *profile_disconnection(DBusConnection *conn,
+					DBusMessage *msg, void *user_data)
+{
+	DBG("");
+
+	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
+						".NotImplemented",
+						"Implementation not provided");
+}
+
+static const GDBusMethodTable profile_methods[] = {
+	{ GDBUS_ASYNC_METHOD("NewConnection",
+				GDBUS_ARGS({ "device", "o"}, { "fd", "h"},
+						{ "fd_properties", "a{sv}" }),
+				NULL, profile_new_connection) },
+	{ GDBUS_METHOD("Release", NULL, NULL, profile_release) },
+	{ GDBUS_METHOD("Cancel", NULL, NULL, profile_cancel) },
+	{ GDBUS_METHOD("RequestDisconnection",
+				GDBUS_ARGS({"device", "o"}), NULL,
+				profile_disconnection) },
+	{ }
+};
+
 static void bluetooth_device_destroy(gpointer user_data)
 {
 	struct bluetooth_device *bt_device = user_data;
@@ -235,6 +289,15 @@ int __dundee_bluetooth_init(void)
 
 	DBG("");
 
+	if (!g_dbus_register_interface(conn, DUN_DT_PROFILE_PATH,
+					BLUEZ_PROFILE_INTERFACE,
+					profile_methods, NULL,
+					NULL, NULL, NULL)) {
+		ofono_error("Register Profile interface failed: %s",
+						DUN_DT_PROFILE_PATH);
+		return -EIO;
+	}
+
 	bluez = g_dbus_client_new(conn, BLUEZ_SERVICE, BLUEZ_MANAGER_PATH);
 	g_dbus_client_set_connect_watch(bluez, connect_handler, NULL);
 	g_dbus_client_set_proxy_handlers(bluez, proxy_added, NULL, NULL, NULL);
@@ -247,8 +310,13 @@ int __dundee_bluetooth_init(void)
 
 void __dundee_bluetooth_cleanup(void)
 {
+	DBusConnection *conn = ofono_dbus_get_connection();
+
 	DBG("");
 
+	g_dbus_unregister_interface(conn, DUN_DT_PROFILE_PATH,
+						BLUEZ_PROFILE_INTERFACE);
+
 	g_dbus_client_unref(bluez);
 	g_hash_table_destroy(registered_devices);
 }
-- 
1.7.9.5


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

* [PATCH v3 11/13] dundee: Add support for driver connect
  2013-03-20 22:26 ` [PATCH v3 " Paulo Borges
                     ` (9 preceding siblings ...)
  2013-03-20 22:26   ` [PATCH v3 10/13] dundee: Add BlueZ Profile handler Paulo Borges
@ 2013-03-20 22:26   ` Paulo Borges
  2013-03-20 22:26   ` [PATCH v3 12/13] dundee: Add dundee disconnect function Paulo Borges
                     ` (2 subsequent siblings)
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-20 22:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 913 bytes --]

This patch glues together the dundee driver interface with the
D-Bus Profile1 interface.

When the dundee driver requests a connection, it will call the
Device1's ConnectProfile.
---
 dundee/bluez5.c |    7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index fdf015d..c5a5ff0 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -114,7 +114,12 @@ static void bluetooth_device_destroy(gpointer user_data)
 static void bluetooth_device_connect(struct dundee_device *device,
 			dundee_device_connect_cb_t cb, void *data)
 {
-	DBG("");
+	struct bluetooth_device *bt_device = dundee_device_get_data(device);
+
+	DBG("%s", bt_device->path);
+
+	bt_connect_profile(ofono_dbus_get_connection(), bt_device->path,
+						DUN_UUID, NULL, NULL);
 }
 
 static void bluetooth_device_disconnect(struct dundee_device *device,
-- 
1.7.9.5


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

* [PATCH v3 12/13] dundee: Add dundee disconnect function
  2013-03-20 22:26 ` [PATCH v3 " Paulo Borges
                     ` (10 preceding siblings ...)
  2013-03-20 22:26   ` [PATCH v3 11/13] dundee: Add support for driver connect Paulo Borges
@ 2013-03-20 22:26   ` Paulo Borges
  2013-03-20 22:26   ` [PATCH v3 13/13] dundee: Handle Profile connect and disconnect Paulo Borges
  2013-03-24 12:31   ` [PATCH v3 00/13] Add support for BlueZ 5 Profile1 API to dundee Daniel Wagner
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-20 22:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1645 bytes --]

---
 dundee/device.c |   14 +++++++++++---
 dundee/dundee.h |    3 +++
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/dundee/device.c b/dundee/device.c
index e5f6424..2d84aaa 100644
--- a/dundee/device.c
+++ b/dundee/device.c
@@ -270,11 +270,13 @@ err:
 	device->pending = NULL;
 }
 
-static void disconnect_callback(const struct dundee_error *error, void *data)
+void dundee_device_disconnect(const struct dundee_error *error,
+						struct dundee_device *device)
 {
-	struct dundee_device *device = data;
+	if (device == NULL)
+		return;
 
-	DBG("%p", device);
+	DBG("%s", device->path);
 
 	g_at_chat_unref(device->chat);
 	device->chat = NULL;
@@ -295,6 +297,12 @@ out:
 	device->pending = NULL;
 }
 
+static void disconnect_callback(const struct dundee_error *error, void *data)
+{
+	struct dundee_device *device = data;
+	dundee_device_disconnect(error, device);
+}
+
 static gboolean ppp_connect_timeout(gpointer user_data)
 {
 	struct dundee_device *device = user_data;
diff --git a/dundee/dundee.h b/dundee/dundee.h
index daf78a5..1889d84 100644
--- a/dundee/dundee.h
+++ b/dundee/dundee.h
@@ -130,6 +130,9 @@ struct dundee_device *dundee_device_create(struct dundee_device_driver *d);
 int dundee_device_register(struct dundee_device *device);
 void dundee_device_unregister(struct dundee_device *device);
 
+void dundee_device_disconnect(const struct dundee_error *error,
+						struct dundee_device *device);
+
 void dundee_device_set_data(struct dundee_device *device, void *data);
 void *dundee_device_get_data(struct dundee_device *device);
 
-- 
1.7.9.5


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

* [PATCH v3 13/13] dundee: Handle Profile connect and disconnect
  2013-03-20 22:26 ` [PATCH v3 " Paulo Borges
                     ` (11 preceding siblings ...)
  2013-03-20 22:26   ` [PATCH v3 12/13] dundee: Add dundee disconnect function Paulo Borges
@ 2013-03-20 22:26   ` Paulo Borges
  2013-03-24 12:31   ` [PATCH v3 00/13] Add support for BlueZ 5 Profile1 API to dundee Daniel Wagner
  13 siblings, 0 replies; 55+ messages in thread
From: Paulo Borges @ 2013-03-20 22:26 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 4628 bytes --]

---
 dundee/bluez5.c |  115 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 105 insertions(+), 10 deletions(-)

diff --git a/dundee/bluez5.c b/dundee/bluez5.c
index c5a5ff0..eb7f005 100644
--- a/dundee/bluez5.c
+++ b/dundee/bluez5.c
@@ -41,16 +41,63 @@ struct bluetooth_device {
 	char *path;
 	char *address;
 	char *name;
+
+	struct cb_data *connect_cbd;
+
+	int fd;
 };
 
 static DBusMessage *profile_new_connection(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
-	DBG("");
+	struct bluetooth_device *bt_device;
+	dundee_device_connect_cb_t cb;
+	DBusMessageIter iter;
+	const char *path;
+	int fd;
 
-	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
-						".NotImplemented",
-						"Implementation not provided");
+	if (!dbus_message_iter_init(msg, &iter))
+		goto error;
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
+		goto error;
+
+	dbus_message_iter_get_basic(&iter, &path);
+
+	bt_device = g_hash_table_lookup(registered_devices, path);
+	if (bt_device == NULL)
+		goto error;
+
+	cb = bt_device->connect_cbd->cb;
+
+	dbus_message_iter_next(&iter);
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UNIX_FD)
+		goto call_failure;
+
+	dbus_message_iter_get_basic(&iter, &fd);
+	if (fd < 0)
+		goto call_failure;
+
+	DBG("%s %d", bt_device->path, fd);
+
+	bt_device->fd = fd;
+
+	CALLBACK_WITH_SUCCESS(cb, fd, bt_device->connect_cbd->data);
+
+	g_free(bt_device->connect_cbd);
+	bt_device->connect_cbd = NULL;
+
+	return dbus_message_new_method_return(msg);
+
+call_failure:
+	CALLBACK_WITH_FAILURE(cb, -1, bt_device->connect_cbd->data);
+
+	g_free(bt_device->connect_cbd);
+	bt_device->connect_cbd = NULL;
+
+error:
+	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE ".Rejected",
+					"Invalid arguments in method call");
 }
 
 static DBusMessage *profile_release(DBusConnection *conn,
@@ -76,11 +123,31 @@ static DBusMessage *profile_cancel(DBusConnection *conn,
 static DBusMessage *profile_disconnection(DBusConnection *conn,
 					DBusMessage *msg, void *user_data)
 {
-	DBG("");
+	struct bluetooth_device *bt_device;
+	DBusMessageIter iter;
+	const char *path;
 
-	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE
-						".NotImplemented",
-						"Implementation not provided");
+	if (!dbus_message_iter_init(msg, &iter))
+		goto error;
+
+	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
+		goto error;
+
+	dbus_message_iter_get_basic(&iter, &path);
+
+	bt_device = g_hash_table_lookup(registered_devices, path);
+	if (bt_device == NULL)
+		goto error;
+
+	DBG("%s", bt_device->path);
+
+	CALLBACK_WITH_SUCCESS(dundee_device_disconnect, bt_device->device);
+
+	return dbus_message_new_method_return(msg);
+
+error:
+	return g_dbus_create_error(msg, BLUEZ_ERROR_INTERFACE ".Rejected",
+					"Invalid arguments in method call");
 }
 
 static const GDBusMethodTable profile_methods[] = {
@@ -105,27 +172,55 @@ static void bluetooth_device_destroy(gpointer user_data)
 	if (bt_device->device != NULL)
 		dundee_device_unregister(bt_device->device);
 
+	if (bt_device->connect_cbd != NULL)
+		g_free(bt_device->connect_cbd);
+
 	g_free(bt_device->path);
 	g_free(bt_device->address);
 	g_free(bt_device->name);
 	g_free(bt_device);
 }
 
+static void bluetooth_device_connect_callback(gboolean success,
+							gpointer user_data)
+{
+	struct bluetooth_device *bt_device = user_data;
+
+	if (success) {
+		DBG("Success");
+		return;
+	}
+
+	DBG("ConnectProfile() returned an error");
+
+	g_free(bt_device->connect_cbd);
+	bt_device->connect_cbd = NULL;
+}
+
 static void bluetooth_device_connect(struct dundee_device *device,
 			dundee_device_connect_cb_t cb, void *data)
 {
 	struct bluetooth_device *bt_device = dundee_device_get_data(device);
+	struct cb_data *cbd = cb_data_new(cb, data);
 
 	DBG("%s", bt_device->path);
 
+	cbd->user = bt_device;
+	bt_device->connect_cbd = cbd;
+
 	bt_connect_profile(ofono_dbus_get_connection(), bt_device->path,
-						DUN_UUID, NULL, NULL);
+		DUN_UUID, bluetooth_device_connect_callback, bt_device);
 }
 
 static void bluetooth_device_disconnect(struct dundee_device *device,
 				dundee_device_disconnect_cb_t cb, void *data)
 {
-	DBG("");
+	struct bluetooth_device *bt_device = dundee_device_get_data(device);
+
+	DBG("%s", bt_device->path);
+
+	shutdown(bt_device->fd, SHUT_RDWR);
+	CALLBACK_WITH_SUCCESS(cb, data);
 }
 
 struct dundee_device_driver bluetooth_driver = {
-- 
1.7.9.5


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

* Re: [PATCH v3 00/13] Add support for BlueZ 5 Profile1 API to dundee
  2013-03-20 22:26 ` [PATCH v3 " Paulo Borges
                     ` (12 preceding siblings ...)
  2013-03-20 22:26   ` [PATCH v3 13/13] dundee: Handle Profile connect and disconnect Paulo Borges
@ 2013-03-24 12:31   ` Daniel Wagner
  2013-03-25 14:43     ` Paulo Borges
  13 siblings, 1 reply; 55+ messages in thread
From: Daniel Wagner @ 2013-03-24 12:31 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 324 bytes --]

Hi Paulo,

I have pushed all patches except patch #3. "dun_gw: Add BlueZ 5 version" 
from Frédéric just added recently the definition for DUN_GW_UUID. 
Obviously, I needed to update your patches to use DUN_GW_UUID instead of 
DUN_UUID. The bluez4.c file also uses DUN_GW_UUID as identifier.

Thanks a lot,
daniel

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

* Re: [PATCH v3 00/13] Add support for BlueZ 5 Profile1 API to dundee
  2013-03-24 12:31   ` [PATCH v3 00/13] Add support for BlueZ 5 Profile1 API to dundee Daniel Wagner
@ 2013-03-25 14:43     ` Paulo Borges
  2013-04-02 13:12       ` Daniel Wagner
  0 siblings, 1 reply; 55+ messages in thread
From: Paulo Borges @ 2013-03-25 14:43 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 897 bytes --]

Hi Daniel,

On Sun, Mar 24, 2013 at 9:31 AM, Daniel Wagner <wagi@monom.org> wrote:

> Hi Paulo,
>
> I have pushed all patches except patch #3. "dun_gw: Add BlueZ 5 version"
> from Frédéric just added recently the definition for DUN_GW_UUID.
> Obviously, I needed to update your patches to use DUN_GW_UUID instead of
> DUN_UUID. The bluez4.c file also uses DUN_GW_UUID as identifier.
>
> Thanks a lot,
> daniel
>

Actually, DUN profile is "asymmetric": it doesn't have an UUID for each
role, they share the same UUID [1]. The only way to distinguish the current
role is to specify it when registering the profile with
bt_register_profile_with_role function.

Specifying the role when registering a DUN profile is important because
only GW should expose a SDP record.

[1]
https://www.bluetooth.org/Technical/AssignedNumbers/service_discovery.htm

Cheers,
Paulo Borges

[-- Attachment #2: attachment.html --]
[-- Type: text/html, Size: 1521 bytes --]

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

* Re: [PATCH v3 00/13] Add support for BlueZ 5 Profile1 API to dundee
  2013-03-25 14:43     ` Paulo Borges
@ 2013-04-02 13:12       ` Daniel Wagner
  0 siblings, 0 replies; 55+ messages in thread
From: Daniel Wagner @ 2013-04-02 13:12 UTC (permalink / raw)
  To: ofono

[-- Attachment #1: Type: text/plain, Size: 1262 bytes --]

Hi Paulo,

[sorry for the late response, was on vacation]

On 03/25/2013 03:43 PM, Paulo Borges wrote:
> Hi Daniel,
>
> On Sun, Mar 24, 2013 at 9:31 AM, Daniel Wagner <wagi@monom.org
> <mailto:wagi@monom.org>> wrote:
>
>     Hi Paulo,
>
>     I have pushed all patches except patch #3. "dun_gw: Add BlueZ 5
>     version" from Frédéric just added recently the definition for
>     DUN_GW_UUID. Obviously, I needed to update your patches to use
>     DUN_GW_UUID instead of DUN_UUID. The bluez4.c file also uses
>     DUN_GW_UUID as identifier.
>
>     Thanks a lot,
>     daniel
>
>
> Actually, DUN profile is "asymmetric": it doesn't have an UUID for each
> role, they share the same UUID [1]. The only way to distinguish the
> current role is to specify it when registering the profile with
> bt_register_profile_with_role function.
>
> Specifying the role when registering a DUN profile is important because
> only GW should expose a SDP record.
>
> [1]
> https://www.bluetooth.org/Technical/AssignedNumbers/service_discovery.htm

I see. The thing I wanted to avoid is to have twice a define for the 
same value. In the end the way how the define is used (as you have 
described above) is essential.

cheers,
daniel


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

end of thread, other threads:[~2013-04-02 13:12 UTC | newest]

Thread overview: 55+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-03-04 19:33 [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Paulo Borges
2013-03-04 19:33 ` [PATCH 01/13] dundee: Rename dundee BlueZ 4 support Paulo Borges
2013-03-04 19:33 ` [PATCH 02/13] dundee: Start BlueZ 5 support Paulo Borges
2013-03-11 17:01   ` Daniel Wagner
2013-03-04 19:33 ` [PATCH 03/13] bluez5: Add DUN_UUID Paulo Borges
2013-03-04 19:33 ` [PATCH 04/13] dundee: Initial GDBusClient for BlueZ 5 Paulo Borges
2013-03-11 17:08   ` Daniel Wagner
2013-03-04 19:33 ` [PATCH 05/13] dundee: Add mechanism to store bluetooth devices Paulo Borges
2013-03-04 19:33 ` [PATCH 06/13] dundee: Add tracking of " Paulo Borges
2013-03-04 19:33 ` [PATCH 07/13] dundee: Listen to devices property changes Paulo Borges
2013-03-11 17:17   ` Daniel Wagner
2013-03-12  9:56     ` Daniel Wagner
2013-03-04 19:33 ` [PATCH 08/13] dundee: Add dundee device driver skeleton Paulo Borges
2013-03-04 19:33 ` [PATCH 09/13] dundee: Register/unregister dundee device Paulo Borges
2013-03-04 19:37 ` [PATCH 10/13] dundee: Add BlueZ Profile handler Paulo Borges
2013-03-04 19:38 ` [PATCH 11/13] dundee: Add support for driver connect Paulo Borges
2013-03-04 19:38 ` [PATCH 12/13] dundee: Add dundee disconnect function Paulo Borges
2013-03-04 19:39 ` [PATCH 13/13] dundee: Handle Profile connect and disconnect Paulo Borges
2013-03-11 17:23 ` [PATCH 00/13] Add support for BlueZ 5 Profile1 API to dundee Daniel Wagner
2013-03-11 20:41   ` Paulo Borges
2013-03-14 13:32 ` [PATCH v2 " Paulo Borges
2013-03-14 13:32   ` [PATCH v2 01/13] dundee: Rename dundee BlueZ 4 support Paulo Borges
2013-03-14 13:32   ` [PATCH v2 02/13] dundee: Start BlueZ 5 support Paulo Borges
2013-03-14 13:32   ` [PATCH v2 03/13] bluez5: Add DUN_UUID Paulo Borges
2013-03-14 13:32   ` [PATCH v2 04/13] dundee: Initial GDBusClient for BlueZ 5 Paulo Borges
2013-03-14 13:32   ` [PATCH v2 05/13] dundee: Add mechanism to store bluetooth devices Paulo Borges
2013-03-14 13:32   ` [PATCH v2 06/13] dundee: Add tracking of " Paulo Borges
2013-03-14 13:32   ` [PATCH v2 07/13] dundee: Listen to devices property changes Paulo Borges
2013-03-19 21:10     ` Daniel Wagner
2013-03-14 13:32   ` [PATCH v2 08/13] dundee: Add dundee device driver skeleton Paulo Borges
2013-03-14 13:32   ` [PATCH v2 09/13] dundee: Register/unregister dundee device Paulo Borges
2013-03-14 13:32   ` [PATCH v2 10/13] dundee: Add BlueZ Profile handler Paulo Borges
2013-03-14 13:32   ` [PATCH v2 11/13] dundee: Add support for driver connect Paulo Borges
2013-03-18  8:38     ` Daniel Wagner
2013-03-14 13:32   ` [PATCH v2 12/13] dundee: Add dundee disconnect function Paulo Borges
2013-03-14 13:32   ` [PATCH v2 13/13] dundee: Handle Profile connect and disconnect Paulo Borges
2013-03-18  9:55   ` [PATCH v2 00/13] Add support for BlueZ 5 Profile1 API to dundee Daniel Wagner
2013-03-19 17:11     ` Vinicius Costa Gomes
2013-03-20 22:26 ` [PATCH v3 " Paulo Borges
2013-03-20 22:26   ` [PATCH v3 01/13] dundee: Rename dundee BlueZ 4 support Paulo Borges
2013-03-20 22:26   ` [PATCH v3 02/13] dundee: Start BlueZ 5 support Paulo Borges
2013-03-20 22:26   ` [PATCH v3 03/13] bluez5: Add DUN_UUID Paulo Borges
2013-03-20 22:26   ` [PATCH v3 04/13] dundee: Initial GDBusClient for BlueZ 5 Paulo Borges
2013-03-20 22:26   ` [PATCH v3 05/13] dundee: Add mechanism to store bluetooth devices Paulo Borges
2013-03-20 22:26   ` [PATCH v3 06/13] dundee: Add tracking of " Paulo Borges
2013-03-20 22:26   ` [PATCH v3 07/13] dundee: Listen to devices property changes Paulo Borges
2013-03-20 22:26   ` [PATCH v3 08/13] dundee: Add dundee device driver skeleton Paulo Borges
2013-03-20 22:26   ` [PATCH v3 09/13] dundee: Register/unregister dundee device Paulo Borges
2013-03-20 22:26   ` [PATCH v3 10/13] dundee: Add BlueZ Profile handler Paulo Borges
2013-03-20 22:26   ` [PATCH v3 11/13] dundee: Add support for driver connect Paulo Borges
2013-03-20 22:26   ` [PATCH v3 12/13] dundee: Add dundee disconnect function Paulo Borges
2013-03-20 22:26   ` [PATCH v3 13/13] dundee: Handle Profile connect and disconnect Paulo Borges
2013-03-24 12:31   ` [PATCH v3 00/13] Add support for BlueZ 5 Profile1 API to dundee Daniel Wagner
2013-03-25 14:43     ` Paulo Borges
2013-04-02 13:12       ` Daniel Wagner

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.