Linux bluetooth development
 help / color / mirror / Atom feed
* [PATCH v7 06/13] heartrate: Read Body Sensor Location characteristics
From: Andrzej Kaczmarek @ 2012-09-21 15:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Rafal Garbat
In-Reply-To: <1348240570-7532-1-git-send-email-andrzej.kaczmarek@tieto.com>

From: Rafal Garbat <rafal.garbat@tieto.com>

This patch adds support to read and store Body Sensor Location
characteristic value.
---
 profiles/heartrate/heartrate.c | 35 ++++++++++++++++++++++++++++++++++-
 1 file changed, 34 insertions(+), 1 deletion(-)

diff --git a/profiles/heartrate/heartrate.c b/profiles/heartrate/heartrate.c
index d3d6d43..2547f9b 100644
--- a/profiles/heartrate/heartrate.c
+++ b/profiles/heartrate/heartrate.c
@@ -54,6 +54,9 @@ struct heartrate {
 	uint16_t			measurement_val_handle;
 	uint16_t			measurement_ccc_handle;
 	uint16_t			hrcp_val_handle;
+
+	gboolean			has_location;
+	uint8_t				location;
 };
 
 static GSList *heartrate_adapters = NULL;
@@ -113,6 +116,34 @@ static void destroy_heartrate_adapter(gpointer user_data)
 	g_free(hradapter);
 }
 
+static void read_sensor_location_cb(guint8 status, const guint8 *pdu,
+						guint16 len, gpointer user_data)
+{
+	struct heartrate *hr = user_data;
+	uint8_t value;
+	ssize_t vlen;
+
+	if (status != 0) {
+		error("Body Sensor Location read failed: %s",
+							att_ecode2str(status));
+		return;
+	}
+
+	vlen = dec_read_resp(pdu, len, &value, sizeof(value));
+	if (vlen < 0) {
+		error("Protocol error");
+		return;
+	}
+
+	if (vlen != sizeof(value)) {
+		error("Invalid length for Body Sensor Location");
+		return;
+	}
+
+	hr->has_location = TRUE;
+	hr->location = value;
+}
+
 static void discover_ccc_cb(guint8 status, const guint8 *pdu,
 						guint16 len, gpointer user_data)
 {
@@ -194,7 +225,9 @@ static void discover_char_cb(GSList *chars, guint8 status, gpointer user_data)
 			discover_measurement_ccc(hr, c, c_next);
 		} else if (g_strcmp0(c->uuid, BODY_SENSOR_LOCATION_UUID) == 0) {
 			DBG("Body Sensor Location supported");
-			/* TODO: read characterictic value */
+
+			gatt_read_char(hr->attrib, c->value_handle, 0,
+						read_sensor_location_cb, hr);
 		} else if (g_strcmp0(c->uuid,
 					HEART_RATE_CONTROL_POINT_UUID) == 0) {
 			DBG("Heart Rate Control Point supported");
-- 
1.7.11.3


^ permalink raw reply related

* [PATCH v7 05/13] heartrate: Discover Heart Rate Measurement CCC
From: Andrzej Kaczmarek @ 2012-09-21 15:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek
In-Reply-To: <1348240570-7532-1-git-send-email-andrzej.kaczmarek@tieto.com>

This patch adds support to discover CCC descriptor for Heart Rate
Measurement characteristic.
---
 profiles/heartrate/heartrate.c | 66 +++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 65 insertions(+), 1 deletion(-)

diff --git a/profiles/heartrate/heartrate.c b/profiles/heartrate/heartrate.c
index a6733d3..d3d6d43 100644
--- a/profiles/heartrate/heartrate.c
+++ b/profiles/heartrate/heartrate.c
@@ -52,6 +52,7 @@ struct heartrate {
 	struct att_range		*svc_range;	/* primary svc range */
 
 	uint16_t			measurement_val_handle;
+	uint16_t			measurement_ccc_handle;
 	uint16_t			hrcp_val_handle;
 };
 
@@ -112,6 +113,65 @@ static void destroy_heartrate_adapter(gpointer user_data)
 	g_free(hradapter);
 }
 
+static void discover_ccc_cb(guint8 status, const guint8 *pdu,
+						guint16 len, gpointer user_data)
+{
+	struct heartrate *hr = user_data;
+	struct att_data_list *list;
+	uint8_t format;
+	int i;
+
+	if (status != 0) {
+		error("Discover Heart Rate Measurement descriptors failed: %s",
+							att_ecode2str(status));
+		return;
+	}
+
+	list = dec_find_info_resp(pdu, len, &format);
+	if (list == NULL)
+		return;
+
+	if (format != ATT_FIND_INFO_RESP_FMT_16BIT)
+		goto done;
+
+	for (i = 0; i < list->num; i++) {
+		uint8_t *value;
+		uint16_t handle, uuid;
+
+		value = list->data[i];
+		handle = att_get_u16(value);
+		uuid = att_get_u16(value + 2);
+
+		if (uuid == GATT_CLIENT_CHARAC_CFG_UUID) {
+			hr->measurement_ccc_handle = handle;
+			break;
+		}
+	}
+
+done:
+	att_data_list_free(list);
+}
+
+static void discover_measurement_ccc(struct heartrate *hr,
+				struct gatt_char *c, struct gatt_char *c_next)
+{
+	uint16_t start, end;
+
+	start = c->value_handle + 1;
+
+	if (c_next != NULL) {
+		if (start == c_next->handle)
+			return;
+		end = c_next->handle - 1;
+	} else if (c->value_handle != hr->svc_range->end) {
+		end = hr->svc_range->end;
+	} else {
+		return;
+	}
+
+	gatt_find_info(hr->attrib, start, end, discover_ccc_cb, hr);
+}
+
 static void discover_char_cb(GSList *chars, guint8 status, gpointer user_data)
 {
 	struct heartrate *hr = user_data;
@@ -126,8 +186,12 @@ static void discover_char_cb(GSList *chars, guint8 status, gpointer user_data)
 		struct gatt_char *c = chars->data;
 
 		if (g_strcmp0(c->uuid, HEART_RATE_MEASUREMENT_UUID) == 0) {
+			struct gatt_char *c_next =
+				(chars->next ? chars->next->data : NULL);
+
 			hr->measurement_val_handle = c->value_handle;
-			/* TODO: discover CCC handle */
+
+			discover_measurement_ccc(hr, c, c_next);
 		} else if (g_strcmp0(c->uuid, BODY_SENSOR_LOCATION_UUID) == 0) {
 			DBG("Body Sensor Location supported");
 			/* TODO: read characterictic value */
-- 
1.7.11.3


^ permalink raw reply related

* [PATCH v7 04/13] heartrate: Discover HRS characteristics
From: Andrzej Kaczmarek @ 2012-09-21 15:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek
In-Reply-To: <1348240570-7532-1-git-send-email-andrzej.kaczmarek@tieto.com>

This patch adds support to discover known Heart Rate Service
characteristics.
---
 lib/uuid.h                     |  3 +++
 profiles/heartrate/heartrate.c | 43 +++++++++++++++++++++++++++++++++++++++++-
 profiles/heartrate/heartrate.h |  3 ++-
 profiles/heartrate/manager.c   | 19 ++++++++++++++++++-
 4 files changed, 65 insertions(+), 3 deletions(-)

diff --git a/lib/uuid.h b/lib/uuid.h
index 3488e66..9da1b54 100644
--- a/lib/uuid.h
+++ b/lib/uuid.h
@@ -64,6 +64,9 @@ extern "C" {
 #define SAP_UUID		"0000112D-0000-1000-8000-00805f9b34fb"
 
 #define HEART_RATE_UUID			"0000180d-0000-1000-8000-00805f9b34fb"
+#define HEART_RATE_MEASUREMENT_UUID	"00002a37-0000-1000-8000-00805f9b34fb"
+#define BODY_SENSOR_LOCATION_UUID	"00002a38-0000-1000-8000-00805f9b34fb"
+#define HEART_RATE_CONTROL_POINT_UUID	"00002a39-0000-1000-8000-00805f9b34fb"
 
 #define HEALTH_THERMOMETER_UUID		"00001809-0000-1000-8000-00805f9b34fb"
 #define TEMPERATURE_MEASUREMENT_UUID	"00002a1c-0000-1000-8000-00805f9b34fb"
diff --git a/profiles/heartrate/heartrate.c b/profiles/heartrate/heartrate.c
index e057180..a6733d3 100644
--- a/profiles/heartrate/heartrate.c
+++ b/profiles/heartrate/heartrate.c
@@ -48,6 +48,11 @@ struct heartrate {
 	struct heartrate_adapter	*hradapter;
 	GAttrib				*attrib;
 	guint				attioid;
+
+	struct att_range		*svc_range;	/* primary svc range */
+
+	uint16_t			measurement_val_handle;
+	uint16_t			hrcp_val_handle;
 };
 
 static GSList *heartrate_adapters = NULL;
@@ -96,6 +101,7 @@ static void destroy_heartrate(gpointer user_data)
 		g_attrib_unref(hr->attrib);
 
 	btd_device_unref(hr->dev);
+	g_free(hr->svc_range);
 	g_free(hr);
 }
 
@@ -106,6 +112,33 @@ static void destroy_heartrate_adapter(gpointer user_data)
 	g_free(hradapter);
 }
 
+static void discover_char_cb(GSList *chars, guint8 status, gpointer user_data)
+{
+	struct heartrate *hr = user_data;
+
+	if (status) {
+		error("Discover HRS characteristics failed: %s",
+							att_ecode2str(status));
+		return;
+	}
+
+	for (; chars; chars = chars->next) {
+		struct gatt_char *c = chars->data;
+
+		if (g_strcmp0(c->uuid, HEART_RATE_MEASUREMENT_UUID) == 0) {
+			hr->measurement_val_handle = c->value_handle;
+			/* TODO: discover CCC handle */
+		} else if (g_strcmp0(c->uuid, BODY_SENSOR_LOCATION_UUID) == 0) {
+			DBG("Body Sensor Location supported");
+			/* TODO: read characterictic value */
+		} else if (g_strcmp0(c->uuid,
+					HEART_RATE_CONTROL_POINT_UUID) == 0) {
+			DBG("Heart Rate Control Point supported");
+			hr->hrcp_val_handle = c->value_handle;
+		}
+	}
+}
+
 static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
 {
 	struct heartrate *hr = user_data;
@@ -113,6 +146,9 @@ static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
 	DBG("");
 
 	hr->attrib = g_attrib_ref(attrib);
+
+	gatt_discover_char(hr->attrib, hr->svc_range->start, hr->svc_range->end,
+						NULL, discover_char_cb, hr);
 }
 
 static void attio_disconnected_cb(gpointer user_data)
@@ -150,7 +186,8 @@ void heartrate_adapter_unregister(struct btd_adapter *adapter)
 	destroy_heartrate_adapter(hradapter);
 }
 
-int heartrate_device_register(struct btd_device *device)
+int heartrate_device_register(struct btd_device *device,
+						struct gatt_primary *prim)
 {
 	struct btd_adapter *adapter;
 	struct heartrate_adapter *hradapter;
@@ -167,6 +204,10 @@ int heartrate_device_register(struct btd_device *device)
 	hr->dev = btd_device_ref(device);
 	hr->hradapter = hradapter;
 
+	hr->svc_range = g_new0(struct att_range, 1);
+	hr->svc_range->start = prim->range.start;
+	hr->svc_range->end = prim->range.end;
+
 	hradapter->devices = g_slist_prepend(hradapter->devices, hr);
 
 	hr->attioid = btd_device_add_attio_callback(device, attio_connected_cb,
diff --git a/profiles/heartrate/heartrate.h b/profiles/heartrate/heartrate.h
index 486f5b3..064939d 100644
--- a/profiles/heartrate/heartrate.h
+++ b/profiles/heartrate/heartrate.h
@@ -22,5 +22,6 @@
 
 int heartrate_adapter_register(struct btd_adapter *adapter);
 void heartrate_adapter_unregister(struct btd_adapter *adapter);
-int heartrate_device_register(struct btd_device *device);
+int heartrate_device_register(struct btd_device *device,
+						struct gatt_primary *prim);
 void heartrate_device_unregister(struct btd_device *device);
diff --git a/profiles/heartrate/manager.c b/profiles/heartrate/manager.c
index 2a9326d..a0997bd 100644
--- a/profiles/heartrate/manager.c
+++ b/profiles/heartrate/manager.c
@@ -34,6 +34,14 @@
 #include "heartrate.h"
 #include "manager.h"
 
+static gint primary_uuid_cmp(gconstpointer a, gconstpointer b)
+{
+	const struct gatt_primary *prim = a;
+	const char *uuid = b;
+
+	return g_strcmp0(prim->uuid, uuid);
+}
+
 static int heartrate_adapter_probe(struct btd_adapter *adapter)
 {
 	return heartrate_adapter_register(adapter);
@@ -46,7 +54,16 @@ static void heartrate_adapter_remove(struct btd_adapter *adapter)
 
 static int heartrate_device_probe(struct btd_device *device, GSList *uuids)
 {
-	return heartrate_device_register(device);
+	GSList *primaries;
+	GSList *l;
+
+	primaries = btd_device_get_primaries(device);
+
+	l = g_slist_find_custom(primaries, HEART_RATE_UUID, primary_uuid_cmp);
+	if (l == NULL)
+		return -EINVAL;
+
+	return heartrate_device_register(device, l->data);
 }
 
 static void heartrate_device_remove(struct btd_device *device)
-- 
1.7.11.3


^ permalink raw reply related

* [PATCH v7 03/13] heartrate: Add attio callbacks
From: Andrzej Kaczmarek @ 2012-09-21 15:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek
In-Reply-To: <1348240570-7532-1-git-send-email-andrzej.kaczmarek@tieto.com>

---
 profiles/heartrate/heartrate.c | 35 +++++++++++++++++++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/profiles/heartrate/heartrate.c b/profiles/heartrate/heartrate.c
index 87bc309..e057180 100644
--- a/profiles/heartrate/heartrate.c
+++ b/profiles/heartrate/heartrate.c
@@ -31,6 +31,11 @@
 
 #include "adapter.h"
 #include "device.h"
+#include "gattrib.h"
+#include "att.h"
+#include "gatt.h"
+#include "attio.h"
+#include "log.h"
 #include "heartrate.h"
 
 struct heartrate_adapter {
@@ -41,6 +46,8 @@ struct heartrate_adapter {
 struct heartrate {
 	struct btd_device		*dev;
 	struct heartrate_adapter	*hradapter;
+	GAttrib				*attrib;
+	guint				attioid;
 };
 
 static GSList *heartrate_adapters = NULL;
@@ -82,6 +89,12 @@ static void destroy_heartrate(gpointer user_data)
 {
 	struct heartrate *hr = user_data;
 
+	if (hr->attioid > 0)
+		btd_device_remove_attio_callback(hr->dev, hr->attioid);
+
+	if (hr->attrib != NULL)
+		g_attrib_unref(hr->attrib);
+
 	btd_device_unref(hr->dev);
 	g_free(hr);
 }
@@ -93,6 +106,25 @@ static void destroy_heartrate_adapter(gpointer user_data)
 	g_free(hradapter);
 }
 
+static void attio_connected_cb(GAttrib *attrib, gpointer user_data)
+{
+	struct heartrate *hr = user_data;
+
+	DBG("");
+
+	hr->attrib = g_attrib_ref(attrib);
+}
+
+static void attio_disconnected_cb(gpointer user_data)
+{
+	struct heartrate *hr = user_data;
+
+	DBG("");
+
+	g_attrib_unref(hr->attrib);
+	hr->attrib = NULL;
+}
+
 int heartrate_adapter_register(struct btd_adapter *adapter)
 {
 	struct heartrate_adapter *hradapter;
@@ -137,6 +169,9 @@ int heartrate_device_register(struct btd_device *device)
 
 	hradapter->devices = g_slist_prepend(hradapter->devices, hr);
 
+	hr->attioid = btd_device_add_attio_callback(device, attio_connected_cb,
+						attio_disconnected_cb, hr);
+
 	return 0;
 }
 
-- 
1.7.11.3


^ permalink raw reply related

* [PATCH v7 02/13] heartrate: Add initial HRP client support
From: Andrzej Kaczmarek @ 2012-09-21 15:15 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Rafal Garbat
In-Reply-To: <1348240570-7532-1-git-send-email-andrzej.kaczmarek@tieto.com>

From: Rafal Garbat <rafal.garbat@tieto.com>

This patch adds initial support for the Heart Rate Profile client.
Profile driver is registered to keep track of adapters and devices.
---
 Makefile.am                    |   9 ++-
 lib/uuid.h                     |   2 +
 profiles/heartrate/heartrate.c | 165 +++++++++++++++++++++++++++++++++++++++++
 profiles/heartrate/heartrate.h |  26 +++++++
 profiles/heartrate/main.c      |  52 +++++++++++++
 profiles/heartrate/manager.c   |  76 +++++++++++++++++++
 profiles/heartrate/manager.h   |  24 ++++++
 7 files changed, 352 insertions(+), 2 deletions(-)
 create mode 100644 profiles/heartrate/heartrate.c
 create mode 100644 profiles/heartrate/heartrate.h
 create mode 100644 profiles/heartrate/main.c
 create mode 100644 profiles/heartrate/manager.c
 create mode 100644 profiles/heartrate/manager.h

diff --git a/Makefile.am b/Makefile.am
index 372111a..808a81f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -211,7 +211,7 @@ endif
 
 if GATTMODULES
 builtin_modules += thermometer alert time gatt_example proximity deviceinfo \
-			gatt
+			gatt heartrate
 builtin_sources += profiles/thermometer/main.c \
 			profiles/thermometer/manager.h \
 			profiles/thermometer/manager.c \
@@ -240,7 +240,12 @@ builtin_sources += profiles/thermometer/main.c \
 			profiles/deviceinfo/deviceinfo.c \
 			profiles/gatt/main.c profiles/gatt/manager.h \
 			profiles/gatt/manager.c profiles/gatt/gas.h \
-			profiles/gatt/gas.c
+			profiles/gatt/gas.c \
+			profiles/heartrate/main.c \
+			profiles/heartrate/manager.c \
+			profiles/heartrate/manager.h \
+			profiles/heartrate/heartrate.c \
+			profiles/heartrate/heartrate.h
 endif
 
 builtin_modules += formfactor
diff --git a/lib/uuid.h b/lib/uuid.h
index aa6efdf..3488e66 100644
--- a/lib/uuid.h
+++ b/lib/uuid.h
@@ -63,6 +63,8 @@ extern "C" {
 
 #define SAP_UUID		"0000112D-0000-1000-8000-00805f9b34fb"
 
+#define HEART_RATE_UUID			"0000180d-0000-1000-8000-00805f9b34fb"
+
 #define HEALTH_THERMOMETER_UUID		"00001809-0000-1000-8000-00805f9b34fb"
 #define TEMPERATURE_MEASUREMENT_UUID	"00002a1c-0000-1000-8000-00805f9b34fb"
 #define TEMPERATURE_TYPE_UUID		"00002a1d-0000-1000-8000-00805f9b34fb"
diff --git a/profiles/heartrate/heartrate.c b/profiles/heartrate/heartrate.c
new file mode 100644
index 0000000..87bc309
--- /dev/null
+++ b/profiles/heartrate/heartrate.c
@@ -0,0 +1,165 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2012 Tieto Poland
+ *
+ *  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 <errno.h>
+#include <stdbool.h>
+#include <glib.h>
+#include <bluetooth/uuid.h>
+
+#include "adapter.h"
+#include "device.h"
+#include "heartrate.h"
+
+struct heartrate_adapter {
+	struct btd_adapter	*adapter;
+	GSList			*devices;
+};
+
+struct heartrate {
+	struct btd_device		*dev;
+	struct heartrate_adapter	*hradapter;
+};
+
+static GSList *heartrate_adapters = NULL;
+
+static gint cmp_adapter(gconstpointer a, gconstpointer b)
+{
+	const struct heartrate_adapter *hradapter = a;
+	const struct btd_adapter *adapter = b;
+
+	if (adapter == hradapter->adapter)
+		return 0;
+
+	return -1;
+}
+
+static gint cmp_device(gconstpointer a, gconstpointer b)
+{
+	const struct heartrate *hr = a;
+	const struct btd_device *dev = b;
+
+	if (dev == hr->dev)
+		return 0;
+
+	return -1;
+}
+
+static struct heartrate_adapter *
+find_heartrate_adapter(struct btd_adapter *adapter)
+{
+	GSList *l = g_slist_find_custom(heartrate_adapters, adapter,
+								cmp_adapter);
+	if (!l)
+		return NULL;
+
+	return l->data;
+}
+
+static void destroy_heartrate(gpointer user_data)
+{
+	struct heartrate *hr = user_data;
+
+	btd_device_unref(hr->dev);
+	g_free(hr);
+}
+
+static void destroy_heartrate_adapter(gpointer user_data)
+{
+	struct heartrate_adapter *hradapter = user_data;
+
+	g_free(hradapter);
+}
+
+int heartrate_adapter_register(struct btd_adapter *adapter)
+{
+	struct heartrate_adapter *hradapter;
+
+	hradapter = g_new0(struct heartrate_adapter, 1);
+	hradapter->adapter = adapter;
+
+	heartrate_adapters = g_slist_prepend(heartrate_adapters, hradapter);
+
+	return 0;
+}
+
+void heartrate_adapter_unregister(struct btd_adapter *adapter)
+{
+	struct heartrate_adapter *hradapter;
+
+	hradapter = find_heartrate_adapter(adapter);
+	if (hradapter == NULL)
+		return;
+
+	heartrate_adapters = g_slist_remove(heartrate_adapters, hradapter);
+
+	destroy_heartrate_adapter(hradapter);
+}
+
+int heartrate_device_register(struct btd_device *device)
+{
+	struct btd_adapter *adapter;
+	struct heartrate_adapter *hradapter;
+	struct heartrate *hr;
+
+	adapter = device_get_adapter(device);
+
+	hradapter = find_heartrate_adapter(adapter);
+
+	if (hradapter == NULL)
+		return -1;
+
+	hr = g_new0(struct heartrate, 1);
+	hr->dev = btd_device_ref(device);
+	hr->hradapter = hradapter;
+
+	hradapter->devices = g_slist_prepend(hradapter->devices, hr);
+
+	return 0;
+}
+
+void heartrate_device_unregister(struct btd_device *device)
+{
+	struct btd_adapter *adapter;
+	struct heartrate_adapter *hradapter;
+	struct heartrate *hr;
+	GSList *l;
+
+	adapter = device_get_adapter(device);
+
+	hradapter = find_heartrate_adapter(adapter);
+	if (hradapter == NULL)
+		return;
+
+	l = g_slist_find_custom(hradapter->devices, device, cmp_device);
+	if (l == NULL)
+		return;
+
+	hr = l->data;
+
+	hradapter->devices = g_slist_remove(hradapter->devices, hr);
+
+	destroy_heartrate(hr);
+}
diff --git a/profiles/heartrate/heartrate.h b/profiles/heartrate/heartrate.h
new file mode 100644
index 0000000..486f5b3
--- /dev/null
+++ b/profiles/heartrate/heartrate.h
@@ -0,0 +1,26 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2012 Tieto Poland
+ *
+ *  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
+ *
+ */
+
+int heartrate_adapter_register(struct btd_adapter *adapter);
+void heartrate_adapter_unregister(struct btd_adapter *adapter);
+int heartrate_device_register(struct btd_device *device);
+void heartrate_device_unregister(struct btd_device *device);
diff --git a/profiles/heartrate/main.c b/profiles/heartrate/main.c
new file mode 100644
index 0000000..40f34bc
--- /dev/null
+++ b/profiles/heartrate/main.c
@@ -0,0 +1,52 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2012 Tieto Poland
+ *
+ *  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 <errno.h>
+
+#include "plugin.h"
+#include "manager.h"
+#include "hcid.h"
+#include "log.h"
+
+static int heartrate_init(void)
+{
+	if (!main_opts.gatt_enabled) {
+		DBG("GATT is disabled");
+		return -ENOTSUP;
+	}
+
+	return heartrate_manager_init();
+}
+
+static void heartrate_exit(void)
+{
+	heartrate_manager_exit();
+}
+
+BLUETOOTH_PLUGIN_DEFINE(heartrate, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT,
+					heartrate_init, heartrate_exit)
diff --git a/profiles/heartrate/manager.c b/profiles/heartrate/manager.c
new file mode 100644
index 0000000..2a9326d
--- /dev/null
+++ b/profiles/heartrate/manager.c
@@ -0,0 +1,76 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2012 Tieto Poland
+ *
+ *  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
+ *
+ */
+
+#include <gdbus.h>
+#include <errno.h>
+#include <stdbool.h>
+#include <bluetooth/uuid.h>
+
+#include "adapter.h"
+#include "device.h"
+#include "profile.h"
+#include "att.h"
+#include "gattrib.h"
+#include "gatt.h"
+#include "heartrate.h"
+#include "manager.h"
+
+static int heartrate_adapter_probe(struct btd_adapter *adapter)
+{
+	return heartrate_adapter_register(adapter);
+}
+
+static void heartrate_adapter_remove(struct btd_adapter *adapter)
+{
+	heartrate_adapter_unregister(adapter);
+}
+
+static int heartrate_device_probe(struct btd_device *device, GSList *uuids)
+{
+	return heartrate_device_register(device);
+}
+
+static void heartrate_device_remove(struct btd_device *device)
+{
+	heartrate_device_unregister(device);
+}
+
+static struct btd_profile hrp_profile = {
+	.name		= "Heart Rate GATT Driver",
+	.remote_uuids	= BTD_UUIDS(HEART_RATE_UUID),
+
+	.device_probe	= heartrate_device_probe,
+	.device_remove	= heartrate_device_remove,
+
+	.adapter_probe	= heartrate_adapter_probe,
+	.adapter_remove	= heartrate_adapter_remove,
+};
+
+int heartrate_manager_init(void)
+{
+	return btd_profile_register(&hrp_profile);
+}
+
+void heartrate_manager_exit(void)
+{
+	btd_profile_unregister(&hrp_profile);
+}
diff --git a/profiles/heartrate/manager.h b/profiles/heartrate/manager.h
new file mode 100644
index 0000000..de799f6
--- /dev/null
+++ b/profiles/heartrate/manager.h
@@ -0,0 +1,24 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2012 Tieto Poland
+ *
+ *  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
+ *
+ */
+
+int heartrate_manager_init(void);
+void heartrate_manager_exit(void);
-- 
1.7.11.3


^ permalink raw reply related

* [PATCH v7 01/13] Heart Rate Profile (HRP) client API
From: Andrzej Kaczmarek @ 2012-09-21 15:15 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Santiago Carot-Nemesio
In-Reply-To: <1348240570-7532-1-git-send-email-andrzej.kaczmarek@tieto.com>

From: Santiago Carot-Nemesio <sancane@gmail.com>

---
 doc/heartrate-api.txt | 84 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 84 insertions(+)
 create mode 100644 doc/heartrate-api.txt

diff --git a/doc/heartrate-api.txt b/doc/heartrate-api.txt
new file mode 100644
index 0000000..1fa9d0b
--- /dev/null
+++ b/doc/heartrate-api.txt
@@ -0,0 +1,84 @@
+Heart Rate API description
+****************************************
+
+Copyright (C) 2012	Santiago Carot-Nemesio <sancane@gmail.com>
+Copyright (C) 2012	Tieto Poland
+
+Heart Rate Manager hierarchy
+============================
+
+Service		org.bluez
+Interface	org.bluez.HeartRateManager
+Object path	[variable prefix]/{hci0,hci1,...}
+
+Methods		RegisterWatcher(object agent)
+
+			Registers a watcher to monitor heart rate measurements.
+
+			Possible Errors: org.bluez.Error.InvalidArguments
+
+		UnregisterWatcher(object agent)
+
+			Unregisters a watcher.
+
+Heart Rate Profile hierarchy
+============================
+
+Service		org.bluez
+Interface	org.bluez.HeartRate
+Object path	[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX
+
+Methods		dict GetProperties()
+
+			Returns all properties for the interface. See the
+			Properties section for the available properties.
+
+		Reset()
+
+			Restart the accumulation of energy expended from zero.
+
+			Possible Errors: org.bluez.Error.NotSupported
+
+Properties	String Location (optional) [readonly]
+
+			Possible values: "Other", "Chest", "Wrist","Finger",
+					"Hand", "Earlobe", "Foot"
+
+		boolean ResetSupported [readonly]
+
+			True if energy expended is supported.
+
+Heart Rate Watcher hierarchy
+
+============================
+Service		unique name
+Interface	org.bluez.HeartRateWatcher
+Object path	freely definable
+
+Methods		void MeasurementReceived(object device, dict measurement)
+
+			This callback is called whenever a heart rate
+			measurement is received from the heart rate device.
+
+			Measurement:
+
+				uint16 Value:
+
+					Measurement value expressed in beats per
+					minute (bpm)
+
+				uint16 Energy (optional):
+
+					Accumulated energy expended in kilo Joules
+
+				boolean Contact (optional):
+
+					true if skin contact is detected by sensor,
+					false otherwise
+
+				array{uint16} Interval (optional):
+
+					RR-Interval values which represent the time
+					between two consecutive R waves in an ECG.
+					Values are ordered starting from oldest to
+					most recent.
-- 
1.7.11.3


^ permalink raw reply related

* [PATCH v7 00/13] Heart Rate Profile plugin
From: Andrzej Kaczmarek @ 2012-09-21 15:15 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Andrzej Kaczmarek

Hi,

Changes since v6:
- rebased to latest upstream master
- fixed issues pointed out by Johan
  (except double const stuff as discussed on IRC)


Andrzej Kaczmarek (6):
  heartrate: Add attio callbacks
  heartrate: Discover HRS characteristics
  heartrate: Discover Heart Rate Measurement CCC
  heartrate: Add support to enable notifications
  heartrate: Process measurement notifications
  heartrate: Add support to reset Energy Expended

Rafal Garbat (6):
  heartrate: Add initial HRP client support
  heartrate: Read Body Sensor Location characteristics
  heartrate: Add HeartRateManager interface
  heartrate: Add GetProperties method
  heartrate: Add HeartRateWatcher interface to default policy
  heartrate: Add test script

Santiago Carot-Nemesio (1):
  Heart Rate Profile (HRP) client API

 Makefile.am                    |   9 +-
 Makefile.tools                 |   4 +-
 doc/heartrate-api.txt          |  84 +++++
 lib/uuid.h                     |   5 +
 profiles/heartrate/heartrate.c | 826 +++++++++++++++++++++++++++++++++++++++++
 profiles/heartrate/heartrate.h |  27 ++
 profiles/heartrate/main.c      |  52 +++
 profiles/heartrate/manager.c   |  93 +++++
 profiles/heartrate/manager.h   |  24 ++
 src/bluetooth.conf             |   1 +
 test/test-heartrate            | 103 +++++
 11 files changed, 1224 insertions(+), 4 deletions(-)
 create mode 100644 doc/heartrate-api.txt
 create mode 100644 profiles/heartrate/heartrate.c
 create mode 100644 profiles/heartrate/heartrate.h
 create mode 100644 profiles/heartrate/main.c
 create mode 100644 profiles/heartrate/manager.c
 create mode 100644 profiles/heartrate/manager.h
 create mode 100755 test/test-heartrate

-- 
1.7.11.3


^ permalink raw reply

* Re: [PATCH] wiimote: add Wii Balance Board detection
From: Johan Hedberg @ 2012-09-21 13:51 UTC (permalink / raw)
  To: David Herrmann; +Cc: linux-bluetooth, floe
In-Reply-To: <1347485573-23623-1-git-send-email-dh.herrmann@googlemail.com>

Hi David,

On Wed, Sep 12, 2012, David Herrmann wrote:
> Add the name of the Wii Balance Board so it can be paired with BlueZ like
> any other Wii Remote. Reported by Florian Echtler.
> ---
>  plugins/wiimote.c | 1 +
>  1 file changed, 1 insertion(+)

Applied (after a minor coding style fix). Thanks!

Johan

^ permalink raw reply

* Re: [PATCH v6 11/13] heartrate: Add GetProperties method
From: Johan Hedberg @ 2012-09-21 13:45 UTC (permalink / raw)
  To: Andrzej Kaczmarek; +Cc: linux-bluetooth, Rafal Garbat
In-Reply-To: <1348139690-26985-12-git-send-email-andrzej.kaczmarek@tieto.com>

Hi Andrzej,

On Thu, Sep 20, 2012, Andrzej Kaczmarek wrote:
> +static const char * const location_enum[] = {
> +	"Other",
> +	"Chest",
> +	"Wrist",
> +	"Finger",
> +	"Hand",
> +	"Earlobe",
> +	"Foot"
> +};

Please add a "," to the end of the last entry to make patches that add
new entries look nicer (they don't have to first remove the last line
and then add two new lines).

Also, is the "const * const" stuff really needed? I think in most places
in the code base with tables like this we've just left out the second
one.

Johan

^ permalink raw reply

* Re: [PATCH v6 08/13] heartrate: Add support to enable notifications
From: Johan Hedberg @ 2012-09-21 13:42 UTC (permalink / raw)
  To: Andrzej Kaczmarek; +Cc: linux-bluetooth
In-Reply-To: <1348139690-26985-9-git-send-email-andrzej.kaczmarek@tieto.com>

Hi Andrzej,

On Thu, Sep 20, 2012, Andrzej Kaczmarek wrote:
> @@ -238,6 +249,18 @@ static void discover_ccc_cb(guint8 status, const guint8 *pdu,
>  
>  		if (uuid == GATT_CLIENT_CHARAC_CFG_UUID) {
>  			hr->measurement_ccc_handle = handle;
> +
> +			if (g_slist_length(hr->hradapter->watchers) > 0) {
> +				uint8_t value[2];
> +				char *msg;
> +
> +				att_put_u16(GATT_CLIENT_CHARAC_CFG_NOTIF_BIT,
> +									value);
> +				msg = g_strdup("Enable measurement");
> +
> +				gatt_write_char(hr->attrib, handle, value,
> +					sizeof(value), char_write_cb, msg);
> +			}
>  			break;
>  		}

Seems like you could avoid the extra indentation above by inverting the
g_slist_length test:

	if (g_slist_length(hr->hradapter->watchers) == 0)
		break;

	...
	break;

>  	g_dbus_remove_watch(conn, watcher->id);
> +
> +
> +	if (g_slist_length(hradapter->watchers) == 0)

Two consecutive empty lines should never be needed. Please remove one.

Johan

^ permalink raw reply

* Re: [PATCH v6 07/13] heartrate: Add HeartRateManager interface
From: Johan Hedberg @ 2012-09-21 13:39 UTC (permalink / raw)
  To: Andrzej Kaczmarek; +Cc: linux-bluetooth, Rafal Garbat
In-Reply-To: <1348139690-26985-8-git-send-email-andrzej.kaczmarek@tieto.com>

Hi Andrzej,

On Thu, Sep 20, 2012, Andrzej Kaczmarek wrote:
> This patch adds support for org.bluez.HeartRateManager interface on adapters
> which allows to register and unregister per-adapter watcher.
> ---
>  profiles/heartrate/heartrate.c | 154 ++++++++++++++++++++++++++++++++++++++++-
>  1 file changed, 153 insertions(+), 1 deletion(-)

This one will need to be redone due to the btd_get_dbus_connection
patches that went in.

Also, please go through all your commit messages and ensure that your
line widths are less than 74 (the summary line needs to be max 72 due to
"git shortlog" indenting by 8 characters so for simplicity you could
just configure your editor to use 72 for all commit messages).

Johan

^ permalink raw reply

* Re: [PATCH v6 06/13] heartrate: Read Body Sensor Location characteristics
From: Johan Hedberg @ 2012-09-21 13:35 UTC (permalink / raw)
  To: Andrzej Kaczmarek; +Cc: linux-bluetooth, Rafal Garbat
In-Reply-To: <1348139690-26985-7-git-send-email-andrzej.kaczmarek@tieto.com>

Hi Andrzej,

On Thu, Sep 20, 2012, Andrzej Kaczmarek wrote:
> +static void read_sensor_location_cb(guint8 status, const guint8 *pdu,
> +						guint16 len, gpointer user_data)
> +{
> +	struct heartrate *hr = user_data;
> +	uint8_t value;
> +	ssize_t vlen;
> +
> +	if (status != 0) {
> +		error("Body Sensor Location read failed: %s",
> +							att_ecode2str(status));
> +		return;
> +	}
> +
> +	vlen = dec_read_resp(pdu, len, &value, sizeof(value));
> +	if (vlen < 0) {
> +		error("Protocol error");
> +		return;
> +	}
> +
> +	if (vlen != 1) {
> +		error("Invalid length for Body Sensor Location");
> +		return;
> +	}

Minor nitpick: vlen != sizeof(value) would make it more clear exactly
what you want to compare with.

Johan

^ permalink raw reply

* Re: [PATCH BlueZ] media: Fix possible crash when endpoint exit
From: Johan Hedberg @ 2012-09-21 13:20 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
In-Reply-To: <1348233143-27796-1-git-send-email-luiz.dentz@gmail.com>

Hi Luiz,

On Fri, Sep 21, 2012, Luiz Augusto von Dentz wrote:
> a2dp_sep_unlock may free the endpoint if it is not registered anymore
> which leads to destroying all related transport causing the following:
> 
> Invalid read of size 1
>    at 0x4A09F09: memcpy@GLIBC_2.2.5 (mc_replace_strmem.c:836)
>    by 0x4F7C02D: ??? (in /usr/lib64/libdbus-1.so.3.5.6)
>    by 0x4F7AAE5: ??? (in /usr/lib64/libdbus-1.so.3.5.6)
>    by 0x4F7B10B: ??? (in /usr/lib64/libdbus-1.so.3.5.6)
>    by 0x4F68DA0: ??? (in /usr/lib64/libdbus-1.so.3.5.6)
>    by 0x4F66788: ??? (in /usr/lib64/libdbus-1.so.3.5.6)
>    by 0x4F66B41: ??? (in /usr/lib64/libdbus-1.so.3.5.6)
>    by 0x4F6D64E: dbus_message_new_signal (in /usr/lib64/libdbus-1.so.3.5.6)
>    by 0x180FC2: emit_property_changed (dbus-common.c:130)
>    by 0x13FD15: transport_set_state (transport.c:206)
>    by 0x140519: suspend_a2dp (transport.c:460)
>    by 0x122436: service_filter (watch.c:476)
>  Address 0x6546110 is 48 bytes inside a block of size 49 free'd
>    at 0x4A079AE: free (vg_replace_malloc.c:427)
>    by 0x4C8037E: g_free (in /usr/lib64/libglib-2.0.so.0.3200.4)
>    by 0x1409F9: media_transport_free (transport.c:1160)
>    by 0x12282F: remove_interface (object.c:553)
>    by 0x123699: g_dbus_unregister_interface (object.c:1231)
>    by 0x141547: media_transport_destroy (transport.c:228)
>    by 0x4C95ACC: g_slist_foreach (in /usr/lib64/libglib-2.0.so.0.3200.4)
>    by 0x4C95AEA: g_slist_free_full (in /usr/lib64/libglib-2.0.so.0.3200.4)
>    by 0x13E53D: media_endpoint_remove (media.c:162)
>    by 0x133F62: a2dp_unregister_sep (a2dp.c:1247)
>    by 0x1369D7: a2dp_sep_unlock (a2dp.c:1814)
>    by 0x1404D3: suspend_a2dp (transport.c:455)
> ---
>  audio/transport.c | 16 ++++++----------
>  1 file changed, 6 insertions(+), 10 deletions(-)

Applied. Thanks.

Johan

^ permalink raw reply

* Re: [PATCH v2] gatt: Delay D-Bus reply on char discovery
From: Johan Hedberg @ 2012-09-21 13:19 UTC (permalink / raw)
  To: chen.ganir; +Cc: linux-bluetooth
In-Reply-To: <1347353240-1942-1-git-send-email-chen.ganir@ti.com>

Hi Chen,

On Tue, Sep 11, 2012, chen.ganir@ti.com wrote:
> Delay sending the D-Bus reply for the discover_characteristics
> command. The D-Bus reply for characteristics is sent before all
> the relevant characteristic information is gathered. This can
> cause problems, when trying to get characteristic information too
> soon. This patch moves the D-Bus reply to the end of the char
> discovery process. Only after all descriptors are discovered and
> read, the D-Bus reply is sent.
> ---
>  attrib/client.c |  138 +++++++++++++++++++++++++++++++++++++------------------
>  1 file changed, 93 insertions(+), 45 deletions(-)

This one needs to be rebased against latest git (I think the
btd_get_dbus_connection patch broke it).

Johan

^ permalink raw reply

* [PATCH BlueZ] media: Fix possible crash when endpoint exit
From: Luiz Augusto von Dentz @ 2012-09-21 13:12 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

a2dp_sep_unlock may free the endpoint if it is not registered anymore
which leads to destroying all related transport causing the following:

Invalid read of size 1
   at 0x4A09F09: memcpy@GLIBC_2.2.5 (mc_replace_strmem.c:836)
   by 0x4F7C02D: ??? (in /usr/lib64/libdbus-1.so.3.5.6)
   by 0x4F7AAE5: ??? (in /usr/lib64/libdbus-1.so.3.5.6)
   by 0x4F7B10B: ??? (in /usr/lib64/libdbus-1.so.3.5.6)
   by 0x4F68DA0: ??? (in /usr/lib64/libdbus-1.so.3.5.6)
   by 0x4F66788: ??? (in /usr/lib64/libdbus-1.so.3.5.6)
   by 0x4F66B41: ??? (in /usr/lib64/libdbus-1.so.3.5.6)
   by 0x4F6D64E: dbus_message_new_signal (in /usr/lib64/libdbus-1.so.3.5.6)
   by 0x180FC2: emit_property_changed (dbus-common.c:130)
   by 0x13FD15: transport_set_state (transport.c:206)
   by 0x140519: suspend_a2dp (transport.c:460)
   by 0x122436: service_filter (watch.c:476)
 Address 0x6546110 is 48 bytes inside a block of size 49 free'd
   at 0x4A079AE: free (vg_replace_malloc.c:427)
   by 0x4C8037E: g_free (in /usr/lib64/libglib-2.0.so.0.3200.4)
   by 0x1409F9: media_transport_free (transport.c:1160)
   by 0x12282F: remove_interface (object.c:553)
   by 0x123699: g_dbus_unregister_interface (object.c:1231)
   by 0x141547: media_transport_destroy (transport.c:228)
   by 0x4C95ACC: g_slist_foreach (in /usr/lib64/libglib-2.0.so.0.3200.4)
   by 0x4C95AEA: g_slist_free_full (in /usr/lib64/libglib-2.0.so.0.3200.4)
   by 0x13E53D: media_endpoint_remove (media.c:162)
   by 0x133F62: a2dp_unregister_sep (a2dp.c:1247)
   by 0x1369D7: a2dp_sep_unlock (a2dp.c:1814)
   by 0x1404D3: suspend_a2dp (transport.c:455)
---
 audio/transport.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)

diff --git a/audio/transport.c b/audio/transport.c
index 281895e..23e7ddd 100644
--- a/audio/transport.c
+++ b/audio/transport.c
@@ -451,18 +451,14 @@ static guint suspend_a2dp(struct media_transport *transport,
 	struct media_endpoint *endpoint = transport->endpoint;
 	struct a2dp_sep *sep = media_endpoint_get_sep(endpoint);
 
-	if (!owner) {
-		a2dp_sep_unlock(sep, a2dp->session);
-
-		if (a2dp_sep_is_playing(sep))
-			transport_set_state(transport, TRANSPORT_STATE_PENDING);
-		else
-			transport_set_state(transport, TRANSPORT_STATE_IDLE);
+	if (owner != NULL)
+		return a2dp_suspend(a2dp->session, sep, a2dp_suspend_complete,
+									owner);
 
-		return 0;
-	}
+	transport_set_state(transport, TRANSPORT_STATE_IDLE);
+	a2dp_sep_unlock(sep, a2dp->session);
 
-	return a2dp_suspend(a2dp->session, sep, a2dp_suspend_complete, owner);
+	return 0;
 }
 
 static void cancel_a2dp(struct media_transport *transport, guint id)
-- 
1.7.11.4


^ permalink raw reply related

* Re: bluetoothd: Refusing input device connect: Operation already in progress (114)
From: Johan Hedberg @ 2012-09-21 12:43 UTC (permalink / raw)
  To: Pacho Ramos; +Cc: linux-bluetooth
In-Reply-To: <1347704153.24322.11.camel@belkin4>

Hi,

On Sat, Sep 15, 2012, Pacho Ramos wrote:
> Downstream we got the following report:
> https://bugs.gentoo.org/show_bug.cgi?id=431624
> 
> After adding mouse (via Blueman's "Add device" dialog) it works fine
> until sleeping or powering off. After that it fails reconnecting.
> In /var/log/messages appears strings like these:
> 
> Aug 16 15:40:31 user bluetoothd[3222]: Refusing input device connect:
> Operation already in progress (114)
> Aug 16 15:45:13 user bluetoothd[3222]: Refusing input device connect:
> Operation already in progress (114)
> Aug 16 15:45:16 user bluetoothd[3222]: Refusing input device connect:
> Operation already in progress (114)
> Aug 16 15:45:17 user bluetoothd[3222]: Refusing input device connect:
> Operation already in progress (114)
> Aug 16 15:45:19 user bluetoothd[3222]: Refusing input device connect:
> Operation already in progress (114)
> Aug 16 15:47:46 user bluetoothd[3222]: Refusing input device connect:
> Operation already in progress (114)
> 
> Searching, I found this thread that pointed to the culprit, but I
> haven't found what finally occurred with it, if patch was reverted or a
> different fix was pulled in:
> http://www.spinics.net/lists/linux-bluetooth/msg26442.html

This is a different issue but the cause seems to be similar. You don't
need to patch bluetoothd though but just disable the mgmt part by
passing -P mgmtops to bluetoothd. For whatever reason the connection
state isn't cleaned up with mgmt (which shouldn't be dependent on mgmt
to begin with) and the input_device_set_channel function returns
-EALREADY when accepting a connection.

Johan

^ permalink raw reply

* [PATCH v3 18/18] neard: Implement RequestOOB function
From: Szymon Janc @ 2012-09-21 12:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1348230995-8967-1-git-send-email-szymon.janc@tieto.com>

This function is used by neard to request data to be transmitted over
OOB channel. It also allows neard to provide data to be used in OOB
pairing without initializing pairing it self.

---
 plugins/neard.c |   85 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 82 insertions(+), 3 deletions(-)

diff --git a/plugins/neard.c b/plugins/neard.c
index dd6a422..288a47e 100644
--- a/plugins/neard.c
+++ b/plugins/neard.c
@@ -42,6 +42,7 @@
 #include "storage.h"
 #include "agent.h"
 #include "oob.h"
+#include "hcid.h"
 
 #define NEARD_NAME "org.neard"
 #define NEARD_PATH "/"
@@ -56,6 +57,9 @@ static gboolean agent_registered = FALSE;
 static struct btd_adapter *pending_adapter = NULL;
 static DBusMessage *pending_msg = NULL;
 
+/* For NFC mimetype limits max OOB EIR size */
+#define NFC_OOB_EIR_MAX UINT8_MAX
+
 static DBusMessage *error_reply(DBusMessage *msg, int error)
 {
 	switch (error) {
@@ -156,6 +160,60 @@ unregister:
 							AGENT_INTERFACE);
 }
 
+static void read_local_complete(struct btd_adapter *adapter, uint8_t *hash,
+							uint8_t *randomizer)
+{
+	DBusMessage *reply;
+
+	DBG("hci%u", adapter_get_dev_id(adapter));
+
+	if (pending_adapter != adapter)
+		return;
+
+	if (hash && randomizer) {
+		int len;
+		uint8_t eir[NFC_OOB_EIR_MAX];
+		uint8_t *peir = eir;
+		bdaddr_t addr;
+		DBusMessageIter iter;
+		DBusMessageIter dict;
+
+		adapter_get_address(adapter, &addr);
+
+		len = eir_create_oob(&addr, btd_adapter_get_name(adapter),
+				btd_adapter_get_class(adapter), hash,
+				randomizer, main_opts.did_vendor,
+				main_opts.did_product, main_opts.did_version,
+				main_opts.did_source,
+				btd_adapter_get_services(adapter), eir);
+
+		reply = dbus_message_new_method_return(pending_msg);
+
+		dbus_message_iter_init_append(reply, &iter);
+
+		dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
+					DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
+					DBUS_TYPE_STRING_AS_STRING
+					DBUS_TYPE_VARIANT_AS_STRING
+					DBUS_DICT_ENTRY_END_CHAR_AS_STRING,
+					&dict);
+
+		dict_append_array(&dict, "EIR", DBUS_TYPE_BYTE, &peir, len);
+
+		dbus_message_iter_close_container(&iter, &dict);
+
+	} else {
+		reply = error_reply(pending_msg, EIO);
+	}
+
+	dbus_message_unref(pending_msg);
+	pending_msg = NULL;
+	pending_adapter = NULL;
+
+	if (!g_dbus_send_message(btd_get_dbus_connection(), reply))
+		error("D-Bus send failed");
+}
+
 static void pairing_complete(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 							uint8_t status)
 {
@@ -293,7 +351,7 @@ static int process_params(DBusMessageIter *iter, struct btd_adapter *adapter,
 		dbus_message_iter_recurse(&value, &array);
 		dbus_message_iter_get_fixed_array(&array, &eir, &size);
 
-		return process_eir(adapter, eir, size, TRUE);
+		return process_eir(adapter, eir, size, pair);
 	} else if (strcasecmp(key, "nokia.com:bt") == 0) {
 		/* TODO add support for Nokia BT 2.0 proprietary stuff */
 		return -ENOTSUP;
@@ -354,9 +412,30 @@ static DBusMessage *push_oob(DBusConnection *conn, DBusMessage *msg, void *data)
 static DBusMessage *request_oob(DBusConnection *conn, DBusMessage *msg,
 								void *data)
 {
+	struct btd_adapter *adapter;
+	DBusMessageIter iter;
+	int ret;
+
 	DBG("");
 
-	return error_reply(msg, ENOTSUP);
+	adapter = manager_get_default_adapter();
+	ret = check_adapter(adapter);
+	if (ret < 0)
+		return error_reply(msg, -ret);
+
+	dbus_message_iter_init(msg, &iter);
+
+	ret = process_params(&iter, adapter, FALSE);
+	if (ret < 0)
+		return error_reply(msg, -ret);
+
+	ret = btd_adapter_read_local_oob_data(adapter);
+	if (ret < 0)
+		return error_reply(msg, -ret);
+
+	pending_adapter = adapter;
+	pending_msg = dbus_message_ref(msg);
+	return NULL;
 }
 
 static DBusMessage *release(DBusConnection *conn, DBusMessage *msg,
@@ -414,7 +493,7 @@ static void neard_vanished(DBusConnection *conn, void *user_data)
 }
 
 static struct oob_handler neard_handler = {
-	.read_local_cb = NULL,
+	.read_local_cb = read_local_complete,
 	.pairing_cb = pairing_complete,
 };
 
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v3 17/18] adapter: Add btd_adapter_get_class function
From: Szymon Janc @ 2012-09-21 12:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1348230995-8967-1-git-send-email-szymon.janc@tieto.com>

This is a simple getter to get current Class Of Device of adapter.

---
 src/adapter.c |    5 +++++
 src/adapter.h |    2 ++
 2 files changed, 7 insertions(+)

diff --git a/src/adapter.c b/src/adapter.c
index ae61f6d..43df465 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2185,6 +2185,11 @@ void btd_adapter_read_class(struct btd_adapter *adapter, uint8_t *major,
 	*minor = cls[0];
 }
 
+uint32_t btd_adapter_get_class(struct btd_adapter *adapter)
+{
+	return adapter->dev_class;
+}
+
 const char *btd_adapter_get_name(struct btd_adapter *adapter)
 {
 	return adapter->name;
diff --git a/src/adapter.h b/src/adapter.h
index f7c4237..4f2f39f 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -86,6 +86,8 @@ void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
 
 void btd_adapter_read_class(struct btd_adapter *adapter, uint8_t *major,
 							uint8_t *minor);
+
+uint32_t btd_adapter_get_class(struct btd_adapter *adapter);
 const char *btd_adapter_get_name(struct btd_adapter *adapter);
 struct btd_device *adapter_get_device(struct btd_adapter *adapter,
 							const char *address);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v3 16/18] adapter: Rename btd_adapter_get_class to btd_adapter_read_class
From: Szymon Janc @ 2012-09-21 12:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1348230995-8967-1-git-send-email-szymon.janc@tieto.com>

It better suits what this function really does.

---
 src/adapter.c |    2 +-
 src/adapter.h |    2 +-
 src/mgmt.c    |    2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index a938c24..ae61f6d 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2171,7 +2171,7 @@ void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
 		*pairable = adapter->pairable;
 }
 
-void btd_adapter_get_class(struct btd_adapter *adapter, uint8_t *major,
+void btd_adapter_read_class(struct btd_adapter *adapter, uint8_t *major,
 								uint8_t *minor)
 {
 	uint8_t cls[3];
diff --git a/src/adapter.h b/src/adapter.h
index 4afe40f..f7c4237 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -84,7 +84,7 @@ void btd_adapter_get_mode(struct btd_adapter *adapter, uint8_t *mode,
 						uint16_t *discoverable_timeout,
 						gboolean *pairable);
 
-void btd_adapter_get_class(struct btd_adapter *adapter, uint8_t *major,
+void btd_adapter_read_class(struct btd_adapter *adapter, uint8_t *major,
 							uint8_t *minor);
 const char *btd_adapter_get_name(struct btd_adapter *adapter);
 struct btd_device *adapter_get_device(struct btd_adapter *adapter,
diff --git a/src/mgmt.c b/src/mgmt.c
index a3f31dd..8902836 100644
--- a/src/mgmt.c
+++ b/src/mgmt.c
@@ -1116,7 +1116,7 @@ static void read_info_complete(int sk, uint16_t index, void *buf, size_t len)
 	else
 		adapter_name_changed(adapter, (char *) rp->name);
 
-	btd_adapter_get_class(adapter, &major, &minor);
+	btd_adapter_read_class(adapter, &major, &minor);
 	mgmt_set_dev_class(index, major, minor);
 
 	btd_adapter_get_mode(adapter, &mode, NULL, NULL, NULL);
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v3 15/18] adapter: Add btd_adapter_get_services function
From: Szymon Janc @ 2012-09-21 12:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1348230995-8967-1-git-send-email-szymon.janc@tieto.com>

Services will be used to create EIR to be send over OOB.

---
 src/adapter.c |    5 +++++
 src/adapter.h |    1 +
 2 files changed, 6 insertions(+)

diff --git a/src/adapter.c b/src/adapter.c
index 6d2ca69..a938c24 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -990,6 +990,11 @@ struct btd_device *adapter_get_device(struct btd_adapter *adapter,
 	return adapter_create_device(adapter, address, BDADDR_BREDR);
 }
 
+sdp_list_t *btd_adapter_get_services(struct btd_adapter *adapter)
+{
+	return adapter->services;
+}
+
 static gboolean discovery_cb(gpointer user_data)
 {
 	struct btd_adapter *adapter = user_data;
diff --git a/src/adapter.h b/src/adapter.h
index eece6f5..4afe40f 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -89,6 +89,7 @@ void btd_adapter_get_class(struct btd_adapter *adapter, uint8_t *major,
 const char *btd_adapter_get_name(struct btd_adapter *adapter);
 struct btd_device *adapter_get_device(struct btd_adapter *adapter,
 							const char *address);
+sdp_list_t *btd_adapter_get_services(struct btd_adapter *adapter);
 
 struct btd_device *adapter_find_device(struct btd_adapter *adapter, const char *dest);
 
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v3 14/18] eir: Add support for creating proper OOB EIR
From: Szymon Janc @ 2012-09-21 12:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1348230995-8967-1-git-send-email-szymon.janc@tieto.com>

Address and total length field are mandatory part of OOB EIR.

---
 src/eir.c |   39 ++++++++++++++++++++++++++-------------
 src/eir.h |    2 +-
 2 files changed, 27 insertions(+), 14 deletions(-)

diff --git a/src/eir.c b/src/eir.c
index 78ae070..05b3723 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -282,7 +282,7 @@ static void eir_generate_uuid128(sdp_list_t *list, uint8_t *ptr,
 	}
 }
 
-int eir_create_oob(const char *name, uint32_t cod,
+int eir_create_oob(bdaddr_t *addr, const char *name, uint32_t cod,
 			uint8_t *hash, uint8_t *randomizer,
 			uint16_t did_vendor, uint16_t did_product,
 			uint16_t did_version, uint16_t did_source,
@@ -290,12 +290,19 @@ int eir_create_oob(const char *name, uint32_t cod,
 {
 	sdp_list_t *l;
 	uint8_t *ptr = data;
-	uint16_t eir_len = 0;
+	uint16_t eir_optional_len = 0;
+	uint16_t eir_total_len;
 	uint16_t uuid16[HCI_MAX_EIR_LENGTH / 2];
 	int i, uuid_count = 0;
 	gboolean truncated = FALSE;
 	size_t name_len;
 
+	eir_total_len =  sizeof(uint16_t) + sizeof(bdaddr_t);
+	ptr += sizeof(uint16_t);
+
+	memcpy(ptr, addr, sizeof(bdaddr_t));
+	ptr += sizeof(bdaddr_t);
+
 	if (cod > 0) {
 		uint8_t class[3];
 
@@ -309,7 +316,7 @@ int eir_create_oob(const char *name, uint32_t cod,
 		memcpy(ptr, class, sizeof(class));
 		ptr += sizeof(class);
 
-		eir_len += sizeof(class) + 2;
+		eir_optional_len += sizeof(class) + 2;
 	}
 
 	if (hash) {
@@ -319,7 +326,7 @@ int eir_create_oob(const char *name, uint32_t cod,
 		memcpy(ptr, hash, 16);
 		ptr += 16;
 
-		eir_len += 16 + 2;
+		eir_optional_len += 16 + 2;
 	}
 
 	if (randomizer) {
@@ -329,7 +336,7 @@ int eir_create_oob(const char *name, uint32_t cod,
 		memcpy(ptr, randomizer, 16);
 		ptr += 16;
 
-		eir_len += 16 + 2;
+		eir_optional_len += 16 + 2;
 	}
 
 	name_len = strlen(name);
@@ -347,7 +354,7 @@ int eir_create_oob(const char *name, uint32_t cod,
 
 		memcpy(ptr + 2, name, name_len);
 
-		eir_len += (name_len + 2);
+		eir_optional_len += (name_len + 2);
 		ptr += (name_len + 2);
 	}
 
@@ -362,7 +369,7 @@ int eir_create_oob(const char *name, uint32_t cod,
 		*ptr++ = (did_product & 0xff00) >> 8;
 		*ptr++ = (did_version & 0x00ff);
 		*ptr++ = (did_version & 0xff00) >> 8;
-		eir_len += 10;
+		eir_optional_len += 10;
 	}
 
 	/* Group all UUID16 types */
@@ -380,7 +387,8 @@ int eir_create_oob(const char *name, uint32_t cod,
 			continue;
 
 		/* Stop if not enough space to put next UUID16 */
-		if ((eir_len + 2 + sizeof(uint16_t)) > HCI_MAX_EIR_LENGTH) {
+		if ((eir_optional_len + 2 + sizeof(uint16_t)) >
+				HCI_MAX_EIR_LENGTH) {
 			truncated = TRUE;
 			break;
 		}
@@ -394,7 +402,7 @@ int eir_create_oob(const char *name, uint32_t cod,
 			continue;
 
 		uuid16[uuid_count++] = uuid->value.uuid16;
-		eir_len += sizeof(uint16_t);
+		eir_optional_len += sizeof(uint16_t);
 	}
 
 	if (uuid_count > 0) {
@@ -404,7 +412,7 @@ int eir_create_oob(const char *name, uint32_t cod,
 		ptr[1] = truncated ? EIR_UUID16_SOME : EIR_UUID16_ALL;
 
 		ptr += 2;
-		eir_len += 2;
+		eir_optional_len += 2;
 
 		for (i = 0; i < uuid_count; i++) {
 			*ptr++ = (uuid16[i] & 0x00ff);
@@ -413,10 +421,15 @@ int eir_create_oob(const char *name, uint32_t cod,
 	}
 
 	/* Group all UUID128 types */
-	if (eir_len <= HCI_MAX_EIR_LENGTH - 2)
-		eir_generate_uuid128(uuids, ptr, &eir_len);
+	if (eir_optional_len <= HCI_MAX_EIR_LENGTH - 2)
+		eir_generate_uuid128(uuids, ptr, &eir_optional_len);
 
-	return eir_len;
+	eir_total_len += eir_optional_len;
+
+	/* store total length */
+	bt_put_le16(eir_total_len, data);
+
+	return eir_total_len;
 }
 
 gboolean eir_has_data_type(uint8_t *data, size_t len, uint8_t type)
diff --git a/src/eir.h b/src/eir.h
index 0755da5..d8c5e32 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -53,7 +53,7 @@ struct eir_data {
 void eir_data_free(struct eir_data *eir);
 int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len);
 int eir_parse_oob(struct eir_data *eir, uint8_t *eir_data, uint16_t eir_len);
-int eir_create_oob(const char *name, uint32_t cod,
+int eir_create_oob(bdaddr_t *addr, const char *name, uint32_t cod,
 			uint8_t *hash, uint8_t *randomizer,
 			uint16_t did_vendor, uint16_t did_product,
 			uint16_t did_version, uint16_t did_source,
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v3 13/18] eir: Remove struct uuid_info
From: Szymon Janc @ 2012-09-21 12:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1348230995-8967-1-git-send-email-szymon.janc@tieto.com>

Remove struct uuid_info and convert functions to use sdp_record_t
list instead. This will allow to easily use services list from
struct btd_adapter to create EIR.

---
 src/eir.c |   29 ++++++++++++++++-------------
 src/eir.h |    7 +------
 2 files changed, 17 insertions(+), 19 deletions(-)

diff --git a/src/eir.c b/src/eir.c
index 598c0e4..78ae070 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -224,7 +224,8 @@ int eir_parse_oob(struct eir_data *eir, uint8_t *eir_data, uint16_t eir_len)
 
 #define SIZEOF_UUID128 16
 
-static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
+static void eir_generate_uuid128(sdp_list_t *list, uint8_t *ptr,
+							uint16_t *eir_len)
 {
 	int i, k, uuid_count = 0;
 	uint16_t len = *eir_len;
@@ -235,10 +236,11 @@ static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
 	uuid128 = ptr + 2;
 
 	for (; list; list = list->next) {
-		struct uuid_info *uuid = list->data;
-		uint8_t *uuid128_data = uuid->uuid.value.uuid128.data;
+		sdp_record_t *rec = list->data;
+		uuid_t *uuid = &rec->svclass;
+		uint8_t *uuid128_data = uuid->value.uuid128.data;
 
-		if (uuid->uuid.type != SDP_UUID128)
+		if (uuid->type != SDP_UUID128)
 			continue;
 
 		/* Stop if not enough space to put next UUID128 */
@@ -284,9 +286,9 @@ int eir_create_oob(const char *name, uint32_t cod,
 			uint8_t *hash, uint8_t *randomizer,
 			uint16_t did_vendor, uint16_t did_product,
 			uint16_t did_version, uint16_t did_source,
-			GSList *uuids, uint8_t *data)
+			sdp_list_t *uuids, uint8_t *data)
 {
-	GSList *l;
+	sdp_list_t *l;
 	uint8_t *ptr = data;
 	uint16_t eir_len = 0;
 	uint16_t uuid16[HCI_MAX_EIR_LENGTH / 2];
@@ -364,16 +366,17 @@ int eir_create_oob(const char *name, uint32_t cod,
 	}
 
 	/* Group all UUID16 types */
-	for (l = uuids; l != NULL; l = g_slist_next(l)) {
-		struct uuid_info *uuid = l->data;
+	for (l = uuids; l != NULL; l = l->next) {
+		sdp_record_t *rec = l->data;
+		uuid_t *uuid = &rec->svclass;
 
-		if (uuid->uuid.type != SDP_UUID16)
+		if (uuid->type != SDP_UUID16)
 			continue;
 
-		if (uuid->uuid.value.uuid16 < 0x1100)
+		if (uuid->value.uuid16 < 0x1100)
 			continue;
 
-		if (uuid->uuid.value.uuid16 == PNP_INFO_SVCLASS_ID)
+		if (uuid->value.uuid16 == PNP_INFO_SVCLASS_ID)
 			continue;
 
 		/* Stop if not enough space to put next UUID16 */
@@ -384,13 +387,13 @@ int eir_create_oob(const char *name, uint32_t cod,
 
 		/* Check for duplicates */
 		for (i = 0; i < uuid_count; i++)
-			if (uuid16[i] == uuid->uuid.value.uuid16)
+			if (uuid16[i] == uuid->value.uuid16)
 				break;
 
 		if (i < uuid_count)
 			continue;
 
-		uuid16[uuid_count++] = uuid->uuid.value.uuid16;
+		uuid16[uuid_count++] = uuid->value.uuid16;
 		eir_len += sizeof(uint16_t);
 	}
 
diff --git a/src/eir.h b/src/eir.h
index 036172e..0755da5 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -38,11 +38,6 @@
 #define EIR_DEVICE_ID               0x10  /* device ID */
 #define EIR_GAP_APPEARANCE          0x19  /* GAP appearance */
 
-struct uuid_info {
-	uuid_t uuid;
-	uint8_t svc_hint;
-};
-
 struct eir_data {
 	GSList *services;
 	int flags;
@@ -62,7 +57,7 @@ int eir_create_oob(const char *name, uint32_t cod,
 			uint8_t *hash, uint8_t *randomizer,
 			uint16_t did_vendor, uint16_t did_product,
 			uint16_t did_version, uint16_t did_source,
-			GSList *uuids, uint8_t *data);
+			sdp_list_t *uuids, uint8_t *data);
 
 gboolean eir_has_data_type(uint8_t *data, size_t len, uint8_t type);
 
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v3 12/18] eir: Return number of bytes written by eir_create_oob
From: Szymon Janc @ 2012-09-21 12:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1348230995-8967-1-git-send-email-szymon.janc@tieto.com>

In OOB EIR is not zero padded.

---
 src/eir.c |    4 +++-
 src/eir.h |    2 +-
 2 files changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/eir.c b/src/eir.c
index c67cf6f..598c0e4 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -280,7 +280,7 @@ static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
 	}
 }
 
-void eir_create_oob(const char *name, uint32_t cod,
+int eir_create_oob(const char *name, uint32_t cod,
 			uint8_t *hash, uint8_t *randomizer,
 			uint16_t did_vendor, uint16_t did_product,
 			uint16_t did_version, uint16_t did_source,
@@ -412,6 +412,8 @@ void eir_create_oob(const char *name, uint32_t cod,
 	/* Group all UUID128 types */
 	if (eir_len <= HCI_MAX_EIR_LENGTH - 2)
 		eir_generate_uuid128(uuids, ptr, &eir_len);
+
+	return eir_len;
 }
 
 gboolean eir_has_data_type(uint8_t *data, size_t len, uint8_t type)
diff --git a/src/eir.h b/src/eir.h
index d5c4afc..036172e 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -58,7 +58,7 @@ struct eir_data {
 void eir_data_free(struct eir_data *eir);
 int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len);
 int eir_parse_oob(struct eir_data *eir, uint8_t *eir_data, uint16_t eir_len);
-void eir_create_oob(const char *name, uint32_t cod,
+int eir_create_oob(const char *name, uint32_t cod,
 			uint8_t *hash, uint8_t *randomizer,
 			uint16_t did_vendor, uint16_t did_product,
 			uint16_t did_version, uint16_t did_source,
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v3 11/18] eir: Remove support for creating EIR with tx_power fields
From: Szymon Janc @ 2012-09-21 12:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1348230995-8967-1-git-send-email-szymon.janc@tieto.com>

This field is not used for OOB EIR.

---
 src/eir.c |    9 +--------
 src/eir.h |    2 +-
 2 files changed, 2 insertions(+), 9 deletions(-)

diff --git a/src/eir.c b/src/eir.c
index a3c99e8..c67cf6f 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -280,7 +280,7 @@ static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
 	}
 }
 
-void eir_create_oob(const char *name, int8_t tx_power, uint32_t cod,
+void eir_create_oob(const char *name, uint32_t cod,
 			uint8_t *hash, uint8_t *randomizer,
 			uint16_t did_vendor, uint16_t did_product,
 			uint16_t did_version, uint16_t did_source,
@@ -349,13 +349,6 @@ void eir_create_oob(const char *name, int8_t tx_power, uint32_t cod,
 		ptr += (name_len + 2);
 	}
 
-	if (tx_power != 0) {
-		*ptr++ = 2;
-		*ptr++ = EIR_TX_POWER;
-		*ptr++ = (uint8_t) tx_power;
-		eir_len += 3;
-	}
-
 	if (did_vendor != 0x0000) {
 		*ptr++ = 9;
 		*ptr++ = EIR_DEVICE_ID;
diff --git a/src/eir.h b/src/eir.h
index 55289f9..d5c4afc 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -58,7 +58,7 @@ struct eir_data {
 void eir_data_free(struct eir_data *eir);
 int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len);
 int eir_parse_oob(struct eir_data *eir, uint8_t *eir_data, uint16_t eir_len);
-void eir_create_oob(const char *name, int8_t tx_power, uint32_t cod,
+void eir_create_oob(const char *name, uint32_t cod,
 			uint8_t *hash, uint8_t *randomizer,
 			uint16_t did_vendor, uint16_t did_product,
 			uint16_t did_version, uint16_t did_source,
-- 
1.7.9.5


^ permalink raw reply related

* [PATCH v3 10/18] eir: Rename eir_create to eir_create_oob
From: Szymon Janc @ 2012-09-21 12:36 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Szymon Janc
In-Reply-To: <1348230995-8967-1-git-send-email-szymon.janc@tieto.com>

With mgmt interface EIR is created by kernel. Renaming this function
makes it clear what is a purpose of it in userspace. It also contains
support for EIR data types that shall be transmitted only over OOB
channel.

---
 src/eir.c |    2 +-
 src/eir.h |    2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/src/eir.c b/src/eir.c
index 46dde5a..a3c99e8 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -280,7 +280,7 @@ static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
 	}
 }
 
-void eir_create(const char *name, int8_t tx_power, uint32_t cod,
+void eir_create_oob(const char *name, int8_t tx_power, uint32_t cod,
 			uint8_t *hash, uint8_t *randomizer,
 			uint16_t did_vendor, uint16_t did_product,
 			uint16_t did_version, uint16_t did_source,
diff --git a/src/eir.h b/src/eir.h
index 1c7a603..55289f9 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -58,7 +58,7 @@ struct eir_data {
 void eir_data_free(struct eir_data *eir);
 int eir_parse(struct eir_data *eir, uint8_t *eir_data, uint8_t eir_len);
 int eir_parse_oob(struct eir_data *eir, uint8_t *eir_data, uint16_t eir_len);
-void eir_create(const char *name, int8_t tx_power, uint32_t cod,
+void eir_create_oob(const char *name, int8_t tx_power, uint32_t cod,
 			uint8_t *hash, uint8_t *randomizer,
 			uint16_t did_vendor, uint16_t did_product,
 			uint16_t did_version, uint16_t did_source,
-- 
1.7.9.5


^ permalink raw reply related


This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox