Skip to contentSkip to conversation

Enhanced support for Extended Inquiry Response

PATCH Superseded Inga Stotland 2 participants 5 messages Jun 17, 2010 – Jun 30, 2010 Bluetooth drivers

v1 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

cover Enhanced support for Extended Inquiry Response

Added code to update EIR whenever local SDP record is changed. Added support for sending UUID128 in EIR.

Signature · 3 lines
Inga Stotland
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#1 lore raw

PATCH 1/2 Added Code Aurora Forum Copyrights

---
 plugins/service.c  |    1 +
 src/adapter.c      |    1 +
 src/adapter.h      |    1 +
 src/dbus-hci.c     |    1 +
 src/sdpd-service.c |    1 +
 src/sdpd.h         |    1 +
 6 files changed, 6 insertions(+), 0 deletions(-)
plugins/service.c +1 -0
index 96280bd..33cb27d 100644
@@ -4,6 +4,7 @@
  *
  *  Copyright (C) 2006-2010  Nokia Corporation
  *  Copyright (C) 2004-2010  Marcel Holtmann <[email protected]>
+ *  Copyright (C) 2010, Code Aurora Forum. All rights reserved.
  *
  *
  *  This program is free software; you can redistribute it and/or modify
src/adapter.c +1 -0
index 7100191..ef41d83 100644
@@ -4,6 +4,7 @@
  *
  *  Copyright (C) 2006-2010  Nokia Corporation
  *  Copyright (C) 2004-2010  Marcel Holtmann <[email protected]>
+ *  Copyright (C) 2010, Code Aurora Forum. All rights reserved.
  *
  *
  *  This program is free software; you can redistribute it and/or modify
src/adapter.h +1 -0
index 71d3387..d141e32 100644
@@ -4,6 +4,7 @@
  *
  *  Copyright (C) 2006-2010  Nokia Corporation
  *  Copyright (C) 2004-2010  Marcel Holtmann <[email protected]>
+ *  Copyright (C) 2010, Code Aurora Forum. All rights reserved.
  *
  *
  *  This program is free software; you can redistribute it and/or modify
src/dbus-hci.c +1 -0
index 19748a7..daec192 100644
@@ -4,6 +4,7 @@
  *
  *  Copyright (C) 2006-2010  Nokia Corporation
  *  Copyright (C) 2004-2010  Marcel Holtmann <[email protected]>
+ *  Copyright (C) 2010, Code Aurora Forum. All rights reserved.
  *
  *
  *  This program is free software; you can redistribute it and/or modify
src/sdpd-service.c +1 -0
index cdbb4f4..798e49d 100644
@@ -6,6 +6,7 @@
  *  Copyright (C) 2002-2003  Maxim Krasnyansky <[email protected]>
  *  Copyright (C) 2002-2010  Marcel Holtmann <[email protected]>
  *  Copyright (C) 2002-2003  Stephen Crane <[email protected]>
+ *  Copyright (C) 2010, Code Aurora Forum. All rights reserved.
  *
  *
  *  This program is free software; you can redistribute it and/or modify
src/sdpd.h +1 -0
index e93b0b6..1d2e169 100644
@@ -6,6 +6,7 @@
  *  Copyright (C) 2002-2003  Maxim Krasnyansky <[email protected]>
  *  Copyright (C) 2002-2010  Marcel Holtmann <[email protected]>
  *  Copyright (C) 2002-2003  Stephen Crane <[email protected]>
+ *  Copyright (C) 2010, Code Aurora Forum. All rights reserved.
  *
  *
  *  This program is free software; you can redistribute it and/or modify
Signature · 6 lines
1.7.1

-- 
Inga Stotland
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#2 lore raw

PATCH 2/2 Added support for updating EIR whenever record is added or removed

In reply to Inga Stotland
---
 plugins/service.c  |   18 ++++++
 src/adapter.c      |  148 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 src/adapter.h      |    5 +-
 src/dbus-hci.c     |    6 +-
 src/sdpd-service.c |  106 +++++++++++++++++++++++++++++++------
 src/sdpd.h         |   20 +++++++
 6 files changed, 277 insertions(+), 26 deletions(-)
plugins/service.c +18 -0
index 33cb27d..8ec4df4 100644
@@ -446,6 +446,8 @@ static DBusMessage *update_record(DBusConnection *conn, DBusMessage *msg,
 				strerror(EIO));
 	}
 
+	adapter_update_ext_inquiry_response(&src);
+
 	return dbus_message_new_method_return(msg);
 }
 
@@ -517,6 +519,7 @@ static DBusMessage *add_service_record(DBusConnection *conn,
 	const char *sender, *record;
 	dbus_uint32_t handle;
 	int err;
+	bdaddr_t addr;
 
 	if (dbus_message_get_args(msg, NULL,
 			DBUS_TYPE_STRING, &record, DBUS_TYPE_INVALID) == FALSE)
@@ -527,6 +530,13 @@ static DBusMessage *add_service_record(DBusConnection *conn,
 	if (err < 0)
 		return failed_strerror(msg, err);
 
+	if (serv_adapter->adapter)
+		adapter_get_address(serv_adapter->adapter, &addr);
+	else
+		bacpy(&addr, BDADDR_ANY);
+
+	adapter_update_ext_inquiry_response(&addr);
+
 	reply = dbus_message_new_method_return(msg);
 	if (!reply)
 		return NULL;
@@ -551,6 +561,7 @@ static DBusMessage *remove_service_record(DBusConnection *conn,
 	struct service_adapter *serv_adapter = data;
 	dbus_uint32_t handle;
 	const char *sender;
+	bdaddr_t addr;
 
 	if (dbus_message_get_args(msg, NULL, DBUS_TYPE_UINT32, &handle,
 						DBUS_TYPE_INVALID) == FALSE)
@@ -561,6 +572,13 @@ static DBusMessage *remove_service_record(DBusConnection *conn,
 	if (remove_record(conn, sender, serv_adapter, handle) < 0)
 		return not_available(msg);
 
+	if (serv_adapter->adapter)
+		adapter_get_address(serv_adapter->adapter, &addr);
+	else
+		bacpy(&addr, BDADDR_ANY);
+
+	adapter_update_ext_inquiry_response(&addr);
+
 	return dbus_message_new_method_return(msg);
 }
 
src/adapter.c +143 -5

211 lines not on this page · raw message

src/adapter.h +3 -2
index d141e32..891a133 100644
@@ -114,10 +114,10 @@ struct remote_dev_info *adapter_search_found_devices(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,
-				name_status_t name_status);
+				name_status_t name_status, uint8_t *eir_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);
+                               struct remote_dev_info *dev, uint8_t *eir_data);
 void adapter_update_oor_devices(struct btd_adapter *adapter);
 void adapter_mode_changed(struct btd_adapter *adapter, uint8_t scan_mode);
 void adapter_setname_complete(bdaddr_t *local, uint8_t status);
@@ -127,6 +127,7 @@ void adapter_service_insert(const bdaddr_t *bdaddr, void *rec);
 void adapter_service_remove(const bdaddr_t *bdaddr, void *rec);
 sdp_list_t *adapter_get_services(struct btd_adapter *adapter);
 void adapter_set_class_complete(bdaddr_t *bdaddr, uint8_t status);
+void adapter_update_ext_inquiry_response(const bdaddr_t *src);
 
 struct agent *adapter_get_agent(struct btd_adapter *adapter);
 void adapter_add_connection(struct btd_adapter *adapter,
src/dbus-hci.c +3 -3
index daec192..64f8186 100644
@@ -516,7 +516,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 	if (dev) {
 		adapter_update_found_devices(adapter, peer, rssi, class,
 						NULL, NULL, dev->legacy,
-						NAME_NOT_REQUIRED);
+						NAME_NOT_REQUIRED, data);
 		return;
 	}
 
@@ -567,7 +567,7 @@ void hcid_dbus_inquiry_result(bdaddr_t *local, bdaddr_t *peer, uint32_t class,
 
 	/* add in the list to track name sent/pending */
 	adapter_update_found_devices(adapter, peer, rssi, class, name, alias,
-					legacy, name_status);
+					legacy, name_status, data);
 
 	g_free(name);
 	g_free(alias);
@@ -643,7 +643,7 @@ void hcid_dbus_remote_name(bdaddr_t *local, bdaddr_t *peer, uint8_t status,
 	if (dev_info) {
 		g_free(dev_info->name);
 		dev_info->name = g_strdup(name);
-		adapter_emit_device_found(adapter, dev_info);
+		adapter_emit_device_found(adapter, dev_info, NULL);
 	}
 
 	if (device)
src/sdpd-service.c +90 -16

157 lines not on this page · raw message

src/sdpd.h +20 -0
index 1d2e169..1425c64 100644
@@ -35,6 +35,26 @@
 #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 OOB_CLASS_OF_DEVICE         0x0D  /* Class of Device (OOB only) */
+#define OOB_SIMPLE_PAIRING_HASH_C   0x0E  /* Simple Pairing HashC (OOB only) */
+#define OOB_SIMPLE_PAIRING_RAND_R   0x0F  /* Simple Pairing RandR (OOB only) */
+#define EIR_DEVICE_ID               0x10  /* Device ID */
+#define EIR_MANF_DATA               0xFF  /* Manufacturer Specific Data */
+
+#define SIZEOF_UUID128 16
+
 typedef struct request {
 	bdaddr_t device;
 	bdaddr_t bdaddr;
Signature · 6 lines
1.7.1

-- 
Inga Stotland
Sent by an employee of the Qualcomm Innovation Center, Inc.
The Qualcomm Innovation Center, Inc. is a member of the Code Aurora Forum.
#3 lore raw

Re: [PATCH 2/2] Added support for updating EIR whenever record is added or removed

Hi Inga,

Quoted 8 lines · Inga Stotland
---
 plugins/service.c  |   18 ++++++
 src/adapter.c      |  148 ++++++++++++++++++++++++++++++++++++++++++++++++++--
 src/adapter.h      |    5 +-
 src/dbus-hci.c     |    6 +-
 src/sdpd-service.c |  106 +++++++++++++++++++++++++++++++------
 src/sdpd.h         |   20 +++++++
 6 files changed, 277 insertions(+), 26 deletions(-)

Could you please split this patch up into smaller chunks if possible. It seems it has several parts which could be considered logically independent.

Some other comments:

Quoted 15 lines

void adapter_set_class_complete(bdaddr_t *bdaddr, uint8_t status) {

src/adapter.c +1 -0
 	uint8_t class[3];
@@ -2677,6 +2698,7 @@ static void append_dict_valist(DBusMessageIter *iter,
 	DBusMessageIter dict;
 	const char *key;
 	int type;
+	int n_elements;
 	void *val;
 
 	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
@@ -2688,7 +2710,12 @@ static void append_dict_valist(DBusMessageIter *iter,
 	while (key) {
 		type = va_arg(var_args, int);
 		val = va_arg(var_args, void *);

src/adapter.c static void append_dict_valist(DBusMessageIter *iter, · line 2721

Quoted 10 lines
src/adapter.c +6 -1
-		dict_append_entry(&dict, key, type, val);
+		if (type == DBUS_TYPE_ARRAY) {
+			n_elements = va_arg(var_args, int);
+			if (n_elements > 0)
+				dict_append_array(&dict, key, DBUS_TYPE_STRING, val, n_elements);
+		} else
+			dict_append_entry(&dict, key, type, val);
 		key = va_arg(var_args, char *);
 	}
 

It looks like this at least could be a separate patch (DBUS_TYPE_ARRAY support for append_dict_valist).

src/adapter.c static void emit_device_found(const char *path, const char *address, · line 2750

Quoted 6 lines
src/adapter.c +2 -0
@@ -2719,8 +2746,106 @@ static void emit_device_found(const char *path, const char *address,
 	g_dbus_send_message(connection, signal);
 }
 
+
+static int get_uuid_count_eir (uint8_t *eir_data)

Why the extra empty line? In general there should never be a need for two consecutive empty lines.

Quoted 11 lines
src/adapter.c +11 -0
+{
+	uint8_t type;
+	uint8_t len = 0;
+	uint8_t field_len;
+	int count = 0;
+
+	while (len < EIR_DATA_LENGTH) {
+		type = eir_data[1];
+		field_len = eir_data[0];
+		if ((type == EIR_UUID16_SOME) || (type == EIR_UUID16_ALL))
+			count += field_len/2;

src/adapter.c static void emit_device_found(const char *path, const char *address, · line 2771

Quoted 10 lines
src/adapter.c +10 -0
+		else if ((type == EIR_UUID32_SOME) || (type == EIR_UUID32_ALL))
+			count += field_len/4;
+		else if ((type == EIR_UUID128_SOME) || (type == EIR_UUID128_ALL))
+			count += field_len/16;
+		len += field_len + 1;
+		eir_data += field_len + 1;
+	}
+
+	return count;
+}

Variables should always be declared in the minimum scope possible. In the above function only the count and len variables need to be in the function scope whereas all other should be declared inside the while loop.

Quoted 5 lines
src/adapter.c +5 -0
+static void get_uuids_eir(char **uuids, uint8_t *eir_data)
+{
+	uint8_t type;
+	uint8_t len = 0;
+	uint8_t field_len = 0;

src/adapter.c static void emit_device_found(const char *path, const char *address, · line 2787

Quoted 10 lines
src/adapter.c +10 -0
+	int count = 0;
+	int size;
+	uuid_t service;
+	gboolean service_found;
+
+	/* Count UUID16, UUID32 and UUID128 */
+	while (len < EIR_DATA_LENGTH) {
+		type = eir_data[1];
+		field_len =  eir_data[0];
+		service_found = FALSE;

Same comment regarding the scope of variables.

Quoted 5 lines
src/adapter.c +5 -0
+		if ((type == EIR_UUID16_SOME) || (type == EIR_UUID16_ALL)) {
+			size = 2;
+			service.type = SDP_UUID16;
+			service_found = TRUE;
+		} else if ((type == EIR_UUID32_SOME) || (type == EIR_UUID32_ALL)) {

src/adapter.c static void emit_device_found(const char *path, const char *address, · line 2802

Quoted 10 lines
src/adapter.c +10 -0
+			size = 4;
+			service.type = SDP_UUID32;
+			service_found = TRUE;
+		} else if ((type == EIR_UUID128_SOME) || (type == EIR_UUID128_ALL)) {
+			size = 16;
+			service.type = SDP_UUID128;
+			service_found = TRUE;
+		}
+
+		if (service_found) {

I think it'd be more readable to have

if (!service_found)

	continue;

The two last operations in the loop still need to be executed to which the solution would be to use a for loop and have the commands in the third part (i.e. for (...; ...; <whatever needs to be done every time>) or use a label+goto.

src/adapter.c static void emit_device_found(const char *path, const char *address, · line 2808

Quoted 6 lines
src/adapter.c +6 -0
+			uint8_t *data = &eir_data[2];
+			uint16_t val16;
+			uint32_t val32;
+			int i, k;
+
+			count = field_len/size;

Space before and after /

Quoted 7 lines
src/adapter.c +7 -0
+
+			/* Generate uuids in SDP format (EIR data is Little Endian) */
+			switch (service.type) {
+			case SDP_UUID16:
+				for (i = 0; i < count; i++) {
+					val16 = data[1];
+					val16 = (val16<<8) + data[0];

src/adapter.c static void emit_device_found(const char *path, const char *address, · line 2825

Quoted 10 lines
src/adapter.c +10 -0
+					service.value.uuid16 = val16;
+					*uuids++ = bt_uuid2string(&service);
+					data += size;
+				}
+				break;
+			case SDP_UUID32:
+				for (i = 0; i < count; i++) {
+					val32 = data[3];
+					for (k = size-2 ; k >= 0; k--)
+						val32 = (val32<<8) + data[k];

Space before and after <<

src/adapter.c static void emit_device_found(const char *path, const char *address, · line 2834

Quoted 9 lines
src/adapter.c +9 -0
+					service.value.uuid32 = val32;
+					*uuids++ = bt_uuid2string(&service);
+					data += size;
+				}
+				break;
+			case SDP_UUID128:
+				for (i = 0; i < count; i++) {
+					for (k = 0; k < size; k++)
+						service.value.uuid128.data[k] = data[size-k-1];

Space before and after -

You're running into trouble with the 80-character line limit while still keeping the code readable, but imho the core issue is just a too complex and long function. Please consider if you could find a way to refactor or rearrange it somehow.

src/adapter.h struct remote_dev_info *adapter_search_found_devices(struct btd_adapter *adapter · line 120

Quoted 3 lines
src/adapter.h +1 -1
 void adapter_emit_device_found(struct btd_adapter *adapter,
-				struct remote_dev_info *dev);
+                               struct remote_dev_info *dev, uint8_t *eir_data);

Looks like a mixed tabs & spaces coding style violation.

src/sdpd-service.c void create_ext_inquiry_response(const char *name,

Quoted 5 lines
src/sdpd-service.c +0 -0
index 798e49d..5aa00f1 100644
@@ -181,23 +181,30 @@ void create_ext_inquiry_response(const char *name,

With your changes this function is growing quite ridiculously huge. Would there be any way to avoid that?

src/sdpd-service.c void create_ext_inquiry_response(const char *name, · line 206

Quoted 2 lines
src/sdpd-service.c +1 -1
-		ptr += len + 2;
+		eir_len	 += (len + 2);

Tab & space before the += (it should just be a space)

src/sdpd-service.c void create_ext_inquiry_response(const char *name, · line 229

Quoted 3 lines
src/sdpd-service.c +1 -0
 		*ptr++ = (did_version & 0xff00) >> 8;
+		eir_len	 += 10;
 	}

Same here.

src/sdpd-service.c void create_ext_inquiry_response(const char *name, · line 286

Quoted 7 lines
src/sdpd-service.c +7 -0
+	/* Group all UUID128 types */
+	if (!truncated && (eir_len <= EIR_DATA_LENGTH - 2 )) {
+
+		list = services;
+		index = 0;
+
+		/* Store UUID128 in place, skipping first 2 bytes to insert type and length later */

Looks to me like this is beyond the 80-character limit.

Quoted 8 lines
src/sdpd-service.c +8 -0
+		uuid128 = ptr + 2;
+
+		for (; list; list = list->next) {
+			sdp_record_t *rec = (sdp_record_t *) list->data;
+
+			if (rec->svclass.type != SDP_UUID128)
+				continue;
+

src/sdpd-service.c void create_ext_inquiry_response(const char *name, · line 304

Quoted 10 lines
src/sdpd-service.c +10 -0
+			/* Stop if not enough space to put next UUID128 */
+			if ((eir_len + 2 + SIZEOF_UUID128) > EIR_DATA_LENGTH) {
+				truncated = TRUE;
+				break;
+			}
+
+			/* Check for duplicates, EIR data is Little Endian	*/
+			for (i = 0; i < index; i++) {
+				for (k = 0; k < SIZEOF_UUID128; k++) {
+					if (uuid128[i*SIZEOF_UUID128 + k] !=

Space before and after *

src/sdpd-service.c void create_ext_inquiry_response(const char *name, · line 305

Quoted 1 line
src/sdpd-service.c +1 -0
+						rec->svclass.value.uuid128.data[SIZEOF_UUID128 - k])

80-character limit exceeded

src/sdpd-service.c void create_ext_inquiry_response(const char *name, · line 332

Quoted 1 line
src/sdpd-service.c +1 -0
+			ptr	 = data + eir_len;

Tab & space before = (it should be just a space)

Quoted 9 lines
src/sdpd-service.c +9 -0
+#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 */

src/sdpd-service.c

Quoted 10 lines
src/sdpd-service.c +10 -0
+#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 OOB_CLASS_OF_DEVICE         0x0D  /* Class of Device (OOB only) */
+#define OOB_SIMPLE_PAIRING_HASH_C   0x0E  /* Simple Pairing HashC (OOB only) */
+#define OOB_SIMPLE_PAIRING_RAND_R   0x0F  /* Simple Pairing RandR (OOB only) */
+#define EIR_DEVICE_ID               0x10  /* Device ID */
+#define EIR_MANF_DATA               0xFF  /* Manufacturer Specific Data */
+
+#define SIZEOF_UUID128 16

Do all of these defines really need to be in the sdpd.h header? At least stuff like SIZEOF_UUID128 should be moved into the .c file that uses it (if it's really needed at all).

Johan

#4 lore raw

Re: [PATCH 2/2] Added support for updating EIR whenever record is added or removed

Hi Johan,

Thank you for your comprehensive comments. I will incorporate your suggestions and investigate the feasibility of splitting the patch into smaller functional pieces.

Inga

Quoted 279 lines

Hi Inga,

Quoted 9 lines · Inga Stotland
---
 plugins/service.c  |   18 ++++++
 src/adapter.c      |  148
++++++++++++++++++++++++++++++++++++++++++++++++++--
 src/adapter.h      |    5 +-
 src/dbus-hci.c     |    6 +-
 src/sdpd-service.c |  106 +++++++++++++++++++++++++++++++------
 src/sdpd.h         |   20 +++++++
 6 files changed, 277 insertions(+), 26 deletions(-)

Could you please split this patch up into smaller chunks if possible. It seems it has several parts which could be considered logically independent.

Some other comments:

Quoted 17 lines

void adapter_set_class_complete(bdaddr_t *bdaddr, uint8_t status) {

src/adapter.c +1 -0
 	uint8_t class[3];
@@ -2677,6 +2698,7 @@ static void append_dict_valist(DBusMessageIter
 *iter,
 	DBusMessageIter dict;
 	const char *key;
 	int type;
+	int n_elements;
 	void *val;
 
src/adapter.c +0 -0
 	dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY,
@@ -2688,7 +2710,12 @@ static void append_dict_valist(DBusMessageIter
 *iter,
 	while (key) {
 		type = va_arg(var_args, int);

src/adapter.c static void append_dict_valist(DBusMessageIter · line 2721

Quoted 10 lines
src/adapter.c +6 -1
 		val = va_arg(var_args, void *);
-		dict_append_entry(&dict, key, type, val);
+		if (type == DBUS_TYPE_ARRAY) {
+			n_elements = va_arg(var_args, int);
+			if (n_elements > 0)
+				dict_append_array(&dict, key, DBUS_TYPE_STRING, val, n_elements);
+		} else
+			dict_append_entry(&dict, key, type, val);
 		key = va_arg(var_args, char *);
 	}

It looks like this at least could be a separate patch (DBUS_TYPE_ARRAY support for append_dict_valist).

src/adapter.c static void emit_device_found(const char *path, · line 2751

Quoted 7 lines
src/adapter.c +2 -0
@@ -2719,8 +2746,106 @@ static void emit_device_found(const char *path,
 const char *address,
 	g_dbus_send_message(connection, signal);
 }
 
+
+static int get_uuid_count_eir (uint8_t *eir_data)

Why the extra empty line? In general there should never be a need for two consecutive empty lines.

Quoted 11 lines
src/adapter.c +11 -0
+{
+	uint8_t type;
+	uint8_t len = 0;
+	uint8_t field_len;
+	int count = 0;
+
+	while (len < EIR_DATA_LENGTH) {
+		type = eir_data[1];
+		field_len = eir_data[0];
+		if ((type == EIR_UUID16_SOME) || (type == EIR_UUID16_ALL))
+			count += field_len/2;

src/adapter.c static void emit_device_found(const char *path, const char *address, · line 2771

Quoted 10 lines
src/adapter.c +10 -0
+		else if ((type == EIR_UUID32_SOME) || (type == EIR_UUID32_ALL))
+			count += field_len/4;
+		else if ((type == EIR_UUID128_SOME) || (type == EIR_UUID128_ALL))
+			count += field_len/16;
+		len += field_len + 1;
+		eir_data += field_len + 1;
+	}
+
+	return count;
+}

Variables should always be declared in the minimum scope possible. In the above function only the count and len variables need to be in the function scope whereas all other should be declared inside the while loop.

Quoted 5 lines
src/adapter.c +5 -0
+static void get_uuids_eir(char **uuids, uint8_t *eir_data)
+{
+	uint8_t type;
+	uint8_t len = 0;
+	uint8_t field_len = 0;

src/adapter.c static void emit_device_found(const char *path, const char *address, · line 2787

Quoted 10 lines
src/adapter.c +10 -0
+	int count = 0;
+	int size;
+	uuid_t service;
+	gboolean service_found;
+
+	/* Count UUID16, UUID32 and UUID128 */
+	while (len < EIR_DATA_LENGTH) {
+		type = eir_data[1];
+		field_len =  eir_data[0];
+		service_found = FALSE;

Same comment regarding the scope of variables.

Quoted 5 lines
src/adapter.c +5 -0
+		if ((type == EIR_UUID16_SOME) || (type == EIR_UUID16_ALL)) {
+			size = 2;
+			service.type = SDP_UUID16;
+			service_found = TRUE;
+		} else if ((type == EIR_UUID32_SOME) || (type == EIR_UUID32_ALL)) {

src/adapter.c static void emit_device_found(const char *path, const char *address, · line 2802

Quoted 10 lines
src/adapter.c +10 -0
+			size = 4;
+			service.type = SDP_UUID32;
+			service_found = TRUE;
+		} else if ((type == EIR_UUID128_SOME) || (type == EIR_UUID128_ALL)) {
+			size = 16;
+			service.type = SDP_UUID128;
+			service_found = TRUE;
+		}
+
+		if (service_found) {

I think it'd be more readable to have

if (!service_found)

	continue;

The two last operations in the loop still need to be executed to which the solution would be to use a for loop and have the commands in the third part (i.e. for (...; ...; <whatever needs to be done every time>) or use a label+goto.

src/adapter.c static void emit_device_found(const char *path, const char *address, · line 2808

Quoted 6 lines
src/adapter.c +6 -0
+			uint8_t *data = &eir_data[2];
+			uint16_t val16;
+			uint32_t val32;
+			int i, k;
+
+			count = field_len/size;

Space before and after /

Quoted 7 lines
src/adapter.c +7 -0
+
+			/* Generate uuids in SDP format (EIR data is Little Endian) */
+			switch (service.type) {
+			case SDP_UUID16:
+				for (i = 0; i < count; i++) {
+					val16 = data[1];
+					val16 = (val16<<8) + data[0];

src/adapter.c static void emit_device_found(const char *path, const char *address, · line 2825

Quoted 10 lines
src/adapter.c +10 -0
+					service.value.uuid16 = val16;
+					*uuids++ = bt_uuid2string(&service);
+					data += size;
+				}
+				break;
+			case SDP_UUID32:
+				for (i = 0; i < count; i++) {
+					val32 = data[3];
+					for (k = size-2 ; k >= 0; k--)
+						val32 = (val32<<8) + data[k];

Space before and after <<

src/adapter.c static void emit_device_found(const char *path, const char *address, · line 2834

Quoted 9 lines
src/adapter.c +9 -0
+					service.value.uuid32 = val32;
+					*uuids++ = bt_uuid2string(&service);
+					data += size;
+				}
+				break;
+			case SDP_UUID128:
+				for (i = 0; i < count; i++) {
+					for (k = 0; k < size; k++)
+						service.value.uuid128.data[k] = data[size-k-1];

Space before and after -

You're running into trouble with the 80-character line limit while still keeping the code readable, but imho the core issue is just a too complex and long function. Please consider if you could find a way to refactor or rearrange it somehow.

src/adapter.h struct remote_dev_info *adapter_search_found_devices(struct btd_adapter *adapter

Quoted 4 lines
src/adapter.h +1 -1
 void adapter_emit_device_found(struct btd_adapter *adapter,
-				struct remote_dev_info *dev);
+                               struct remote_dev_info *dev, uint8_t
 *eir_data);

Looks like a mixed tabs & spaces coding style violation.

src/sdpd-service.c void create_ext_inquiry_response(const char *name,

Quoted 5 lines
src/sdpd-service.c +0 -0
index 798e49d..5aa00f1 100644
@@ -181,23 +181,30 @@ void create_ext_inquiry_response(const char *name,

With your changes this function is growing quite ridiculously huge. Would there be any way to avoid that?

src/sdpd-service.c void create_ext_inquiry_response(const char *name, · line 206

Quoted 2 lines
src/sdpd-service.c +1 -1
-		ptr += len + 2;
+		eir_len	 += (len + 2);

Tab & space before the += (it should just be a space)

src/sdpd-service.c void create_ext_inquiry_response(const char *name, · line 229

Quoted 3 lines
src/sdpd-service.c +1 -0
 		*ptr++ = (did_version & 0xff00) >> 8;
+		eir_len	 += 10;
 	}

Same here.

Quoted 8 lines
src/sdpd-service.c +7 -0
+	/* Group all UUID128 types */
+	if (!truncated && (eir_len <= EIR_DATA_LENGTH - 2 )) {
+
+		list = services;
+		index = 0;
+
+		/* Store UUID128 in place, skipping first 2 bytes to insert type and

length later */

Looks to me like this is beyond the 80-character limit.

Quoted 8 lines
src/sdpd-service.c +8 -0
+		uuid128 = ptr + 2;
+
+		for (; list; list = list->next) {
+			sdp_record_t *rec = (sdp_record_t *) list->data;
+
+			if (rec->svclass.type != SDP_UUID128)
+				continue;
+

src/sdpd-service.c void create_ext_inquiry_response(const char *name, · line 304

Quoted 10 lines
src/sdpd-service.c +10 -0
+			/* Stop if not enough space to put next UUID128 */
+			if ((eir_len + 2 + SIZEOF_UUID128) > EIR_DATA_LENGTH) {
+				truncated = TRUE;
+				break;
+			}
+
+			/* Check for duplicates, EIR data is Little Endian	*/
+			for (i = 0; i < index; i++) {
+				for (k = 0; k < SIZEOF_UUID128; k++) {
+					if (uuid128[i*SIZEOF_UUID128 + k] !=

Space before and after *

src/sdpd-service.c void create_ext_inquiry_response(const char *name, · line 305

Quoted 1 line
src/sdpd-service.c +1 -0
+						rec->svclass.value.uuid128.data[SIZEOF_UUID128 - k])

80-character limit exceeded

src/sdpd-service.c void create_ext_inquiry_response(const char *name, · line 332

Quoted 1 line
src/sdpd-service.c +1 -0
+			ptr	 = data + eir_len;

Tab & space before = (it should be just a space)

Quoted 25 lines
src/sdpd-service.c +4 -0
+#define EIR_DATA_LENGTH  240
+
+#define EIR_FLAGS                   0x01  /* Flags */
+#define EIR_UUID16_SOME             0x02  /* 16-bit UUID, more

available */

src/sdpd-service.c +2 -0
+#define EIR_UUID16_ALL              0x03  /* 16-bit UUID, all listed */
+#define EIR_UUID32_SOME             0x04  /* 32-bit UUID, more

available */

src/sdpd-service.c +2 -0
+#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
*/

src/sdpd-service.c +4 -0
+#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 OOB_CLASS_OF_DEVICE         0x0D  /* Class of Device (OOB only)

*/
+#define OOB_SIMPLE_PAIRING_HASH_C 0x0E /* Simple Pairing HashC (OOB
only) */
+#define OOB_SIMPLE_PAIRING_RAND_R 0x0F /* Simple Pairing RandR (OOB
only) */

src/sdpd-service.c +2 -0
+#define EIR_DEVICE_ID               0x10  /* Device ID */
+#define EIR_MANF_DATA               0xFF  /* Manufacturer Specific Data

*/

src/sdpd-service.c

Quoted 2 lines
src/sdpd-service.c +2 -0
+
+#define SIZEOF_UUID128 16

Do all of these defines really need to be in the sdpd.h header? At least stuff like SIZEOF_UUID128 should be moved into the .c file that uses it (if it's really needed at all).

Johan