* [RFC BlueZ v0 07/17] gatt: Implement UnregisterService
From: Claudio Takahasi @ 2013-11-27 20:50 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Alvaro Silva
In-Reply-To: <1385585457-26951-1-git-send-email-claudio.takahasi@openbossa.org>
From: Alvaro Silva <alvaro.silva@openbossa.org>
This patch implements UnregisterService method of ServiceManager1.
External applications may call this method to unregister a given
service without leaving the system bus.
---
src/gatt-dbus.c | 25 +++++++++++++++++++++++++
1 file changed, 25 insertions(+)
diff --git a/src/gatt-dbus.c b/src/gatt-dbus.c
index a53eed2..a7424d5 100644
--- a/src/gatt-dbus.c
+++ b/src/gatt-dbus.c
@@ -243,6 +243,31 @@ invalid:
static DBusMessage *unregister_service(DBusConnection *conn,
DBusMessage *msg, void *user_data)
{
+ struct external_app *eapp = user_data;
+ DBusMessageIter iter;
+ const char *path;
+ GSList *list;
+
+ DBG("Unregistering GATT Service");
+
+ if (dbus_message_iter_init(msg, &iter) == false)
+ return btd_error_invalid_args(msg);
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
+ return btd_error_invalid_args(msg);
+
+ dbus_message_iter_get_basic(&iter, &path);
+
+ list = g_slist_find_custom(external_apps, path, external_app_path_cmp);
+ if (list == NULL)
+ return btd_error_does_not_exist(msg);
+
+ eapp = list->data;
+ if (g_strcmp0(dbus_message_get_sender(msg), eapp->owner) != 0)
+ return btd_error_does_not_exist(msg);
+
+ g_dbus_remove_watch(conn, eapp->watch);
+
return dbus_message_new_method_return(msg);
}
--
1.8.3.1
^ permalink raw reply related
* [RFC BlueZ v0 06/17] gatt: Add external services tracking
From: Claudio Takahasi @ 2013-11-27 20:50 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Alvaro Silva
In-Reply-To: <1385585457-26951-1-git-send-email-claudio.takahasi@openbossa.org>
From: Alvaro Silva <alvaro.silva@openbossa.org>
All primary services declarations provided by an external application
will be automatically inserted in the attribute database.
---
src/gatt-dbus.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 106 insertions(+)
diff --git a/src/gatt-dbus.c b/src/gatt-dbus.c
index 69581a4..a53eed2 100644
--- a/src/gatt-dbus.c
+++ b/src/gatt-dbus.c
@@ -39,15 +39,21 @@
#include "log.h"
#include "error.h"
+#include "gatt.h"
#include "gatt-dbus.h"
+#define SERVICE_IFACE "org.bluez.Service1"
#define SERVICE_MGR_IFACE "org.bluez.ServiceManager1"
+#define REGISTER_TIMER 1
+
struct external_app {
char *owner;
char *path;
GDBusClient *client;
+ GSList *proxies;
unsigned int watch;
+ guint register_timer;
};
static GSList *external_apps = NULL;
@@ -60,6 +66,36 @@ static int external_app_path_cmp(gconstpointer a, gconstpointer b)
return g_strcmp0(eapp->path, path);
}
+static void proxy_added(GDBusProxy *proxy, void *user_data)
+{
+ struct external_app *eapp = user_data;
+ const char *interface, *path;
+
+ interface = g_dbus_proxy_get_interface(proxy);
+ path = g_dbus_proxy_get_path(proxy);
+
+ DBG("path %s iface %s", path, interface);
+
+ if (g_strcmp0(interface, SERVICE_IFACE) != 0)
+ return;
+
+ eapp->proxies = g_slist_append(eapp->proxies, proxy);
+}
+
+static void proxy_removed(GDBusProxy *proxy, void *user_data)
+{
+ struct external_app *eapp = user_data;
+ const char *interface, *path;
+
+ interface = g_dbus_proxy_get_interface(proxy);
+ path = g_dbus_proxy_get_path(proxy);
+
+ DBG("path %s iface %s", path, interface);
+
+ eapp->proxies = g_slist_remove(eapp->proxies, proxy);
+}
+
+
static void external_app_watch_destroy(gpointer user_data)
{
struct external_app *eapp = user_data;
@@ -70,6 +106,9 @@ static void external_app_watch_destroy(gpointer user_data)
g_dbus_client_unref(eapp->client);
+ if (eapp->register_timer)
+ g_source_remove(eapp->register_timer);
+
g_free(eapp->owner);
g_free(eapp->path);
g_free(eapp);
@@ -99,9 +138,72 @@ static struct external_app *new_external_app(DBusConnection *conn,
eapp->client = client;
eapp->path = g_strdup(path);
+ g_dbus_client_set_proxy_handlers(client, proxy_added, proxy_removed,
+ NULL, eapp);
+
return eapp;
}
+static int register_external_service(GDBusProxy *proxy)
+{
+ DBusMessageIter iter;
+ const char *uuid;
+ bt_uuid_t btuuid;
+
+ if (!g_dbus_proxy_get_property(proxy, "UUID", &iter))
+ return -EINVAL;
+
+ dbus_message_iter_get_basic(&iter, &uuid);
+
+ if (bt_string_to_uuid(&btuuid, uuid) < 0)
+ return -EINVAL;
+
+ if (btd_gatt_add_service(&btuuid) == NULL)
+ return -EINVAL;
+
+ return 0;
+}
+
+static gboolean finish_register(gpointer user_data)
+{
+ struct external_app *eapp = user_data;
+ GSList *list;
+
+ /*
+ * It is not possible to detect when the last proxy object
+ * was reported. "Proxy added" handler reports objects
+ * added on demand or returned by GetManagedObjects().
+ * This timer helps to register all the GATT declarations
+ * (services, characteristics and descriptors) after fetching
+ * all the D-Bus objects.
+ */
+
+ eapp->register_timer = 0;
+
+ for (list = eapp->proxies; list; list = g_slist_next(list)) {
+ const char *interface, *path;
+ GDBusProxy *proxy = list->data;
+
+ interface = g_dbus_proxy_get_interface(proxy);
+ path = g_dbus_proxy_get_path(proxy);
+
+ if (g_strcmp0(SERVICE_IFACE, interface) != 0)
+ continue;
+
+ if (g_strcmp0(path, eapp->path) != 0)
+ continue;
+
+ if (register_external_service(proxy) < 0) {
+ DBG("Inconsistent external service: %s", path);
+ continue;
+ }
+
+ DBG("External service: %s", path);
+ }
+
+ return FALSE;
+}
+
static DBusMessage *register_service(DBusConnection *conn,
DBusMessage *msg, void *user_data)
{
@@ -109,6 +211,8 @@ static DBusMessage *register_service(DBusConnection *conn,
DBusMessageIter iter;
const char *path;
+ DBG("Registering GATT Service");
+
if (dbus_message_iter_init(msg, &iter) == false)
goto invalid;
@@ -127,6 +231,8 @@ static DBusMessage *register_service(DBusConnection *conn,
external_apps = g_slist_prepend(external_apps, eapp);
DBG("New app %p: %s", eapp, path);
+ eapp->register_timer = g_timeout_add_seconds(REGISTER_TIMER,
+ finish_register, eapp);
return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
--
1.8.3.1
^ permalink raw reply related
* [RFC BlueZ v0 05/17] gatt: Add helper for creating GATT services
From: Claudio Takahasi @ 2013-11-27 20:50 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Andre Guedes
In-Reply-To: <1385585457-26951-1-git-send-email-claudio.takahasi@openbossa.org>
From: Andre Guedes <andre.guedes@openbossa.org>
This patch adds the btd_gatt_add_service() helper which adds a
GATT Service declaration to the local attribute database.
---
lib/uuid.c | 14 ++++++++++++++
lib/uuid.h | 2 ++
src/gatt.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
src/gatt.h | 10 ++++++++++
4 files changed, 76 insertions(+)
diff --git a/lib/uuid.c b/lib/uuid.c
index 4363aee..15d1321 100644
--- a/lib/uuid.c
+++ b/lib/uuid.c
@@ -276,3 +276,17 @@ int bt_uuid_strcmp(const void *a, const void *b)
{
return strcasecmp(a, b);
}
+
+int bt_uuid_len(const bt_uuid_t *uuid)
+{
+ switch (uuid->type) {
+ case BT_UUID16:
+ return 2;
+ case BT_UUID32:
+ return 4;
+ case BT_UUID128:
+ return 16;
+ default:
+ return 0;
+ }
+}
diff --git a/lib/uuid.h b/lib/uuid.h
index 87e0bd0..f8b2593 100644
--- a/lib/uuid.h
+++ b/lib/uuid.h
@@ -136,6 +136,8 @@ void bt_uuid_to_uuid128(const bt_uuid_t *src, bt_uuid_t *dst);
int bt_uuid_to_string(const bt_uuid_t *uuid, char *str, size_t n);
int bt_string_to_uuid(bt_uuid_t *uuid, const char *string);
+int bt_uuid_len(const bt_uuid_t *uuid);
+
#ifdef __cplusplus
}
#endif
diff --git a/src/gatt.c b/src/gatt.c
index 45fd9f8..86023a4 100644
--- a/src/gatt.c
+++ b/src/gatt.c
@@ -27,11 +27,61 @@
#include <glib.h>
+#include "adapter.h"
+#include "device.h"
+
#include "log.h"
+#include "lib/uuid.h"
+#include "attrib/att.h"
#include "gatt-dbus.h"
#include "gatt.h"
+/* Common GATT UUIDs */
+static const bt_uuid_t primary_uuid = { .type = BT_UUID16,
+ .value.u16 = GATT_PRIM_SVC_UUID };
+
+struct btd_attribute {
+ uint16_t handle;
+ bt_uuid_t type;
+ uint16_t value_len;
+ uint8_t value[0];
+};
+
+static GList *local_attribute_db = NULL;
+static uint16_t next_handle = 0x0001;
+
+static int local_database_add(uint16_t handle, struct btd_attribute *attr)
+{
+ attr->handle = handle;
+
+ local_attribute_db = g_list_append(local_attribute_db, attr);
+
+ return 0;
+}
+
+struct btd_attribute *btd_gatt_add_service(const bt_uuid_t *uuid)
+{
+ uint16_t len = bt_uuid_len(uuid);
+ struct btd_attribute *attr = g_malloc0(sizeof(struct btd_attribute) +
+ len);
+
+ memcpy(&attr->type, &primary_uuid, sizeof(primary_uuid));
+
+ att_put_uuid(*uuid, attr->value);
+ attr->value_len = len;
+
+ if (local_database_add(next_handle, attr) < 0) {
+ g_free(attr);
+ return NULL;
+ }
+
+ /* TODO: missing overflow checking */
+ next_handle = next_handle + 1;
+
+ return attr;
+}
+
void gatt_init(void)
{
DBG("Starting GATT server");
diff --git a/src/gatt.h b/src/gatt.h
index 03a68a1..41ca4b6 100644
--- a/src/gatt.h
+++ b/src/gatt.h
@@ -21,6 +21,16 @@
*
*/
+struct btd_attribute;
+
void gatt_init(void);
void gatt_cleanup(void);
+
+/* btd_gatt_add_service - Add a service declaration to local attribute database.
+ * @uuid: Service UUID.
+ *
+ * Returns a reference to service declaration attribute. In case of error,
+ * NULL is returned.
+ */
+struct btd_attribute *btd_gatt_add_service(const bt_uuid_t *uuid);
--
1.8.3.1
^ permalink raw reply related
* [RFC BlueZ v0 04/17] lib: Add GATT Primary Service UUID
From: Claudio Takahasi @ 2013-11-27 20:50 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <1385585457-26951-1-git-send-email-claudio.takahasi@openbossa.org>
---
lib/uuid.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/lib/uuid.h b/lib/uuid.h
index 95e5a9a..87e0bd0 100644
--- a/lib/uuid.h
+++ b/lib/uuid.h
@@ -105,6 +105,9 @@ extern "C" {
#define OBEX_MNS_UUID "00001133-0000-1000-8000-00805f9b34fb"
#define OBEX_MAP_UUID "00001134-0000-1000-8000-00805f9b34fb"
+/* GATT UUIDs section */
+#define GATT_PRIM_SVC_UUID 0x2800
+
typedef struct {
enum {
BT_UUID_UNSPEC = 0,
--
1.8.3.1
^ permalink raw reply related
* [RFC BlueZ v0 03/17] gatt: Add registering external service
From: Claudio Takahasi @ 2013-11-27 20:50 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Alvaro Silva
In-Reply-To: <1385585457-26951-1-git-send-email-claudio.takahasi@openbossa.org>
From: Alvaro Silva <alvaro.silva@openbossa.org>
This patch allows external applications register a given service on
Bluez. Applications must provide an object path and a dictionary of
options. Options dictionary will be used later to provide additional
service information.
---
src/gatt-dbus.c | 92 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 91 insertions(+), 1 deletion(-)
diff --git a/src/gatt-dbus.c b/src/gatt-dbus.c
index c28c33c..69581a4 100644
--- a/src/gatt-dbus.c
+++ b/src/gatt-dbus.c
@@ -26,22 +26,112 @@
#endif
#include <stdint.h>
+#include <errno.h>
#include <glib.h>
#include <dbus/dbus.h>
#include <gdbus/gdbus.h>
+#include "adapter.h"
+#include "device.h"
+#include "lib/uuid.h"
#include "dbus-common.h"
#include "log.h"
+#include "error.h"
#include "gatt-dbus.h"
#define SERVICE_MGR_IFACE "org.bluez.ServiceManager1"
+struct external_app {
+ char *owner;
+ char *path;
+ GDBusClient *client;
+ unsigned int watch;
+};
+
+static GSList *external_apps = NULL;
+
+static int external_app_path_cmp(gconstpointer a, gconstpointer b)
+{
+ const struct external_app *eapp = a;
+ const char *path = b;
+
+ return g_strcmp0(eapp->path, path);
+}
+
+static void external_app_watch_destroy(gpointer user_data)
+{
+ struct external_app *eapp = user_data;
+
+ /* TODO: Remove from the database */
+
+ external_apps = g_slist_remove(external_apps, eapp);
+
+ g_dbus_client_unref(eapp->client);
+
+ g_free(eapp->owner);
+ g_free(eapp->path);
+ g_free(eapp);
+}
+
+static struct external_app *new_external_app(DBusConnection *conn,
+ const char *sender, const char *path)
+{
+ struct external_app *eapp;
+ GDBusClient *client;
+
+ client = g_dbus_client_new(conn, sender, "/");
+ if (client == NULL)
+ return NULL;
+
+ eapp = g_new0(struct external_app, 1);
+
+ eapp->watch = g_dbus_add_disconnect_watch(btd_get_dbus_connection(),
+ sender, NULL, eapp, external_app_watch_destroy);
+ if (eapp->watch == 0) {
+ g_dbus_client_unref(client);
+ g_free(eapp);
+ return NULL;
+ }
+
+ eapp->owner = g_strdup(sender);
+ eapp->client = client;
+ eapp->path = g_strdup(path);
+
+ return eapp;
+}
+
static DBusMessage *register_service(DBusConnection *conn,
DBusMessage *msg, void *user_data)
{
- return dbus_message_new_method_return(msg);
+ struct external_app *eapp;
+ DBusMessageIter iter;
+ const char *path;
+
+ if (dbus_message_iter_init(msg, &iter) == false)
+ goto invalid;
+
+ if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_OBJECT_PATH)
+ goto invalid;
+
+ dbus_message_iter_get_basic(&iter, &path);
+
+ if (g_slist_find_custom(external_apps, path, external_app_path_cmp))
+ return btd_error_already_exists(msg);
+
+ eapp = new_external_app(conn, dbus_message_get_sender(msg), path);
+ if (eapp == NULL)
+ return btd_error_failed(msg, "Not enough resources");
+
+ external_apps = g_slist_prepend(external_apps, eapp);
+
+ DBG("New app %p: %s", eapp, path);
+
+ return g_dbus_create_reply(msg, DBUS_TYPE_INVALID);
+
+invalid:
+ return btd_error_invalid_args(msg);
}
static DBusMessage *unregister_service(DBusConnection *conn,
--
1.8.3.1
^ permalink raw reply related
* [RFC BlueZ v0 02/17] gatt: Register Manager D-Bus Interface
From: Claudio Takahasi @ 2013-11-27 20:50 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Alvaro Silva
In-Reply-To: <1385585457-26951-1-git-send-email-claudio.takahasi@openbossa.org>
From: Alvaro Silva <alvaro.silva@openbossa.org>
This patch registers the Service Manager D-Bus Interface. This
interface implements the methods to allow external application register
and unregister GATT Services.
---
Makefile.am | 1 +
src/gatt-dbus.c | 75 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
src/gatt-dbus.h | 25 +++++++++++++++++++
src/gatt.c | 9 +++++++
4 files changed, 110 insertions(+)
create mode 100644 src/gatt-dbus.c
create mode 100644 src/gatt-dbus.h
diff --git a/Makefile.am b/Makefile.am
index 395f23e..d88b1cb 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -146,6 +146,7 @@ src_bluetoothd_SOURCES = $(builtin_sources) \
src/adapter.h src/adapter.c \
src/profile.h src/profile.c \
src/service.h src/service.c \
+ src/gatt-dbus.h src/gatt-dbus.c \
src/gatt.h src/gatt.c \
src/device.h src/device.c src/attio.h \
src/dbus-common.c src/dbus-common.h \
diff --git a/src/gatt-dbus.c b/src/gatt-dbus.c
new file mode 100644
index 0000000..c28c33c
--- /dev/null
+++ b/src/gatt-dbus.c
@@ -0,0 +1,75 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * 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 as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 <stdint.h>
+
+#include <glib.h>
+#include <dbus/dbus.h>
+#include <gdbus/gdbus.h>
+
+#include "dbus-common.h"
+#include "log.h"
+
+#include "gatt-dbus.h"
+
+#define SERVICE_MGR_IFACE "org.bluez.ServiceManager1"
+
+static DBusMessage *register_service(DBusConnection *conn,
+ DBusMessage *msg, void *user_data)
+{
+ return dbus_message_new_method_return(msg);
+}
+
+static DBusMessage *unregister_service(DBusConnection *conn,
+ DBusMessage *msg, void *user_data)
+{
+ return dbus_message_new_method_return(msg);
+}
+
+static const GDBusMethodTable methods[] = {
+ { GDBUS_EXPERIMENTAL_METHOD("RegisterService",
+ GDBUS_ARGS({ "service", "o"},
+ { "options", "a{sv}"}),
+ NULL, register_service) },
+ { GDBUS_EXPERIMENTAL_METHOD("UnregisterService",
+ GDBUS_ARGS({"service", "o"}),
+ NULL, unregister_service) },
+ { }
+};
+
+gboolean gatt_dbus_manager_register(void)
+{
+ return g_dbus_register_interface(btd_get_dbus_connection(),
+ "/org/bluez", SERVICE_MGR_IFACE,
+ methods, NULL, NULL, NULL, NULL);
+}
+
+void gatt_dbus_manager_unregister(void)
+{
+ g_dbus_unregister_interface(btd_get_dbus_connection(), "/org/bluez",
+ SERVICE_MGR_IFACE);
+}
diff --git a/src/gatt-dbus.h b/src/gatt-dbus.h
new file mode 100644
index 0000000..7812ba1
--- /dev/null
+++ b/src/gatt-dbus.h
@@ -0,0 +1,25 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * 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 as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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
+ *
+ */
+
+gboolean gatt_dbus_manager_register(void);
+void gatt_dbus_manager_unregister(void);
diff --git a/src/gatt.c b/src/gatt.c
index 1ada2ed..45fd9f8 100644
--- a/src/gatt.c
+++ b/src/gatt.c
@@ -25,14 +25,23 @@
#include <config.h>
#endif
+#include <glib.h>
+
+#include "log.h"
+
+#include "gatt-dbus.h"
#include "gatt.h"
void gatt_init(void)
{
+ DBG("Starting GATT server");
+ gatt_dbus_manager_register();
}
void gatt_cleanup(void)
{
+ DBG("Stopping GATT server");
+ gatt_dbus_manager_unregister();
}
--
1.8.3.1
^ permalink raw reply related
* [RFC BlueZ v0 01/17] gatt: Add stub for gatt file
From: Claudio Takahasi @ 2013-11-27 20:50 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Alvaro Silva
In-Reply-To: <1385585457-26951-1-git-send-email-claudio.takahasi@openbossa.org>
From: Alvaro Silva <alvaro.silva@openbossa.org>
This file intend to implement functions to manipulate ATT transactions,
and expose functions to allow other entities to manage GATT based
services.
---
Makefile.am | 1 +
src/gatt.c | 38 ++++++++++++++++++++++++++++++++++++++
src/gatt.h | 26 ++++++++++++++++++++++++++
src/main.c | 4 ++++
4 files changed, 69 insertions(+)
create mode 100644 src/gatt.c
create mode 100644 src/gatt.h
diff --git a/Makefile.am b/Makefile.am
index 2bb2eb5..395f23e 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -146,6 +146,7 @@ src_bluetoothd_SOURCES = $(builtin_sources) \
src/adapter.h src/adapter.c \
src/profile.h src/profile.c \
src/service.h src/service.c \
+ src/gatt.h src/gatt.c \
src/device.h src/device.c src/attio.h \
src/dbus-common.c src/dbus-common.h \
src/eir.h src/eir.c \
diff --git a/src/gatt.c b/src/gatt.c
new file mode 100644
index 0000000..1ada2ed
--- /dev/null
+++ b/src/gatt.c
@@ -0,0 +1,38 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * 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 as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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 "gatt.h"
+
+void gatt_init(void)
+{
+
+}
+
+void gatt_cleanup(void)
+{
+
+}
diff --git a/src/gatt.h b/src/gatt.h
new file mode 100644
index 0000000..03a68a1
--- /dev/null
+++ b/src/gatt.h
@@ -0,0 +1,26 @@
+/*
+ *
+ * BlueZ - Bluetooth protocol stack for Linux
+ *
+ * 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 as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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
+ *
+ */
+
+void gatt_init(void);
+
+void gatt_cleanup(void);
diff --git a/src/main.c b/src/main.c
index 91d90b4..fccc838 100644
--- a/src/main.c
+++ b/src/main.c
@@ -55,6 +55,7 @@
#include "dbus-common.h"
#include "agent.h"
#include "profile.h"
+#include "gatt.h"
#include "systemd.h"
#define BLUEZ_NAME "org.bluez"
@@ -545,6 +546,8 @@ int main(int argc, char *argv[])
g_dbus_set_flags(gdbus_flags);
+ gatt_init();
+
if (option_compat == TRUE)
sdp_flags |= SDP_SERVER_COMPAT;
@@ -595,6 +598,7 @@ int main(int argc, char *argv[])
btd_profile_cleanup();
btd_agent_cleanup();
btd_device_cleanup();
+ gatt_cleanup();
adapter_cleanup();
--
1.8.3.1
^ permalink raw reply related
* [RFC BlueZ v0 00/17] GATT API: External Services
From: Claudio Takahasi @ 2013-11-27 20:50 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
This patchset implements the minimal support for managing local
services declarations. Based on "[RFC BlueZ v2] doc: Add GATT API"
Features:
* API for internal and external services declaration
* Unix socket for testing purpose: services are exported
through unix sockets to avoid breaking the current attribute
server.
How to test:
Replace bluetooth.conf and reload DBus settings
$gatttool -L --primary (or interactive mode)
Upstreaming plan (steps):
* GATT Server: External Services
* GATT Server: External Characteristics (Server)
* GATT Server: External Descriptors (Server)
* Remove ATTIO and automatic connection mechanism from userspace
* Replace attribute server
* Fix all GATT internal plugins
* GATT Client: Remote Services
* ...
Alvaro Silva (7):
gatt: Add stub for gatt file
gatt: Register Manager D-Bus Interface
gatt: Add registering external service
gatt: Add external services tracking
gatt: Implement UnregisterService
gatt: Register ATT command/event handler
gatt: Add Discover All Primary Services
Andre Guedes (1):
gatt: Add helper for creating GATT services
Claudio Takahasi (9):
lib: Add GATT Primary Service UUID
gatt: Add server unix socket
gattrib: Use default ATT LE MTU for non-standard sockets
test: Add external service GATT skeleton
test: Add signal handling for gatt-service
test: Add registering external service
gatttool: Add unix socket connect
gatttool: Add unix socket support for interactive mode
bluetooth.conf: Add ObjectManager interface
Makefile.am | 2 +
Makefile.tools | 5 +
attrib/gattrib.c | 16 +--
attrib/gatttool.c | 27 +++-
attrib/gatttool.h | 1 +
attrib/interactive.c | 18 +--
attrib/utils.c | 54 ++++++++
lib/uuid.c | 14 ++
lib/uuid.h | 5 +
src/bluetooth.conf | 1 +
src/gatt-dbus.c | 296 ++++++++++++++++++++++++++++++++++++++++
src/gatt-dbus.h | 25 ++++
src/gatt.c | 371 +++++++++++++++++++++++++++++++++++++++++++++++++++
src/gatt.h | 36 +++++
src/main.c | 4 +
test/gatt-service.c | 254 +++++++++++++++++++++++++++++++++++
16 files changed, 1106 insertions(+), 23 deletions(-)
create mode 100644 src/gatt-dbus.c
create mode 100644 src/gatt-dbus.h
create mode 100644 src/gatt.c
create mode 100644 src/gatt.h
create mode 100644 test/gatt-service.c
--
1.8.3.1
^ permalink raw reply
* [RFC BlueZ v2] doc: Add GATT API
From: Claudio Takahasi @ 2013-11-27 20:27 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Claudio Takahasi
In-Reply-To: <CAKT1EBdB7cvhmnqf2FV-F=RWwdnvhpUuc3AENHaYCao_dNyH_w@mail.gmail.com>
This patch proposes an unified GATT API for local and remote services.
---
v2: API similar to Profile1 and ProfileManager1
doc/gatt-api.txt | 145 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 145 insertions(+)
create mode 100644 doc/gatt-api.txt
diff --git a/doc/gatt-api.txt b/doc/gatt-api.txt
new file mode 100644
index 0000000..d2545b2
--- /dev/null
+++ b/doc/gatt-api.txt
@@ -0,0 +1,145 @@
+BlueZ D-Bus GATT API description
+********************************
+
+GATT local and remote services share the same high-level D-Bus API. Local
+refers to GATT based service exported by a BlueZ plugin or an external
+application. Remote refers to GATT services exported by the peer.
+
+BlueZ acts as a proxy, translating ATT operations to D-Bus method calls and
+Properties (or the opposite). Support for D-Bus Object Manager is mandatory for
+external services to allow seamless GATT declarations (Service, Characteristic
+and Descriptors) discovery.
+
+Service hierarchy
+=================
+
+GATT remote and local service representation. Object path for local services
+is freely definable.
+
+External applications implementing local services must register the services
+using ServiceManager1 registration method and must implement the methods and
+properties defined in Service1 interface.
+
+Service org.bluez
+Interface org.bluez.Service1 [Experimental]
+Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX
+
+Methods void Release()
+
+ Release this service. At this point, it will not be
+ used by BlueZ anymore and can be destroyed by the
+ owner. Method applicable to external GATT services
+ implementations only (GATT servers).
+
+Properties string UUID [read-only]
+
+ 128-bit service UUID.
+
+ array{object} Includes [read-only]: Not implemented
+
+ Array of object paths representing the included
+ services of this service.
+
+
+Characteristic hierarchy
+========================
+
+For local GATT defined services, the object paths need to follow the service
+path hierarchy and are freely definable.
+
+Service org.bluez
+Interface org.bluez.Characteristic1 [Experimental]
+Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX/charYYYY
+
+Properties string UUID [read-only]
+
+ 128-bit characteristic UUID.
+
+ object Service [read-only]
+
+ Object path of the GATT service the characteristc
+ belongs to.
+
+ array{byte} Value [read-write]
+
+ Value read from the remote Bluetooth device or from
+ the external application implementing GATT services.
+
+ array{string} Flags [read-only, optional]
+
+ Defines how the characteristic value can be used. See
+ Core spec page 1898, "Table 3.5: Characteristic
+ Properties bit field" and page 1900, "Table 3.8:
+ Characteristic Extended Properties bit field". Allowed
+ values: "broadcast", "read", "write-without-response",
+ "write", "notify", "indicate",
+ "authenticated-signed-writes", "reliable-write", and
+ "writable-auxiliaries".
+
+
+Characteristic Descriptors hierarchy
+====================================
+
+Local or remote GATT characteristic descriptors hierarchy.
+
+Service org.bluez
+Interface org.bluez.Descriptor1 [Experimental]
+Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX/charYYYY/descriptorZZZ
+
+Properties string UUID [read-only]
+
+ 128-bit descriptor UUID.
+
+ object Characteristic [read-only]
+
+ Object path of the GATT characteristc the descriptor
+ belongs to.
+
+ array{byte} Value [read-write]
+
+ Raw characteristic descriptor value read from the
+ remote Bluetooth device or from the external
+ application implementing GATT services.
+
+ string Permissions [read-only]: To be defined
+
+ Defines read/write authentication and authorization
+ requirements.
+
+Service Manager hierarchy
+=============================
+
+Service Manager allows external applications to register GATT based
+services. Services must follow the API for Service and Characteristic
+described above.
+
+Local GATT services, characteristics and characteristic descriptors are
+discovered automatically using the D-Bus Object Manager interface.
+
+Service org.bluez
+Interface org.bluez.ServiceManager1 [Experimental]
+Object path /org/bluez
+
+Methods RegisterService(object service, dict options)
+
+ Registers remote application service exported under
+ the interface Service1. Characteristic objects must
+ be hierarchical to their service and must use the
+ interface Characteristic1. D-Bus Object Manager is
+ used to fetch the exported objects.
+
+ "service" object path together with the D-Bus system
+ bus connection ID define the identification of the
+ application registering a GATT based service.
+
+ Possible errors: org.bluez.Error.InvalidArguments
+ org.bluez.Error.AlreadyExists
+
+ UnregisterService(object service)
+
+ This unregisters the service that has been
+ previously registered. The object path parameter
+ must match the same value that has been used
+ on registration.
+
+ Possible errors: org.bluez.Error.DoesNotExist
--
1.8.3.1
^ permalink raw reply related
* Re: [PATCH 3/5] android/main: Remove signal source on exit
From: Andrei Emeltchenko @ 2013-11-27 20:25 UTC (permalink / raw)
To: Bluetooth Linux
In-Reply-To: <1385569154-11579-3-git-send-email-Andrei.Emeltchenko.news@gmail.com>
Hi,
On Wed, Nov 27, 2013 at 6:19 PM, Andrei Emeltchenko
<Andrei.Emeltchenko.news@gmail.com> wrote:
> From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
>
> Remove signal source on exit and move check capability function in order
> to avoid extra check.
> ---
> android/main.c | 8 +++++---
> 1 file changed, 5 insertions(+), 3 deletions(-)
>
> diff --git a/android/main.c b/android/main.c
> index dd5c622..e408c21 100644
> --- a/android/main.c
> +++ b/android/main.c
> @@ -536,6 +536,9 @@ int main(int argc, char *argv[])
> GError *err = NULL;
> guint signal;
>
> + if (!set_capabilities())
> + return EXIT_FAILURE;
> +
Please disregard this patch, debug needs to be initialized first.
> /* Core Service (ID=0) should always be considered registered */
> services[0] = true;
>
> @@ -565,18 +568,17 @@ int main(int argc, char *argv[])
>
> __btd_log_init("*", 0);
>
> - if (!set_capabilities())
> - return EXIT_FAILURE;
> -
> bluetooth_start_timeout = g_timeout_add_seconds(STARTUP_GRACE_SECONDS,
> quit_eventloop, NULL);
> if (bluetooth_start_timeout == 0) {
> error("Failed to init startup timeout");
> + g_source_remove(signal);
> return EXIT_FAILURE;
> }
>
> if (!bt_bluetooth_start(option_index, adapter_ready)) {
> g_source_remove(bluetooth_start_timeout);
> + g_source_remove(signal);
> return EXIT_FAILURE;
> }
>
> --
> 1.8.3.2
>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at http://vger.kernel.org/majordomo-info.html
^ permalink raw reply
* Re: [RFC BlueZ v1] doc: Add GATT API
From: Claudio Takahasi @ 2013-11-27 19:45 UTC (permalink / raw)
To: Scott James Remnant; +Cc: linux-bluetooth@vger.kernel.org
In-Reply-To: <CAHZ1yCmKocpuqhZXA_-=sxR6SPmfB1UdcRYH93evneM_nCqU7Q@mail.gmail.com>
Hi Scott:
On Fri, Nov 15, 2013 at 4:47 PM, Scott James Remnant <keybuk@google.com> wrote:
> On Tue, Nov 12, 2013 at 10:49 AM, Claudio Takahasi
> <claudio.takahasi@openbossa.org> wrote:
>
>> On Mon, Nov 11, 2013 at 3:56 PM, Scott James Remnant <keybuk@google.com> wrote:
>>> How will service changed be handled? How will BlueZ track the set of
>>> applications, and the set of services etc. defined by those
>>> applications in a manner that keeps handles consistent? How will it
>>> handle generating the Services Changed notification in the cases where
>>> the set of applications and/or services change, or the handles change?
>>
>> We implemented a hash of declarations. Using the "Id" provided in the
>> options dictionary (see RegisterAgent) we are able to identity if the
>> external service changed its attributes.
>> However, I don' t think we will upstream this approach soon, Marcel
>> wants a simpler approach: always send ServiceChanged.
>>
>
> While this is probably "spec sufficient", and probably sufficient for
> passing qualification, I'm not sure that this is necessarily the best
> approach since this means that BlueZ when acting as a GATT Server
> wouldn't be behaving quite the same as, say, a commodity BTLE device.
>
>>>> +Characteristic hierarchy
>>>> +========================
>>> :
>>>> +Service org.bluez
>>>> +Interface org.bluez.Characteristic1 [Experimental]
>>>> +Object path [variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX/serviceXX/charYYYY
>>>
>>> This would also need a "Permissions" property akin to the one you have
>>> for Descriptors - characteristics can be "not accessible", read-only,
>>> write-only, read/write - and can also require authorization,
>>> authentication, encryption and minimum encryption key sizes - as with
>>> descriptors.
>>
>> It is implemented already, there is an optional "Flags" property :
>> "array{string} Flags [read-only, optional]"
>>
>
> Flags seemed to correspond to the Flags characteristic descriptor and
> not the simple permissions of the characteristic itself.
"Flags" refers to Core SPEC page 1898: "3.3.1.1 Characteristic Properties"
The naming is not helping here. The original suggestion was
"Properties", but it may mislead to D-Bus Properties.
>
>>>> + array{byte} Value [read-write]
>>>> +
>>>> + Cached Value of the characteristic. If present, the
>>>> + value will be cached by bluetoothd and updated when the
>>>> + PropertiesChanged signal is emitted.
>>>> +
>>>> + External services must emit this signal when the
>>>> + characteristic supports notification/indication, so
>>>> + that clients can be notified of the new value.
>>>
>>> The PropertiesChanged signal explains how Notification will be handled
>>> - but how will Indication? How will a service receive the Indication
>>> Confirmation from the remote devices?
>>
>> The bluetoothd core manages the Confirmation. In my opinion clients
>> listening for PropertiesChanged don' t need to know the difference
>> between notification and indication.
>> Allow an external client to manage the Confirmation will insert
>> additional complexity without giving real benefits.
>>
>
> I'm thinking of the opposite way around - not the clients, but the services.
>
> If I implement a service over the D-Bus API, and a characteristic
> supports Indication, then is it not important that the service be
> informed when the clients confirm the Indication that is sent out?
I understand your concerns. However, moving this control to the
servers may require persistence, and access to device and connection
information in the server implementation.
One alternative could be extend the ApplcationAgent1 interface adding
a method to inform timeout (confirmation not received for a given
characteristic).
>
> Otherwise it makes Indications identical to Notifications when
> implementing a service using the BlueZ D-Bus API, which may cause
> issues with implementing certain profiles.
We can assume that Indication has higher priority, and the Properties
( Indication/Notification) can be inferred during the declaration.
>
>
>>>> +Application Agent hierarchy
>>>> +===========================
>>>> +
>>>> +Service unique name
>>>> +Interface org.bluez.ApplicationAgent1 [Experimental]
>>>> +Object path freely definable
>>>> +
>>>
>>> "Agent" seems unnnecessary here - if the object is an Application,
>>> then org.bluez.Application1 would be a decent enough name. Thus an
>>> "Application" consists of multiple Services, each of which consists of
>>> multiple Characteristics, each of which has multiple Descriptors
>>
>> IMO "Agent" gives a better association with its functionality, it
>> reminds me org.bluez.Agent1.
>> Let's wait the opinion of the others developers...
>>
>
> I was more thinking that we have "AgentManager" -> "Agent",
> "ProfileManager" -> "Profile", "ServiceManager" -> "Service" ... all
> of those use the agent-style pattern, but only "Pairing" Agent is
> called Agent.
>
> But honestly, bike shedding ;-) I'm only complaining because calling
> it "ApplicationAgent" would slightly screw up my naming convention
> inside Chromium
My first proposal was ServiceManager1 and Service1.
Maybe renaming the registration method to RegisterService() and moving
Release method to Service1 will make it similar to Profile1, and
easier to understand. Potential errors can be reported through a
method under Service1 interface.
However, this last suggestion will trigger unneeded calls of
GetManagedObjects(), basically one call per service registration.
I will try a new round based on your inputs and wait for feedbacks.
Regards,
Claudio
^ permalink raw reply
* [PATCH 5/5] android/socket: Fix rfsock lists
From: Andrei Emeltchenko @ 2013-11-27 16:19 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385569154-11579-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This fixes several places where rfsock structure were not removed
from the list due to connection errors.
---
android/socket.c | 9 ++++++---
1 file changed, 6 insertions(+), 3 deletions(-)
diff --git a/android/socket.c b/android/socket.c
index d55db54..3f07dc6 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -625,8 +625,6 @@ static void accept_cb(GIOChannel *io, GError *err, gpointer user_data)
return;
}
- connections = g_list_append(connections, rfsock_acc);
-
DBG("rfsock: fd %d real_sock %d chan %u sock %d",
rfsock->fd, rfsock->real_sock, rfsock->channel,
sock_acc);
@@ -636,6 +634,8 @@ static void accept_cb(GIOChannel *io, GError *err, gpointer user_data)
return;
}
+ connections = g_list_append(connections, rfsock_acc);
+
/* Handle events from Android */
cond = G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL;
io_stack = g_io_channel_unix_new(rfsock_acc->fd);
@@ -700,7 +700,6 @@ static int handle_listen(void *buf)
}
rfsock->real_sock = g_io_channel_unix_get_fd(io);
- servers = g_list_append(servers, rfsock);
/* TODO: Add server watch */
g_io_channel_set_close_on_unref(io, TRUE);
@@ -717,6 +716,8 @@ static int handle_listen(void *buf)
rfsock->service_handle = sdp_service_register(profile, cmd->name);
+ servers = g_list_append(servers, rfsock);
+
return hal_fd;
}
@@ -787,6 +788,7 @@ static void connect_cb(GIOChannel *io, GError *err, gpointer user_data)
return;
fail:
+ connections = g_list_remove(connections, rfsock);
cleanup_rfsock(rfsock);
}
@@ -865,6 +867,7 @@ static void sdp_search_cb(sdp_list_t *recs, int err, gpointer data)
return;
fail:
+ connections = g_list_remove(connections, rfsock);
cleanup_rfsock(rfsock);
}
--
1.8.3.2
^ permalink raw reply related
* [PATCH 4/5] android/socket: Cleanup sockets on unregister
From: Andrei Emeltchenko @ 2013-11-27 16:19 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385569154-11579-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This cleans up rfsock structures closing all sockets and making general cleanup
for servers and for connections. This will be called form socket unregister.
---
android/socket.c | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/android/socket.c b/android/socket.c
index 1fb154d..d55db54 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -943,7 +943,27 @@ bool bt_socket_register(int sk, const bdaddr_t *addr)
return true;
}
+static void free_connection(gpointer data, gpointer user_data)
+{
+ struct rfcomm_sock *rfsock = data;
+
+ connections = g_list_remove(connections, rfsock);
+ cleanup_rfsock(rfsock);
+}
+
+static void free_server(gpointer data, gpointer user_data)
+{
+ struct rfcomm_sock *rfsock = data;
+
+ servers = g_list_remove(servers, rfsock);
+ cleanup_rfsock(rfsock);
+}
+
void bt_socket_unregister(void)
{
DBG("");
+
+ g_list_foreach(connections, free_connection, NULL);
+
+ g_list_foreach(servers, free_server, NULL);
}
--
1.8.3.2
^ permalink raw reply related
* [PATCH 3/5] android/main: Remove signal source on exit
From: Andrei Emeltchenko @ 2013-11-27 16:19 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385569154-11579-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Remove signal source on exit and move check capability function in order
to avoid extra check.
---
android/main.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/android/main.c b/android/main.c
index dd5c622..e408c21 100644
--- a/android/main.c
+++ b/android/main.c
@@ -536,6 +536,9 @@ int main(int argc, char *argv[])
GError *err = NULL;
guint signal;
+ if (!set_capabilities())
+ return EXIT_FAILURE;
+
/* Core Service (ID=0) should always be considered registered */
services[0] = true;
@@ -565,18 +568,17 @@ int main(int argc, char *argv[])
__btd_log_init("*", 0);
- if (!set_capabilities())
- return EXIT_FAILURE;
-
bluetooth_start_timeout = g_timeout_add_seconds(STARTUP_GRACE_SECONDS,
quit_eventloop, NULL);
if (bluetooth_start_timeout == 0) {
error("Failed to init startup timeout");
+ g_source_remove(signal);
return EXIT_FAILURE;
}
if (!bt_bluetooth_start(option_index, adapter_ready)) {
g_source_remove(bluetooth_start_timeout);
+ g_source_remove(signal);
return EXIT_FAILURE;
}
--
1.8.3.2
^ permalink raw reply related
* [PATCH 2/5] android/main: Remove timeout source on exit
From: Andrei Emeltchenko @ 2013-11-27 16:19 UTC (permalink / raw)
To: linux-bluetooth
In-Reply-To: <1385569154-11579-1-git-send-email-Andrei.Emeltchenko.news@gmail.com>
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
This fixes memory leak types of warnings from some tools.
---
android/main.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/android/main.c b/android/main.c
index 830eef2..dd5c622 100644
--- a/android/main.c
+++ b/android/main.c
@@ -575,8 +575,10 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
- if (!bt_bluetooth_start(option_index, adapter_ready))
+ if (!bt_bluetooth_start(option_index, adapter_ready)) {
+ g_source_remove(bluetooth_start_timeout);
return EXIT_FAILURE;
+ }
/* Use params: mtu = 0, flags = 0 */
start_sdp_server(0, 0);
@@ -589,6 +591,9 @@ int main(int argc, char *argv[])
g_source_remove(signal);
+ if (bluetooth_start_timeout > 0)
+ g_source_remove(bluetooth_start_timeout);
+
cleanup_hal_connection();
stop_sdp_server();
bt_bluetooth_cleanup();
--
1.8.3.2
^ permalink raw reply related
* [PATCH 1/5] android: Avoid memory leak warnings for event_loop
From: Andrei Emeltchenko @ 2013-11-27 16:19 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Move creation of event_loop closer to g_main_loop_run. This avoids
calling g_main_loop_unref too many times in initialization error paths.
This is safe since g_main_loop_quit eval to NOOP if parameter == NULL.
---
android/main.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/android/main.c b/android/main.c
index bfd2a87..830eef2 100644
--- a/android/main.c
+++ b/android/main.c
@@ -559,7 +559,6 @@ int main(int argc, char *argv[])
exit(EXIT_SUCCESS);
}
- event_loop = g_main_loop_new(NULL, FALSE);
signal = setup_signalfd();
if (!signal)
return EXIT_FAILURE;
@@ -584,6 +583,8 @@ int main(int argc, char *argv[])
DBG("Entering main loop");
+ event_loop = g_main_loop_new(NULL, FALSE);
+
g_main_loop_run(event_loop);
g_source_remove(signal);
--
1.8.3.2
^ permalink raw reply related
* [RFC] build: Force GLib version check while building in maintainer mode
From: Szymon Janc @ 2013-11-27 15:44 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
This will allow to catch up build errors introduced by using GLib API
introduced in newer GLib than minimal required even if building with
newer version.
---
acinclude.m4 | 2 ++
1 file changed, 2 insertions(+)
diff --git a/acinclude.m4 b/acinclude.m4
index 5bfa29d..2065852 100644
--- a/acinclude.m4
+++ b/acinclude.m4
@@ -21,6 +21,8 @@ AC_DEFUN([COMPILER_FLAGS], [
with_cflags="$with_cflags -Wredundant-decls"
with_cflags="$with_cflags -Wcast-align"
with_cflags="$with_cflags -DG_DISABLE_DEPRECATED"
+ with_cflags="$with_cflags -DGLIB_VERSION_MIN_REQUIRED=GLIB_VERSION_2_28"
+ with_cflags="$with_cflags -DGLIB_VERSION_MAX_ALLOWED=GLIB_VERSION_2_28"
fi
AC_SUBST([WARNING_CFLAGS], $with_cflags)
])
--
1.8.3.2
^ permalink raw reply related
* [PATCH] android: Avoid memory leak warnings for event_loop
From: Andrei Emeltchenko @ 2013-11-27 15:17 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Move creation of event_loop closer to g_main_loop_run. This avoids
calling g_main_loop_unref too many times in initialization error paths.
This is safe since g_main_loop_quit eval to NOOP if parameter == NULL.
---
android/main.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/android/main.c b/android/main.c
index c9733f3..9eaef7f 100644
--- a/android/main.c
+++ b/android/main.c
@@ -558,7 +558,6 @@ int main(int argc, char *argv[])
exit(EXIT_SUCCESS);
}
- event_loop = g_main_loop_new(NULL, FALSE);
signal = setup_signalfd();
if (!signal)
return EXIT_FAILURE;
@@ -583,6 +582,8 @@ int main(int argc, char *argv[])
DBG("Entering main loop");
+ event_loop = g_main_loop_new(NULL, FALSE);
+
g_main_loop_run(event_loop);
g_source_remove(signal);
--
1.8.3.2
^ permalink raw reply related
* [PATCH] android/main: Remove signal source on exit
From: Andrei Emeltchenko @ 2013-11-27 14:54 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
Remove signal source on exit and move check capability function in order
to avoid extra check.
---
android/main.c | 8 +++++---
1 file changed, 5 insertions(+), 3 deletions(-)
diff --git a/android/main.c b/android/main.c
index 79e17fe..0f478c7 100644
--- a/android/main.c
+++ b/android/main.c
@@ -535,6 +535,9 @@ int main(int argc, char *argv[])
GError *err = NULL;
guint signal;
+ if (!set_capabilities())
+ return EXIT_FAILURE;
+
/* Core Service (ID=0) should always be considered registered */
services[0] = true;
@@ -564,18 +567,17 @@ int main(int argc, char *argv[])
__btd_log_init("*", 0);
- if (!set_capabilities())
- return EXIT_FAILURE;
-
bluetooth_start_timeout = g_timeout_add_seconds(STARTUP_GRACE_SECONDS,
quit_eventloop, NULL);
if (bluetooth_start_timeout == 0) {
error("Failed to init startup timeout");
+ g_source_remove(signal);
return EXIT_FAILURE;
}
if (!bt_bluetooth_start(option_index, adapter_ready)) {
g_source_remove(bluetooth_start_timeout);
+ g_source_remove(signal);
return EXIT_FAILURE;
}
--
1.8.3.2
^ permalink raw reply related
* [PATCH] android/main: Remove timeout source on exit
From: Andrei Emeltchenko @ 2013-11-27 14:51 UTC (permalink / raw)
To: linux-bluetooth
From: Andrei Emeltchenko <andrei.emeltchenko@intel.com>
---
android/main.c | 7 ++++++-
1 file changed, 6 insertions(+), 1 deletion(-)
diff --git a/android/main.c b/android/main.c
index 9eaef7f..79e17fe 100644
--- a/android/main.c
+++ b/android/main.c
@@ -574,8 +574,10 @@ int main(int argc, char *argv[])
return EXIT_FAILURE;
}
- if (!bt_bluetooth_start(option_index, adapter_ready))
+ if (!bt_bluetooth_start(option_index, adapter_ready)) {
+ g_source_remove(bluetooth_start_timeout);
return EXIT_FAILURE;
+ }
/* Use params: mtu = 0, flags = 0 */
start_sdp_server(0, 0);
@@ -588,6 +590,9 @@ int main(int argc, char *argv[])
g_source_remove(signal);
+ if (bluetooth_start_timeout)
+ g_source_remove(bluetooth_start_timeout);
+
cleanup_hal_connection();
stop_sdp_server();
bt_bluetooth_cleanup();
--
1.8.3.2
^ permalink raw reply related
* Re: Crasher during remote initiated pairing
From: Bastien Nocera @ 2013-11-27 13:58 UTC (permalink / raw)
To: Johan Hedberg; +Cc: linux-bluetooth
In-Reply-To: <20131127090605.GA28918@x220.p-661hnu-f1>
On Wed, 2013-11-27 at 11:06 +0200, Johan Hedberg wrote:
<snip>
> The agent_auth_cb is actually not used for pairing but for
> authorization, so whether it's RequestPinCode or RequestPasskey wont
> matter for the above backtrace. Anyway, I was never able to reproduce
> the exact same issue as you had, but I did find two places needing some
> extra checks (one in adapter.c and another in agent.c). So it'd be good
> if you could give the latest git a spin and see if you can still
> reproduce the crash.
That seems to work fine, thanks.
^ permalink raw reply
* [PATCH 13/13] android/hal-bluetooth: Fix sending invalid adapter property
From: Szymon Janc @ 2013-11-27 11:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1385553305-5807-1-git-send-email-szymon.janc@tieto.com>
If property to be set is of enum type it should be first converted to
byte value as size of enum might varry depending on architecture.
To keep code simple command buffer uses len received from framework
as this is more or equal to HAL property size.
---
android/hal-bluetooth.c | 36 +++++++++++++++++++++++++++++++-----
android/socket.c | 2 +-
2 files changed, 32 insertions(+), 6 deletions(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index f232afd..87d6fc7 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -35,6 +35,18 @@ static const bt_callbacks_t *bt_hal_cbacks = NULL;
e = *((uint8_t *) (hal_prop->val)); \
} while (0)
+#define enum_prop_from_hal(prop, hal_len, hal_val, enum_type) do { \
+ enum_type e; \
+ if (prop->len != sizeof(e)) { \
+ error("invalid HAL property %u (%u vs %zu), aborting ", \
+ prop->type, prop->len, sizeof(e)); \
+ exit(EXIT_FAILURE); \
+ } \
+ memcpy(&e, prop->val, sizeof(e)); \
+ *((uint8_t *) hal_val) = e; /* enums are mapped to 1 byte */ \
+ *hal_len = 1; \
+} while (0)
+
static void handle_adapter_state_changed(void *buf, uint16_t len)
{
struct hal_ev_adapter_state_changed *ev = buf;
@@ -91,6 +103,23 @@ static void adapter_props_to_hal(bt_property_t *send_props,
exit(EXIT_FAILURE);
}
+static void adapter_prop_from_hal(const bt_property_t *property, uint8_t *type,
+ uint16_t *len, void *val)
+{
+ /* type match IPC type */
+ *type = property->type;
+
+ switch(property->type) {
+ case HAL_PROP_ADAPTER_SCAN_MODE:
+ enum_prop_from_hal(property, len, val, bt_scan_mode_t);
+ break;
+ default:
+ *len = property->len;
+ memcpy(val, property->val, property->len);
+ break;
+ }
+}
+
static void device_props_to_hal(bt_property_t *send_props,
struct hal_property *prop, uint8_t num_props,
uint16_t len)
@@ -458,13 +487,10 @@ static int set_adapter_property(const bt_property_t *property)
if (!interface_ready())
return BT_STATUS_NOT_READY;
- /* type match IPC type */
- cmd->type = property->type;
- cmd->len = property->len;
- memcpy(cmd->val, property->val, property->len);
+ adapter_prop_from_hal(property, &cmd->type, &cmd->len, cmd->val);
return hal_ipc_cmd(HAL_SERVICE_ID_BLUETOOTH, HAL_OP_SET_ADAPTER_PROP,
- sizeof(buf), cmd, 0, NULL, NULL);
+ sizeof(*cmd) + cmd->len, cmd, 0, NULL, NULL);
}
static int get_remote_device_properties(bt_bdaddr_t *remote_addr)
diff --git a/android/socket.c b/android/socket.c
index ba97d8a..7fcb091 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -890,7 +890,7 @@ static void handle_connect(const void *buf, uint16_t len)
rfsock = create_rfsock(-1, &hal_fd);
if (!rfsock)
- return -1;
+ goto fail;
android2bdaddr(cmd->bdaddr, &rfsock->dst);
--
1.8.3.2
^ permalink raw reply related
* [PATCH 12/13] android/hal-bluetooth: Rename create_enum_prop to enum_prop_to_hal
From: Szymon Janc @ 2013-11-27 11:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1385553305-5807-1-git-send-email-szymon.janc@tieto.com>
This better describes purpose of this macro.
---
android/hal-bluetooth.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/android/hal-bluetooth.c b/android/hal-bluetooth.c
index a879583..f232afd 100644
--- a/android/hal-bluetooth.c
+++ b/android/hal-bluetooth.c
@@ -28,7 +28,7 @@
static const bt_callbacks_t *bt_hal_cbacks = NULL;
-#define create_enum_prop(prop, hal_prop, type) do { \
+#define enum_prop_to_hal(prop, hal_prop, type) do { \
static type e; \
prop.val = &e; \
prop.len = sizeof(e); \
@@ -63,11 +63,11 @@ static void adapter_props_to_hal(bt_property_t *send_props,
switch (prop->type) {
case HAL_PROP_ADAPTER_TYPE:
- create_enum_prop(send_props[i], prop,
+ enum_prop_to_hal(send_props[i], prop,
bt_device_type_t);
break;
case HAL_PROP_ADAPTER_SCAN_MODE:
- create_enum_prop(send_props[i], prop,
+ enum_prop_to_hal(send_props[i], prop,
bt_scan_mode_t);
break;
case HAL_PROP_ADAPTER_SERVICE_REC:
@@ -109,7 +109,7 @@ static void device_props_to_hal(bt_property_t *send_props,
switch (prop->type) {
case HAL_PROP_DEVICE_TYPE:
- create_enum_prop(send_props[i], prop,
+ enum_prop_to_hal(send_props[i], prop,
bt_device_type_t);
break;
case HAL_PROP_DEVICE_SERVICE_REC:
--
1.8.3.2
^ permalink raw reply related
* [PATCH 11/13] android/socket: Use generic IPC message handling for commands
From: Szymon Janc @ 2013-11-27 11:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1385553305-5807-1-git-send-email-szymon.janc@tieto.com>
Handlers are registered on service register and unregistered on
unregister.
---
android/socket.c | 111 +++++++++++++++++++++++++++++--------------------------
1 file changed, 59 insertions(+), 52 deletions(-)
diff --git a/android/socket.c b/android/socket.c
index 47338e7..ba97d8a 100644
--- a/android/socket.c
+++ b/android/socket.c
@@ -52,6 +52,7 @@
#define SVC_HINT_OBEX 0x10
+static int command_sk = -1;
static bdaddr_t adapter_addr;
/* Simple list of RFCOMM server sockets */
@@ -655,15 +656,15 @@ static void accept_cb(GIOChannel *io, GError *err, gpointer user_data)
rfsock_acc->rfcomm_watch);
}
-static int handle_listen(void *buf)
+static void handle_listen(const void *buf, uint16_t len)
{
- struct hal_cmd_sock_listen *cmd = buf;
+ const struct hal_cmd_sock_listen *cmd = buf;
const struct profile_info *profile;
- struct rfcomm_sock *rfsock;
+ struct rfcomm_sock *rfsock = NULL;
BtIOSecLevel sec_level;
GIOChannel *io;
GError *err = NULL;
- int hal_fd;
+ int hal_fd = -1;
int chan;
DBG("");
@@ -671,11 +672,10 @@ static int handle_listen(void *buf)
profile = get_profile_by_uuid(cmd->uuid);
if (!profile) {
if (!cmd->channel)
- return -1;
- else {
- chan = cmd->channel;
- sec_level = BT_IO_SEC_MEDIUM;
- }
+ goto fail;
+
+ chan = cmd->channel;
+ sec_level = BT_IO_SEC_MEDIUM;
} else {
chan = profile->channel;
sec_level = profile->sec_level;
@@ -685,7 +685,7 @@ static int handle_listen(void *buf)
rfsock = create_rfsock(-1, &hal_fd);
if (!rfsock)
- return -1;
+ goto fail;
io = bt_io_listen(accept_cb, NULL, rfsock, NULL, &err,
BT_IO_OPT_SOURCE_BDADDR, &adapter_addr,
@@ -695,8 +695,7 @@ static int handle_listen(void *buf)
if (!io) {
error("Failed listen: %s", err->message);
g_error_free(err);
- cleanup_rfsock(rfsock);
- return -1;
+ goto fail;
}
rfsock->real_sock = g_io_channel_unix_get_fd(io);
@@ -711,13 +710,25 @@ static int handle_listen(void *buf)
if (write(rfsock->fd, &chan, sizeof(chan)) != sizeof(chan)) {
error("Error sending RFCOMM channel");
- cleanup_rfsock(rfsock);
- return -1;
+ goto fail;
}
rfsock->service_handle = sdp_service_register(profile, cmd->name);
- return hal_fd;
+ ipc_send(command_sk, HAL_SERVICE_ID_SOCK, HAL_OP_SOCK_LISTEN, 0, NULL,
+ hal_fd);
+ close(hal_fd);
+ return;
+
+fail:
+ ipc_send_rsp(command_sk, HAL_SERVICE_ID_SOCK, HAL_OP_SOCK_LISTEN,
+ HAL_STATUS_FAILED);
+
+ if (rfsock)
+ cleanup_rfsock(rfsock);
+
+ if (hal_fd >= 0)
+ close(hal_fd);
}
static bool sock_send_connect(struct rfcomm_sock *rfsock, bdaddr_t *bdaddr)
@@ -868,9 +879,9 @@ fail:
cleanup_rfsock(rfsock);
}
-static int handle_connect(void *buf)
+static void handle_connect(const void *buf, uint16_t len)
{
- struct hal_cmd_sock_connect *cmd = buf;
+ const struct hal_cmd_sock_connect *cmd = buf;
struct rfcomm_sock *rfsock;
uuid_t uuid;
int hal_fd = -1;
@@ -893,57 +904,53 @@ static int handle_connect(void *buf)
sdp_search_cb, rfsock, NULL) < 0) {
error("Failed to search SDP records");
cleanup_rfsock(rfsock);
- return -1;
+ goto fail;
}
- return hal_fd;
-}
-
-void bt_sock_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)
-{
- int fd;
-
- switch (opcode) {
- case HAL_OP_SOCK_LISTEN:
- fd = handle_listen(buf);
- if (fd < 0)
- break;
-
- ipc_send(sk, HAL_SERVICE_ID_SOCK, opcode, 0, NULL, fd);
-
- if (close(fd) < 0)
- error("close() fd %d failed: %s", fd, strerror(errno));
-
- return;
- case HAL_OP_SOCK_CONNECT:
- fd = handle_connect(buf);
- if (fd < 0)
- break;
-
- ipc_send(sk, HAL_SERVICE_ID_SOCK, opcode, 0, NULL, fd);
-
- if (close(fd) < 0)
- error("close() fd %d failed: %s", fd, strerror(errno));
+ ipc_send(command_sk, HAL_SERVICE_ID_SOCK, HAL_OP_SOCK_CONNECT, 0, NULL,
+ hal_fd);
+ close(hal_fd);
+ return;
- return;
- default:
- DBG("Unhandled command, opcode 0x%x", opcode);
- break;
- }
+fail:
+ ipc_send_rsp(command_sk, HAL_SERVICE_ID_SOCK, HAL_OP_SOCK_CONNECT,
+ HAL_STATUS_FAILED);
- ipc_send_rsp(sk, HAL_SERVICE_ID_SOCK, opcode, HAL_STATUS_FAILED);
+ if (hal_fd >= 0)
+ close(hal_fd);
}
+static const struct ipc_handler cmd_handlers[] = {
+ { /* HAL_OP_SOCK_LISTEN */
+ .handler = handle_listen,
+ .var_len = false,
+ .data_len = sizeof(struct hal_cmd_sock_listen)
+ },
+ { /* HAL_OP_SOCK_CONNECT */
+ .handler = handle_connect,
+ .var_len = false,
+ .data_len = sizeof(struct hal_cmd_sock_connect)
+ },
+};
+
bool bt_socket_register(int cmd_sk, int notif_sk, const bdaddr_t *addr)
{
DBG("");
+ command_sk = cmd_sk;
bacpy(&adapter_addr, addr);
+ ipc_register(HAL_SERVICE_ID_SOCK, cmd_handlers,
+ sizeof(cmd_handlers)/sizeof(cmd_handlers[0]));
+
return true;
}
void bt_socket_unregister(void)
{
DBG("");
+
+ command_sk = -1;
+
+ ipc_unregister(HAL_SERVICE_ID_SOCK);
}
--
1.8.3.2
^ permalink raw reply related
* [PATCH 10/13] android/a2dp: Use generic IPC message handling for commands
From: Szymon Janc @ 2013-11-27 11:55 UTC (permalink / raw)
To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1385553305-5807-1-git-send-email-szymon.janc@tieto.com>
Handlers are registered on service register and unregistered on
unregister.
---
android/a2dp.c | 73 +++++++++++++++++++++++++++++++---------------------------
android/a2dp.h | 2 --
2 files changed, 39 insertions(+), 36 deletions(-)
diff --git a/android/a2dp.c b/android/a2dp.c
index 87b1abb..6f79cc5 100644
--- a/android/a2dp.c
+++ b/android/a2dp.c
@@ -166,9 +166,11 @@ static void signaling_connect_cb(GIOChannel *chan, GError *err,
bt_a2dp_notify_state(dev, HAL_A2DP_STATE_CONNECTED);
}
-static uint8_t bt_a2dp_connect(struct hal_cmd_a2dp_connect *cmd, uint16_t len)
+static void bt_a2dp_connect(const void *buf, uint16_t len)
{
+ const struct hal_cmd_a2dp_connect *cmd = buf;
struct a2dp_device *dev;
+ uint8_t status = HAL_STATUS_SUCCESS;
char addr[18];
bdaddr_t dst;
GSList *l;
@@ -176,14 +178,13 @@ static uint8_t bt_a2dp_connect(struct hal_cmd_a2dp_connect *cmd, uint16_t len)
DBG("");
- if (len < sizeof(*cmd))
- return HAL_STATUS_INVALID;
-
android2bdaddr(&cmd->bdaddr, &dst);
l = g_slist_find_custom(devices, &dst, device_cmp);
- if (l)
- return HAL_STATUS_FAILED;
+ if (l) {
+ status = HAL_STATUS_FAILED;
+ goto fail;
+ }
dev = a2dp_device_new(&dst);
dev->io = bt_io_connect(signaling_connect_cb, dev, NULL, &err,
@@ -196,7 +197,8 @@ static uint8_t bt_a2dp_connect(struct hal_cmd_a2dp_connect *cmd, uint16_t len)
error("%s", err->message);
g_error_free(err);
a2dp_device_free(dev);
- return HAL_STATUS_FAILED;
+ status = HAL_STATUS_FAILED;
+ goto fail;
}
ba2str(&dev->dst, addr);
@@ -204,26 +206,28 @@ static uint8_t bt_a2dp_connect(struct hal_cmd_a2dp_connect *cmd, uint16_t len)
bt_a2dp_notify_state(dev, HAL_A2DP_STATE_CONNECTING);
- return HAL_STATUS_SUCCESS;
+fail:
+ ipc_send_rsp(command_sk, HAL_SERVICE_ID_A2DP, HAL_OP_A2DP_CONNECT,
+ status);
}
-static uint8_t bt_a2dp_disconnect(struct hal_cmd_a2dp_connect *cmd,
- uint16_t len)
+static void bt_a2dp_disconnect(const void *buf, uint16_t len)
{
+ const struct hal_cmd_a2dp_connect *cmd = buf;
+ uint8_t status = HAL_STATUS_SUCCESS;
struct a2dp_device *dev;
GSList *l;
bdaddr_t dst;
DBG("");
- if (len < sizeof(*cmd))
- return HAL_STATUS_INVALID;
-
android2bdaddr(&cmd->bdaddr, &dst);
l = g_slist_find_custom(devices, &dst, device_cmp);
- if (!l)
- return HAL_STATUS_FAILED;
+ if (!l) {
+ status = HAL_STATUS_FAILED;
+ goto fail;
+ }
dev = l->data;
@@ -233,27 +237,23 @@ static uint8_t bt_a2dp_disconnect(struct hal_cmd_a2dp_connect *cmd,
bt_a2dp_notify_state(dev, HAL_A2DP_STATE_DISCONNECTING);
- return HAL_STATUS_SUCCESS;
+fail:
+ ipc_send_rsp(command_sk, HAL_SERVICE_ID_A2DP, HAL_OP_A2DP_DISCONNECT,
+ status);
}
-void bt_a2dp_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len)
-{
- uint8_t status = HAL_STATUS_FAILED;
-
- switch (opcode) {
- case HAL_OP_A2DP_CONNECT:
- status = bt_a2dp_connect(buf, len);
- break;
- case HAL_OP_A2DP_DISCONNECT:
- status = bt_a2dp_disconnect(buf, len);
- break;
- default:
- DBG("Unhandled command, opcode 0x%x", opcode);
- break;
- }
-
- ipc_send_rsp(sk, HAL_SERVICE_ID_A2DP, opcode, status);
-}
+static const struct ipc_handler cmd_handlers[] = {
+ { /* HAL_OP_A2DP_CONNECT */
+ .handler = bt_a2dp_connect,
+ .var_len = false,
+ .data_len = sizeof(struct hal_cmd_a2dp_connect)
+ },
+ { /* HAL_OP_A2DP_DISCONNECT */
+ .handler = bt_a2dp_disconnect,
+ .var_len = false,
+ .data_len = sizeof(struct hal_cmd_a2dp_disconnect)
+ },
+};
static void connect_cb(GIOChannel *chan, GError *err, gpointer user_data)
{
@@ -388,6 +388,9 @@ bool bt_a2dp_register(int cmd_sk, int notif_sk, const bdaddr_t *addr)
notification_sk = notif_sk;
command_sk = cmd_sk;
+ ipc_register(HAL_SERVICE_ID_A2DP, cmd_handlers,
+ sizeof(cmd_handlers)/sizeof(cmd_handlers[0]));
+
return true;
}
@@ -411,6 +414,8 @@ void bt_a2dp_unregister(void)
notification_sk = -1;
command_sk = -1;
+ ipc_unregister(HAL_SERVICE_ID_A2DP);
+
bt_adapter_remove_record(record_id);
record_id = 0;
diff --git a/android/a2dp.h b/android/a2dp.h
index 720b681..e23fe3a 100644
--- a/android/a2dp.h
+++ b/android/a2dp.h
@@ -21,7 +21,5 @@
*
*/
-void bt_a2dp_handle_cmd(int sk, uint8_t opcode, void *buf, uint16_t len);
-
bool bt_a2dp_register(int cmd_sk, int notif_sk, const bdaddr_t *addr);
void bt_a2dp_unregister(void);
--
1.8.3.2
^ permalink raw reply related
page: next (older) | prev (newer) | latest
- recent:[subjects (threaded)|topics (new)|topics (active)]
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox