Skip to contentSkip to conversation

Add support for BlueZ 5 Profile1 API to dundee

PATCH Superseded Paulo Borges 3 participants 55 messages Mar 4, 2013 – Apr 2, 2013 Kbuild

lore
Share & tools
lore
#0 lore raw

cover Add support for BlueZ 5 Profile1 API to dundee

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
Signature · 1 line
1.7.9.5
#1 lore raw

PATCH 1/13 dundee: Rename dundee BlueZ 4 support

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
Makefile.am +1 -1
index 557f499..ed35988 100644
@@ -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
 
dundee/bluetooth.c deleted +0 -297

297 lines not on this page · raw message

dundee/bluez4.c new file +297 -0

297 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#2 lore raw

PATCH 2/13 dundee: Start BlueZ 5 support

In reply to Paulo Borges

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
Makefile.am +10 -6
index ed35988..1748d06 100644
@@ -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
dundee/bluez5.c new file +37 -0
new file mode 100644
index 0000000..6685b4c
@@ -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("");
+}
Signature · 1 line
1.7.9.5
#3 lore raw

Re: [PATCH 02/13] dundee: Start BlueZ 5 support

Hi Paulo,

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

Just a nitpick in this one.

Quoted 26 lines · Paulo Borges

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

Makefile.am +3 -5
index ed35988..1748d06 100644
@@ -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

Makefile.am endif · line 773

Quoted 10 lines
Makefile.am +0 -1
 
  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

#4 lore raw

PATCH 3/13 bluez5: Add DUN_UUID

In reply to Paulo Borges
---
 plugins/bluez5.h |    1 +
 1 file changed, 1 insertion(+)
plugins/bluez5.h +1 -0
index f7f3d7e..09654b7 100644
@@ -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"
 
Signature · 1 line
1.7.9.5
#5 lore raw

PATCH 4/13 dundee: Initial GDBusClient for BlueZ 5

In reply to Paulo Borges

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(+)
dundee/bluez5.c +60 -0
index 6685b4c..40df700 100644
@@ -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);
 }
dundee/dundee.h +2 -0
index db932b6..daf78a5 100644
@@ -26,6 +26,8 @@
 
 #include <ofono/types.h>
 
+#define DUN_VERSION_1_2 0x0102
+
 void __dundee_exit(void);
 
 enum dundee_error_type {
Signature · 1 line
1.7.9.5
#6 lore raw

Re: [PATCH 04/13] dundee: Initial GDBusClient for BlueZ 5

Hi Paulo,

Quoted 23 lines · Paulo Borges

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(+)
dundee/bluez5.c +7 -0
index 6685b4c..40df700 100644
@@ -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"

dundee/bluez5.c line 42

Quoted 10 lines
dundee/bluez5.c +10 -0
+
+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

#7 lore raw

PATCH 5/13 dundee: Add mechanism to store bluetooth devices

In reply to Paulo Borges

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(+)
dundee/bluez5.c +23 -0
index 40df700..970f3a2 100644
@@ -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);
 }
Signature · 1 line
1.7.9.5
#8 lore raw

PATCH 6/13 dundee: Add tracking of bluetooth devices

In reply to Paulo Borges

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(+)
dundee/bluez5.c +90 -0
index 970f3a2..8d8e656 100644
@@ -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,
Signature · 1 line
1.7.9.5
#9 lore raw

PATCH 7/13 dundee: Listen to devices property changes

In reply to Paulo Borges

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(-)
dundee/bluez5.c +25 -1
index 8d8e656..623201f 100644
@@ -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)
Signature · 1 line
1.7.9.5
#10 lore raw

Re: [PATCH 07/13] dundee: Listen to devices property changes

Hi Paulo,

Quoted 34 lines · Paulo Borges

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(-)
dundee/bluez5.c +15 -1
index 8d8e656..623201f 100644
@@ -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) {

dundee/bluez5.c static void property_changed(GDBusProxy *proxy, const char *name, · line 200

Quoted 10 lines
dundee/bluez5.c +10 -0
+		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

#11 lore raw

Re: [PATCH 07/13] dundee: Listen to devices property changes

Quoted 11 lines

dundee/bluez5.c static void property_changed(GDBusProxy *proxy, const char *name, · line 200

Quoted 8 lines
dundee/bluez5.c +8 -0
+        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

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

Obviously, some braces are needed :)

#12 lore raw

PATCH 8/13 dundee: Add dundee device driver skeleton

In reply to Paulo Borges

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(+)
dundee/bluez5.c +18 -0
index 623201f..19111e7 100644
@@ -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)
 {
Signature · 1 line
1.7.9.5
#13 lore raw

PATCH 9/13 dundee: Register/unregister dundee device

In reply to Paulo Borges

This patch adds the dundee device struct to the our Bluetooth device representation.

---
 dundee/bluez5.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
dundee/bluez5.c +25 -0
index 19111e7..12f0cf0 100644
@@ -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)
Signature · 1 line
1.7.9.5
#14 lore raw

PATCH 10/13 dundee: Add BlueZ Profile handler

In reply to Paulo Borges

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(+)
dundee/bluez5.c +68 -0
index 12f0cf0..becff32 100644
@@ -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);
 }
Signature · 1 line
1.7.9.5
#15 lore raw

PATCH 11/13 dundee: Add support for driver connect

In reply to Paulo Borges

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(-)
dundee/bluez5.c +6 -1
index becff32..31bdfea 100644
@@ -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,
Signature · 1 line
1.7.9.5
#16 lore raw

PATCH 12/13 dundee: Add dundee disconnect function

In reply to Paulo Borges
---
 dundee/device.c |   14 +++++++++++---
 dundee/dundee.h |    3 +++
 2 files changed, 14 insertions(+), 3 deletions(-)
dundee/device.c +11 -3
index e5f6424..2d84aaa 100644
@@ -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;
dundee/dundee.h +3 -0
index daf78a5..1889d84 100644
@@ -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);
 
Signature · 1 line
1.7.9.5
#17 lore raw

PATCH 13/13 dundee: Handle Profile connect and disconnect

In reply to Paulo Borges
---
 dundee/bluez5.c |  115 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 105 insertions(+), 10 deletions(-)
dundee/bluez5.c +105 -10
index 31bdfea..a92cbae 100644
@@ -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 = {
Signature · 1 line
1.7.9.5
#18 lore raw
In reply to Paulo Borges

Hi Paulo,

Quoted 6 lines · Paulo Borges

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

#19 lore raw

Hi Daniel,

Quoted 8 lines · Daniel Wagner

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

#20 lore raw

v2 cover Add support for BlueZ 5 Profile1 API to dundee

In reply to Paulo Borges

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
Signature · 1 line
1.7.9.5
#21 lore raw

PATCH v2 1/13 dundee: Rename dundee BlueZ 4 support

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
Makefile.am +1 -1
index 3b998af..3a7a8dc 100644
@@ -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
 
dundee/bluetooth.c deleted +0 -297

297 lines not on this page · raw message

dundee/bluez4.c new file +297 -0

297 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#22 lore raw

PATCH v2 2/13 dundee: Start BlueZ 5 support

In reply to Paulo Borges

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
Makefile.am +10 -5
index 3a7a8dc..44cf7d7 100644
@@ -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
dundee/bluez5.c new file +37 -0
new file mode 100644
index 0000000..6685b4c
@@ -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("");
+}
Signature · 1 line
1.7.9.5
#23 lore raw

PATCH v2 3/13 bluez5: Add DUN_UUID

In reply to Paulo Borges
---
 plugins/bluez5.h |    1 +
 1 file changed, 1 insertion(+)
plugins/bluez5.h +1 -0
index 573a54c..898a010 100644
@@ -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"
 
Signature · 1 line
1.7.9.5
#24 lore raw

PATCH v2 4/13 dundee: Initial GDBusClient for BlueZ 5

In reply to Paulo Borges

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(+)
dundee/bluez5.c +60 -0
index 6685b4c..1b2c8e1 100644
@@ -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);
 }
dundee/dundee.h +2 -0
index db932b6..daf78a5 100644
@@ -26,6 +26,8 @@
 
 #include <ofono/types.h>
 
+#define DUN_VERSION_1_2 0x0102
+
 void __dundee_exit(void);
 
 enum dundee_error_type {
Signature · 1 line
1.7.9.5
#25 lore raw

PATCH v2 5/13 dundee: Add mechanism to store bluetooth devices

In reply to Paulo Borges

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(+)
dundee/bluez5.c +23 -0
index 1b2c8e1..f2c9fed 100644
@@ -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);
 }
Signature · 1 line
1.7.9.5
#26 lore raw

PATCH v2 6/13 dundee: Add tracking of bluetooth devices

In reply to Paulo Borges

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(+)
dundee/bluez5.c +90 -0
index f2c9fed..ca44656 100644
@@ -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,
Signature · 1 line
1.7.9.5
#27 lore raw

PATCH v2 7/13 dundee: Listen to devices property changes

In reply to Paulo Borges

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(-)
dundee/bluez5.c +27 -1
index ca44656..d48aadf 100644
@@ -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)
Signature · 1 line
1.7.9.5
#28 lore raw

Re: [PATCH v2 07/13] dundee: Listen to devices property changes

Hi Paulo,

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

Quoted 36 lines · Paulo Borges

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(-)
dundee/bluez5.c +17 -1
index ca44656..d48aadf 100644
@@ -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);
+

dundee/bluez5.c static void property_changed(GDBusProxy *proxy, const char *name, · line 202

Quoted 10 lines
dundee/bluez5.c +10 -0
+		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.

dundee/bluez5.c static void property_changed(GDBusProxy *proxy, const char *name, · line 205

Quoted 4 lines
dundee/bluez5.c +0 -0
  }
 
  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

#29 lore raw

PATCH v2 8/13 dundee: Add dundee device driver skeleton

In reply to Paulo Borges

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(+)
dundee/bluez5.c +18 -0
index d48aadf..9568fde 100644
@@ -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)
 {
Signature · 1 line
1.7.9.5
#30 lore raw

PATCH v2 9/13 dundee: Register/unregister dundee device

In reply to Paulo Borges

This patch adds the dundee device struct to the our Bluetooth device representation.

---
 dundee/bluez5.c |   25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)
dundee/bluez5.c +25 -0
index 9568fde..b4f6918 100644
@@ -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)
Signature · 1 line
1.7.9.5
#31 lore raw

PATCH v2 10/13 dundee: Add BlueZ Profile handler

In reply to Paulo Borges

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(+)
dundee/bluez5.c +68 -0
index b4f6918..82bb7aa 100644
@@ -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);
 }
Signature · 1 line
1.7.9.5
#32 lore raw

PATCH v2 11/13 dundee: Add support for driver connect

In reply to Paulo Borges

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(-)
dundee/bluez5.c +6 -1
index 82bb7aa..2d10e5a 100644
@@ -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,
Signature · 1 line
1.7.9.5
#33 lore raw

Re: [PATCH v2 11/13] dundee: Add support for driver connect

Hi Paulo,

The series breaks to compile at this patch.

Quoted 18 lines · Paulo Borges

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(-)
dundee/bluez5.c +0 -0
index 82bb7aa..2d10e5a 100644
@@ -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)
  {

dundee/bluez5.c static void bluetooth_device_destroy(gpointer user_data) · line 125

Quoted 10 lines
dundee/bluez5.c +6 -1
-	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

#34 lore raw

PATCH v2 12/13 dundee: Add dundee disconnect function

In reply to Paulo Borges
---
 dundee/device.c |   14 +++++++++++---
 dundee/dundee.h |    3 +++
 2 files changed, 14 insertions(+), 3 deletions(-)
dundee/device.c +11 -3
index e5f6424..2d84aaa 100644
@@ -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;
dundee/dundee.h +3 -0
index daf78a5..1889d84 100644
@@ -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);
 
Signature · 1 line
1.7.9.5
#35 lore raw

PATCH v2 13/13 dundee: Handle Profile connect and disconnect

In reply to Paulo Borges
---
 dundee/bluez5.c |  115 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 105 insertions(+), 10 deletions(-)
dundee/bluez5.c +105 -10
index 2d10e5a..d859eae 100644
@@ -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 = {
Signature · 1 line
1.7.9.5
#36 lore raw
In reply to Paulo Borges

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

#37 lore raw

Hi Daniel,

Quoted 6 lines · Daniel Wagner

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,

Signature · 1 line
Vinicius
#38 lore raw

v3 cover Add support for BlueZ 5 Profile1 API to dundee

In reply to Paulo Borges

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
Signature · 1 line
1.7.9.5
#39 lore raw

PATCH v3 1/13 dundee: Rename dundee BlueZ 4 support

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
Makefile.am +1 -1
index 3b998af..3a7a8dc 100644
@@ -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
 
dundee/bluetooth.c deleted +0 -297

297 lines not on this page · raw message

dundee/bluez4.c new file +297 -0

297 lines not on this page · raw message

Signature · 1 line
1.7.9.5
#40 lore raw

PATCH v3 2/13 dundee: Start BlueZ 5 support

In reply to Paulo Borges

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
Makefile.am +10 -5
index 3a7a8dc..44cf7d7 100644
@@ -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
dundee/bluez5.c new file +37 -0
new file mode 100644
index 0000000..6685b4c
@@ -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("");
+}
Signature · 1 line
1.7.9.5
#41 lore raw

PATCH v3 3/13 bluez5: Add DUN_UUID

In reply to Paulo Borges
---
 plugins/bluez5.h |    1 +
 1 file changed, 1 insertion(+)
plugins/bluez5.h +1 -0
index 573a54c..898a010 100644
@@ -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"
 
Signature · 1 line
1.7.9.5
#42 lore raw

PATCH v3 4/13 dundee: Initial GDBusClient for BlueZ 5

In reply to Paulo Borges

This patch adds callbacks to track additions of BlueZ related interfaces.

---
 dundee/bluez5.c |   36 ++++++++++++++++++++++++++++++++++++
 dundee/dundee.h |    2 ++
 2 files changed, 38 insertions(+)
dundee/bluez5.c +36 -0
index 6685b4c..4ab7904 100644
@@ -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);
 }
dundee/dundee.h +2 -0
index db932b6..daf78a5 100644
@@ -26,6 +26,8 @@
 
 #include <ofono/types.h>
 
+#define DUN_VERSION_1_2 0x0102
+
 void __dundee_exit(void);
 
 enum dundee_error_type {
Signature · 1 line
1.7.9.5
#43 lore raw

PATCH v3 5/13 dundee: Add mechanism to store bluetooth devices

In reply to Paulo Borges

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(+)
dundee/bluez5.c +23 -0
index 4ab7904..7a9e0fe 100644
@@ -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);
 }
Signature · 1 line
1.7.9.5
#44 lore raw

PATCH v3 6/13 dundee: Add tracking of bluetooth devices

In reply to Paulo Borges

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(+)
dundee/bluez5.c +102 -0
index 7a9e0fe..3688753 100644
@@ -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)
Signature · 1 line
1.7.9.5
#45 lore raw

PATCH v3 7/13 dundee: Listen to devices property changes

In reply to Paulo Borges

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(+)
dundee/bluez5.c +15 -0
index 3688753..f0c51df 100644
@@ -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);
 }
Signature · 1 line
1.7.9.5
#46 lore raw

PATCH v3 8/13 dundee: Add dundee device driver skeleton

In reply to Paulo Borges

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(+)
dundee/bluez5.c +18 -0
index f0c51df..c78c445 100644
@@ -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)
 {
Signature · 1 line
1.7.9.5
#47 lore raw

PATCH v3 9/13 dundee: Register/unregister dundee device

In reply to Paulo Borges

This patch adds the dundee device struct to the our Bluetooth device representation.

---
 dundee/bluez5.c |   23 +++++++++++++++++++++++
 1 file changed, 23 insertions(+)
dundee/bluez5.c +23 -0
index c78c445..504e2e0 100644
@@ -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)
Signature · 1 line
1.7.9.5
#48 lore raw

PATCH v3 10/13 dundee: Add BlueZ Profile handler

In reply to Paulo Borges

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(+)
dundee/bluez5.c +68 -0
index 504e2e0..fdf015d 100644
@@ -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);
 }
Signature · 1 line
1.7.9.5
#49 lore raw

PATCH v3 11/13 dundee: Add support for driver connect

In reply to Paulo Borges

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(-)
dundee/bluez5.c +6 -1
index fdf015d..c5a5ff0 100644
@@ -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,
Signature · 1 line
1.7.9.5
#50 lore raw

PATCH v3 12/13 dundee: Add dundee disconnect function

In reply to Paulo Borges
---
 dundee/device.c |   14 +++++++++++---
 dundee/dundee.h |    3 +++
 2 files changed, 14 insertions(+), 3 deletions(-)
dundee/device.c +11 -3
index e5f6424..2d84aaa 100644
@@ -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;
dundee/dundee.h +3 -0
index daf78a5..1889d84 100644
@@ -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);
 
Signature · 1 line
1.7.9.5
#51 lore raw

PATCH v3 13/13 dundee: Handle Profile connect and disconnect

In reply to Paulo Borges
---
 dundee/bluez5.c |  115 ++++++++++++++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 105 insertions(+), 10 deletions(-)
dundee/bluez5.c +105 -10
index c5a5ff0..eb7f005 100644
@@ -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 = {
Signature · 1 line
1.7.9.5
#52 lore raw
In reply to Paulo Borges

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

#53 lore raw

Hi Daniel,

Quoted 10 lines · Daniel Wagner

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

#54 lore raw

Hi Paulo,

[sorry for the late response, was on vacation]

Quoted 22 lines · Paulo Borges

Hi Daniel,

On Sun, Mar 24, 2013 at 9:31 AM, Daniel Wagner <[email protected] <mailto:[email protected]>> 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.

Quoted 5 lines

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