All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3 01/12] Move EIR related functions to a new file
@ 2011-05-16 20:49 Claudio Takahasi
  2011-05-16 20:49 ` [PATCH v3 02/12] Initial device found cleanup Claudio Takahasi
                   ` (10 more replies)
  0 siblings, 11 replies; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-16 20:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 Makefile.am      |    2 +-
 plugins/hciops.c |  170 +----------------------------
 src/eir.c        |  320 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 src/eir.h        |   42 +++++++
 src/event.c      |  126 +---------------------
 src/sdpd.h       |   14 ---
 6 files changed, 369 insertions(+), 305 deletions(-)
 create mode 100644 src/eir.c
 create mode 100644 src/eir.h

diff --git a/Makefile.am b/Makefile.am
index caffbe2..175f8c9 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -251,7 +251,7 @@ src_bluetoothd_SOURCES = $(gdbus_sources) $(builtin_sources) \
 			src/device.h src/device.c \
 			src/dbus-common.c src/dbus-common.h \
 			src/event.h src/event.c \
-			src/oob.h src/oob.c
+			src/oob.h src/oob.c src/eir.h src/eir.c
 src_bluetoothd_LDADD = lib/libbluetooth.la @GLIB_LIBS@ @DBUS_LIBS@ \
 							@CAPNG_LIBS@ -ldl -lrt
 src_bluetoothd_LDFLAGS = -Wl,--export-dynamic \
diff --git a/plugins/hciops.c b/plugins/hciops.c
index af638c8..07643a1 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -51,6 +51,7 @@
 #include "event.h"
 #include "manager.h"
 #include "oob.h"
+#include "eir.h"
 
 #define DISCOV_HALTED 0
 #define DISCOV_INQ 1
@@ -84,11 +85,6 @@ enum {
 	PENDING_NAME,
 };
 
-struct uuid_info {
-	uuid_t uuid;
-	uint8_t svc_hint;
-};
-
 struct bt_conn {
 	struct dev_info *dev;
 	bdaddr_t bdaddr;
@@ -1435,167 +1431,6 @@ static void read_local_features_complete(int index,
 		init_adapter(index);
 }
 
-#define SIZEOF_UUID128 16
-
-static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
-{
-	int i, k, uuid_count = 0;
-	uint16_t len = *eir_len;
-	uint8_t *uuid128;
-	gboolean truncated = FALSE;
-
-	/* Store UUIDs in place, skip 2 bytes to write type and length later */
-	uuid128 = ptr + 2;
-
-	for (; list; list = list->next) {
-		struct uuid_info *uuid = list->data;
-		uint8_t *uuid128_data = uuid->uuid.value.uuid128.data;
-
-		if (uuid->uuid.type != SDP_UUID128)
-			continue;
-
-		/* Stop if not enough space to put next UUID128 */
-		if ((len + 2 + SIZEOF_UUID128) > EIR_DATA_LENGTH) {
-			truncated = TRUE;
-			break;
-		}
-
-		/* Check for duplicates, EIR data is Little Endian */
-		for (i = 0; i < uuid_count; i++) {
-			for (k = 0; k < SIZEOF_UUID128; k++) {
-				if (uuid128[i * SIZEOF_UUID128 + k] !=
-					uuid128_data[SIZEOF_UUID128 - 1 - k])
-					break;
-			}
-			if (k == SIZEOF_UUID128)
-				break;
-		}
-
-		if (i < uuid_count)
-			continue;
-
-		/* EIR data is Little Endian */
-		for (k = 0; k < SIZEOF_UUID128; k++)
-			uuid128[uuid_count * SIZEOF_UUID128 + k] =
-				uuid128_data[SIZEOF_UUID128 - 1 - k];
-
-		len += SIZEOF_UUID128;
-		uuid_count++;
-	}
-
-	if (uuid_count > 0 || truncated) {
-		/* EIR Data length */
-		ptr[0] = (uuid_count * SIZEOF_UUID128) + 1;
-		/* EIR Data type */
-		ptr[1] = truncated ? EIR_UUID128_SOME : EIR_UUID128_ALL;
-		len += 2;
-		*eir_len = len;
-	}
-}
-
-static void create_ext_inquiry_response(int index, uint8_t *data)
-{
-	struct dev_info *dev = &devs[index];
-	GSList *l;
-	uint8_t *ptr = data;
-	uint16_t eir_len = 0;
-	uint16_t uuid16[EIR_DATA_LENGTH / 2];
-	int i, uuid_count = 0;
-	gboolean truncated = FALSE;
-	size_t name_len;
-
-	name_len = strlen(dev->name);
-
-	if (name_len > 0) {
-		/* EIR Data type */
-		if (name_len > 48) {
-			name_len = 48;
-			ptr[1] = EIR_NAME_SHORT;
-		} else
-			ptr[1] = EIR_NAME_COMPLETE;
-
-		/* EIR Data length */
-		ptr[0] = name_len + 1;
-
-		memcpy(ptr + 2, dev->name, name_len);
-
-		eir_len += (name_len + 2);
-		ptr += (name_len + 2);
-	}
-
-	if (dev->tx_power != 0) {
-		*ptr++ = 2;
-		*ptr++ = EIR_TX_POWER;
-		*ptr++ = (uint8_t) dev->tx_power;
-		eir_len += 3;
-	}
-
-	if (dev->did_vendor != 0x0000) {
-		uint16_t source = 0x0002;
-		*ptr++ = 9;
-		*ptr++ = EIR_DEVICE_ID;
-		*ptr++ = (source & 0x00ff);
-		*ptr++ = (source & 0xff00) >> 8;
-		*ptr++ = (dev->did_vendor & 0x00ff);
-		*ptr++ = (dev->did_vendor & 0xff00) >> 8;
-		*ptr++ = (dev->did_product & 0x00ff);
-		*ptr++ = (dev->did_product & 0xff00) >> 8;
-		*ptr++ = (dev->did_version & 0x00ff);
-		*ptr++ = (dev->did_version & 0xff00) >> 8;
-		eir_len += 10;
-	}
-
-	/* Group all UUID16 types */
-	for (l = dev->uuids; l != NULL; l = g_slist_next(l)) {
-		struct uuid_info *uuid = l->data;
-
-		if (uuid->uuid.type != SDP_UUID16)
-			continue;
-
-		if (uuid->uuid.value.uuid16 < 0x1100)
-			continue;
-
-		if (uuid->uuid.value.uuid16 == PNP_INFO_SVCLASS_ID)
-			continue;
-
-		/* Stop if not enough space to put next UUID16 */
-		if ((eir_len + 2 + sizeof(uint16_t)) > EIR_DATA_LENGTH) {
-			truncated = TRUE;
-			break;
-		}
-
-		/* Check for duplicates */
-		for (i = 0; i < uuid_count; i++)
-			if (uuid16[i] == uuid->uuid.value.uuid16)
-				break;
-
-		if (i < uuid_count)
-			continue;
-
-		uuid16[uuid_count++] = uuid->uuid.value.uuid16;
-		eir_len += sizeof(uint16_t);
-	}
-
-	if (uuid_count > 0) {
-		/* EIR Data length */
-		ptr[0] = (uuid_count * sizeof(uint16_t)) + 1;
-		/* EIR Data type */
-		ptr[1] = truncated ? EIR_UUID16_SOME : EIR_UUID16_ALL;
-
-		ptr += 2;
-		eir_len += 2;
-
-		for (i = 0; i < uuid_count; i++) {
-			*ptr++ = (uuid16[i] & 0x00ff);
-			*ptr++ = (uuid16[i] & 0xff00) >> 8;
-		}
-	}
-
-	/* Group all UUID128 types */
-	if (eir_len <= EIR_DATA_LENGTH - 2)
-		eir_generate_uuid128(dev->uuids, ptr, &eir_len);
-}
-
 static void update_ext_inquiry_response(int index)
 {
 	struct dev_info *dev = &devs[index];
@@ -1614,7 +1449,8 @@ static void update_ext_inquiry_response(int index)
 
 	memset(&cp, 0, sizeof(cp));
 
-	create_ext_inquiry_response(index, cp.data);
+	eir_create(dev->name, dev->tx_power, dev->did_vendor, dev->did_product,
+					dev->did_version, dev->uuids, cp.data);
 
 	if (memcmp(cp.data, dev->eir, sizeof(cp.data)) == 0)
 		return;
diff --git a/src/eir.c b/src/eir.c
new file mode 100644
index 0000000..d827c7e
--- /dev/null
+++ b/src/eir.c
@@ -0,0 +1,320 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2011  Nokia Corporation
+ *  Copyright (C) 2011  Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ *  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 <errno.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <glib.h>
+
+#include <bluetooth/bluetooth.h>
+#include <bluetooth/sdp.h>
+
+#include "glib-helper.h"
+#include "eir.h"
+
+#define EIR_FLAGS                   0x01  /* flags */
+#define EIR_UUID16_SOME             0x02  /* 16-bit UUID, more available */
+#define EIR_UUID16_ALL              0x03  /* 16-bit UUID, all listed */
+#define EIR_UUID32_SOME             0x04  /* 32-bit UUID, more available */
+#define EIR_UUID32_ALL              0x05  /* 32-bit UUID, all listed */
+#define EIR_UUID128_SOME            0x06  /* 128-bit UUID, more available */
+#define EIR_UUID128_ALL             0x07  /* 128-bit UUID, all listed */
+#define EIR_NAME_SHORT              0x08  /* shortened local name */
+#define EIR_NAME_COMPLETE           0x09  /* complete local name */
+#define EIR_TX_POWER                0x0A  /* transmit power level */
+#define EIR_DEVICE_ID               0x10  /* device ID */
+
+int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
+{
+	uint16_t len = 0;
+	size_t total;
+	size_t uuid16_count = 0;
+	size_t uuid32_count = 0;
+	size_t uuid128_count = 0;
+	uint8_t *uuid16 = NULL;
+	uint8_t *uuid32 = NULL;
+	uint8_t *uuid128 = NULL;
+	uuid_t service;
+	char *uuid_str;
+	unsigned int i;
+
+	eir->flags = -1;
+
+	/* No EIR data to parse */
+	if (eir_data == NULL || eir_length == 0)
+		return 0;
+
+	while (len < eir_length - 1) {
+		uint8_t field_len = eir_data[0];
+
+		/* Check for the end of EIR */
+		if (field_len == 0)
+			break;
+
+		switch (eir_data[1]) {
+		case EIR_UUID16_SOME:
+		case EIR_UUID16_ALL:
+			uuid16_count = field_len / 2;
+			uuid16 = &eir_data[2];
+			break;
+		case EIR_UUID32_SOME:
+		case EIR_UUID32_ALL:
+			uuid32_count = field_len / 4;
+			uuid32 = &eir_data[2];
+			break;
+		case EIR_UUID128_SOME:
+		case EIR_UUID128_ALL:
+			uuid128_count = field_len / 16;
+			uuid128 = &eir_data[2];
+			break;
+		case EIR_FLAGS:
+			eir->flags = eir_data[2];
+			break;
+		case EIR_NAME_SHORT:
+		case EIR_NAME_COMPLETE:
+			if (g_utf8_validate((char *) &eir_data[2],
+							field_len - 1, NULL))
+				eir->name = g_strndup((char *) &eir_data[2],
+								field_len - 1);
+			else
+				eir->name = g_strdup("");
+			eir->name_complete = eir_data[1] == EIR_NAME_COMPLETE;
+			break;
+		}
+
+		len += field_len + 1;
+		eir_data += field_len + 1;
+	}
+
+	/* Bail out if got incorrect length */
+	if (len > eir_length)
+		return -EINVAL;
+
+	total = uuid16_count + uuid32_count + uuid128_count;
+
+	/* No UUIDs were parsed, so skip code below */
+	if (!total)
+		return 0;
+
+	/* Generate uuids in SDP format (EIR data is Little Endian) */
+	service.type = SDP_UUID16;
+	for (i = 0; i < uuid16_count; i++) {
+		uint16_t val16 = uuid16[1];
+
+		val16 = (val16 << 8) + uuid16[0];
+		service.value.uuid16 = val16;
+		uuid_str = bt_uuid2string(&service);
+		eir->services = g_slist_append(eir->services, uuid_str);
+		uuid16 += 2;
+	}
+
+	service.type = SDP_UUID32;
+	for (i = uuid16_count; i < uuid32_count + uuid16_count; i++) {
+		uint32_t val32 = uuid32[3];
+		int k;
+
+		for (k = 2; k >= 0; k--)
+			val32 = (val32 << 8) + uuid32[k];
+
+		service.value.uuid32 = val32;
+		uuid_str = bt_uuid2string(&service);
+		eir->services = g_slist_append(eir->services, uuid_str);
+		uuid32 += 4;
+	}
+
+	service.type = SDP_UUID128;
+	for (i = uuid32_count + uuid16_count; i < total; i++) {
+		int k;
+
+		for (k = 0; k < 16; k++)
+			service.value.uuid128.data[k] = uuid128[16 - k - 1];
+
+		uuid_str = bt_uuid2string(&service);
+		eir->services = g_slist_append(eir->services, uuid_str);
+		uuid128 += 16;
+	}
+
+	return 0;
+}
+
+#define SIZEOF_UUID128 16
+
+static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
+{
+	int i, k, uuid_count = 0;
+	uint16_t len = *eir_len;
+	uint8_t *uuid128;
+	gboolean truncated = FALSE;
+
+	/* Store UUIDs in place, skip 2 bytes to write type and length later */
+	uuid128 = ptr + 2;
+
+	for (; list; list = list->next) {
+		struct uuid_info *uuid = list->data;
+		uint8_t *uuid128_data = uuid->uuid.value.uuid128.data;
+
+		if (uuid->uuid.type != SDP_UUID128)
+			continue;
+
+		/* Stop if not enough space to put next UUID128 */
+		if ((len + 2 + SIZEOF_UUID128) > EIR_DATA_LENGTH) {
+			truncated = TRUE;
+			break;
+		}
+
+		/* Check for duplicates, EIR data is Little Endian */
+		for (i = 0; i < uuid_count; i++) {
+			for (k = 0; k < SIZEOF_UUID128; k++) {
+				if (uuid128[i * SIZEOF_UUID128 + k] !=
+					uuid128_data[SIZEOF_UUID128 - 1 - k])
+					break;
+			}
+			if (k == SIZEOF_UUID128)
+				break;
+		}
+
+		if (i < uuid_count)
+			continue;
+
+		/* EIR data is Little Endian */
+		for (k = 0; k < SIZEOF_UUID128; k++)
+			uuid128[uuid_count * SIZEOF_UUID128 + k] =
+				uuid128_data[SIZEOF_UUID128 - 1 - k];
+
+		len += SIZEOF_UUID128;
+		uuid_count++;
+	}
+
+	if (uuid_count > 0 || truncated) {
+		/* EIR Data length */
+		ptr[0] = (uuid_count * SIZEOF_UUID128) + 1;
+		/* EIR Data type */
+		ptr[1] = truncated ? EIR_UUID128_SOME : EIR_UUID128_ALL;
+		len += 2;
+		*eir_len = len;
+	}
+}
+
+void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
+			uint16_t did_product, uint16_t did_version,
+			GSList *uuids, uint8_t *data)
+{
+	GSList *l;
+	uint8_t *ptr = data;
+	uint16_t eir_len = 0;
+	uint16_t uuid16[EIR_DATA_LENGTH / 2];
+	int i, uuid_count = 0;
+	gboolean truncated = FALSE;
+	size_t name_len;
+
+	name_len = strlen(name);
+
+	if (name_len > 0) {
+		/* EIR Data type */
+		if (name_len > 48) {
+			name_len = 48;
+			ptr[1] = EIR_NAME_SHORT;
+		} else
+			ptr[1] = EIR_NAME_COMPLETE;
+
+		/* EIR Data length */
+		ptr[0] = name_len + 1;
+
+		memcpy(ptr + 2, name, name_len);
+
+		eir_len += (name_len + 2);
+		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) {
+		uint16_t source = 0x0002;
+		*ptr++ = 9;
+		*ptr++ = EIR_DEVICE_ID;
+		*ptr++ = (source & 0x00ff);
+		*ptr++ = (source & 0xff00) >> 8;
+		*ptr++ = (did_vendor & 0x00ff);
+		*ptr++ = (did_vendor & 0xff00) >> 8;
+		*ptr++ = (did_product & 0x00ff);
+		*ptr++ = (did_product & 0xff00) >> 8;
+		*ptr++ = (did_version & 0x00ff);
+		*ptr++ = (did_version & 0xff00) >> 8;
+		eir_len += 10;
+	}
+
+	/* Group all UUID16 types */
+	for (l = uuids; l != NULL; l = g_slist_next(l)) {
+		struct uuid_info *uuid = l->data;
+
+		if (uuid->uuid.type != SDP_UUID16)
+			continue;
+
+		if (uuid->uuid.value.uuid16 < 0x1100)
+			continue;
+
+		if (uuid->uuid.value.uuid16 == PNP_INFO_SVCLASS_ID)
+			continue;
+
+		/* Stop if not enough space to put next UUID16 */
+		if ((eir_len + 2 + sizeof(uint16_t)) > EIR_DATA_LENGTH) {
+			truncated = TRUE;
+			break;
+		}
+
+		/* Check for duplicates */
+		for (i = 0; i < uuid_count; i++)
+			if (uuid16[i] == uuid->uuid.value.uuid16)
+				break;
+
+		if (i < uuid_count)
+			continue;
+
+		uuid16[uuid_count++] = uuid->uuid.value.uuid16;
+		eir_len += sizeof(uint16_t);
+	}
+
+	if (uuid_count > 0) {
+		/* EIR Data length */
+		ptr[0] = (uuid_count * sizeof(uint16_t)) + 1;
+		/* EIR Data type */
+		ptr[1] = truncated ? EIR_UUID16_SOME : EIR_UUID16_ALL;
+
+		ptr += 2;
+		eir_len += 2;
+
+		for (i = 0; i < uuid_count; i++) {
+			*ptr++ = (uuid16[i] & 0x00ff);
+			*ptr++ = (uuid16[i] & 0xff00) >> 8;
+		}
+	}
+
+	/* Group all UUID128 types */
+	if (eir_len <= EIR_DATA_LENGTH - 2)
+		eir_generate_uuid128(uuids, ptr, &eir_len);
+}
diff --git a/src/eir.h b/src/eir.h
new file mode 100644
index 0000000..c7699eb
--- /dev/null
+++ b/src/eir.h
@@ -0,0 +1,42 @@
+/*
+ *
+ *  BlueZ - Bluetooth protocol stack for Linux
+ *
+ *  Copyright (C) 2011  Nokia Corporation
+ *  Copyright (C) 2011  Marcel Holtmann <marcel@holtmann.org>
+ *
+ *
+ *  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
+ *
+ */
+
+#define EIR_DATA_LENGTH  240
+
+struct uuid_info {
+	uuid_t uuid;
+	uint8_t svc_hint;
+};
+
+struct eir_data {
+	GSList *services;
+	int flags;
+	char *name;
+	gboolean name_complete;
+};
+
+int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length);
+void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
+			uint16_t did_product, uint16_t did_version,
+			GSList *uuids, uint8_t *data);
diff --git a/src/event.c b/src/event.c
index 141a04e..dc1b659 100644
--- a/src/event.c
+++ b/src/event.c
@@ -58,13 +58,7 @@
 #include "storage.h"
 #include "event.h"
 #include "sdpd.h"
-
-struct eir_data {
-	GSList *services;
-	int flags;
-	char *name;
-	gboolean name_complete;
-};
+#include "eir.h"
 
 static gboolean get_adapter_and_device(bdaddr_t *src, bdaddr_t *dst,
 					struct btd_adapter **adapter,
@@ -287,120 +281,6 @@ void btd_event_simple_pairing_complete(bdaddr_t *local, bdaddr_t *peer,
 	device_simple_pairing_complete(device, status);
 }
 
-static int parse_eir_data(struct eir_data *eir, uint8_t *eir_data,
-							size_t eir_length)
-{
-	uint16_t len = 0;
-	size_t total;
-	size_t uuid16_count = 0;
-	size_t uuid32_count = 0;
-	size_t uuid128_count = 0;
-	uint8_t *uuid16 = NULL;
-	uint8_t *uuid32 = NULL;
-	uint8_t *uuid128 = NULL;
-	uuid_t service;
-	char *uuid_str;
-	unsigned int i;
-
-	eir->flags = -1;
-
-	/* No EIR data to parse */
-	if (eir_data == NULL || eir_length == 0)
-		return 0;
-
-	while (len < eir_length - 1) {
-		uint8_t field_len = eir_data[0];
-
-		/* Check for the end of EIR */
-		if (field_len == 0)
-			break;
-
-		switch (eir_data[1]) {
-		case EIR_UUID16_SOME:
-		case EIR_UUID16_ALL:
-			uuid16_count = field_len / 2;
-			uuid16 = &eir_data[2];
-			break;
-		case EIR_UUID32_SOME:
-		case EIR_UUID32_ALL:
-			uuid32_count = field_len / 4;
-			uuid32 = &eir_data[2];
-			break;
-		case EIR_UUID128_SOME:
-		case EIR_UUID128_ALL:
-			uuid128_count = field_len / 16;
-			uuid128 = &eir_data[2];
-			break;
-		case EIR_FLAGS:
-			eir->flags = eir_data[2];
-			break;
-		case EIR_NAME_SHORT:
-		case EIR_NAME_COMPLETE:
-			if (g_utf8_validate((char *) &eir_data[2],
-							field_len - 1, NULL))
-				eir->name = g_strndup((char *) &eir_data[2],
-								field_len - 1);
-			else
-				eir->name = g_strdup("");
-			eir->name_complete = eir_data[1] == EIR_NAME_COMPLETE;
-			break;
-		}
-
-		len += field_len + 1;
-		eir_data += field_len + 1;
-	}
-
-	/* Bail out if got incorrect length */
-	if (len > eir_length)
-		return -EINVAL;
-
-	total = uuid16_count + uuid32_count + uuid128_count;
-
-	/* No UUIDs were parsed, so skip code below */
-	if (!total)
-		return 0;
-
-	/* Generate uuids in SDP format (EIR data is Little Endian) */
-	service.type = SDP_UUID16;
-	for (i = 0; i < uuid16_count; i++) {
-		uint16_t val16 = uuid16[1];
-
-		val16 = (val16 << 8) + uuid16[0];
-		service.value.uuid16 = val16;
-		uuid_str = bt_uuid2string(&service);
-		eir->services = g_slist_append(eir->services, uuid_str);
-		uuid16 += 2;
-	}
-
-	service.type = SDP_UUID32;
-	for (i = uuid16_count; i < uuid32_count + uuid16_count; i++) {
-		uint32_t val32 = uuid32[3];
-		int k;
-
-		for (k = 2; k >= 0; k--)
-			val32 = (val32 << 8) + uuid32[k];
-
-		service.value.uuid32 = val32;
-		uuid_str = bt_uuid2string(&service);
-		eir->services = g_slist_append(eir->services, uuid_str);
-		uuid32 += 4;
-	}
-
-	service.type = SDP_UUID128;
-	for (i = uuid32_count + uuid16_count; i < total; i++) {
-		int k;
-
-		for (k = 0; k < 16; k++)
-			service.value.uuid128.data[k] = uuid128[16 - k - 1];
-
-		uuid_str = bt_uuid2string(&service);
-		eir->services = g_slist_append(eir->services, uuid_str);
-		uuid128 += 16;
-	}
-
-	return 0;
-}
-
 static void free_eir_data(struct eir_data *eir)
 {
 	g_slist_foreach(eir->services, (GFunc) g_free, NULL);
@@ -422,7 +302,7 @@ void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info)
 	}
 
 	memset(&eir_data, 0, sizeof(eir_data));
-	err = parse_eir_data(&eir_data, info->data, info->length);
+	err = eir_parse(&eir_data, info->data, info->length);
 	if (err < 0)
 		error("Error parsing advertising data: %s (%d)",
 							strerror(-err), -err);
@@ -511,7 +391,7 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 		legacy = TRUE;
 
 	memset(&eir_data, 0, sizeof(eir_data));
-	err = parse_eir_data(&eir_data, data, EIR_DATA_LENGTH);
+	err = eir_parse(&eir_data, data, EIR_DATA_LENGTH);
 	if (err < 0)
 		error("Error parsing EIR data: %s (%d)", strerror(-err), -err);
 
diff --git a/src/sdpd.h b/src/sdpd.h
index 471e9cc..9f5415f 100644
--- a/src/sdpd.h
+++ b/src/sdpd.h
@@ -34,20 +34,6 @@
 #define SDPDBG(fmt...)
 #endif
 
-#define EIR_DATA_LENGTH  240
-
-#define EIR_FLAGS                   0x01  /* flags */
-#define EIR_UUID16_SOME             0x02  /* 16-bit UUID, more available */
-#define EIR_UUID16_ALL              0x03  /* 16-bit UUID, all listed */
-#define EIR_UUID32_SOME             0x04  /* 32-bit UUID, more available */
-#define EIR_UUID32_ALL              0x05  /* 32-bit UUID, all listed */
-#define EIR_UUID128_SOME            0x06  /* 128-bit UUID, more available */
-#define EIR_UUID128_ALL             0x07  /* 128-bit UUID, all listed */
-#define EIR_NAME_SHORT              0x08  /* shortened local name */
-#define EIR_NAME_COMPLETE           0x09  /* complete local name */
-#define EIR_TX_POWER                0x0A  /* transmit power level */
-#define EIR_DEVICE_ID               0x10  /* device ID */
-
 typedef struct request {
 	bdaddr_t device;
 	bdaddr_t bdaddr;
-- 
1.7.5.rc3


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

* [PATCH v3 02/12] Initial device found cleanup
  2011-05-16 20:49 [PATCH v3 01/12] Move EIR related functions to a new file Claudio Takahasi
@ 2011-05-16 20:49 ` Claudio Takahasi
  2011-05-16 20:49 ` [PATCH v3 03/12] Move legacy verification to a new function Claudio Takahasi
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-16 20:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Moves EIR parsing call and stored name loading to adapter. This patch
doesn't change the implemented logic, it is only the initial step to
integrated inquiry results and LE advertises.
---
 src/adapter.c |   70 ++++++++++++++++++++++++++++++++++++++++++++++++++------
 src/adapter.h |    4 +--
 src/event.c   |   60 +------------------------------------------------
 3 files changed, 64 insertions(+), 70 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index a85980c..3188974 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -58,6 +58,7 @@
 #include "storage.h"
 #include "attrib-server.h"
 #include "att.h"
+#include "eir.h"
 
 /* Flags Descriptions */
 #define EIR_LIM_DISC                0x01 /* LE Limited Discoverable Mode */
@@ -3002,18 +3003,71 @@ void adapter_update_device_from_info(struct btd_adapter *adapter,
 }
 
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-				int8_t rssi, uint32_t class, const char *name,
-				const char *alias, gboolean legacy,
-				GSList *services, name_status_t name_status)
+				uint32_t class, int8_t rssi, uint8_t *data)
 {
+	char local_addr[18], peer_addr[18], filename[PATH_MAX + 1];
 	struct remote_dev_info *dev;
-	gboolean new_dev;
+	struct eir_data eir_data;
+	char *alias, *name;
+	gboolean new_dev, legacy;
+	name_status_t name_status;
+	unsigned char features[8];
+	const char *dev_name;
+	int err;
+
+	memset(&eir_data, 0, sizeof(eir_data));
+	err = eir_parse(&eir_data, data, EIR_DATA_LENGTH);
+	if (err < 0) {
+		error("Error parsing EIR data: %s (%d)", strerror(-err), -err);
+		return;
+	}
+
+	/* the inquiry result can be triggered by NON D-Bus client */
+	if (main_opts.name_resolv && adapter_has_discov_sessions(adapter))
+		name_status = NAME_REQUIRED;
+	else
+		name_status = NAME_NOT_REQUIRED;
+
+	ba2str(&adapter->bdaddr, local_addr);
+	ba2str(bdaddr, peer_addr);
+
+	create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "aliases");
+	alias = textfile_get(filename, peer_addr);
+
+	create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "names");
+	name = textfile_get(filename, peer_addr);
+
+	if (data)
+		legacy = FALSE;
+	else if (name == NULL)
+		legacy = TRUE;
+	else if (read_remote_features(&adapter->bdaddr, bdaddr, NULL,
+							features) == 0) {
+		if (features[0] & 0x01)
+			legacy = FALSE;
+		else
+			legacy = TRUE;
+	} else
+		legacy = TRUE;
+
+	/* Complete EIR names are always used. Shortened EIR names are only
+	 * used if there is no name already in storage. */
+	dev_name = name;
+	if (eir_data.name != NULL) {
+		if (eir_data.name_complete) {
+			write_device_name(&adapter->bdaddr, bdaddr,
+							eir_data.name);
+			name_status = NAME_NOT_REQUIRED;
+			dev_name = eir_data.name;
+		} else if (name == NULL)
+			dev_name = eir_data.name;
+	}
 
 	dev = get_found_dev(adapter, bdaddr, &new_dev);
 
 	if (new_dev) {
-		if (name)
-			dev->name = g_strdup(name);
+		if (dev_name)
+			dev->name = g_strdup(dev_name);
 
 		if (alias)
 			dev->alias = g_strdup(alias);
@@ -3030,8 +3084,8 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	adapter->found_devices = g_slist_sort(adapter->found_devices,
 						(GCompareFunc) dev_rssi_cmp);
 
-	g_slist_foreach(services, remove_same_uuid, dev);
-	g_slist_foreach(services, dev_prepend_uuid, dev);
+	g_slist_foreach(eir_data.services, remove_same_uuid, dev);
+	g_slist_foreach(eir_data.services, dev_prepend_uuid, dev);
 
 	adapter_emit_device_found(adapter, dev);
 }
diff --git a/src/adapter.h b/src/adapter.h
index 51e8c30..4785d5c 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -113,9 +113,7 @@ void adapter_update_device_from_info(struct btd_adapter *adapter,
 					const char *name, GSList *services,
 					int flags);
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-				int8_t rssi, uint32_t class, const char *name,
-				const char *alias, gboolean legacy,
-				GSList *services, name_status_t name_status);
+				uint32_t class, int8_t rssi, uint8_t *data);
 int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr);
 void adapter_emit_device_found(struct btd_adapter *adapter,
 						struct remote_dev_info *dev);
diff --git a/src/event.c b/src/event.c
index dc1b659..2c893f0 100644
--- a/src/event.c
+++ b/src/event.c
@@ -341,18 +341,7 @@ static void update_lastused(bdaddr_t *sba, bdaddr_t *dba)
 void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 				int8_t rssi, uint8_t *data)
 {
-	char filename[PATH_MAX + 1];
 	struct btd_adapter *adapter;
-	char local_addr[18], peer_addr[18], *alias, *name;
-	name_status_t name_status;
-	struct eir_data eir_data;
-	int err;
-	dbus_bool_t legacy;
-	unsigned char features[8];
-	const char *dev_name;
-
-	ba2str(local, local_addr);
-	ba2str(peer, peer_addr);
 
 	adapter = manager_find_adapter(local);
 	if (!adapter) {
@@ -366,54 +355,7 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 	if (data)
 		write_remote_eir(local, peer, data);
 
-	/* the inquiry result can be triggered by NON D-Bus client */
-	if (main_opts.name_resolv && adapter_has_discov_sessions(adapter))
-		name_status = NAME_REQUIRED;
-	else
-		name_status = NAME_NOT_REQUIRED;
-
-	create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "aliases");
-	alias = textfile_get(filename, peer_addr);
-
-	create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "names");
-	name = textfile_get(filename, peer_addr);
-
-	if (data)
-		legacy = FALSE;
-	else if (name == NULL)
-		legacy = TRUE;
-	else if (read_remote_features(local, peer, NULL, features) == 0) {
-		if (features[0] & 0x01)
-			legacy = FALSE;
-		else
-			legacy = TRUE;
-	} else
-		legacy = TRUE;
-
-	memset(&eir_data, 0, sizeof(eir_data));
-	err = eir_parse(&eir_data, data, EIR_DATA_LENGTH);
-	if (err < 0)
-		error("Error parsing EIR data: %s (%d)", strerror(-err), -err);
-
-	/* Complete EIR names are always used. Shortened EIR names are only
-	 * used if there is no name already in storage. */
-	dev_name = name;
-	if (eir_data.name != NULL) {
-		if (eir_data.name_complete) {
-			write_device_name(local, peer, eir_data.name);
-			name_status = NAME_NOT_REQUIRED;
-			dev_name = eir_data.name;
-		} else if (name == NULL)
-			dev_name = eir_data.name;
-	}
-
-	adapter_update_found_devices(adapter, peer, rssi, class, dev_name,
-					alias, legacy, eir_data.services,
-					name_status);
-
-	free_eir_data(&eir_data);
-	free(name);
-	free(alias);
+	adapter_update_found_devices(adapter, peer, class, rssi, data);
 }
 
 void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
-- 
1.7.5.rc3


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

* [PATCH v3 03/12] Move legacy verification to a new function
  2011-05-16 20:49 [PATCH v3 01/12] Move EIR related functions to a new file Claudio Takahasi
  2011-05-16 20:49 ` [PATCH v3 02/12] Initial device found cleanup Claudio Takahasi
@ 2011-05-16 20:49 ` Claudio Takahasi
  2011-05-17 16:13   ` Johan Hedberg
  2011-05-16 20:49 ` [PATCH v3 04/12] Cleanup read name and alias from storage Claudio Takahasi
                   ` (8 subsequent siblings)
  10 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-16 20:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/adapter.c |   40 ++++++++++++++++++++++++++++------------
 1 files changed, 28 insertions(+), 12 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 3188974..6f85abf 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3002,6 +3002,31 @@ void adapter_update_device_from_info(struct btd_adapter *adapter,
 	adapter_emit_device_found(adapter, dev);
 }
 
+static int pairing_is_legacy(bdaddr_t *local, bdaddr_t *peer, gboolean eir,
+					gboolean name, gboolean *legacy)
+{
+	unsigned char features[8];
+	int err;
+
+	if (eir) {
+		*legacy = FALSE;
+		return 0;
+	}
+
+	if (name == FALSE) {
+		*legacy = TRUE;
+		return 0;
+	}
+
+	err = read_remote_features(local, peer, NULL, features);
+	if (err < 0)
+		return err;
+
+	*legacy = (features[0] & 0x01 ? FALSE : TRUE);
+
+	return 0;
+}
+
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 				uint32_t class, int8_t rssi, uint8_t *data)
 {
@@ -3011,7 +3036,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	char *alias, *name;
 	gboolean new_dev, legacy;
 	name_status_t name_status;
-	unsigned char features[8];
 	const char *dev_name;
 	int err;
 
@@ -3037,17 +3061,9 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "names");
 	name = textfile_get(filename, peer_addr);
 
-	if (data)
-		legacy = FALSE;
-	else if (name == NULL)
-		legacy = TRUE;
-	else if (read_remote_features(&adapter->bdaddr, bdaddr, NULL,
-							features) == 0) {
-		if (features[0] & 0x01)
-			legacy = FALSE;
-		else
-			legacy = TRUE;
-	} else
+	if (pairing_is_legacy(&adapter->bdaddr, bdaddr,
+				data ? TRUE : FALSE, name ? TRUE : FALSE,
+				&legacy) < 0)
 		legacy = TRUE;
 
 	/* Complete EIR names are always used. Shortened EIR names are only
-- 
1.7.5.rc3


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

* [PATCH v3 04/12] Cleanup read name and alias from storage
  2011-05-16 20:49 [PATCH v3 01/12] Move EIR related functions to a new file Claudio Takahasi
  2011-05-16 20:49 ` [PATCH v3 02/12] Initial device found cleanup Claudio Takahasi
  2011-05-16 20:49 ` [PATCH v3 03/12] Move legacy verification to a new function Claudio Takahasi
@ 2011-05-16 20:49 ` Claudio Takahasi
  2011-05-17 18:25   ` [PATCH v4 " Claudio Takahasi
  2011-05-16 20:49 ` [PATCH v3 05/12] Don't resolve name if the name is in the storage Claudio Takahasi
                   ` (7 subsequent siblings)
  10 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-16 20:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/adapter.c |   36 +++++++++++++++++++++++-------------
 1 files changed, 23 insertions(+), 13 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 6f85abf..701558c 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3027,13 +3027,24 @@ static int pairing_is_legacy(bdaddr_t *local, bdaddr_t *peer, gboolean eir,
 	return 0;
 }
 
+static char *read_stored_data(bdaddr_t *local, bdaddr_t *peer, const char *file)
+{
+	char local_addr[18], peer_addr[18], filename[PATH_MAX + 1];
+
+	ba2str(local, local_addr);
+	ba2str(peer, peer_addr);
+
+	create_name(filename, PATH_MAX, STORAGEDIR, local_addr, file);
+
+	return textfile_get(filename, peer_addr);
+}
+
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 				uint32_t class, int8_t rssi, uint8_t *data)
 {
-	char local_addr[18], peer_addr[18], filename[PATH_MAX + 1];
 	struct remote_dev_info *dev;
 	struct eir_data eir_data;
-	char *alias, *name;
+	char *name;
 	gboolean new_dev, legacy;
 	name_status_t name_status;
 	const char *dev_name;
@@ -3052,15 +3063,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	else
 		name_status = NAME_NOT_REQUIRED;
 
-	ba2str(&adapter->bdaddr, local_addr);
-	ba2str(bdaddr, peer_addr);
-
-	create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "aliases");
-	alias = textfile_get(filename, peer_addr);
-
-	create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "names");
-	name = textfile_get(filename, peer_addr);
-
+	name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
 	if (pairing_is_legacy(&adapter->bdaddr, bdaddr,
 				data ? TRUE : FALSE, name ? TRUE : FALSE,
 				&legacy) < 0)
@@ -3082,18 +3085,22 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	dev = get_found_dev(adapter, bdaddr, &new_dev);
 
 	if (new_dev) {
+		char *alias;
 		if (dev_name)
 			dev->name = g_strdup(dev_name);
 
-		if (alias)
+		alias = read_stored_data(&adapter->bdaddr, bdaddr, "aliases");
+		if (alias) {
 			dev->alias = g_strdup(alias);
+			free(alias);
+		}
 
 		dev->le = FALSE;
 		dev->class = class;
 		dev->legacy = legacy;
 		dev->name_status = name_status;
 	} else if (dev->rssi == rssi)
-		return;
+		goto done;
 
 	dev->rssi = rssi;
 
@@ -3104,6 +3111,9 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	g_slist_foreach(eir_data.services, dev_prepend_uuid, dev);
 
 	adapter_emit_device_found(adapter, dev);
+
+done:
+	free(name);
 }
 
 int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr)
-- 
1.7.5.rc3


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

* [PATCH v3 05/12] Don't resolve name if the name is in the storage
  2011-05-16 20:49 [PATCH v3 01/12] Move EIR related functions to a new file Claudio Takahasi
                   ` (2 preceding siblings ...)
  2011-05-16 20:49 ` [PATCH v3 04/12] Cleanup read name and alias from storage Claudio Takahasi
@ 2011-05-16 20:49 ` Claudio Takahasi
  2011-05-17 18:25   ` [PATCH v4 " Claudio Takahasi
  2011-05-16 20:49 ` [PATCH v3 06/12] Unify inquiry results and advertises Claudio Takahasi
                   ` (6 subsequent siblings)
  10 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-16 20:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/adapter.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 701558c..e91ab81 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3057,18 +3057,18 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 		return;
 	}
 
-	/* the inquiry result can be triggered by NON D-Bus client */
-	if (main_opts.name_resolv && adapter_has_discov_sessions(adapter))
-		name_status = NAME_REQUIRED;
-	else
-		name_status = NAME_NOT_REQUIRED;
-
 	name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
 	if (pairing_is_legacy(&adapter->bdaddr, bdaddr,
 				data ? TRUE : FALSE, name ? TRUE : FALSE,
 				&legacy) < 0)
 		legacy = TRUE;
 
+	if (!name && main_opts.name_resolv &&
+			adapter_has_discov_sessions(adapter))
+		name_status = NAME_REQUIRED;
+	else
+		name_status = NAME_NOT_REQUIRED;
+
 	/* Complete EIR names are always used. Shortened EIR names are only
 	 * used if there is no name already in storage. */
 	dev_name = name;
-- 
1.7.5.rc3


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

* [PATCH v3 06/12] Unify inquiry results and advertises
  2011-05-16 20:49 [PATCH v3 01/12] Move EIR related functions to a new file Claudio Takahasi
                   ` (3 preceding siblings ...)
  2011-05-16 20:49 ` [PATCH v3 05/12] Don't resolve name if the name is in the storage Claudio Takahasi
@ 2011-05-16 20:49 ` Claudio Takahasi
  2011-05-17 18:25   ` [PATCH v4 " Claudio Takahasi
  2011-05-16 20:49 ` [PATCH v3 07/12] Fix memory leak of EIR data Claudio Takahasi
                   ` (5 subsequent siblings)
  10 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-16 20:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Adapter needs to have only one method to allow discovery results
integration for both interfaces: hciops and mgmtops. This patch
moves the code related to advertises parsing to the same function
that handles inquiry results.
---
 src/adapter.c |   75 +++++++++++++++++++-------------------------------------
 src/adapter.h |    7 +----
 src/event.c   |   25 +++----------------
 3 files changed, 32 insertions(+), 75 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index e91ab81..556a537 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2966,42 +2966,6 @@ static void dev_prepend_uuid(gpointer data, gpointer user_data)
 	dev->services = g_slist_prepend(dev->services, g_strdup(new_uuid));
 }
 
-void adapter_update_device_from_info(struct btd_adapter *adapter,
-					bdaddr_t bdaddr, int8_t rssi,
-					const char *name, GSList *services,
-					int flags)
-{
-	struct remote_dev_info *dev;
-	gboolean new_dev;
-
-	dev = get_found_dev(adapter, &bdaddr, &new_dev);
-
-	if (new_dev)
-		dev->le = TRUE;
-	else if (dev->rssi == rssi)
-		return;
-
-	dev->rssi = rssi;
-
-	adapter->found_devices = g_slist_sort(adapter->found_devices,
-						(GCompareFunc) dev_rssi_cmp);
-
-	g_slist_foreach(services, remove_same_uuid, dev);
-	g_slist_foreach(services, dev_prepend_uuid, dev);
-
-	if (flags >= 0)
-		dev->flags = flags;
-
-	if (name) {
-		g_free(dev->name);
-		dev->name = g_strdup(name);
-	}
-
-	/* FIXME: check if other information was changed before emitting the
-	 * signal */
-	adapter_emit_device_found(adapter, dev);
-}
-
 static int pairing_is_legacy(bdaddr_t *local, bdaddr_t *peer, gboolean eir,
 					gboolean name, gboolean *legacy)
 {
@@ -3040,13 +3004,14 @@ static char *read_stored_data(bdaddr_t *local, bdaddr_t *peer, const char *file)
 }
 
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-				uint32_t class, int8_t rssi, uint8_t *data)
+					uint32_t class, int8_t rssi,
+					uint8_t *data, size_t eir_size)
 {
 	struct remote_dev_info *dev;
 	struct eir_data eir_data;
 	char *name;
-	gboolean new_dev, legacy;
-	name_status_t name_status;
+	gboolean new_dev, legacy, le;
+	name_status_t name_status = NAME_NOT_REQUIRED;
 	const char *dev_name;
 	int err;
 
@@ -3058,16 +3023,24 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	}
 
 	name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
-	if (pairing_is_legacy(&adapter->bdaddr, bdaddr,
-				data ? TRUE : FALSE, name ? TRUE : FALSE,
-				&legacy) < 0)
-		legacy = TRUE;
-
-	if (!name && main_opts.name_resolv &&
-			adapter_has_discov_sessions(adapter))
-		name_status = NAME_REQUIRED;
-	else
-		name_status = NAME_NOT_REQUIRED;
+
+	if (eir_data.flags < 0) {
+		le = FALSE;
+
+		if (pairing_is_legacy(&adapter->bdaddr, bdaddr,
+					data ? TRUE : FALSE,
+					name ? TRUE : FALSE, &legacy) < 0)
+			legacy = TRUE;
+
+		if (!name && main_opts.name_resolv &&
+				adapter_has_discov_sessions(adapter))
+			name_status = NAME_REQUIRED;
+		else
+			name_status = NAME_NOT_REQUIRED;
+	} else {
+		le = TRUE;
+		legacy = FALSE;
+	}
 
 	/* Complete EIR names are always used. Shortened EIR names are only
 	 * used if there is no name already in storage. */
@@ -3099,6 +3072,10 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 		dev->class = class;
 		dev->legacy = legacy;
 		dev->name_status = name_status;
+
+		if (eir_data.flags >= 0)
+			dev->flags = eir_data.flags;
+
 	} else if (dev->rssi == rssi)
 		goto done;
 
diff --git a/src/adapter.h b/src/adapter.h
index 4785d5c..4c07e92 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -108,12 +108,9 @@ int adapter_get_state(struct btd_adapter *adapter);
 int adapter_get_discover_type(struct btd_adapter *adapter);
 struct remote_dev_info *adapter_search_found_devices(struct btd_adapter *adapter,
 						struct remote_dev_info *match);
-void adapter_update_device_from_info(struct btd_adapter *adapter,
-					bdaddr_t bdaddr, int8_t rssi,
-					const char *name, GSList *services,
-					int flags);
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-				uint32_t class, int8_t rssi, uint8_t *data);
+					uint32_t class, int8_t rssi,
+					uint8_t *data, size_t eir_size);
 int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr);
 void adapter_emit_device_found(struct btd_adapter *adapter,
 						struct remote_dev_info *dev);
diff --git a/src/event.c b/src/event.c
index 2c893f0..115b285 100644
--- a/src/event.c
+++ b/src/event.c
@@ -281,19 +281,10 @@ void btd_event_simple_pairing_complete(bdaddr_t *local, bdaddr_t *peer,
 	device_simple_pairing_complete(device, status);
 }
 
-static void free_eir_data(struct eir_data *eir)
-{
-	g_slist_foreach(eir->services, (GFunc) g_free, NULL);
-	g_slist_free(eir->services);
-	g_free(eir->name);
-}
-
 void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info)
 {
 	struct btd_adapter *adapter;
-	struct eir_data eir_data;
 	int8_t rssi;
-	int err;
 
 	adapter = manager_find_adapter(local);
 	if (adapter == NULL) {
@@ -301,19 +292,10 @@ void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info)
 		return;
 	}
 
-	memset(&eir_data, 0, sizeof(eir_data));
-	err = eir_parse(&eir_data, info->data, info->length);
-	if (err < 0)
-		error("Error parsing advertising data: %s (%d)",
-							strerror(-err), -err);
-
 	rssi = *(info->data + info->length);
 
-	adapter_update_device_from_info(adapter, info->bdaddr, rssi,
-					eir_data.name, eir_data.services,
-					eir_data.flags);
-
-	free_eir_data(&eir_data);
+	adapter_update_found_devices(adapter, &info->bdaddr, 0, rssi,
+						info->data, info->length);
 }
 
 static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba)
@@ -355,7 +337,8 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 	if (data)
 		write_remote_eir(local, peer, data);
 
-	adapter_update_found_devices(adapter, peer, class, rssi, data);
+	adapter_update_found_devices(adapter, peer, class, rssi,
+						data, EIR_DATA_LENGTH);
 }
 
 void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
-- 
1.7.5.rc3


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

* [PATCH v3 07/12] Fix memory leak of EIR data
  2011-05-16 20:49 [PATCH v3 01/12] Move EIR related functions to a new file Claudio Takahasi
                   ` (4 preceding siblings ...)
  2011-05-16 20:49 ` [PATCH v3 06/12] Unify inquiry results and advertises Claudio Takahasi
@ 2011-05-16 20:49 ` Claudio Takahasi
  2011-05-17 18:26   ` [PATCH v4 " Claudio Takahasi
  2011-05-16 20:49 ` [PATCH v3 08/12] Remove btd_event_advertising_report Claudio Takahasi
                   ` (4 subsequent siblings)
  10 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-16 20:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/adapter.c |    1 +
 src/eir.c     |    7 +++++++
 src/eir.h     |    1 +
 3 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 556a537..a274f26 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3091,6 +3091,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 
 done:
 	free(name);
+	eir_data_free(&eir_data);
 }
 
 int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr)
diff --git a/src/eir.c b/src/eir.c
index d827c7e..2fbd919 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -44,6 +44,13 @@
 #define EIR_TX_POWER                0x0A  /* transmit power level */
 #define EIR_DEVICE_ID               0x10  /* device ID */
 
+void eir_data_free(struct eir_data *eir)
+{
+	g_slist_foreach(eir->services, (GFunc) g_free, NULL);
+	g_slist_free(eir->services);
+	g_free(eir->name);
+}
+
 int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
 {
 	uint16_t len = 0;
diff --git a/src/eir.h b/src/eir.h
index c7699eb..aacd16a 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -36,6 +36,7 @@ struct eir_data {
 	gboolean name_complete;
 };
 
+void eir_data_free(struct eir_data *eir);
 int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length);
 void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 			uint16_t did_product, uint16_t did_version,
-- 
1.7.5.rc3


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

* [PATCH v3 08/12] Remove btd_event_advertising_report
  2011-05-16 20:49 [PATCH v3 01/12] Move EIR related functions to a new file Claudio Takahasi
                   ` (5 preceding siblings ...)
  2011-05-16 20:49 ` [PATCH v3 07/12] Fix memory leak of EIR data Claudio Takahasi
@ 2011-05-16 20:49 ` Claudio Takahasi
  2011-05-17 18:26   ` [PATCH v4 " Claudio Takahasi
  2011-05-16 20:49 ` [PATCH v3 09/12] Change the order to write/read the remote's name Claudio Takahasi
                   ` (3 subsequent siblings)
  10 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-16 20:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

Advertises should be notified using btd_event_device_found function
to keep the compatibility with mgmtops plugin.
---
 plugins/hciops.c |   13 ++++++++++---
 src/event.c      |   17 -----------------
 src/event.h      |    1 -
 3 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 07643a1..65ad4f3 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -2171,19 +2171,26 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
 {
 	struct dev_info *dev = &devs[index];
 	le_advertising_info *info;
-	uint8_t num_reports;
+	uint8_t num_reports, rssi;
 	const uint8_t RSSI_SIZE = 1;
 
 	num_reports = meta->data[0];
 
 	info = (le_advertising_info *) &meta->data[1];
-	btd_event_advertising_report(&dev->bdaddr, info);
+	rssi = *(info->data + info->length);
+
+	btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi,
+								info->data);
+
 	num_reports--;
 
 	while (num_reports--) {
 		info = (le_advertising_info *) (info->data + info->length +
 								RSSI_SIZE);
-		btd_event_advertising_report(&dev->bdaddr, info);
+		rssi = *(info->data + info->length);
+
+		btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi,
+								info->data);
 	}
 }
 
diff --git a/src/event.c b/src/event.c
index 115b285..3ee8802 100644
--- a/src/event.c
+++ b/src/event.c
@@ -281,23 +281,6 @@ void btd_event_simple_pairing_complete(bdaddr_t *local, bdaddr_t *peer,
 	device_simple_pairing_complete(device, status);
 }
 
-void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info)
-{
-	struct btd_adapter *adapter;
-	int8_t rssi;
-
-	adapter = manager_find_adapter(local);
-	if (adapter == NULL) {
-		error("No matching adapter found");
-		return;
-	}
-
-	rssi = *(info->data + info->length);
-
-	adapter_update_found_devices(adapter, &info->bdaddr, 0, rssi,
-						info->data, info->length);
-}
-
 static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba)
 {
 	time_t t;
diff --git a/src/event.h b/src/event.h
index 005d8a7..22c199e 100644
--- a/src/event.h
+++ b/src/event.h
@@ -23,7 +23,6 @@
  */
 
 int btd_event_request_pin(bdaddr_t *sba, bdaddr_t *dba);
-void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info);
 void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 						int8_t rssi, uint8_t *data);
 void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer, gboolean legacy);
-- 
1.7.5.rc3


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

* [PATCH v3 09/12] Change the order to write/read the remote's name
  2011-05-16 20:49 [PATCH v3 01/12] Move EIR related functions to a new file Claudio Takahasi
                   ` (6 preceding siblings ...)
  2011-05-16 20:49 ` [PATCH v3 08/12] Remove btd_event_advertising_report Claudio Takahasi
@ 2011-05-16 20:49 ` Claudio Takahasi
  2011-05-17 18:26   ` [PATCH v4 " Claudio Takahasi
  2011-05-16 20:49 ` [PATCH v3 10/12] Cleanup inserting new device found entry Claudio Takahasi
                   ` (2 subsequent siblings)
  10 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-16 20:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

When discovering, write the EIR "complete" name first before to read
the name. Only names retrieved from EIR "complete" name and HCI Remote
Name Request Complete event are stored. This patch doesn't change the
final result: the value of the name sent in the signal.
---
 src/adapter.c |   19 +++++--------------
 1 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index a274f26..6d5fdc9 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3012,7 +3012,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	char *name;
 	gboolean new_dev, legacy, le;
 	name_status_t name_status = NAME_NOT_REQUIRED;
-	const char *dev_name;
 	int err;
 
 	memset(&eir_data, 0, sizeof(eir_data));
@@ -3022,6 +3021,9 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 		return;
 	}
 
+	if (eir_data.name != NULL && eir_data.name_complete)
+		write_device_name(&adapter->bdaddr, bdaddr, eir_data.name);
+
 	name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
 
 	if (eir_data.flags < 0) {
@@ -3042,23 +3044,12 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 		legacy = FALSE;
 	}
 
-	/* Complete EIR names are always used. Shortened EIR names are only
-	 * used if there is no name already in storage. */
-	dev_name = name;
-	if (eir_data.name != NULL) {
-		if (eir_data.name_complete) {
-			write_device_name(&adapter->bdaddr, bdaddr,
-							eir_data.name);
-			name_status = NAME_NOT_REQUIRED;
-			dev_name = eir_data.name;
-		} else if (name == NULL)
-			dev_name = eir_data.name;
-	}
-
 	dev = get_found_dev(adapter, bdaddr, &new_dev);
 
 	if (new_dev) {
+		const char *dev_name = (name ? name : eir_data.name);
 		char *alias;
+
 		if (dev_name)
 			dev->name = g_strdup(dev_name);
 
-- 
1.7.5.rc3


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

* [PATCH v3 10/12] Cleanup inserting new device found entry
  2011-05-16 20:49 [PATCH v3 01/12] Move EIR related functions to a new file Claudio Takahasi
                   ` (7 preceding siblings ...)
  2011-05-16 20:49 ` [PATCH v3 09/12] Change the order to write/read the remote's name Claudio Takahasi
@ 2011-05-16 20:49 ` Claudio Takahasi
  2011-05-17 18:26   ` [PATCH v4 " Claudio Takahasi
  2011-05-16 20:50 ` [PATCH v3 11/12] Replace EIR_DATA_LENGTH with HCI_MAX_EIR_LENGTH Claudio Takahasi
  2011-05-16 20:50 ` [PATCH v3 12/12] Drop variable EIR length Claudio Takahasi
  10 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-16 20:49 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/adapter.c |   97 +++++++++++++++++++++++++++-----------------------------
 1 files changed, 47 insertions(+), 50 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 6d5fdc9..f4359f9 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2914,29 +2914,24 @@ void adapter_emit_device_found(struct btd_adapter *adapter,
 	g_free(alias);
 }
 
-static struct remote_dev_info *get_found_dev(struct btd_adapter *adapter,
-						const bdaddr_t *bdaddr,
-						gboolean *new_dev)
+static struct remote_dev_info *found_device_new(const bdaddr_t *bdaddr,
+					gboolean le, const char *name,
+					const char *alias, uint32_t class,
+					gboolean legacy, name_status_t status,
+					int flags)
 {
-	struct remote_dev_info *dev, match;
+	struct remote_dev_info *dev;
 
-	memset(&match, 0, sizeof(struct remote_dev_info));
-	bacpy(&match.bdaddr, bdaddr);
-	match.name_status = NAME_ANY;
-
-	dev = adapter_search_found_devices(adapter, &match);
-	if (dev) {
-		*new_dev = FALSE;
-		/* Out of range list update */
-		adapter->oor_devices = g_slist_remove(adapter->oor_devices,
-							dev);
-	} else {
-		*new_dev = TRUE;
-		dev = g_new0(struct remote_dev_info, 1);
-		bacpy(&dev->bdaddr, bdaddr);
-		adapter->found_devices = g_slist_prepend(adapter->found_devices,
-									dev);
-	}
+	dev = g_new0(struct remote_dev_info, 1);
+	bacpy(&dev->bdaddr, bdaddr);
+	dev->le = le;
+	dev->name = g_strdup(name);
+	dev->alias = g_strdup(alias);
+	dev->class = class;
+	dev->legacy = legacy;
+	dev->name_status = status;
+	if (flags >= 0)
+		dev->flags = flags;
 
 	return dev;
 }
@@ -3007,11 +3002,11 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 					uint32_t class, int8_t rssi,
 					uint8_t *data, size_t eir_size)
 {
-	struct remote_dev_info *dev;
+	struct remote_dev_info *dev, match;
 	struct eir_data eir_data;
-	char *name;
-	gboolean new_dev, legacy, le;
-	name_status_t name_status = NAME_NOT_REQUIRED;
+	char *alias, *name;
+	gboolean legacy, le;
+	name_status_t name_status;
 	int err;
 
 	memset(&eir_data, 0, sizeof(eir_data));
@@ -3024,6 +3019,25 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	if (eir_data.name != NULL && eir_data.name_complete)
 		write_device_name(&adapter->bdaddr, bdaddr, eir_data.name);
 
+	/* Device already seen in the discovery session ? */
+	memset(&match, 0, sizeof(struct remote_dev_info));
+	bacpy(&match.bdaddr, bdaddr);
+	match.name_status = NAME_ANY;
+
+	dev = adapter_search_found_devices(adapter, &match);
+	if (dev) {
+		adapter->oor_devices = g_slist_remove(adapter->oor_devices,
+							dev);
+		if (dev->rssi != rssi)
+			goto done;
+
+		eir_data_free(&eir_data);
+
+		return;
+	}
+
+	/* New device in the discovery session */
+
 	name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
 
 	if (eir_data.flags < 0) {
@@ -3042,34 +3056,19 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	} else {
 		le = TRUE;
 		legacy = FALSE;
+		name_status = NAME_NOT_REQUIRED;
 	}
 
-	dev = get_found_dev(adapter, bdaddr, &new_dev);
-
-	if (new_dev) {
-		const char *dev_name = (name ? name : eir_data.name);
-		char *alias;
+	alias = read_stored_data(&adapter->bdaddr, bdaddr, "aliases");
 
-		if (dev_name)
-			dev->name = g_strdup(dev_name);
-
-		alias = read_stored_data(&adapter->bdaddr, bdaddr, "aliases");
-		if (alias) {
-			dev->alias = g_strdup(alias);
-			free(alias);
-		}
-
-		dev->le = FALSE;
-		dev->class = class;
-		dev->legacy = legacy;
-		dev->name_status = name_status;
+	dev = found_device_new(bdaddr, le, name, alias, class, legacy,
+						name_status, eir_data.flags);
+	free(name);
+	free(alias);
 
-		if (eir_data.flags >= 0)
-			dev->flags = eir_data.flags;
-
-	} else if (dev->rssi == rssi)
-		goto done;
+	adapter->found_devices = g_slist_prepend(adapter->found_devices, dev);
 
+done:
 	dev->rssi = rssi;
 
 	adapter->found_devices = g_slist_sort(adapter->found_devices,
@@ -3080,8 +3079,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 
 	adapter_emit_device_found(adapter, dev);
 
-done:
-	free(name);
 	eir_data_free(&eir_data);
 }
 
-- 
1.7.5.rc3


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

* [PATCH v3 11/12] Replace EIR_DATA_LENGTH with HCI_MAX_EIR_LENGTH
  2011-05-16 20:49 [PATCH v3 01/12] Move EIR related functions to a new file Claudio Takahasi
                   ` (8 preceding siblings ...)
  2011-05-16 20:49 ` [PATCH v3 10/12] Cleanup inserting new device found entry Claudio Takahasi
@ 2011-05-16 20:50 ` Claudio Takahasi
  2011-05-17 18:26   ` [PATCH v4 " Claudio Takahasi
  2011-05-16 20:50 ` [PATCH v3 12/12] Drop variable EIR length Claudio Takahasi
  10 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-16 20:50 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

Both defines have the same value (240) and meaning.
---
 src/adapter.c |    2 +-
 src/eir.c     |    9 +++++----
 src/eir.h     |    2 --
 src/event.c   |    2 +-
 4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index f4359f9..84e8ca6 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3010,7 +3010,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	int err;
 
 	memset(&eir_data, 0, sizeof(eir_data));
-	err = eir_parse(&eir_data, data, EIR_DATA_LENGTH);
+	err = eir_parse(&eir_data, data, HCI_MAX_EIR_LENGTH);
 	if (err < 0) {
 		error("Error parsing EIR data: %s (%d)", strerror(-err), -err);
 		return;
diff --git a/src/eir.c b/src/eir.c
index 2fbd919..7dfc444 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -27,6 +27,7 @@
 #include <glib.h>
 
 #include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
 #include <bluetooth/sdp.h>
 
 #include "glib-helper.h"
@@ -184,7 +185,7 @@ static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
 			continue;
 
 		/* Stop if not enough space to put next UUID128 */
-		if ((len + 2 + SIZEOF_UUID128) > EIR_DATA_LENGTH) {
+		if ((len + 2 + SIZEOF_UUID128) > HCI_MAX_EIR_LENGTH) {
 			truncated = TRUE;
 			break;
 		}
@@ -229,7 +230,7 @@ void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 	GSList *l;
 	uint8_t *ptr = data;
 	uint16_t eir_len = 0;
-	uint16_t uuid16[EIR_DATA_LENGTH / 2];
+	uint16_t uuid16[HCI_MAX_EIR_LENGTH / 2];
 	int i, uuid_count = 0;
 	gboolean truncated = FALSE;
 	size_t name_len;
@@ -289,7 +290,7 @@ void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 			continue;
 
 		/* Stop if not enough space to put next UUID16 */
-		if ((eir_len + 2 + sizeof(uint16_t)) > EIR_DATA_LENGTH) {
+		if ((eir_len + 2 + sizeof(uint16_t)) > HCI_MAX_EIR_LENGTH) {
 			truncated = TRUE;
 			break;
 		}
@@ -322,6 +323,6 @@ void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 	}
 
 	/* Group all UUID128 types */
-	if (eir_len <= EIR_DATA_LENGTH - 2)
+	if (eir_len <= HCI_MAX_EIR_LENGTH - 2)
 		eir_generate_uuid128(uuids, ptr, &eir_len);
 }
diff --git a/src/eir.h b/src/eir.h
index aacd16a..ea38570 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -22,8 +22,6 @@
  *
  */
 
-#define EIR_DATA_LENGTH  240
-
 struct uuid_info {
 	uuid_t uuid;
 	uint8_t svc_hint;
diff --git a/src/event.c b/src/event.c
index 8a7db17..cd5e9e1 100644
--- a/src/event.c
+++ b/src/event.c
@@ -321,7 +321,7 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 		write_remote_eir(local, peer, data);
 
 	adapter_update_found_devices(adapter, peer, class, rssi,
-						data, EIR_DATA_LENGTH);
+						data, HCI_MAX_EIR_LENGTH);
 }
 
 void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
-- 
1.7.5.rc3


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

* [PATCH v3 12/12] Drop variable EIR length
  2011-05-16 20:49 [PATCH v3 01/12] Move EIR related functions to a new file Claudio Takahasi
                   ` (9 preceding siblings ...)
  2011-05-16 20:50 ` [PATCH v3 11/12] Replace EIR_DATA_LENGTH with HCI_MAX_EIR_LENGTH Claudio Takahasi
@ 2011-05-16 20:50 ` Claudio Takahasi
  2011-05-17 18:26   ` [PATCH v4 " Claudio Takahasi
  10 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-16 20:50 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

The functions eir_parse() and adapter_update_found_devices() now
assume that the EIR buffer has always 240 octets. For advertising
reports, the advertising data is stored on a buffer with 240 bytes,
padded with zeroes.
---
 plugins/hciops.c |   13 +++++++++----
 src/adapter.c    |    6 +++---
 src/adapter.h    |    4 ++--
 src/eir.c        |    8 ++++----
 src/eir.h        |    2 +-
 src/event.c      |    3 +--
 6 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 37b2d8e..d976822 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -2171,7 +2171,7 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
 {
 	struct dev_info *dev = &devs[index];
 	le_advertising_info *info;
-	uint8_t num_reports, rssi;
+	uint8_t num_reports, rssi, eir[HCI_MAX_EIR_LENGTH];
 	const uint8_t RSSI_SIZE = 1;
 
 	num_reports = meta->data[0];
@@ -2179,8 +2179,10 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
 	info = (le_advertising_info *) &meta->data[1];
 	rssi = *(info->data + info->length);
 
-	btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi,
-								info->data);
+	memset(eir, 0, sizeof(eir));
+	memcpy(eir, info->data, info->length);
+
+	btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi, eir);
 
 	num_reports--;
 
@@ -2189,8 +2191,11 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
 								RSSI_SIZE);
 		rssi = *(info->data + info->length);
 
+		memset(eir, 0, sizeof(eir));
+		memcpy(eir, info->data, info->length);
+
 		btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi,
-								info->data);
+									eir);
 	}
 }
 
diff --git a/src/adapter.c b/src/adapter.c
index 84e8ca6..33fd354 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2999,8 +2999,8 @@ static char *read_stored_data(bdaddr_t *local, bdaddr_t *peer, const char *file)
 }
 
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-					uint32_t class, int8_t rssi,
-					uint8_t *data, size_t eir_size)
+						uint32_t class, int8_t rssi,
+						uint8_t *data)
 {
 	struct remote_dev_info *dev, match;
 	struct eir_data eir_data;
@@ -3010,7 +3010,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	int err;
 
 	memset(&eir_data, 0, sizeof(eir_data));
-	err = eir_parse(&eir_data, data, HCI_MAX_EIR_LENGTH);
+	err = eir_parse(&eir_data, data);
 	if (err < 0) {
 		error("Error parsing EIR data: %s (%d)", strerror(-err), -err);
 		return;
diff --git a/src/adapter.h b/src/adapter.h
index 4c07e92..3526849 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -109,8 +109,8 @@ int adapter_get_discover_type(struct btd_adapter *adapter);
 struct remote_dev_info *adapter_search_found_devices(struct btd_adapter *adapter,
 						struct remote_dev_info *match);
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-					uint32_t class, int8_t rssi,
-					uint8_t *data, size_t eir_size);
+						uint32_t class, int8_t rssi,
+						uint8_t *data);
 int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr);
 void adapter_emit_device_found(struct btd_adapter *adapter,
 						struct remote_dev_info *dev);
diff --git a/src/eir.c b/src/eir.c
index 7dfc444..01b6ac5 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -52,7 +52,7 @@ void eir_data_free(struct eir_data *eir)
 	g_free(eir->name);
 }
 
-int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
+int eir_parse(struct eir_data *eir, uint8_t *eir_data)
 {
 	uint16_t len = 0;
 	size_t total;
@@ -69,10 +69,10 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
 	eir->flags = -1;
 
 	/* No EIR data to parse */
-	if (eir_data == NULL || eir_length == 0)
+	if (eir_data == NULL)
 		return 0;
 
-	while (len < eir_length - 1) {
+	while (len < HCI_MAX_EIR_LENGTH - 1) {
 		uint8_t field_len = eir_data[0];
 
 		/* Check for the end of EIR */
@@ -115,7 +115,7 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
 	}
 
 	/* Bail out if got incorrect length */
-	if (len > eir_length)
+	if (len > HCI_MAX_EIR_LENGTH)
 		return -EINVAL;
 
 	total = uuid16_count + uuid32_count + uuid128_count;
diff --git a/src/eir.h b/src/eir.h
index ea38570..d225973 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -35,7 +35,7 @@ struct eir_data {
 };
 
 void eir_data_free(struct eir_data *eir);
-int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length);
+int eir_parse(struct eir_data *eir, uint8_t *eir_data);
 void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 			uint16_t did_product, uint16_t did_version,
 			GSList *uuids, uint8_t *data);
diff --git a/src/event.c b/src/event.c
index cd5e9e1..55ffadb 100644
--- a/src/event.c
+++ b/src/event.c
@@ -320,8 +320,7 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 	if (data)
 		write_remote_eir(local, peer, data);
 
-	adapter_update_found_devices(adapter, peer, class, rssi,
-						data, HCI_MAX_EIR_LENGTH);
+	adapter_update_found_devices(adapter, peer, class, rssi, data);
 }
 
 void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
-- 
1.7.5.rc3


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

* Re: [PATCH v3 03/12] Move legacy verification to a new function
  2011-05-16 20:49 ` [PATCH v3 03/12] Move legacy verification to a new function Claudio Takahasi
@ 2011-05-17 16:13   ` Johan Hedberg
  2011-05-17 18:25     ` [PATCH v4 " Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Johan Hedberg @ 2011-05-17 16:13 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth

Hi Claudio,

On Mon, May 16, 2011, Claudio Takahasi wrote:
> ---
>  src/adapter.c |   40 ++++++++++++++++++++++++++++------------
>  1 files changed, 28 insertions(+), 12 deletions(-)
> 
> diff --git a/src/adapter.c b/src/adapter.c
> index 3188974..6f85abf 100644
> --- a/src/adapter.c
> +++ b/src/adapter.c
> @@ -3002,6 +3002,31 @@ void adapter_update_device_from_info(struct btd_adapter *adapter,
>  	adapter_emit_device_found(adapter, dev);
>  }
>  
> +static int pairing_is_legacy(bdaddr_t *local, bdaddr_t *peer, gboolean eir,
> +					gboolean name, gboolean *legacy)
> +{

The first two patches in this set have been pushed upstream, however
could you consider the following change to this one: since you just
assume legacy == TRUE if the storage read fails, why not just make this
pairing_is_legacy function return a gboolean instead of returning the
value by reference? (it's look cleaner, especially considering the name
of the function)

Johan

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

* [PATCH v4 03/12] Move legacy verification to a new function
  2011-05-17 16:13   ` Johan Hedberg
@ 2011-05-17 18:25     ` Claudio Takahasi
  2011-05-18 19:18       ` Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-17 18:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/adapter.c |   35 ++++++++++++++++++++++-------------
 1 files changed, 22 insertions(+), 13 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 3188974..d4e1121 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3002,6 +3002,26 @@ void adapter_update_device_from_info(struct btd_adapter *adapter,
 	adapter_emit_device_found(adapter, dev);
 }
 
+static gboolean pairing_is_legacy(bdaddr_t *local, bdaddr_t *peer,
+					gboolean eir, gboolean name)
+{
+	unsigned char features[8];
+
+	if (eir)
+		return FALSE;
+
+	if (name == FALSE)
+		return TRUE;
+
+	if (read_remote_features(local, peer, NULL, features) < 0)
+		return TRUE;
+
+	if (features[0] & 0x01)
+		return FALSE;
+	else
+		return TRUE;
+}
+
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 				uint32_t class, int8_t rssi, uint8_t *data)
 {
@@ -3011,7 +3031,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	char *alias, *name;
 	gboolean new_dev, legacy;
 	name_status_t name_status;
-	unsigned char features[8];
 	const char *dev_name;
 	int err;
 
@@ -3037,18 +3056,8 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "names");
 	name = textfile_get(filename, peer_addr);
 
-	if (data)
-		legacy = FALSE;
-	else if (name == NULL)
-		legacy = TRUE;
-	else if (read_remote_features(&adapter->bdaddr, bdaddr, NULL,
-							features) == 0) {
-		if (features[0] & 0x01)
-			legacy = FALSE;
-		else
-			legacy = TRUE;
-	} else
-		legacy = TRUE;
+	legacy = pairing_is_legacy(&adapter->bdaddr, bdaddr,
+				data ? TRUE : FALSE, name ? TRUE : FALSE);
 
 	/* Complete EIR names are always used. Shortened EIR names are only
 	 * used if there is no name already in storage. */
-- 
1.7.5.rc3


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

* [PATCH v4 04/12] Cleanup read name and alias from storage
  2011-05-16 20:49 ` [PATCH v3 04/12] Cleanup read name and alias from storage Claudio Takahasi
@ 2011-05-17 18:25   ` Claudio Takahasi
  2011-05-18 19:38     ` [PATCH v5 " Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-17 18:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/adapter.c |   35 +++++++++++++++++++++++------------
 1 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index d4e1121..7cc725c 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3022,13 +3022,24 @@ static gboolean pairing_is_legacy(bdaddr_t *local, bdaddr_t *peer,
 		return TRUE;
 }
 
+static char *read_stored_data(bdaddr_t *local, bdaddr_t *peer, const char *file)
+{
+	char local_addr[18], peer_addr[18], filename[PATH_MAX + 1];
+
+	ba2str(local, local_addr);
+	ba2str(peer, peer_addr);
+
+	create_name(filename, PATH_MAX, STORAGEDIR, local_addr, file);
+
+	return textfile_get(filename, peer_addr);
+}
+
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 				uint32_t class, int8_t rssi, uint8_t *data)
 {
-	char local_addr[18], peer_addr[18], filename[PATH_MAX + 1];
 	struct remote_dev_info *dev;
 	struct eir_data eir_data;
-	char *alias, *name;
+	char *name;
 	gboolean new_dev, legacy;
 	name_status_t name_status;
 	const char *dev_name;
@@ -3047,14 +3058,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	else
 		name_status = NAME_NOT_REQUIRED;
 
-	ba2str(&adapter->bdaddr, local_addr);
-	ba2str(bdaddr, peer_addr);
-
-	create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "aliases");
-	alias = textfile_get(filename, peer_addr);
-
-	create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "names");
-	name = textfile_get(filename, peer_addr);
+	name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
 
 	legacy = pairing_is_legacy(&adapter->bdaddr, bdaddr,
 				data ? TRUE : FALSE, name ? TRUE : FALSE);
@@ -3075,18 +3079,22 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	dev = get_found_dev(adapter, bdaddr, &new_dev);
 
 	if (new_dev) {
+		char *alias;
 		if (dev_name)
 			dev->name = g_strdup(dev_name);
 
-		if (alias)
+		alias = read_stored_data(&adapter->bdaddr, bdaddr, "aliases");
+		if (alias) {
 			dev->alias = g_strdup(alias);
+			free(alias);
+		}
 
 		dev->le = FALSE;
 		dev->class = class;
 		dev->legacy = legacy;
 		dev->name_status = name_status;
 	} else if (dev->rssi == rssi)
-		return;
+		goto done;
 
 	dev->rssi = rssi;
 
@@ -3097,6 +3105,9 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	g_slist_foreach(eir_data.services, dev_prepend_uuid, dev);
 
 	adapter_emit_device_found(adapter, dev);
+
+done:
+	free(name);
 }
 
 int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr)
-- 
1.7.5.rc3


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

* [PATCH v4 05/12] Don't resolve name if the name is in the storage
  2011-05-16 20:49 ` [PATCH v3 05/12] Don't resolve name if the name is in the storage Claudio Takahasi
@ 2011-05-17 18:25   ` Claudio Takahasi
  2011-05-18 19:38     ` [PATCH v5 " Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-17 18:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/adapter.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 7cc725c..1f535e1 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3052,17 +3052,17 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 		return;
 	}
 
-	/* the inquiry result can be triggered by NON D-Bus client */
-	if (main_opts.name_resolv && adapter_has_discov_sessions(adapter))
-		name_status = NAME_REQUIRED;
-	else
-		name_status = NAME_NOT_REQUIRED;
-
 	name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
 
 	legacy = pairing_is_legacy(&adapter->bdaddr, bdaddr,
 				data ? TRUE : FALSE, name ? TRUE : FALSE);
 
+	if (!name && main_opts.name_resolv &&
+			adapter_has_discov_sessions(adapter))
+		name_status = NAME_REQUIRED;
+	else
+		name_status = NAME_NOT_REQUIRED;
+
 	/* Complete EIR names are always used. Shortened EIR names are only
 	 * used if there is no name already in storage. */
 	dev_name = name;
-- 
1.7.5.rc3


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

* [PATCH v4 06/12] Unify inquiry results and advertises
  2011-05-16 20:49 ` [PATCH v3 06/12] Unify inquiry results and advertises Claudio Takahasi
@ 2011-05-17 18:25   ` Claudio Takahasi
  2011-05-18 19:39     ` [PATCH v5 " Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-17 18:25 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Adapter needs to have only one method to allow discovery results
integration for both interfaces: hciops and mgmtops. This patch
moves the code related to advertises parsing to the same function
that handles inquiry results.
---
 src/adapter.c |   69 +++++++++++++++++++--------------------------------------
 src/adapter.h |    7 +----
 src/event.c   |   25 +++-----------------
 3 files changed, 29 insertions(+), 72 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 1f535e1..c053d6c 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2966,42 +2966,6 @@ static void dev_prepend_uuid(gpointer data, gpointer user_data)
 	dev->services = g_slist_prepend(dev->services, g_strdup(new_uuid));
 }
 
-void adapter_update_device_from_info(struct btd_adapter *adapter,
-					bdaddr_t bdaddr, int8_t rssi,
-					const char *name, GSList *services,
-					int flags)
-{
-	struct remote_dev_info *dev;
-	gboolean new_dev;
-
-	dev = get_found_dev(adapter, &bdaddr, &new_dev);
-
-	if (new_dev)
-		dev->le = TRUE;
-	else if (dev->rssi == rssi)
-		return;
-
-	dev->rssi = rssi;
-
-	adapter->found_devices = g_slist_sort(adapter->found_devices,
-						(GCompareFunc) dev_rssi_cmp);
-
-	g_slist_foreach(services, remove_same_uuid, dev);
-	g_slist_foreach(services, dev_prepend_uuid, dev);
-
-	if (flags >= 0)
-		dev->flags = flags;
-
-	if (name) {
-		g_free(dev->name);
-		dev->name = g_strdup(name);
-	}
-
-	/* FIXME: check if other information was changed before emitting the
-	 * signal */
-	adapter_emit_device_found(adapter, dev);
-}
-
 static gboolean pairing_is_legacy(bdaddr_t *local, bdaddr_t *peer,
 					gboolean eir, gboolean name)
 {
@@ -3035,13 +2999,14 @@ static char *read_stored_data(bdaddr_t *local, bdaddr_t *peer, const char *file)
 }
 
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-				uint32_t class, int8_t rssi, uint8_t *data)
+					uint32_t class, int8_t rssi,
+					uint8_t *data, size_t eir_size)
 {
 	struct remote_dev_info *dev;
 	struct eir_data eir_data;
 	char *name;
-	gboolean new_dev, legacy;
-	name_status_t name_status;
+	gboolean new_dev, legacy, le;
+	name_status_t name_status = NAME_NOT_REQUIRED;
 	const char *dev_name;
 	int err;
 
@@ -3054,14 +3019,22 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 
 	name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
 
-	legacy = pairing_is_legacy(&adapter->bdaddr, bdaddr,
-				data ? TRUE : FALSE, name ? TRUE : FALSE);
+	if (eir_data.flags < 0) {
+		le = FALSE;
 
-	if (!name && main_opts.name_resolv &&
-			adapter_has_discov_sessions(adapter))
-		name_status = NAME_REQUIRED;
-	else
-		name_status = NAME_NOT_REQUIRED;
+		legacy = pairing_is_legacy(&adapter->bdaddr, bdaddr,
+						data ? TRUE : FALSE,
+						name ? TRUE : FALSE);
+
+		if (!name && main_opts.name_resolv &&
+				adapter_has_discov_sessions(adapter))
+			name_status = NAME_REQUIRED;
+		else
+			name_status = NAME_NOT_REQUIRED;
+	} else {
+		le = TRUE;
+		legacy = FALSE;
+	}
 
 	/* Complete EIR names are always used. Shortened EIR names are only
 	 * used if there is no name already in storage. */
@@ -3093,6 +3066,10 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 		dev->class = class;
 		dev->legacy = legacy;
 		dev->name_status = name_status;
+
+		if (eir_data.flags >= 0)
+			dev->flags = eir_data.flags;
+
 	} else if (dev->rssi == rssi)
 		goto done;
 
diff --git a/src/adapter.h b/src/adapter.h
index 4785d5c..4c07e92 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -108,12 +108,9 @@ int adapter_get_state(struct btd_adapter *adapter);
 int adapter_get_discover_type(struct btd_adapter *adapter);
 struct remote_dev_info *adapter_search_found_devices(struct btd_adapter *adapter,
 						struct remote_dev_info *match);
-void adapter_update_device_from_info(struct btd_adapter *adapter,
-					bdaddr_t bdaddr, int8_t rssi,
-					const char *name, GSList *services,
-					int flags);
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-				uint32_t class, int8_t rssi, uint8_t *data);
+					uint32_t class, int8_t rssi,
+					uint8_t *data, size_t eir_size);
 int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr);
 void adapter_emit_device_found(struct btd_adapter *adapter,
 						struct remote_dev_info *dev);
diff --git a/src/event.c b/src/event.c
index 2c893f0..115b285 100644
--- a/src/event.c
+++ b/src/event.c
@@ -281,19 +281,10 @@ void btd_event_simple_pairing_complete(bdaddr_t *local, bdaddr_t *peer,
 	device_simple_pairing_complete(device, status);
 }
 
-static void free_eir_data(struct eir_data *eir)
-{
-	g_slist_foreach(eir->services, (GFunc) g_free, NULL);
-	g_slist_free(eir->services);
-	g_free(eir->name);
-}
-
 void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info)
 {
 	struct btd_adapter *adapter;
-	struct eir_data eir_data;
 	int8_t rssi;
-	int err;
 
 	adapter = manager_find_adapter(local);
 	if (adapter == NULL) {
@@ -301,19 +292,10 @@ void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info)
 		return;
 	}
 
-	memset(&eir_data, 0, sizeof(eir_data));
-	err = eir_parse(&eir_data, info->data, info->length);
-	if (err < 0)
-		error("Error parsing advertising data: %s (%d)",
-							strerror(-err), -err);
-
 	rssi = *(info->data + info->length);
 
-	adapter_update_device_from_info(adapter, info->bdaddr, rssi,
-					eir_data.name, eir_data.services,
-					eir_data.flags);
-
-	free_eir_data(&eir_data);
+	adapter_update_found_devices(adapter, &info->bdaddr, 0, rssi,
+						info->data, info->length);
 }
 
 static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba)
@@ -355,7 +337,8 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 	if (data)
 		write_remote_eir(local, peer, data);
 
-	adapter_update_found_devices(adapter, peer, class, rssi, data);
+	adapter_update_found_devices(adapter, peer, class, rssi,
+						data, EIR_DATA_LENGTH);
 }
 
 void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
-- 
1.7.5.rc3


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

* [PATCH v4 07/12] Fix memory leak of EIR data
  2011-05-16 20:49 ` [PATCH v3 07/12] Fix memory leak of EIR data Claudio Takahasi
@ 2011-05-17 18:26   ` Claudio Takahasi
  2011-05-18 19:39     ` [PATCH v5 " Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-17 18:26 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/adapter.c |    1 +
 src/eir.c     |    7 +++++++
 src/eir.h     |    1 +
 3 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index c053d6c..9afb0d4 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3085,6 +3085,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 
 done:
 	free(name);
+	eir_data_free(&eir_data);
 }
 
 int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr)
diff --git a/src/eir.c b/src/eir.c
index d827c7e..2fbd919 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -44,6 +44,13 @@
 #define EIR_TX_POWER                0x0A  /* transmit power level */
 #define EIR_DEVICE_ID               0x10  /* device ID */
 
+void eir_data_free(struct eir_data *eir)
+{
+	g_slist_foreach(eir->services, (GFunc) g_free, NULL);
+	g_slist_free(eir->services);
+	g_free(eir->name);
+}
+
 int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
 {
 	uint16_t len = 0;
diff --git a/src/eir.h b/src/eir.h
index c7699eb..aacd16a 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -36,6 +36,7 @@ struct eir_data {
 	gboolean name_complete;
 };
 
+void eir_data_free(struct eir_data *eir);
 int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length);
 void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 			uint16_t did_product, uint16_t did_version,
-- 
1.7.5.rc3


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

* [PATCH v4 08/12] Remove btd_event_advertising_report
  2011-05-16 20:49 ` [PATCH v3 08/12] Remove btd_event_advertising_report Claudio Takahasi
@ 2011-05-17 18:26   ` Claudio Takahasi
  2011-05-18 19:39     ` [PATCH v5 " Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-17 18:26 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

Advertises should be notified using btd_event_device_found function
to keep the compatibility with mgmtops plugin.
---
 plugins/hciops.c |   13 ++++++++++---
 src/event.c      |   17 -----------------
 src/event.h      |    1 -
 3 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 07643a1..65ad4f3 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -2171,19 +2171,26 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
 {
 	struct dev_info *dev = &devs[index];
 	le_advertising_info *info;
-	uint8_t num_reports;
+	uint8_t num_reports, rssi;
 	const uint8_t RSSI_SIZE = 1;
 
 	num_reports = meta->data[0];
 
 	info = (le_advertising_info *) &meta->data[1];
-	btd_event_advertising_report(&dev->bdaddr, info);
+	rssi = *(info->data + info->length);
+
+	btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi,
+								info->data);
+
 	num_reports--;
 
 	while (num_reports--) {
 		info = (le_advertising_info *) (info->data + info->length +
 								RSSI_SIZE);
-		btd_event_advertising_report(&dev->bdaddr, info);
+		rssi = *(info->data + info->length);
+
+		btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi,
+								info->data);
 	}
 }
 
diff --git a/src/event.c b/src/event.c
index 115b285..3ee8802 100644
--- a/src/event.c
+++ b/src/event.c
@@ -281,23 +281,6 @@ void btd_event_simple_pairing_complete(bdaddr_t *local, bdaddr_t *peer,
 	device_simple_pairing_complete(device, status);
 }
 
-void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info)
-{
-	struct btd_adapter *adapter;
-	int8_t rssi;
-
-	adapter = manager_find_adapter(local);
-	if (adapter == NULL) {
-		error("No matching adapter found");
-		return;
-	}
-
-	rssi = *(info->data + info->length);
-
-	adapter_update_found_devices(adapter, &info->bdaddr, 0, rssi,
-						info->data, info->length);
-}
-
 static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba)
 {
 	time_t t;
diff --git a/src/event.h b/src/event.h
index 005d8a7..22c199e 100644
--- a/src/event.h
+++ b/src/event.h
@@ -23,7 +23,6 @@
  */
 
 int btd_event_request_pin(bdaddr_t *sba, bdaddr_t *dba);
-void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info);
 void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 						int8_t rssi, uint8_t *data);
 void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer, gboolean legacy);
-- 
1.7.5.rc3


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

* [PATCH v4 09/12] Change the order to write/read the remote's name
  2011-05-16 20:49 ` [PATCH v3 09/12] Change the order to write/read the remote's name Claudio Takahasi
@ 2011-05-17 18:26   ` Claudio Takahasi
  2011-05-18 19:39     ` [PATCH v5 " Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-17 18:26 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

When discovering, write the EIR "complete" name first before to read
the name. Only names retrieved from EIR "complete" name and HCI Remote
Name Request Complete event are stored. This patch doesn't change the
final result: the value of the name sent in the signal.
---
 src/adapter.c |   19 +++++--------------
 1 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 9afb0d4..1a49fb0 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3007,7 +3007,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	char *name;
 	gboolean new_dev, legacy, le;
 	name_status_t name_status = NAME_NOT_REQUIRED;
-	const char *dev_name;
 	int err;
 
 	memset(&eir_data, 0, sizeof(eir_data));
@@ -3017,6 +3016,9 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 		return;
 	}
 
+	if (eir_data.name != NULL && eir_data.name_complete)
+		write_device_name(&adapter->bdaddr, bdaddr, eir_data.name);
+
 	name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
 
 	if (eir_data.flags < 0) {
@@ -3036,23 +3038,12 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 		legacy = FALSE;
 	}
 
-	/* Complete EIR names are always used. Shortened EIR names are only
-	 * used if there is no name already in storage. */
-	dev_name = name;
-	if (eir_data.name != NULL) {
-		if (eir_data.name_complete) {
-			write_device_name(&adapter->bdaddr, bdaddr,
-							eir_data.name);
-			name_status = NAME_NOT_REQUIRED;
-			dev_name = eir_data.name;
-		} else if (name == NULL)
-			dev_name = eir_data.name;
-	}
-
 	dev = get_found_dev(adapter, bdaddr, &new_dev);
 
 	if (new_dev) {
+		const char *dev_name = (name ? name : eir_data.name);
 		char *alias;
+
 		if (dev_name)
 			dev->name = g_strdup(dev_name);
 
-- 
1.7.5.rc3


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

* [PATCH v4 10/12] Cleanup inserting new device found entry
  2011-05-16 20:49 ` [PATCH v3 10/12] Cleanup inserting new device found entry Claudio Takahasi
@ 2011-05-17 18:26   ` Claudio Takahasi
  2011-05-18 19:39     ` [PATCH v5 " Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-17 18:26 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/adapter.c |   97 +++++++++++++++++++++++++++-----------------------------
 1 files changed, 47 insertions(+), 50 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 1a49fb0..ff2b484 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2914,29 +2914,24 @@ void adapter_emit_device_found(struct btd_adapter *adapter,
 	g_free(alias);
 }
 
-static struct remote_dev_info *get_found_dev(struct btd_adapter *adapter,
-						const bdaddr_t *bdaddr,
-						gboolean *new_dev)
+static struct remote_dev_info *found_device_new(const bdaddr_t *bdaddr,
+					gboolean le, const char *name,
+					const char *alias, uint32_t class,
+					gboolean legacy, name_status_t status,
+					int flags)
 {
-	struct remote_dev_info *dev, match;
+	struct remote_dev_info *dev;
 
-	memset(&match, 0, sizeof(struct remote_dev_info));
-	bacpy(&match.bdaddr, bdaddr);
-	match.name_status = NAME_ANY;
-
-	dev = adapter_search_found_devices(adapter, &match);
-	if (dev) {
-		*new_dev = FALSE;
-		/* Out of range list update */
-		adapter->oor_devices = g_slist_remove(adapter->oor_devices,
-							dev);
-	} else {
-		*new_dev = TRUE;
-		dev = g_new0(struct remote_dev_info, 1);
-		bacpy(&dev->bdaddr, bdaddr);
-		adapter->found_devices = g_slist_prepend(adapter->found_devices,
-									dev);
-	}
+	dev = g_new0(struct remote_dev_info, 1);
+	bacpy(&dev->bdaddr, bdaddr);
+	dev->le = le;
+	dev->name = g_strdup(name);
+	dev->alias = g_strdup(alias);
+	dev->class = class;
+	dev->legacy = legacy;
+	dev->name_status = status;
+	if (flags >= 0)
+		dev->flags = flags;
 
 	return dev;
 }
@@ -3002,11 +2997,11 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 					uint32_t class, int8_t rssi,
 					uint8_t *data, size_t eir_size)
 {
-	struct remote_dev_info *dev;
+	struct remote_dev_info *dev, match;
 	struct eir_data eir_data;
-	char *name;
-	gboolean new_dev, legacy, le;
-	name_status_t name_status = NAME_NOT_REQUIRED;
+	char *alias, *name;
+	gboolean legacy, le;
+	name_status_t name_status;
 	int err;
 
 	memset(&eir_data, 0, sizeof(eir_data));
@@ -3019,6 +3014,25 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	if (eir_data.name != NULL && eir_data.name_complete)
 		write_device_name(&adapter->bdaddr, bdaddr, eir_data.name);
 
+	/* Device already seen in the discovery session ? */
+	memset(&match, 0, sizeof(struct remote_dev_info));
+	bacpy(&match.bdaddr, bdaddr);
+	match.name_status = NAME_ANY;
+
+	dev = adapter_search_found_devices(adapter, &match);
+	if (dev) {
+		adapter->oor_devices = g_slist_remove(adapter->oor_devices,
+							dev);
+		if (dev->rssi != rssi)
+			goto done;
+
+		eir_data_free(&eir_data);
+
+		return;
+	}
+
+	/* New device in the discovery session */
+
 	name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
 
 	if (eir_data.flags < 0) {
@@ -3036,34 +3050,19 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	} else {
 		le = TRUE;
 		legacy = FALSE;
+		name_status = NAME_NOT_REQUIRED;
 	}
 
-	dev = get_found_dev(adapter, bdaddr, &new_dev);
-
-	if (new_dev) {
-		const char *dev_name = (name ? name : eir_data.name);
-		char *alias;
+	alias = read_stored_data(&adapter->bdaddr, bdaddr, "aliases");
 
-		if (dev_name)
-			dev->name = g_strdup(dev_name);
-
-		alias = read_stored_data(&adapter->bdaddr, bdaddr, "aliases");
-		if (alias) {
-			dev->alias = g_strdup(alias);
-			free(alias);
-		}
-
-		dev->le = FALSE;
-		dev->class = class;
-		dev->legacy = legacy;
-		dev->name_status = name_status;
+	dev = found_device_new(bdaddr, le, name, alias, class, legacy,
+						name_status, eir_data.flags);
+	free(name);
+	free(alias);
 
-		if (eir_data.flags >= 0)
-			dev->flags = eir_data.flags;
-
-	} else if (dev->rssi == rssi)
-		goto done;
+	adapter->found_devices = g_slist_prepend(adapter->found_devices, dev);
 
+done:
 	dev->rssi = rssi;
 
 	adapter->found_devices = g_slist_sort(adapter->found_devices,
@@ -3074,8 +3073,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 
 	adapter_emit_device_found(adapter, dev);
 
-done:
-	free(name);
 	eir_data_free(&eir_data);
 }
 
-- 
1.7.5.rc3


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

* [PATCH v4 11/12] Replace EIR_DATA_LENGTH with HCI_MAX_EIR_LENGTH
  2011-05-16 20:50 ` [PATCH v3 11/12] Replace EIR_DATA_LENGTH with HCI_MAX_EIR_LENGTH Claudio Takahasi
@ 2011-05-17 18:26   ` Claudio Takahasi
  2011-05-18 19:40     ` [PATCH v5 " Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-17 18:26 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

Both defines have the same value (240) and meaning.
---
 src/adapter.c |    2 +-
 src/eir.c     |    9 +++++----
 src/eir.h     |    2 --
 src/event.c   |    2 +-
 4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index ff2b484..e8fa8e0 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3005,7 +3005,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	int err;
 
 	memset(&eir_data, 0, sizeof(eir_data));
-	err = eir_parse(&eir_data, data, EIR_DATA_LENGTH);
+	err = eir_parse(&eir_data, data, HCI_MAX_EIR_LENGTH);
 	if (err < 0) {
 		error("Error parsing EIR data: %s (%d)", strerror(-err), -err);
 		return;
diff --git a/src/eir.c b/src/eir.c
index 2fbd919..7dfc444 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -27,6 +27,7 @@
 #include <glib.h>
 
 #include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
 #include <bluetooth/sdp.h>
 
 #include "glib-helper.h"
@@ -184,7 +185,7 @@ static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
 			continue;
 
 		/* Stop if not enough space to put next UUID128 */
-		if ((len + 2 + SIZEOF_UUID128) > EIR_DATA_LENGTH) {
+		if ((len + 2 + SIZEOF_UUID128) > HCI_MAX_EIR_LENGTH) {
 			truncated = TRUE;
 			break;
 		}
@@ -229,7 +230,7 @@ void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 	GSList *l;
 	uint8_t *ptr = data;
 	uint16_t eir_len = 0;
-	uint16_t uuid16[EIR_DATA_LENGTH / 2];
+	uint16_t uuid16[HCI_MAX_EIR_LENGTH / 2];
 	int i, uuid_count = 0;
 	gboolean truncated = FALSE;
 	size_t name_len;
@@ -289,7 +290,7 @@ void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 			continue;
 
 		/* Stop if not enough space to put next UUID16 */
-		if ((eir_len + 2 + sizeof(uint16_t)) > EIR_DATA_LENGTH) {
+		if ((eir_len + 2 + sizeof(uint16_t)) > HCI_MAX_EIR_LENGTH) {
 			truncated = TRUE;
 			break;
 		}
@@ -322,6 +323,6 @@ void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 	}
 
 	/* Group all UUID128 types */
-	if (eir_len <= EIR_DATA_LENGTH - 2)
+	if (eir_len <= HCI_MAX_EIR_LENGTH - 2)
 		eir_generate_uuid128(uuids, ptr, &eir_len);
 }
diff --git a/src/eir.h b/src/eir.h
index aacd16a..ea38570 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -22,8 +22,6 @@
  *
  */
 
-#define EIR_DATA_LENGTH  240
-
 struct uuid_info {
 	uuid_t uuid;
 	uint8_t svc_hint;
diff --git a/src/event.c b/src/event.c
index 3ee8802..e28afa3 100644
--- a/src/event.c
+++ b/src/event.c
@@ -321,7 +321,7 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 		write_remote_eir(local, peer, data);
 
 	adapter_update_found_devices(adapter, peer, class, rssi,
-						data, EIR_DATA_LENGTH);
+						data, HCI_MAX_EIR_LENGTH);
 }
 
 void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
-- 
1.7.5.rc3


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

* [PATCH v4 12/12] Drop variable EIR length
  2011-05-16 20:50 ` [PATCH v3 12/12] Drop variable EIR length Claudio Takahasi
@ 2011-05-17 18:26   ` Claudio Takahasi
  2011-05-18 19:40     ` [PATCH v5 " Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-17 18:26 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

The functions eir_parse() and adapter_update_found_devices() now
assume that the EIR buffer has always 240 octets. For advertising
reports, the advertising data is stored on a buffer with 240 bytes,
padded with zeroes.
---
 plugins/hciops.c |   13 +++++++++----
 src/adapter.c    |    6 +++---
 src/adapter.h    |    4 ++--
 src/eir.c        |    8 ++++----
 src/eir.h        |    2 +-
 src/event.c      |    3 +--
 6 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 65ad4f3..9b1225c 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -2171,7 +2171,7 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
 {
 	struct dev_info *dev = &devs[index];
 	le_advertising_info *info;
-	uint8_t num_reports, rssi;
+	uint8_t num_reports, rssi, eir[HCI_MAX_EIR_LENGTH];
 	const uint8_t RSSI_SIZE = 1;
 
 	num_reports = meta->data[0];
@@ -2179,8 +2179,10 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
 	info = (le_advertising_info *) &meta->data[1];
 	rssi = *(info->data + info->length);
 
-	btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi,
-								info->data);
+	memset(eir, 0, sizeof(eir));
+	memcpy(eir, info->data, info->length);
+
+	btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi, eir);
 
 	num_reports--;
 
@@ -2189,8 +2191,11 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
 								RSSI_SIZE);
 		rssi = *(info->data + info->length);
 
+		memset(eir, 0, sizeof(eir));
+		memcpy(eir, info->data, info->length);
+
 		btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi,
-								info->data);
+									eir);
 	}
 }
 
diff --git a/src/adapter.c b/src/adapter.c
index e8fa8e0..8a4fef3 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2994,8 +2994,8 @@ static char *read_stored_data(bdaddr_t *local, bdaddr_t *peer, const char *file)
 }
 
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-					uint32_t class, int8_t rssi,
-					uint8_t *data, size_t eir_size)
+						uint32_t class, int8_t rssi,
+						uint8_t *data)
 {
 	struct remote_dev_info *dev, match;
 	struct eir_data eir_data;
@@ -3005,7 +3005,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	int err;
 
 	memset(&eir_data, 0, sizeof(eir_data));
-	err = eir_parse(&eir_data, data, HCI_MAX_EIR_LENGTH);
+	err = eir_parse(&eir_data, data);
 	if (err < 0) {
 		error("Error parsing EIR data: %s (%d)", strerror(-err), -err);
 		return;
diff --git a/src/adapter.h b/src/adapter.h
index 4c07e92..3526849 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -109,8 +109,8 @@ int adapter_get_discover_type(struct btd_adapter *adapter);
 struct remote_dev_info *adapter_search_found_devices(struct btd_adapter *adapter,
 						struct remote_dev_info *match);
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-					uint32_t class, int8_t rssi,
-					uint8_t *data, size_t eir_size);
+						uint32_t class, int8_t rssi,
+						uint8_t *data);
 int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr);
 void adapter_emit_device_found(struct btd_adapter *adapter,
 						struct remote_dev_info *dev);
diff --git a/src/eir.c b/src/eir.c
index 7dfc444..01b6ac5 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -52,7 +52,7 @@ void eir_data_free(struct eir_data *eir)
 	g_free(eir->name);
 }
 
-int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
+int eir_parse(struct eir_data *eir, uint8_t *eir_data)
 {
 	uint16_t len = 0;
 	size_t total;
@@ -69,10 +69,10 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
 	eir->flags = -1;
 
 	/* No EIR data to parse */
-	if (eir_data == NULL || eir_length == 0)
+	if (eir_data == NULL)
 		return 0;
 
-	while (len < eir_length - 1) {
+	while (len < HCI_MAX_EIR_LENGTH - 1) {
 		uint8_t field_len = eir_data[0];
 
 		/* Check for the end of EIR */
@@ -115,7 +115,7 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
 	}
 
 	/* Bail out if got incorrect length */
-	if (len > eir_length)
+	if (len > HCI_MAX_EIR_LENGTH)
 		return -EINVAL;
 
 	total = uuid16_count + uuid32_count + uuid128_count;
diff --git a/src/eir.h b/src/eir.h
index ea38570..d225973 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -35,7 +35,7 @@ struct eir_data {
 };
 
 void eir_data_free(struct eir_data *eir);
-int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length);
+int eir_parse(struct eir_data *eir, uint8_t *eir_data);
 void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 			uint16_t did_product, uint16_t did_version,
 			GSList *uuids, uint8_t *data);
diff --git a/src/event.c b/src/event.c
index e28afa3..2643a87 100644
--- a/src/event.c
+++ b/src/event.c
@@ -320,8 +320,7 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 	if (data)
 		write_remote_eir(local, peer, data);
 
-	adapter_update_found_devices(adapter, peer, class, rssi,
-						data, HCI_MAX_EIR_LENGTH);
+	adapter_update_found_devices(adapter, peer, class, rssi, data);
 }
 
 void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
-- 
1.7.5.rc3


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

* Re: [PATCH v4 03/12] Move legacy verification to a new function
  2011-05-17 18:25     ` [PATCH v4 " Claudio Takahasi
@ 2011-05-18 19:18       ` Claudio Takahasi
  2011-05-18 19:38         ` [PATCH v5 " Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-18 19:18 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Hi,

On Tue, May 17, 2011 at 3:25 PM, Claudio Takahasi
<claudio.takahasi@openbossa.org> wrote:
> ---
>  src/adapter.c |   35 ++++++++++++++++++++++-------------
>  1 files changed, 22 insertions(+), 13 deletions(-)
>
> diff --git a/src/adapter.c b/src/adapter.c
> index 3188974..d4e1121 100644
> --- a/src/adapter.c
> +++ b/src/adapter.c
> @@ -3002,6 +3002,26 @@ void adapter_update_device_from_info(struct btd_adapter *adapter,
>        adapter_emit_device_found(adapter, dev);
>  }
>
> +static gboolean pairing_is_legacy(bdaddr_t *local, bdaddr_t *peer,
> +                                       gboolean eir, gboolean name)

Based on the discussion in the IRC, a new patch series will be sent
replacing the booleans("name" and "data") by pointers.

Claudio.

> +{
> +       unsigned char features[8];
> +
> +       if (eir)
> +               return FALSE;
> +
> +       if (name == FALSE)
> +               return TRUE;
> +
> +       if (read_remote_features(local, peer, NULL, features) < 0)
> +               return TRUE;
> +
> +       if (features[0] & 0x01)
> +               return FALSE;
> +       else
> +               return TRUE;
> +}
> +
>  void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
>                                uint32_t class, int8_t rssi, uint8_t *data)
>  {
> @@ -3011,7 +3031,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
>        char *alias, *name;
>        gboolean new_dev, legacy;
>        name_status_t name_status;
> -       unsigned char features[8];
>        const char *dev_name;
>        int err;
>
> @@ -3037,18 +3056,8 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
>        create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "names");
>        name = textfile_get(filename, peer_addr);
>
> -       if (data)
> -               legacy = FALSE;
> -       else if (name == NULL)
> -               legacy = TRUE;
> -       else if (read_remote_features(&adapter->bdaddr, bdaddr, NULL,
> -                                                       features) == 0) {
> -               if (features[0] & 0x01)
> -                       legacy = FALSE;
> -               else
> -                       legacy = TRUE;
> -       } else
> -               legacy = TRUE;
> +       legacy = pairing_is_legacy(&adapter->bdaddr, bdaddr,
> +                               data ? TRUE : FALSE, name ? TRUE : FALSE);
>
>        /* Complete EIR names are always used. Shortened EIR names are only
>         * used if there is no name already in storage. */
> --
> 1.7.5.rc3
>
>

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

* [PATCH v5 03/12] Move legacy verification to a new function
  2011-05-18 19:18       ` Claudio Takahasi
@ 2011-05-18 19:38         ` Claudio Takahasi
  0 siblings, 0 replies; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-18 19:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/adapter.c |   34 +++++++++++++++++++++-------------
 1 files changed, 21 insertions(+), 13 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 3188974..5660097 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3002,6 +3002,26 @@ void adapter_update_device_from_info(struct btd_adapter *adapter,
 	adapter_emit_device_found(adapter, dev);
 }
 
+static gboolean pairing_is_legacy(bdaddr_t *local, bdaddr_t *peer,
+					const uint8_t *eir, const char *name)
+{
+	unsigned char features[8];
+
+	if (eir)
+		return FALSE;
+
+	if (name == NULL)
+		return TRUE;
+
+	if (read_remote_features(local, peer, NULL, features) < 0)
+		return TRUE;
+
+	if (features[0] & 0x01)
+		return FALSE;
+	else
+		return TRUE;
+}
+
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 				uint32_t class, int8_t rssi, uint8_t *data)
 {
@@ -3011,7 +3031,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	char *alias, *name;
 	gboolean new_dev, legacy;
 	name_status_t name_status;
-	unsigned char features[8];
 	const char *dev_name;
 	int err;
 
@@ -3037,18 +3056,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "names");
 	name = textfile_get(filename, peer_addr);
 
-	if (data)
-		legacy = FALSE;
-	else if (name == NULL)
-		legacy = TRUE;
-	else if (read_remote_features(&adapter->bdaddr, bdaddr, NULL,
-							features) == 0) {
-		if (features[0] & 0x01)
-			legacy = FALSE;
-		else
-			legacy = TRUE;
-	} else
-		legacy = TRUE;
+	legacy = pairing_is_legacy(&adapter->bdaddr, bdaddr, data, name);
 
 	/* Complete EIR names are always used. Shortened EIR names are only
 	 * used if there is no name already in storage. */
-- 
1.7.5.rc3


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

* [PATCH v5 04/12] Cleanup read name and alias from storage
  2011-05-17 18:25   ` [PATCH v4 " Claudio Takahasi
@ 2011-05-18 19:38     ` Claudio Takahasi
  0 siblings, 0 replies; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-18 19:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/adapter.c |   35 +++++++++++++++++++++++------------
 1 files changed, 23 insertions(+), 12 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 5660097..dacb1dd 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3022,13 +3022,24 @@ static gboolean pairing_is_legacy(bdaddr_t *local, bdaddr_t *peer,
 		return TRUE;
 }
 
+static char *read_stored_data(bdaddr_t *local, bdaddr_t *peer, const char *file)
+{
+	char local_addr[18], peer_addr[18], filename[PATH_MAX + 1];
+
+	ba2str(local, local_addr);
+	ba2str(peer, peer_addr);
+
+	create_name(filename, PATH_MAX, STORAGEDIR, local_addr, file);
+
+	return textfile_get(filename, peer_addr);
+}
+
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 				uint32_t class, int8_t rssi, uint8_t *data)
 {
-	char local_addr[18], peer_addr[18], filename[PATH_MAX + 1];
 	struct remote_dev_info *dev;
 	struct eir_data eir_data;
-	char *alias, *name;
+	char *name;
 	gboolean new_dev, legacy;
 	name_status_t name_status;
 	const char *dev_name;
@@ -3047,14 +3058,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	else
 		name_status = NAME_NOT_REQUIRED;
 
-	ba2str(&adapter->bdaddr, local_addr);
-	ba2str(bdaddr, peer_addr);
-
-	create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "aliases");
-	alias = textfile_get(filename, peer_addr);
-
-	create_name(filename, PATH_MAX, STORAGEDIR, local_addr, "names");
-	name = textfile_get(filename, peer_addr);
+	name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
 
 	legacy = pairing_is_legacy(&adapter->bdaddr, bdaddr, data, name);
 
@@ -3074,18 +3078,22 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	dev = get_found_dev(adapter, bdaddr, &new_dev);
 
 	if (new_dev) {
+		char *alias;
 		if (dev_name)
 			dev->name = g_strdup(dev_name);
 
-		if (alias)
+		alias = read_stored_data(&adapter->bdaddr, bdaddr, "aliases");
+		if (alias) {
 			dev->alias = g_strdup(alias);
+			free(alias);
+		}
 
 		dev->le = FALSE;
 		dev->class = class;
 		dev->legacy = legacy;
 		dev->name_status = name_status;
 	} else if (dev->rssi == rssi)
-		return;
+		goto done;
 
 	dev->rssi = rssi;
 
@@ -3096,6 +3104,9 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	g_slist_foreach(eir_data.services, dev_prepend_uuid, dev);
 
 	adapter_emit_device_found(adapter, dev);
+
+done:
+	free(name);
 }
 
 int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr)
-- 
1.7.5.rc3


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

* [PATCH v5 05/12] Don't resolve name if the name is in the storage
  2011-05-17 18:25   ` [PATCH v4 " Claudio Takahasi
@ 2011-05-18 19:38     ` Claudio Takahasi
  0 siblings, 0 replies; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-18 19:38 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/adapter.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index dacb1dd..f1d9148 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3052,16 +3052,16 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 		return;
 	}
 
-	/* the inquiry result can be triggered by NON D-Bus client */
-	if (main_opts.name_resolv && adapter_has_discov_sessions(adapter))
-		name_status = NAME_REQUIRED;
-	else
-		name_status = NAME_NOT_REQUIRED;
-
 	name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
 
 	legacy = pairing_is_legacy(&adapter->bdaddr, bdaddr, data, name);
 
+	if (!name && main_opts.name_resolv &&
+			adapter_has_discov_sessions(adapter))
+		name_status = NAME_REQUIRED;
+	else
+		name_status = NAME_NOT_REQUIRED;
+
 	/* Complete EIR names are always used. Shortened EIR names are only
 	 * used if there is no name already in storage. */
 	dev_name = name;
-- 
1.7.5.rc3


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

* [PATCH v5 06/12] Unify inquiry results and advertises
  2011-05-17 18:25   ` [PATCH v4 " Claudio Takahasi
@ 2011-05-18 19:39     ` Claudio Takahasi
  2011-05-18 20:53       ` Johan Hedberg
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-18 19:39 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Adapter needs to have only one method to allow discovery results
integration for both interfaces: hciops and mgmtops. This patch
moves the code related to advertises parsing to the same function
that handles inquiry results.
---
 src/adapter.c |   67 ++++++++++++++++++--------------------------------------
 src/adapter.h |    7 +----
 src/event.c   |   25 +++-----------------
 3 files changed, 28 insertions(+), 71 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index f1d9148..e77d3e9 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2966,42 +2966,6 @@ static void dev_prepend_uuid(gpointer data, gpointer user_data)
 	dev->services = g_slist_prepend(dev->services, g_strdup(new_uuid));
 }
 
-void adapter_update_device_from_info(struct btd_adapter *adapter,
-					bdaddr_t bdaddr, int8_t rssi,
-					const char *name, GSList *services,
-					int flags)
-{
-	struct remote_dev_info *dev;
-	gboolean new_dev;
-
-	dev = get_found_dev(adapter, &bdaddr, &new_dev);
-
-	if (new_dev)
-		dev->le = TRUE;
-	else if (dev->rssi == rssi)
-		return;
-
-	dev->rssi = rssi;
-
-	adapter->found_devices = g_slist_sort(adapter->found_devices,
-						(GCompareFunc) dev_rssi_cmp);
-
-	g_slist_foreach(services, remove_same_uuid, dev);
-	g_slist_foreach(services, dev_prepend_uuid, dev);
-
-	if (flags >= 0)
-		dev->flags = flags;
-
-	if (name) {
-		g_free(dev->name);
-		dev->name = g_strdup(name);
-	}
-
-	/* FIXME: check if other information was changed before emitting the
-	 * signal */
-	adapter_emit_device_found(adapter, dev);
-}
-
 static gboolean pairing_is_legacy(bdaddr_t *local, bdaddr_t *peer,
 					const uint8_t *eir, const char *name)
 {
@@ -3035,13 +2999,14 @@ static char *read_stored_data(bdaddr_t *local, bdaddr_t *peer, const char *file)
 }
 
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-				uint32_t class, int8_t rssi, uint8_t *data)
+					uint32_t class, int8_t rssi,
+					uint8_t *data, size_t eir_size)
 {
 	struct remote_dev_info *dev;
 	struct eir_data eir_data;
 	char *name;
-	gboolean new_dev, legacy;
-	name_status_t name_status;
+	gboolean new_dev, legacy, le;
+	name_status_t name_status = NAME_NOT_REQUIRED;
 	const char *dev_name;
 	int err;
 
@@ -3054,13 +3019,21 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 
 	name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
 
-	legacy = pairing_is_legacy(&adapter->bdaddr, bdaddr, data, name);
+	if (eir_data.flags < 0) {
+		le = FALSE;
 
-	if (!name && main_opts.name_resolv &&
-			adapter_has_discov_sessions(adapter))
-		name_status = NAME_REQUIRED;
-	else
-		name_status = NAME_NOT_REQUIRED;
+		legacy = pairing_is_legacy(&adapter->bdaddr, bdaddr, data,
+									name);
+
+		if (!name && main_opts.name_resolv &&
+				adapter_has_discov_sessions(adapter))
+			name_status = NAME_REQUIRED;
+		else
+			name_status = NAME_NOT_REQUIRED;
+	} else {
+		le = TRUE;
+		legacy = FALSE;
+	}
 
 	/* Complete EIR names are always used. Shortened EIR names are only
 	 * used if there is no name already in storage. */
@@ -3092,6 +3065,10 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 		dev->class = class;
 		dev->legacy = legacy;
 		dev->name_status = name_status;
+
+		if (eir_data.flags >= 0)
+			dev->flags = eir_data.flags;
+
 	} else if (dev->rssi == rssi)
 		goto done;
 
diff --git a/src/adapter.h b/src/adapter.h
index 4785d5c..4c07e92 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -108,12 +108,9 @@ int adapter_get_state(struct btd_adapter *adapter);
 int adapter_get_discover_type(struct btd_adapter *adapter);
 struct remote_dev_info *adapter_search_found_devices(struct btd_adapter *adapter,
 						struct remote_dev_info *match);
-void adapter_update_device_from_info(struct btd_adapter *adapter,
-					bdaddr_t bdaddr, int8_t rssi,
-					const char *name, GSList *services,
-					int flags);
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-				uint32_t class, int8_t rssi, uint8_t *data);
+					uint32_t class, int8_t rssi,
+					uint8_t *data, size_t eir_size);
 int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr);
 void adapter_emit_device_found(struct btd_adapter *adapter,
 						struct remote_dev_info *dev);
diff --git a/src/event.c b/src/event.c
index 2c893f0..115b285 100644
--- a/src/event.c
+++ b/src/event.c
@@ -281,19 +281,10 @@ void btd_event_simple_pairing_complete(bdaddr_t *local, bdaddr_t *peer,
 	device_simple_pairing_complete(device, status);
 }
 
-static void free_eir_data(struct eir_data *eir)
-{
-	g_slist_foreach(eir->services, (GFunc) g_free, NULL);
-	g_slist_free(eir->services);
-	g_free(eir->name);
-}
-
 void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info)
 {
 	struct btd_adapter *adapter;
-	struct eir_data eir_data;
 	int8_t rssi;
-	int err;
 
 	adapter = manager_find_adapter(local);
 	if (adapter == NULL) {
@@ -301,19 +292,10 @@ void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info)
 		return;
 	}
 
-	memset(&eir_data, 0, sizeof(eir_data));
-	err = eir_parse(&eir_data, info->data, info->length);
-	if (err < 0)
-		error("Error parsing advertising data: %s (%d)",
-							strerror(-err), -err);
-
 	rssi = *(info->data + info->length);
 
-	adapter_update_device_from_info(adapter, info->bdaddr, rssi,
-					eir_data.name, eir_data.services,
-					eir_data.flags);
-
-	free_eir_data(&eir_data);
+	adapter_update_found_devices(adapter, &info->bdaddr, 0, rssi,
+						info->data, info->length);
 }
 
 static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba)
@@ -355,7 +337,8 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 	if (data)
 		write_remote_eir(local, peer, data);
 
-	adapter_update_found_devices(adapter, peer, class, rssi, data);
+	adapter_update_found_devices(adapter, peer, class, rssi,
+						data, EIR_DATA_LENGTH);
 }
 
 void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
-- 
1.7.5.rc3


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

* [PATCH v5 07/12] Fix memory leak of EIR data
  2011-05-17 18:26   ` [PATCH v4 " Claudio Takahasi
@ 2011-05-18 19:39     ` Claudio Takahasi
  2011-05-18 21:33       ` [PATCH v6 " Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-18 19:39 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/adapter.c |    1 +
 src/eir.c     |    7 +++++++
 src/eir.h     |    1 +
 3 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index e77d3e9..83b010d 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3084,6 +3084,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 
 done:
 	free(name);
+	eir_data_free(&eir_data);
 }
 
 int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr)
diff --git a/src/eir.c b/src/eir.c
index d827c7e..2fbd919 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -44,6 +44,13 @@
 #define EIR_TX_POWER                0x0A  /* transmit power level */
 #define EIR_DEVICE_ID               0x10  /* device ID */
 
+void eir_data_free(struct eir_data *eir)
+{
+	g_slist_foreach(eir->services, (GFunc) g_free, NULL);
+	g_slist_free(eir->services);
+	g_free(eir->name);
+}
+
 int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
 {
 	uint16_t len = 0;
diff --git a/src/eir.h b/src/eir.h
index c7699eb..aacd16a 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -36,6 +36,7 @@ struct eir_data {
 	gboolean name_complete;
 };
 
+void eir_data_free(struct eir_data *eir);
 int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length);
 void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 			uint16_t did_product, uint16_t did_version,
-- 
1.7.5.rc3


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

* [PATCH v5 08/12] Remove btd_event_advertising_report
  2011-05-17 18:26   ` [PATCH v4 " Claudio Takahasi
@ 2011-05-18 19:39     ` Claudio Takahasi
  2011-05-18 21:33       ` [PATCH v6 " Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-18 19:39 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

Advertises should be notified using btd_event_device_found function
to keep the compatibility with mgmtops plugin.
---
 plugins/hciops.c |   13 ++++++++++---
 src/event.c      |   17 -----------------
 src/event.h      |    1 -
 3 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 07643a1..65ad4f3 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -2171,19 +2171,26 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
 {
 	struct dev_info *dev = &devs[index];
 	le_advertising_info *info;
-	uint8_t num_reports;
+	uint8_t num_reports, rssi;
 	const uint8_t RSSI_SIZE = 1;
 
 	num_reports = meta->data[0];
 
 	info = (le_advertising_info *) &meta->data[1];
-	btd_event_advertising_report(&dev->bdaddr, info);
+	rssi = *(info->data + info->length);
+
+	btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi,
+								info->data);
+
 	num_reports--;
 
 	while (num_reports--) {
 		info = (le_advertising_info *) (info->data + info->length +
 								RSSI_SIZE);
-		btd_event_advertising_report(&dev->bdaddr, info);
+		rssi = *(info->data + info->length);
+
+		btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi,
+								info->data);
 	}
 }
 
diff --git a/src/event.c b/src/event.c
index 115b285..3ee8802 100644
--- a/src/event.c
+++ b/src/event.c
@@ -281,23 +281,6 @@ void btd_event_simple_pairing_complete(bdaddr_t *local, bdaddr_t *peer,
 	device_simple_pairing_complete(device, status);
 }
 
-void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info)
-{
-	struct btd_adapter *adapter;
-	int8_t rssi;
-
-	adapter = manager_find_adapter(local);
-	if (adapter == NULL) {
-		error("No matching adapter found");
-		return;
-	}
-
-	rssi = *(info->data + info->length);
-
-	adapter_update_found_devices(adapter, &info->bdaddr, 0, rssi,
-						info->data, info->length);
-}
-
 static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba)
 {
 	time_t t;
diff --git a/src/event.h b/src/event.h
index 005d8a7..22c199e 100644
--- a/src/event.h
+++ b/src/event.h
@@ -23,7 +23,6 @@
  */
 
 int btd_event_request_pin(bdaddr_t *sba, bdaddr_t *dba);
-void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info);
 void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 						int8_t rssi, uint8_t *data);
 void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer, gboolean legacy);
-- 
1.7.5.rc3


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

* [PATCH v5 09/12] Change the order to write/read the remote's name
  2011-05-17 18:26   ` [PATCH v4 " Claudio Takahasi
@ 2011-05-18 19:39     ` Claudio Takahasi
  2011-05-18 21:33       ` [PATCH v6 " Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-18 19:39 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

When discovering, write the EIR "complete" name first before to read
the name. Only names retrieved from EIR "complete" name and HCI Remote
Name Request Complete event are stored. This patch doesn't change the
final result: the value of the name sent in the signal.
---
 src/adapter.c |   19 +++++--------------
 1 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 83b010d..b1cf603 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3007,7 +3007,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	char *name;
 	gboolean new_dev, legacy, le;
 	name_status_t name_status = NAME_NOT_REQUIRED;
-	const char *dev_name;
 	int err;
 
 	memset(&eir_data, 0, sizeof(eir_data));
@@ -3017,6 +3016,9 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 		return;
 	}
 
+	if (eir_data.name != NULL && eir_data.name_complete)
+		write_device_name(&adapter->bdaddr, bdaddr, eir_data.name);
+
 	name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
 
 	if (eir_data.flags < 0) {
@@ -3035,23 +3037,12 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 		legacy = FALSE;
 	}
 
-	/* Complete EIR names are always used. Shortened EIR names are only
-	 * used if there is no name already in storage. */
-	dev_name = name;
-	if (eir_data.name != NULL) {
-		if (eir_data.name_complete) {
-			write_device_name(&adapter->bdaddr, bdaddr,
-							eir_data.name);
-			name_status = NAME_NOT_REQUIRED;
-			dev_name = eir_data.name;
-		} else if (name == NULL)
-			dev_name = eir_data.name;
-	}
-
 	dev = get_found_dev(adapter, bdaddr, &new_dev);
 
 	if (new_dev) {
+		const char *dev_name = (name ? name : eir_data.name);
 		char *alias;
+
 		if (dev_name)
 			dev->name = g_strdup(dev_name);
 
-- 
1.7.5.rc3


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

* [PATCH v5 10/12] Cleanup inserting new device found entry
  2011-05-17 18:26   ` [PATCH v4 " Claudio Takahasi
@ 2011-05-18 19:39     ` Claudio Takahasi
  2011-05-18 21:34       ` [PATCH v6 " Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-18 19:39 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/adapter.c |   97 +++++++++++++++++++++++++++-----------------------------
 1 files changed, 47 insertions(+), 50 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index b1cf603..dc051cd 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2914,29 +2914,24 @@ void adapter_emit_device_found(struct btd_adapter *adapter,
 	g_free(alias);
 }
 
-static struct remote_dev_info *get_found_dev(struct btd_adapter *adapter,
-						const bdaddr_t *bdaddr,
-						gboolean *new_dev)
+static struct remote_dev_info *found_device_new(const bdaddr_t *bdaddr,
+					gboolean le, const char *name,
+					const char *alias, uint32_t class,
+					gboolean legacy, name_status_t status,
+					int flags)
 {
-	struct remote_dev_info *dev, match;
+	struct remote_dev_info *dev;
 
-	memset(&match, 0, sizeof(struct remote_dev_info));
-	bacpy(&match.bdaddr, bdaddr);
-	match.name_status = NAME_ANY;
-
-	dev = adapter_search_found_devices(adapter, &match);
-	if (dev) {
-		*new_dev = FALSE;
-		/* Out of range list update */
-		adapter->oor_devices = g_slist_remove(adapter->oor_devices,
-							dev);
-	} else {
-		*new_dev = TRUE;
-		dev = g_new0(struct remote_dev_info, 1);
-		bacpy(&dev->bdaddr, bdaddr);
-		adapter->found_devices = g_slist_prepend(adapter->found_devices,
-									dev);
-	}
+	dev = g_new0(struct remote_dev_info, 1);
+	bacpy(&dev->bdaddr, bdaddr);
+	dev->le = le;
+	dev->name = g_strdup(name);
+	dev->alias = g_strdup(alias);
+	dev->class = class;
+	dev->legacy = legacy;
+	dev->name_status = status;
+	if (flags >= 0)
+		dev->flags = flags;
 
 	return dev;
 }
@@ -3002,11 +2997,11 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 					uint32_t class, int8_t rssi,
 					uint8_t *data, size_t eir_size)
 {
-	struct remote_dev_info *dev;
+	struct remote_dev_info *dev, match;
 	struct eir_data eir_data;
-	char *name;
-	gboolean new_dev, legacy, le;
-	name_status_t name_status = NAME_NOT_REQUIRED;
+	char *alias, *name;
+	gboolean legacy, le;
+	name_status_t name_status;
 	int err;
 
 	memset(&eir_data, 0, sizeof(eir_data));
@@ -3019,6 +3014,25 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	if (eir_data.name != NULL && eir_data.name_complete)
 		write_device_name(&adapter->bdaddr, bdaddr, eir_data.name);
 
+	/* Device already seen in the discovery session ? */
+	memset(&match, 0, sizeof(struct remote_dev_info));
+	bacpy(&match.bdaddr, bdaddr);
+	match.name_status = NAME_ANY;
+
+	dev = adapter_search_found_devices(adapter, &match);
+	if (dev) {
+		adapter->oor_devices = g_slist_remove(adapter->oor_devices,
+							dev);
+		if (dev->rssi != rssi)
+			goto done;
+
+		eir_data_free(&eir_data);
+
+		return;
+	}
+
+	/* New device in the discovery session */
+
 	name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
 
 	if (eir_data.flags < 0) {
@@ -3035,34 +3049,19 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	} else {
 		le = TRUE;
 		legacy = FALSE;
+		name_status = NAME_NOT_REQUIRED;
 	}
 
-	dev = get_found_dev(adapter, bdaddr, &new_dev);
-
-	if (new_dev) {
-		const char *dev_name = (name ? name : eir_data.name);
-		char *alias;
+	alias = read_stored_data(&adapter->bdaddr, bdaddr, "aliases");
 
-		if (dev_name)
-			dev->name = g_strdup(dev_name);
-
-		alias = read_stored_data(&adapter->bdaddr, bdaddr, "aliases");
-		if (alias) {
-			dev->alias = g_strdup(alias);
-			free(alias);
-		}
-
-		dev->le = FALSE;
-		dev->class = class;
-		dev->legacy = legacy;
-		dev->name_status = name_status;
+	dev = found_device_new(bdaddr, le, name, alias, class, legacy,
+						name_status, eir_data.flags);
+	free(name);
+	free(alias);
 
-		if (eir_data.flags >= 0)
-			dev->flags = eir_data.flags;
-
-	} else if (dev->rssi == rssi)
-		goto done;
+	adapter->found_devices = g_slist_prepend(adapter->found_devices, dev);
 
+done:
 	dev->rssi = rssi;
 
 	adapter->found_devices = g_slist_sort(adapter->found_devices,
@@ -3073,8 +3072,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 
 	adapter_emit_device_found(adapter, dev);
 
-done:
-	free(name);
 	eir_data_free(&eir_data);
 }
 
-- 
1.7.5.rc3


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

* [PATCH v5 11/12] Replace EIR_DATA_LENGTH with HCI_MAX_EIR_LENGTH
  2011-05-17 18:26   ` [PATCH v4 " Claudio Takahasi
@ 2011-05-18 19:40     ` Claudio Takahasi
  2011-05-18 21:34       ` [PATCH v6 " Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-18 19:40 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

Both defines have the same value (240) and meaning.
---
 src/adapter.c |    2 +-
 src/eir.c     |    9 +++++----
 src/eir.h     |    2 --
 src/event.c   |    2 +-
 4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index dc051cd..0210c30 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3005,7 +3005,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	int err;
 
 	memset(&eir_data, 0, sizeof(eir_data));
-	err = eir_parse(&eir_data, data, EIR_DATA_LENGTH);
+	err = eir_parse(&eir_data, data, HCI_MAX_EIR_LENGTH);
 	if (err < 0) {
 		error("Error parsing EIR data: %s (%d)", strerror(-err), -err);
 		return;
diff --git a/src/eir.c b/src/eir.c
index 2fbd919..7dfc444 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -27,6 +27,7 @@
 #include <glib.h>
 
 #include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
 #include <bluetooth/sdp.h>
 
 #include "glib-helper.h"
@@ -184,7 +185,7 @@ static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
 			continue;
 
 		/* Stop if not enough space to put next UUID128 */
-		if ((len + 2 + SIZEOF_UUID128) > EIR_DATA_LENGTH) {
+		if ((len + 2 + SIZEOF_UUID128) > HCI_MAX_EIR_LENGTH) {
 			truncated = TRUE;
 			break;
 		}
@@ -229,7 +230,7 @@ void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 	GSList *l;
 	uint8_t *ptr = data;
 	uint16_t eir_len = 0;
-	uint16_t uuid16[EIR_DATA_LENGTH / 2];
+	uint16_t uuid16[HCI_MAX_EIR_LENGTH / 2];
 	int i, uuid_count = 0;
 	gboolean truncated = FALSE;
 	size_t name_len;
@@ -289,7 +290,7 @@ void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 			continue;
 
 		/* Stop if not enough space to put next UUID16 */
-		if ((eir_len + 2 + sizeof(uint16_t)) > EIR_DATA_LENGTH) {
+		if ((eir_len + 2 + sizeof(uint16_t)) > HCI_MAX_EIR_LENGTH) {
 			truncated = TRUE;
 			break;
 		}
@@ -322,6 +323,6 @@ void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 	}
 
 	/* Group all UUID128 types */
-	if (eir_len <= EIR_DATA_LENGTH - 2)
+	if (eir_len <= HCI_MAX_EIR_LENGTH - 2)
 		eir_generate_uuid128(uuids, ptr, &eir_len);
 }
diff --git a/src/eir.h b/src/eir.h
index aacd16a..ea38570 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -22,8 +22,6 @@
  *
  */
 
-#define EIR_DATA_LENGTH  240
-
 struct uuid_info {
 	uuid_t uuid;
 	uint8_t svc_hint;
diff --git a/src/event.c b/src/event.c
index 3ee8802..e28afa3 100644
--- a/src/event.c
+++ b/src/event.c
@@ -321,7 +321,7 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 		write_remote_eir(local, peer, data);
 
 	adapter_update_found_devices(adapter, peer, class, rssi,
-						data, EIR_DATA_LENGTH);
+						data, HCI_MAX_EIR_LENGTH);
 }
 
 void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
-- 
1.7.5.rc3


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

* [PATCH v5 12/12] Drop variable EIR length
  2011-05-17 18:26   ` [PATCH v4 " Claudio Takahasi
@ 2011-05-18 19:40     ` Claudio Takahasi
  2011-05-18 21:34       ` [PATCH v6 " Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-18 19:40 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

The functions eir_parse() and adapter_update_found_devices() now
assume that the EIR buffer has always 240 octets. For advertising
reports, the advertising data is stored on a buffer with 240 bytes,
padded with zeroes.
---
 plugins/hciops.c |   13 +++++++++----
 src/adapter.c    |    6 +++---
 src/adapter.h    |    4 ++--
 src/eir.c        |    8 ++++----
 src/eir.h        |    2 +-
 src/event.c      |    3 +--
 6 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 65ad4f3..9b1225c 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -2171,7 +2171,7 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
 {
 	struct dev_info *dev = &devs[index];
 	le_advertising_info *info;
-	uint8_t num_reports, rssi;
+	uint8_t num_reports, rssi, eir[HCI_MAX_EIR_LENGTH];
 	const uint8_t RSSI_SIZE = 1;
 
 	num_reports = meta->data[0];
@@ -2179,8 +2179,10 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
 	info = (le_advertising_info *) &meta->data[1];
 	rssi = *(info->data + info->length);
 
-	btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi,
-								info->data);
+	memset(eir, 0, sizeof(eir));
+	memcpy(eir, info->data, info->length);
+
+	btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi, eir);
 
 	num_reports--;
 
@@ -2189,8 +2191,11 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
 								RSSI_SIZE);
 		rssi = *(info->data + info->length);
 
+		memset(eir, 0, sizeof(eir));
+		memcpy(eir, info->data, info->length);
+
 		btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi,
-								info->data);
+									eir);
 	}
 }
 
diff --git a/src/adapter.c b/src/adapter.c
index 0210c30..c30febc 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2994,8 +2994,8 @@ static char *read_stored_data(bdaddr_t *local, bdaddr_t *peer, const char *file)
 }
 
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-					uint32_t class, int8_t rssi,
-					uint8_t *data, size_t eir_size)
+						uint32_t class, int8_t rssi,
+						uint8_t *data)
 {
 	struct remote_dev_info *dev, match;
 	struct eir_data eir_data;
@@ -3005,7 +3005,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	int err;
 
 	memset(&eir_data, 0, sizeof(eir_data));
-	err = eir_parse(&eir_data, data, HCI_MAX_EIR_LENGTH);
+	err = eir_parse(&eir_data, data);
 	if (err < 0) {
 		error("Error parsing EIR data: %s (%d)", strerror(-err), -err);
 		return;
diff --git a/src/adapter.h b/src/adapter.h
index 4c07e92..3526849 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -109,8 +109,8 @@ int adapter_get_discover_type(struct btd_adapter *adapter);
 struct remote_dev_info *adapter_search_found_devices(struct btd_adapter *adapter,
 						struct remote_dev_info *match);
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-					uint32_t class, int8_t rssi,
-					uint8_t *data, size_t eir_size);
+						uint32_t class, int8_t rssi,
+						uint8_t *data);
 int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr);
 void adapter_emit_device_found(struct btd_adapter *adapter,
 						struct remote_dev_info *dev);
diff --git a/src/eir.c b/src/eir.c
index 7dfc444..01b6ac5 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -52,7 +52,7 @@ void eir_data_free(struct eir_data *eir)
 	g_free(eir->name);
 }
 
-int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
+int eir_parse(struct eir_data *eir, uint8_t *eir_data)
 {
 	uint16_t len = 0;
 	size_t total;
@@ -69,10 +69,10 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
 	eir->flags = -1;
 
 	/* No EIR data to parse */
-	if (eir_data == NULL || eir_length == 0)
+	if (eir_data == NULL)
 		return 0;
 
-	while (len < eir_length - 1) {
+	while (len < HCI_MAX_EIR_LENGTH - 1) {
 		uint8_t field_len = eir_data[0];
 
 		/* Check for the end of EIR */
@@ -115,7 +115,7 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
 	}
 
 	/* Bail out if got incorrect length */
-	if (len > eir_length)
+	if (len > HCI_MAX_EIR_LENGTH)
 		return -EINVAL;
 
 	total = uuid16_count + uuid32_count + uuid128_count;
diff --git a/src/eir.h b/src/eir.h
index ea38570..d225973 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -35,7 +35,7 @@ struct eir_data {
 };
 
 void eir_data_free(struct eir_data *eir);
-int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length);
+int eir_parse(struct eir_data *eir, uint8_t *eir_data);
 void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 			uint16_t did_product, uint16_t did_version,
 			GSList *uuids, uint8_t *data);
diff --git a/src/event.c b/src/event.c
index e28afa3..2643a87 100644
--- a/src/event.c
+++ b/src/event.c
@@ -320,8 +320,7 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 	if (data)
 		write_remote_eir(local, peer, data);
 
-	adapter_update_found_devices(adapter, peer, class, rssi,
-						data, HCI_MAX_EIR_LENGTH);
+	adapter_update_found_devices(adapter, peer, class, rssi, data);
 }
 
 void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
-- 
1.7.5.rc3


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

* Re: [PATCH v5 06/12] Unify inquiry results and advertises
  2011-05-18 19:39     ` [PATCH v5 " Claudio Takahasi
@ 2011-05-18 20:53       ` Johan Hedberg
  2011-05-18 21:33         ` [PATCH v6 " Claudio Takahasi
  0 siblings, 1 reply; 43+ messages in thread
From: Johan Hedberg @ 2011-05-18 20:53 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth

Hi Claudio,

On Wed, May 18, 2011, Claudio Takahasi wrote:
> Adapter needs to have only one method to allow discovery results
> integration for both interfaces: hciops and mgmtops. This patch
> moves the code related to advertises parsing to the same function
> that handles inquiry results.
> ---
>  src/adapter.c |   67 ++++++++++++++++++--------------------------------------
>  src/adapter.h |    7 +----
>  src/event.c   |   25 +++-----------------
>  3 files changed, 28 insertions(+), 71 deletions(-)

Patches 3, 4 and 5 have been pushed upstream, but this one causes a
compiler error with gcc 4.6:

src/adapter.c: In function ‘adapter_update_found_devices’:
src/adapter.c:3008:28: error: variable ‘le’ set but not used [-Werror=unused-but-set-variable]

Please fix and resend.

Johan

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

* [PATCH v6 06/12] Unify inquiry results and advertises
  2011-05-18 20:53       ` Johan Hedberg
@ 2011-05-18 21:33         ` Claudio Takahasi
  0 siblings, 0 replies; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-18 21:33 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

Adapter needs to have only one method to allow discovery results
integration for both interfaces: hciops and mgmtops. This patch
moves the code related to advertises parsing to the same function
that handles inquiry results.
---
 src/adapter.c |   69 +++++++++++++++++++--------------------------------------
 src/adapter.h |    7 +----
 src/event.c   |   25 +++-----------------
 3 files changed, 29 insertions(+), 72 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index f1d9148..4c3d027 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2966,42 +2966,6 @@ static void dev_prepend_uuid(gpointer data, gpointer user_data)
 	dev->services = g_slist_prepend(dev->services, g_strdup(new_uuid));
 }
 
-void adapter_update_device_from_info(struct btd_adapter *adapter,
-					bdaddr_t bdaddr, int8_t rssi,
-					const char *name, GSList *services,
-					int flags)
-{
-	struct remote_dev_info *dev;
-	gboolean new_dev;
-
-	dev = get_found_dev(adapter, &bdaddr, &new_dev);
-
-	if (new_dev)
-		dev->le = TRUE;
-	else if (dev->rssi == rssi)
-		return;
-
-	dev->rssi = rssi;
-
-	adapter->found_devices = g_slist_sort(adapter->found_devices,
-						(GCompareFunc) dev_rssi_cmp);
-
-	g_slist_foreach(services, remove_same_uuid, dev);
-	g_slist_foreach(services, dev_prepend_uuid, dev);
-
-	if (flags >= 0)
-		dev->flags = flags;
-
-	if (name) {
-		g_free(dev->name);
-		dev->name = g_strdup(name);
-	}
-
-	/* FIXME: check if other information was changed before emitting the
-	 * signal */
-	adapter_emit_device_found(adapter, dev);
-}
-
 static gboolean pairing_is_legacy(bdaddr_t *local, bdaddr_t *peer,
 					const uint8_t *eir, const char *name)
 {
@@ -3035,13 +2999,14 @@ static char *read_stored_data(bdaddr_t *local, bdaddr_t *peer, const char *file)
 }
 
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-				uint32_t class, int8_t rssi, uint8_t *data)
+					uint32_t class, int8_t rssi,
+					uint8_t *data, size_t eir_size)
 {
 	struct remote_dev_info *dev;
 	struct eir_data eir_data;
 	char *name;
-	gboolean new_dev, legacy;
-	name_status_t name_status;
+	gboolean new_dev, legacy, le;
+	name_status_t name_status = NAME_NOT_REQUIRED;
 	const char *dev_name;
 	int err;
 
@@ -3054,13 +3019,21 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 
 	name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
 
-	legacy = pairing_is_legacy(&adapter->bdaddr, bdaddr, data, name);
+	if (eir_data.flags < 0) {
+		le = FALSE;
 
-	if (!name && main_opts.name_resolv &&
-			adapter_has_discov_sessions(adapter))
-		name_status = NAME_REQUIRED;
-	else
-		name_status = NAME_NOT_REQUIRED;
+		legacy = pairing_is_legacy(&adapter->bdaddr, bdaddr, data,
+									name);
+
+		if (!name && main_opts.name_resolv &&
+				adapter_has_discov_sessions(adapter))
+			name_status = NAME_REQUIRED;
+		else
+			name_status = NAME_NOT_REQUIRED;
+	} else {
+		le = TRUE;
+		legacy = FALSE;
+	}
 
 	/* Complete EIR names are always used. Shortened EIR names are only
 	 * used if there is no name already in storage. */
@@ -3088,10 +3061,14 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 			free(alias);
 		}
 
-		dev->le = FALSE;
+		dev->le = le;
 		dev->class = class;
 		dev->legacy = legacy;
 		dev->name_status = name_status;
+
+		if (eir_data.flags >= 0)
+			dev->flags = eir_data.flags;
+
 	} else if (dev->rssi == rssi)
 		goto done;
 
diff --git a/src/adapter.h b/src/adapter.h
index 4785d5c..4c07e92 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -108,12 +108,9 @@ int adapter_get_state(struct btd_adapter *adapter);
 int adapter_get_discover_type(struct btd_adapter *adapter);
 struct remote_dev_info *adapter_search_found_devices(struct btd_adapter *adapter,
 						struct remote_dev_info *match);
-void adapter_update_device_from_info(struct btd_adapter *adapter,
-					bdaddr_t bdaddr, int8_t rssi,
-					const char *name, GSList *services,
-					int flags);
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-				uint32_t class, int8_t rssi, uint8_t *data);
+					uint32_t class, int8_t rssi,
+					uint8_t *data, size_t eir_size);
 int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr);
 void adapter_emit_device_found(struct btd_adapter *adapter,
 						struct remote_dev_info *dev);
diff --git a/src/event.c b/src/event.c
index 2c893f0..115b285 100644
--- a/src/event.c
+++ b/src/event.c
@@ -281,19 +281,10 @@ void btd_event_simple_pairing_complete(bdaddr_t *local, bdaddr_t *peer,
 	device_simple_pairing_complete(device, status);
 }
 
-static void free_eir_data(struct eir_data *eir)
-{
-	g_slist_foreach(eir->services, (GFunc) g_free, NULL);
-	g_slist_free(eir->services);
-	g_free(eir->name);
-}
-
 void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info)
 {
 	struct btd_adapter *adapter;
-	struct eir_data eir_data;
 	int8_t rssi;
-	int err;
 
 	adapter = manager_find_adapter(local);
 	if (adapter == NULL) {
@@ -301,19 +292,10 @@ void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info)
 		return;
 	}
 
-	memset(&eir_data, 0, sizeof(eir_data));
-	err = eir_parse(&eir_data, info->data, info->length);
-	if (err < 0)
-		error("Error parsing advertising data: %s (%d)",
-							strerror(-err), -err);
-
 	rssi = *(info->data + info->length);
 
-	adapter_update_device_from_info(adapter, info->bdaddr, rssi,
-					eir_data.name, eir_data.services,
-					eir_data.flags);
-
-	free_eir_data(&eir_data);
+	adapter_update_found_devices(adapter, &info->bdaddr, 0, rssi,
+						info->data, info->length);
 }
 
 static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba)
@@ -355,7 +337,8 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 	if (data)
 		write_remote_eir(local, peer, data);
 
-	adapter_update_found_devices(adapter, peer, class, rssi, data);
+	adapter_update_found_devices(adapter, peer, class, rssi,
+						data, EIR_DATA_LENGTH);
 }
 
 void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
-- 
1.7.5.rc3


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

* [PATCH v6 07/12] Fix memory leak of EIR data
  2011-05-18 19:39     ` [PATCH v5 " Claudio Takahasi
@ 2011-05-18 21:33       ` Claudio Takahasi
  0 siblings, 0 replies; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-18 21:33 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/adapter.c |    1 +
 src/eir.c     |    7 +++++++
 src/eir.h     |    1 +
 3 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 4c3d027..556de1a 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3084,6 +3084,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 
 done:
 	free(name);
+	eir_data_free(&eir_data);
 }
 
 int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr)
diff --git a/src/eir.c b/src/eir.c
index d827c7e..2fbd919 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -44,6 +44,13 @@
 #define EIR_TX_POWER                0x0A  /* transmit power level */
 #define EIR_DEVICE_ID               0x10  /* device ID */
 
+void eir_data_free(struct eir_data *eir)
+{
+	g_slist_foreach(eir->services, (GFunc) g_free, NULL);
+	g_slist_free(eir->services);
+	g_free(eir->name);
+}
+
 int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
 {
 	uint16_t len = 0;
diff --git a/src/eir.h b/src/eir.h
index c7699eb..aacd16a 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -36,6 +36,7 @@ struct eir_data {
 	gboolean name_complete;
 };
 
+void eir_data_free(struct eir_data *eir);
 int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length);
 void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 			uint16_t did_product, uint16_t did_version,
-- 
1.7.5.rc3


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

* [PATCH v6 08/12] Remove btd_event_advertising_report
  2011-05-18 19:39     ` [PATCH v5 " Claudio Takahasi
@ 2011-05-18 21:33       ` Claudio Takahasi
  0 siblings, 0 replies; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-18 21:33 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

Advertises should be notified using btd_event_device_found function
to keep the compatibility with mgmtops plugin.
---
 plugins/hciops.c |   13 ++++++++++---
 src/event.c      |   17 -----------------
 src/event.h      |    1 -
 3 files changed, 10 insertions(+), 21 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 07643a1..65ad4f3 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -2171,19 +2171,26 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
 {
 	struct dev_info *dev = &devs[index];
 	le_advertising_info *info;
-	uint8_t num_reports;
+	uint8_t num_reports, rssi;
 	const uint8_t RSSI_SIZE = 1;
 
 	num_reports = meta->data[0];
 
 	info = (le_advertising_info *) &meta->data[1];
-	btd_event_advertising_report(&dev->bdaddr, info);
+	rssi = *(info->data + info->length);
+
+	btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi,
+								info->data);
+
 	num_reports--;
 
 	while (num_reports--) {
 		info = (le_advertising_info *) (info->data + info->length +
 								RSSI_SIZE);
-		btd_event_advertising_report(&dev->bdaddr, info);
+		rssi = *(info->data + info->length);
+
+		btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi,
+								info->data);
 	}
 }
 
diff --git a/src/event.c b/src/event.c
index 115b285..3ee8802 100644
--- a/src/event.c
+++ b/src/event.c
@@ -281,23 +281,6 @@ void btd_event_simple_pairing_complete(bdaddr_t *local, bdaddr_t *peer,
 	device_simple_pairing_complete(device, status);
 }
 
-void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info)
-{
-	struct btd_adapter *adapter;
-	int8_t rssi;
-
-	adapter = manager_find_adapter(local);
-	if (adapter == NULL) {
-		error("No matching adapter found");
-		return;
-	}
-
-	rssi = *(info->data + info->length);
-
-	adapter_update_found_devices(adapter, &info->bdaddr, 0, rssi,
-						info->data, info->length);
-}
-
 static void update_lastseen(bdaddr_t *sba, bdaddr_t *dba)
 {
 	time_t t;
diff --git a/src/event.h b/src/event.h
index 005d8a7..22c199e 100644
--- a/src/event.h
+++ b/src/event.h
@@ -23,7 +23,6 @@
  */
 
 int btd_event_request_pin(bdaddr_t *sba, bdaddr_t *dba);
-void btd_event_advertising_report(bdaddr_t *local, le_advertising_info *info);
 void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 						int8_t rssi, uint8_t *data);
 void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer, gboolean legacy);
-- 
1.7.5.rc3


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

* [PATCH v6 09/12] Change the order to write/read the remote's name
  2011-05-18 19:39     ` [PATCH v5 " Claudio Takahasi
@ 2011-05-18 21:33       ` Claudio Takahasi
  0 siblings, 0 replies; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-18 21:33 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

When discovering, write the EIR "complete" name first before to read
the name. Only names retrieved from EIR "complete" name and HCI Remote
Name Request Complete event are stored. This patch doesn't change the
final result: the value of the name sent in the signal.
---
 src/adapter.c |   19 +++++--------------
 1 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 556de1a..161636e 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3007,7 +3007,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	char *name;
 	gboolean new_dev, legacy, le;
 	name_status_t name_status = NAME_NOT_REQUIRED;
-	const char *dev_name;
 	int err;
 
 	memset(&eir_data, 0, sizeof(eir_data));
@@ -3017,6 +3016,9 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 		return;
 	}
 
+	if (eir_data.name != NULL && eir_data.name_complete)
+		write_device_name(&adapter->bdaddr, bdaddr, eir_data.name);
+
 	name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
 
 	if (eir_data.flags < 0) {
@@ -3035,23 +3037,12 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 		legacy = FALSE;
 	}
 
-	/* Complete EIR names are always used. Shortened EIR names are only
-	 * used if there is no name already in storage. */
-	dev_name = name;
-	if (eir_data.name != NULL) {
-		if (eir_data.name_complete) {
-			write_device_name(&adapter->bdaddr, bdaddr,
-							eir_data.name);
-			name_status = NAME_NOT_REQUIRED;
-			dev_name = eir_data.name;
-		} else if (name == NULL)
-			dev_name = eir_data.name;
-	}
-
 	dev = get_found_dev(adapter, bdaddr, &new_dev);
 
 	if (new_dev) {
+		const char *dev_name = (name ? name : eir_data.name);
 		char *alias;
+
 		if (dev_name)
 			dev->name = g_strdup(dev_name);
 
-- 
1.7.5.rc3


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

* [PATCH v6 10/12] Cleanup inserting new device found entry
  2011-05-18 19:39     ` [PATCH v5 " Claudio Takahasi
@ 2011-05-18 21:34       ` Claudio Takahasi
  0 siblings, 0 replies; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-18 21:34 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Claudio Takahasi

---
 src/adapter.c |   97 +++++++++++++++++++++++++++-----------------------------
 1 files changed, 47 insertions(+), 50 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index 161636e..dc051cd 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2914,29 +2914,24 @@ void adapter_emit_device_found(struct btd_adapter *adapter,
 	g_free(alias);
 }
 
-static struct remote_dev_info *get_found_dev(struct btd_adapter *adapter,
-						const bdaddr_t *bdaddr,
-						gboolean *new_dev)
+static struct remote_dev_info *found_device_new(const bdaddr_t *bdaddr,
+					gboolean le, const char *name,
+					const char *alias, uint32_t class,
+					gboolean legacy, name_status_t status,
+					int flags)
 {
-	struct remote_dev_info *dev, match;
+	struct remote_dev_info *dev;
 
-	memset(&match, 0, sizeof(struct remote_dev_info));
-	bacpy(&match.bdaddr, bdaddr);
-	match.name_status = NAME_ANY;
-
-	dev = adapter_search_found_devices(adapter, &match);
-	if (dev) {
-		*new_dev = FALSE;
-		/* Out of range list update */
-		adapter->oor_devices = g_slist_remove(adapter->oor_devices,
-							dev);
-	} else {
-		*new_dev = TRUE;
-		dev = g_new0(struct remote_dev_info, 1);
-		bacpy(&dev->bdaddr, bdaddr);
-		adapter->found_devices = g_slist_prepend(adapter->found_devices,
-									dev);
-	}
+	dev = g_new0(struct remote_dev_info, 1);
+	bacpy(&dev->bdaddr, bdaddr);
+	dev->le = le;
+	dev->name = g_strdup(name);
+	dev->alias = g_strdup(alias);
+	dev->class = class;
+	dev->legacy = legacy;
+	dev->name_status = status;
+	if (flags >= 0)
+		dev->flags = flags;
 
 	return dev;
 }
@@ -3002,11 +2997,11 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 					uint32_t class, int8_t rssi,
 					uint8_t *data, size_t eir_size)
 {
-	struct remote_dev_info *dev;
+	struct remote_dev_info *dev, match;
 	struct eir_data eir_data;
-	char *name;
-	gboolean new_dev, legacy, le;
-	name_status_t name_status = NAME_NOT_REQUIRED;
+	char *alias, *name;
+	gboolean legacy, le;
+	name_status_t name_status;
 	int err;
 
 	memset(&eir_data, 0, sizeof(eir_data));
@@ -3019,6 +3014,25 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	if (eir_data.name != NULL && eir_data.name_complete)
 		write_device_name(&adapter->bdaddr, bdaddr, eir_data.name);
 
+	/* Device already seen in the discovery session ? */
+	memset(&match, 0, sizeof(struct remote_dev_info));
+	bacpy(&match.bdaddr, bdaddr);
+	match.name_status = NAME_ANY;
+
+	dev = adapter_search_found_devices(adapter, &match);
+	if (dev) {
+		adapter->oor_devices = g_slist_remove(adapter->oor_devices,
+							dev);
+		if (dev->rssi != rssi)
+			goto done;
+
+		eir_data_free(&eir_data);
+
+		return;
+	}
+
+	/* New device in the discovery session */
+
 	name = read_stored_data(&adapter->bdaddr, bdaddr, "names");
 
 	if (eir_data.flags < 0) {
@@ -3035,34 +3049,19 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	} else {
 		le = TRUE;
 		legacy = FALSE;
+		name_status = NAME_NOT_REQUIRED;
 	}
 
-	dev = get_found_dev(adapter, bdaddr, &new_dev);
-
-	if (new_dev) {
-		const char *dev_name = (name ? name : eir_data.name);
-		char *alias;
+	alias = read_stored_data(&adapter->bdaddr, bdaddr, "aliases");
 
-		if (dev_name)
-			dev->name = g_strdup(dev_name);
-
-		alias = read_stored_data(&adapter->bdaddr, bdaddr, "aliases");
-		if (alias) {
-			dev->alias = g_strdup(alias);
-			free(alias);
-		}
-
-		dev->le = le;
-		dev->class = class;
-		dev->legacy = legacy;
-		dev->name_status = name_status;
+	dev = found_device_new(bdaddr, le, name, alias, class, legacy,
+						name_status, eir_data.flags);
+	free(name);
+	free(alias);
 
-		if (eir_data.flags >= 0)
-			dev->flags = eir_data.flags;
-
-	} else if (dev->rssi == rssi)
-		goto done;
+	adapter->found_devices = g_slist_prepend(adapter->found_devices, dev);
 
+done:
 	dev->rssi = rssi;
 
 	adapter->found_devices = g_slist_sort(adapter->found_devices,
@@ -3073,8 +3072,6 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 
 	adapter_emit_device_found(adapter, dev);
 
-done:
-	free(name);
 	eir_data_free(&eir_data);
 }
 
-- 
1.7.5.rc3


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

* [PATCH v6 11/12] Replace EIR_DATA_LENGTH with HCI_MAX_EIR_LENGTH
  2011-05-18 19:40     ` [PATCH v5 " Claudio Takahasi
@ 2011-05-18 21:34       ` Claudio Takahasi
  0 siblings, 0 replies; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-18 21:34 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

Both defines have the same value (240) and meaning.
---
 src/adapter.c |    2 +-
 src/eir.c     |    9 +++++----
 src/eir.h     |    2 --
 src/event.c   |    2 +-
 4 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/src/adapter.c b/src/adapter.c
index dc051cd..0210c30 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -3005,7 +3005,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	int err;
 
 	memset(&eir_data, 0, sizeof(eir_data));
-	err = eir_parse(&eir_data, data, EIR_DATA_LENGTH);
+	err = eir_parse(&eir_data, data, HCI_MAX_EIR_LENGTH);
 	if (err < 0) {
 		error("Error parsing EIR data: %s (%d)", strerror(-err), -err);
 		return;
diff --git a/src/eir.c b/src/eir.c
index 2fbd919..7dfc444 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -27,6 +27,7 @@
 #include <glib.h>
 
 #include <bluetooth/bluetooth.h>
+#include <bluetooth/hci.h>
 #include <bluetooth/sdp.h>
 
 #include "glib-helper.h"
@@ -184,7 +185,7 @@ static void eir_generate_uuid128(GSList *list, uint8_t *ptr, uint16_t *eir_len)
 			continue;
 
 		/* Stop if not enough space to put next UUID128 */
-		if ((len + 2 + SIZEOF_UUID128) > EIR_DATA_LENGTH) {
+		if ((len + 2 + SIZEOF_UUID128) > HCI_MAX_EIR_LENGTH) {
 			truncated = TRUE;
 			break;
 		}
@@ -229,7 +230,7 @@ void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 	GSList *l;
 	uint8_t *ptr = data;
 	uint16_t eir_len = 0;
-	uint16_t uuid16[EIR_DATA_LENGTH / 2];
+	uint16_t uuid16[HCI_MAX_EIR_LENGTH / 2];
 	int i, uuid_count = 0;
 	gboolean truncated = FALSE;
 	size_t name_len;
@@ -289,7 +290,7 @@ void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 			continue;
 
 		/* Stop if not enough space to put next UUID16 */
-		if ((eir_len + 2 + sizeof(uint16_t)) > EIR_DATA_LENGTH) {
+		if ((eir_len + 2 + sizeof(uint16_t)) > HCI_MAX_EIR_LENGTH) {
 			truncated = TRUE;
 			break;
 		}
@@ -322,6 +323,6 @@ void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 	}
 
 	/* Group all UUID128 types */
-	if (eir_len <= EIR_DATA_LENGTH - 2)
+	if (eir_len <= HCI_MAX_EIR_LENGTH - 2)
 		eir_generate_uuid128(uuids, ptr, &eir_len);
 }
diff --git a/src/eir.h b/src/eir.h
index aacd16a..ea38570 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -22,8 +22,6 @@
  *
  */
 
-#define EIR_DATA_LENGTH  240
-
 struct uuid_info {
 	uuid_t uuid;
 	uint8_t svc_hint;
diff --git a/src/event.c b/src/event.c
index 3ee8802..e28afa3 100644
--- a/src/event.c
+++ b/src/event.c
@@ -321,7 +321,7 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 		write_remote_eir(local, peer, data);
 
 	adapter_update_found_devices(adapter, peer, class, rssi,
-						data, EIR_DATA_LENGTH);
+						data, HCI_MAX_EIR_LENGTH);
 }
 
 void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
-- 
1.7.5.rc3


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

* [PATCH v6 12/12] Drop variable EIR length
  2011-05-18 19:40     ` [PATCH v5 " Claudio Takahasi
@ 2011-05-18 21:34       ` Claudio Takahasi
  2011-05-18 23:49         ` Johan Hedberg
  0 siblings, 1 reply; 43+ messages in thread
From: Claudio Takahasi @ 2011-05-18 21:34 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Bruna Moreira

From: Bruna Moreira <bruna.moreira@openbossa.org>

The functions eir_parse() and adapter_update_found_devices() now
assume that the EIR buffer has always 240 octets. For advertising
reports, the advertising data is stored on a buffer with 240 bytes,
padded with zeroes.
---
 plugins/hciops.c |   13 +++++++++----
 src/adapter.c    |    6 +++---
 src/adapter.h    |    4 ++--
 src/eir.c        |    8 ++++----
 src/eir.h        |    2 +-
 src/event.c      |    3 +--
 6 files changed, 20 insertions(+), 16 deletions(-)

diff --git a/plugins/hciops.c b/plugins/hciops.c
index 65ad4f3..9b1225c 100644
--- a/plugins/hciops.c
+++ b/plugins/hciops.c
@@ -2171,7 +2171,7 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
 {
 	struct dev_info *dev = &devs[index];
 	le_advertising_info *info;
-	uint8_t num_reports, rssi;
+	uint8_t num_reports, rssi, eir[HCI_MAX_EIR_LENGTH];
 	const uint8_t RSSI_SIZE = 1;
 
 	num_reports = meta->data[0];
@@ -2179,8 +2179,10 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
 	info = (le_advertising_info *) &meta->data[1];
 	rssi = *(info->data + info->length);
 
-	btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi,
-								info->data);
+	memset(eir, 0, sizeof(eir));
+	memcpy(eir, info->data, info->length);
+
+	btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi, eir);
 
 	num_reports--;
 
@@ -2189,8 +2191,11 @@ static inline void le_advertising_report(int index, evt_le_meta_event *meta)
 								RSSI_SIZE);
 		rssi = *(info->data + info->length);
 
+		memset(eir, 0, sizeof(eir));
+		memcpy(eir, info->data, info->length);
+
 		btd_event_device_found(&dev->bdaddr, &info->bdaddr, 0, rssi,
-								info->data);
+									eir);
 	}
 }
 
diff --git a/src/adapter.c b/src/adapter.c
index 0210c30..c30febc 100644
--- a/src/adapter.c
+++ b/src/adapter.c
@@ -2994,8 +2994,8 @@ static char *read_stored_data(bdaddr_t *local, bdaddr_t *peer, const char *file)
 }
 
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-					uint32_t class, int8_t rssi,
-					uint8_t *data, size_t eir_size)
+						uint32_t class, int8_t rssi,
+						uint8_t *data)
 {
 	struct remote_dev_info *dev, match;
 	struct eir_data eir_data;
@@ -3005,7 +3005,7 @@ void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
 	int err;
 
 	memset(&eir_data, 0, sizeof(eir_data));
-	err = eir_parse(&eir_data, data, HCI_MAX_EIR_LENGTH);
+	err = eir_parse(&eir_data, data);
 	if (err < 0) {
 		error("Error parsing EIR data: %s (%d)", strerror(-err), -err);
 		return;
diff --git a/src/adapter.h b/src/adapter.h
index 4c07e92..3526849 100644
--- a/src/adapter.h
+++ b/src/adapter.h
@@ -109,8 +109,8 @@ int adapter_get_discover_type(struct btd_adapter *adapter);
 struct remote_dev_info *adapter_search_found_devices(struct btd_adapter *adapter,
 						struct remote_dev_info *match);
 void adapter_update_found_devices(struct btd_adapter *adapter, bdaddr_t *bdaddr,
-					uint32_t class, int8_t rssi,
-					uint8_t *data, size_t eir_size);
+						uint32_t class, int8_t rssi,
+						uint8_t *data);
 int adapter_remove_found_device(struct btd_adapter *adapter, bdaddr_t *bdaddr);
 void adapter_emit_device_found(struct btd_adapter *adapter,
 						struct remote_dev_info *dev);
diff --git a/src/eir.c b/src/eir.c
index 7dfc444..01b6ac5 100644
--- a/src/eir.c
+++ b/src/eir.c
@@ -52,7 +52,7 @@ void eir_data_free(struct eir_data *eir)
 	g_free(eir->name);
 }
 
-int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
+int eir_parse(struct eir_data *eir, uint8_t *eir_data)
 {
 	uint16_t len = 0;
 	size_t total;
@@ -69,10 +69,10 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
 	eir->flags = -1;
 
 	/* No EIR data to parse */
-	if (eir_data == NULL || eir_length == 0)
+	if (eir_data == NULL)
 		return 0;
 
-	while (len < eir_length - 1) {
+	while (len < HCI_MAX_EIR_LENGTH - 1) {
 		uint8_t field_len = eir_data[0];
 
 		/* Check for the end of EIR */
@@ -115,7 +115,7 @@ int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length)
 	}
 
 	/* Bail out if got incorrect length */
-	if (len > eir_length)
+	if (len > HCI_MAX_EIR_LENGTH)
 		return -EINVAL;
 
 	total = uuid16_count + uuid32_count + uuid128_count;
diff --git a/src/eir.h b/src/eir.h
index ea38570..d225973 100644
--- a/src/eir.h
+++ b/src/eir.h
@@ -35,7 +35,7 @@ struct eir_data {
 };
 
 void eir_data_free(struct eir_data *eir);
-int eir_parse(struct eir_data *eir, uint8_t *eir_data, size_t eir_length);
+int eir_parse(struct eir_data *eir, uint8_t *eir_data);
 void eir_create(const char *name, int8_t tx_power, uint16_t did_vendor,
 			uint16_t did_product, uint16_t did_version,
 			GSList *uuids, uint8_t *data);
diff --git a/src/event.c b/src/event.c
index e28afa3..2643a87 100644
--- a/src/event.c
+++ b/src/event.c
@@ -320,8 +320,7 @@ void btd_event_device_found(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 	if (data)
 		write_remote_eir(local, peer, data);
 
-	adapter_update_found_devices(adapter, peer, class, rssi,
-						data, HCI_MAX_EIR_LENGTH);
+	adapter_update_found_devices(adapter, peer, class, rssi, data);
 }
 
 void btd_event_set_legacy_pairing(bdaddr_t *local, bdaddr_t *peer,
-- 
1.7.5.rc3


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

* Re: [PATCH v6 12/12] Drop variable EIR length
  2011-05-18 21:34       ` [PATCH v6 " Claudio Takahasi
@ 2011-05-18 23:49         ` Johan Hedberg
  0 siblings, 0 replies; 43+ messages in thread
From: Johan Hedberg @ 2011-05-18 23:49 UTC (permalink / raw)
  To: Claudio Takahasi; +Cc: linux-bluetooth, Bruna Moreira

Hi Claudio,

On Wed, May 18, 2011, Claudio Takahasi wrote:
> The functions eir_parse() and adapter_update_found_devices() now
> assume that the EIR buffer has always 240 octets. For advertising
> reports, the advertising data is stored on a buffer with 240 bytes,
> padded with zeroes.
> ---
>  plugins/hciops.c |   13 +++++++++----
>  src/adapter.c    |    6 +++---
>  src/adapter.h    |    4 ++--
>  src/eir.c        |    8 ++++----
>  src/eir.h        |    2 +-
>  src/event.c      |    3 +--
>  6 files changed, 20 insertions(+), 16 deletions(-)

All patches in this set have now been pushed upstream. Thanks.

Johan

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

end of thread, other threads:[~2011-05-18 23:49 UTC | newest]

Thread overview: 43+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-05-16 20:49 [PATCH v3 01/12] Move EIR related functions to a new file Claudio Takahasi
2011-05-16 20:49 ` [PATCH v3 02/12] Initial device found cleanup Claudio Takahasi
2011-05-16 20:49 ` [PATCH v3 03/12] Move legacy verification to a new function Claudio Takahasi
2011-05-17 16:13   ` Johan Hedberg
2011-05-17 18:25     ` [PATCH v4 " Claudio Takahasi
2011-05-18 19:18       ` Claudio Takahasi
2011-05-18 19:38         ` [PATCH v5 " Claudio Takahasi
2011-05-16 20:49 ` [PATCH v3 04/12] Cleanup read name and alias from storage Claudio Takahasi
2011-05-17 18:25   ` [PATCH v4 " Claudio Takahasi
2011-05-18 19:38     ` [PATCH v5 " Claudio Takahasi
2011-05-16 20:49 ` [PATCH v3 05/12] Don't resolve name if the name is in the storage Claudio Takahasi
2011-05-17 18:25   ` [PATCH v4 " Claudio Takahasi
2011-05-18 19:38     ` [PATCH v5 " Claudio Takahasi
2011-05-16 20:49 ` [PATCH v3 06/12] Unify inquiry results and advertises Claudio Takahasi
2011-05-17 18:25   ` [PATCH v4 " Claudio Takahasi
2011-05-18 19:39     ` [PATCH v5 " Claudio Takahasi
2011-05-18 20:53       ` Johan Hedberg
2011-05-18 21:33         ` [PATCH v6 " Claudio Takahasi
2011-05-16 20:49 ` [PATCH v3 07/12] Fix memory leak of EIR data Claudio Takahasi
2011-05-17 18:26   ` [PATCH v4 " Claudio Takahasi
2011-05-18 19:39     ` [PATCH v5 " Claudio Takahasi
2011-05-18 21:33       ` [PATCH v6 " Claudio Takahasi
2011-05-16 20:49 ` [PATCH v3 08/12] Remove btd_event_advertising_report Claudio Takahasi
2011-05-17 18:26   ` [PATCH v4 " Claudio Takahasi
2011-05-18 19:39     ` [PATCH v5 " Claudio Takahasi
2011-05-18 21:33       ` [PATCH v6 " Claudio Takahasi
2011-05-16 20:49 ` [PATCH v3 09/12] Change the order to write/read the remote's name Claudio Takahasi
2011-05-17 18:26   ` [PATCH v4 " Claudio Takahasi
2011-05-18 19:39     ` [PATCH v5 " Claudio Takahasi
2011-05-18 21:33       ` [PATCH v6 " Claudio Takahasi
2011-05-16 20:49 ` [PATCH v3 10/12] Cleanup inserting new device found entry Claudio Takahasi
2011-05-17 18:26   ` [PATCH v4 " Claudio Takahasi
2011-05-18 19:39     ` [PATCH v5 " Claudio Takahasi
2011-05-18 21:34       ` [PATCH v6 " Claudio Takahasi
2011-05-16 20:50 ` [PATCH v3 11/12] Replace EIR_DATA_LENGTH with HCI_MAX_EIR_LENGTH Claudio Takahasi
2011-05-17 18:26   ` [PATCH v4 " Claudio Takahasi
2011-05-18 19:40     ` [PATCH v5 " Claudio Takahasi
2011-05-18 21:34       ` [PATCH v6 " Claudio Takahasi
2011-05-16 20:50 ` [PATCH v3 12/12] Drop variable EIR length Claudio Takahasi
2011-05-17 18:26   ` [PATCH v4 " Claudio Takahasi
2011-05-18 19:40     ` [PATCH v5 " Claudio Takahasi
2011-05-18 21:34       ` [PATCH v6 " Claudio Takahasi
2011-05-18 23:49         ` Johan Hedberg

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