linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/3] gatt: Make database_add_record detect the UUID
@ 2017-12-04 12:10 Luiz Augusto von Dentz
  2017-12-04 12:10 ` [PATCH BlueZ 2/3] gatt: Use monitor code to decode service name Luiz Augusto von Dentz
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2017-12-04 12:10 UTC (permalink / raw)
  To: linux-bluetooth

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

gatt_db_attribute does carry the UUID so this make database_add_record
add it directly instead of taking as parameter.
---
 src/gatt-database.c | 24 +++++++++++++++++++-----
 1 file changed, 19 insertions(+), 5 deletions(-)

diff --git a/src/gatt-database.c b/src/gatt-database.c
index 3e10c901c..fa94a83f8 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -707,15 +707,30 @@ static sdp_record_t *record_new(uuid_t *uuid, uint16_t start, uint16_t end)
 }
 
 static uint32_t database_add_record(struct btd_gatt_database *database,
-					uint16_t uuid,
 					struct gatt_db_attribute *attr,
 					const char *name)
 {
 	sdp_record_t *record;
 	uint16_t start, end;
 	uuid_t svc, gap_uuid;
+	bt_uuid_t uuid;
+
+	gatt_db_attribute_get_service_uuid(attr, &uuid);
+
+	switch (uuid.type) {
+	case BT_UUID16:
+		sdp_uuid16_create(&svc, uuid.value.u16);
+		break;
+	case BT_UUID32:
+		sdp_uuid32_create(&svc, uuid.value.u32);
+		break;
+	case BT_UUID128:
+		sdp_uuid128_create(&svc, (void *) &uuid.value.u128);
+		break;
+	case BT_UUID_UNSPEC:
+		return 0;
+	}
 
-	sdp_uuid16_create(&svc, uuid);
 	gatt_db_attribute_get_service_handles(attr, &start, &end);
 
 	record = record_new(&svc, start, end);
@@ -747,7 +762,7 @@ static void populate_gap_service(struct btd_gatt_database *database)
 	/* Add the GAP service */
 	bt_uuid16_create(&uuid, UUID_GAP);
 	service = gatt_db_add_service(database->db, &uuid, true, 5);
-	database->gap_handle = database_add_record(database, UUID_GAP, service,
+	database->gap_handle = database_add_record(database, service,
 						"Generic Access Profile");
 
 	/*
@@ -902,8 +917,7 @@ static void populate_gatt_service(struct btd_gatt_database *database)
 	/* Add the GATT service */
 	bt_uuid16_create(&uuid, UUID_GATT);
 	service = gatt_db_add_service(database->db, &uuid, true, 4);
-	database->gatt_handle = database_add_record(database, UUID_GATT,
-						service,
+	database->gatt_handle = database_add_record(database, service,
 						"Generic Attribute Profile");
 
 	bt_uuid16_create(&uuid, GATT_CHARAC_SERVICE_CHANGED);
-- 
2.13.6


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

* [PATCH BlueZ 2/3] gatt: Use monitor code to decode service name
  2017-12-04 12:10 [PATCH BlueZ 1/3] gatt: Make database_add_record detect the UUID Luiz Augusto von Dentz
@ 2017-12-04 12:10 ` Luiz Augusto von Dentz
  2017-12-04 12:10 ` [PATCH BlueZ 3/3] gatt: Add all services as records Luiz Augusto von Dentz
  2017-12-04 17:48 ` [PATCH BlueZ 1/3] gatt: Make database_add_record detect the UUID Luiz Augusto von Dentz
  2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2017-12-04 12:10 UTC (permalink / raw)
  To: linux-bluetooth

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

This makes the daemon reuse the code for decoding service names that
the monitor uses.
---
 Makefile.am         |  3 ++-
 src/gatt-database.c | 16 ++++++++++------
 2 files changed, 12 insertions(+), 7 deletions(-)

diff --git a/Makefile.am b/Makefile.am
index 02f02a100..cda23e7d6 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -188,7 +188,8 @@ src_bluetoothd_SOURCES = $(builtin_sources) \
 			src/gatt-client.h src/gatt-client.c \
 			src/device.h src/device.c \
 			src/dbus-common.c src/dbus-common.h \
-			src/eir.h src/eir.c
+			src/eir.h src/eir.c \
+			monitor/uuid.h monitor/uuid.c
 src_bluetoothd_LDADD = lib/libbluetooth-internal.la \
 			gdbus/libgdbus-internal.la \
 			src/libshared-glib.la \
diff --git a/src/gatt-database.c b/src/gatt-database.c
index fa94a83f8..76ec1cde1 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -30,6 +30,7 @@
 #include "lib/sdp.h"
 #include "lib/sdp_lib.h"
 #include "lib/uuid.h"
+#include "monitor/uuid.h"
 #include "btio/btio.h"
 #include "gdbus/gdbus.h"
 #include "src/shared/util.h"
@@ -707,24 +708,29 @@ static sdp_record_t *record_new(uuid_t *uuid, uint16_t start, uint16_t end)
 }
 
 static uint32_t database_add_record(struct btd_gatt_database *database,
-					struct gatt_db_attribute *attr,
-					const char *name)
+					struct gatt_db_attribute *attr)
 {
 	sdp_record_t *record;
 	uint16_t start, end;
 	uuid_t svc, gap_uuid;
 	bt_uuid_t uuid;
+	const char *name = NULL;
+	char uuidstr[MAX_LEN_UUID_STR];
 
 	gatt_db_attribute_get_service_uuid(attr, &uuid);
 
 	switch (uuid.type) {
 	case BT_UUID16:
+		name = uuid16_to_str(uuid.value.u16);
 		sdp_uuid16_create(&svc, uuid.value.u16);
 		break;
 	case BT_UUID32:
+		name = uuid32_to_str(uuid.value.u32);
 		sdp_uuid32_create(&svc, uuid.value.u32);
 		break;
 	case BT_UUID128:
+		bt_uuid_to_string(&uuid, uuidstr, sizeof(uuidstr));
+		name = uuidstr_to_str(uuidstr);
 		sdp_uuid128_create(&svc, (void *) &uuid.value.u128);
 		break;
 	case BT_UUID_UNSPEC:
@@ -762,8 +768,7 @@ static void populate_gap_service(struct btd_gatt_database *database)
 	/* Add the GAP service */
 	bt_uuid16_create(&uuid, UUID_GAP);
 	service = gatt_db_add_service(database->db, &uuid, true, 5);
-	database->gap_handle = database_add_record(database, service,
-						"Generic Access Profile");
+	database->gap_handle = database_add_record(database, service);
 
 	/*
 	 * Device Name characteristic.
@@ -917,8 +922,7 @@ static void populate_gatt_service(struct btd_gatt_database *database)
 	/* Add the GATT service */
 	bt_uuid16_create(&uuid, UUID_GATT);
 	service = gatt_db_add_service(database->db, &uuid, true, 4);
-	database->gatt_handle = database_add_record(database, service,
-						"Generic Attribute Profile");
+	database->gatt_handle = database_add_record(database, service);
 
 	bt_uuid16_create(&uuid, GATT_CHARAC_SERVICE_CHANGED);
 	database->svc_chngd = gatt_db_service_add_characteristic(service, &uuid,
-- 
2.13.6


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

* [PATCH BlueZ 3/3] gatt: Add all services as records
  2017-12-04 12:10 [PATCH BlueZ 1/3] gatt: Make database_add_record detect the UUID Luiz Augusto von Dentz
  2017-12-04 12:10 ` [PATCH BlueZ 2/3] gatt: Use monitor code to decode service name Luiz Augusto von Dentz
@ 2017-12-04 12:10 ` Luiz Augusto von Dentz
  2017-12-04 17:48 ` [PATCH BlueZ 1/3] gatt: Make database_add_record detect the UUID Luiz Augusto von Dentz
  2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2017-12-04 12:10 UTC (permalink / raw)
  To: linux-bluetooth

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

This uses services changes to trigger the addition/removal of the SDP
records.
---
 src/gatt-database.c | 63 ++++++++++++++++++++++++++++++++++++++---------------
 1 file changed, 45 insertions(+), 18 deletions(-)

diff --git a/src/gatt-database.c b/src/gatt-database.c
index 76ec1cde1..143f2aa7f 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -69,14 +69,19 @@
 #define MIN(a, b) ((a) < (b) ? (a) : (b))
 #endif
 
+struct gatt_record {
+	struct btd_gatt_database *database;
+	uint32_t handle;
+	struct gatt_db_attribute *attr;
+};
+
 struct btd_gatt_database {
 	struct btd_adapter *adapter;
 	struct gatt_db *db;
 	unsigned int db_id;
 	GIOChannel *le_io;
 	GIOChannel *l2cap_io;
-	uint32_t gap_handle;
-	uint32_t gatt_handle;
+	struct queue *records;
 	struct queue *device_states;
 	struct queue *ccc_callbacks;
 	struct gatt_db_attribute *svc_chngd;
@@ -520,6 +525,14 @@ static void app_free(void *data)
 	free(app);
 }
 
+static void gatt_record_free(void *data)
+{
+	struct gatt_record *rec = data;
+
+	adapter_service_remove(rec->database->adapter, rec->handle);
+	free(rec);
+}
+
 static void gatt_database_free(void *data)
 {
 	struct btd_gatt_database *database = data;
@@ -534,16 +547,10 @@ static void gatt_database_free(void *data)
 		g_io_channel_unref(database->l2cap_io);
 	}
 
-	if (database->gatt_handle)
-		adapter_service_remove(database->adapter,
-							database->gatt_handle);
-
-	if (database->gap_handle)
-		adapter_service_remove(database->adapter, database->gap_handle);
-
 	/* TODO: Persistently store CCC states before freeing them */
 	gatt_db_unregister(database->db, database->db_id);
 
+	queue_destroy(database->records, gatt_record_free);
 	queue_destroy(database->device_states, device_state_free);
 	queue_destroy(database->apps, app_free);
 	queue_destroy(database->profiles, profile_free);
@@ -707,9 +714,10 @@ static sdp_record_t *record_new(uuid_t *uuid, uint16_t start, uint16_t end)
 	return record;
 }
 
-static uint32_t database_add_record(struct btd_gatt_database *database,
+static void database_add_record(struct btd_gatt_database *database,
 					struct gatt_db_attribute *attr)
 {
+	struct gatt_record *rec;
 	sdp_record_t *record;
 	uint16_t start, end;
 	uuid_t svc, gap_uuid;
@@ -734,14 +742,14 @@ static uint32_t database_add_record(struct btd_gatt_database *database,
 		sdp_uuid128_create(&svc, (void *) &uuid.value.u128);
 		break;
 	case BT_UUID_UNSPEC:
-		return 0;
+		return;
 	}
 
 	gatt_db_attribute_get_service_handles(attr, &start, &end);
 
 	record = record_new(&svc, start, end);
 	if (!record)
-		return 0;
+		return;
 
 	if (name != NULL)
 		sdp_set_info_attr(record, name, "BlueZ", NULL);
@@ -753,11 +761,16 @@ static uint32_t database_add_record(struct btd_gatt_database *database,
 				"http://www.bluez.org/");
 	}
 
-	if (adapter_service_add(database->adapter, record) == 0)
-		return record->handle;
+	if (adapter_service_add(database->adapter, record) < 0) {
+		sdp_record_free(record);
+		return;
+	}
 
-	sdp_record_free(record);
-	return 0;
+	rec = new0(struct gatt_record, 1);
+	rec->database = database;
+	rec->handle = record->handle;
+	rec->attr = attr;
+	queue_push_tail(database->records, rec);
 }
 
 static void populate_gap_service(struct btd_gatt_database *database)
@@ -768,7 +781,6 @@ static void populate_gap_service(struct btd_gatt_database *database)
 	/* Add the GAP service */
 	bt_uuid16_create(&uuid, UUID_GAP);
 	service = gatt_db_add_service(database->db, &uuid, true, 5);
-	database->gap_handle = database_add_record(database, service);
 
 	/*
 	 * Device Name characteristic.
@@ -922,7 +934,6 @@ static void populate_gatt_service(struct btd_gatt_database *database)
 	/* Add the GATT service */
 	bt_uuid16_create(&uuid, UUID_GATT);
 	service = gatt_db_add_service(database->db, &uuid, true, 4);
-	database->gatt_handle = database_add_record(database, service);
 
 	bt_uuid16_create(&uuid, GATT_CHARAC_SERVICE_CHANGED);
 	database->svc_chngd = gatt_db_service_add_characteristic(service, &uuid,
@@ -1073,6 +1084,8 @@ static void gatt_db_service_added(struct gatt_db_attribute *attrib,
 
 	DBG("GATT Service added to local database");
 
+	database_add_record(database, attrib);
+
 	send_service_changed(database, attrib);
 }
 
@@ -1095,13 +1108,26 @@ static void remove_device_ccc(void *data, void *user_data)
 	queue_remove_all(state->ccc_states, ccc_match_service, user_data, free);
 }
 
+static bool match_gatt_record(const void *data, const void *user_data)
+{
+	const struct gatt_record *rec = data;
+	const struct gatt_db_attribute *attr = user_data;
+
+	return (rec->attr == attr);
+}
+
 static void gatt_db_service_removed(struct gatt_db_attribute *attrib,
 								void *user_data)
 {
 	struct btd_gatt_database *database = user_data;
+	struct gatt_record *rec;
 
 	DBG("Local GATT service removed");
 
+	rec = queue_remove_if(database->records, match_gatt_record, attrib);
+	if (rec)
+		gatt_record_free(rec);
+
 	send_service_changed(database, attrib);
 
 	queue_foreach(database->device_states, remove_device_ccc, attrib);
@@ -2972,6 +2998,7 @@ struct btd_gatt_database *btd_gatt_database_new(struct btd_adapter *adapter)
 	database = new0(struct btd_gatt_database, 1);
 	database->adapter = btd_adapter_ref(adapter);
 	database->db = gatt_db_new();
+	database->records = queue_new();
 	database->device_states = queue_new();
 	database->apps = queue_new();
 	database->profiles = queue_new();
-- 
2.13.6


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

* Re: [PATCH BlueZ 1/3] gatt: Make database_add_record detect the UUID
  2017-12-04 12:10 [PATCH BlueZ 1/3] gatt: Make database_add_record detect the UUID Luiz Augusto von Dentz
  2017-12-04 12:10 ` [PATCH BlueZ 2/3] gatt: Use monitor code to decode service name Luiz Augusto von Dentz
  2017-12-04 12:10 ` [PATCH BlueZ 3/3] gatt: Add all services as records Luiz Augusto von Dentz
@ 2017-12-04 17:48 ` Luiz Augusto von Dentz
  2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2017-12-04 17:48 UTC (permalink / raw)
  To: linux-bluetooth@vger.kernel.org

Hi,

On Mon, Dec 4, 2017 at 2:10 PM, Luiz Augusto von Dentz
<luiz.dentz@gmail.com> wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>
> gatt_db_attribute does carry the UUID so this make database_add_record
> add it directly instead of taking as parameter.
> ---
>  src/gatt-database.c | 24 +++++++++++++++++++-----
>  1 file changed, 19 insertions(+), 5 deletions(-)
>
> diff --git a/src/gatt-database.c b/src/gatt-database.c
> index 3e10c901c..fa94a83f8 100644
> --- a/src/gatt-database.c
> +++ b/src/gatt-database.c
> @@ -707,15 +707,30 @@ static sdp_record_t *record_new(uuid_t *uuid, uint16_t start, uint16_t end)
>  }
>
>  static uint32_t database_add_record(struct btd_gatt_database *database,
> -                                       uint16_t uuid,
>                                         struct gatt_db_attribute *attr,
>                                         const char *name)
>  {
>         sdp_record_t *record;
>         uint16_t start, end;
>         uuid_t svc, gap_uuid;
> +       bt_uuid_t uuid;
> +
> +       gatt_db_attribute_get_service_uuid(attr, &uuid);
> +
> +       switch (uuid.type) {
> +       case BT_UUID16:
> +               sdp_uuid16_create(&svc, uuid.value.u16);
> +               break;
> +       case BT_UUID32:
> +               sdp_uuid32_create(&svc, uuid.value.u32);
> +               break;
> +       case BT_UUID128:
> +               sdp_uuid128_create(&svc, (void *) &uuid.value.u128);
> +               break;
> +       case BT_UUID_UNSPEC:
> +               return 0;
> +       }
>
> -       sdp_uuid16_create(&svc, uuid);
>         gatt_db_attribute_get_service_handles(attr, &start, &end);
>
>         record = record_new(&svc, start, end);
> @@ -747,7 +762,7 @@ static void populate_gap_service(struct btd_gatt_database *database)
>         /* Add the GAP service */
>         bt_uuid16_create(&uuid, UUID_GAP);
>         service = gatt_db_add_service(database->db, &uuid, true, 5);
> -       database->gap_handle = database_add_record(database, UUID_GAP, service,
> +       database->gap_handle = database_add_record(database, service,
>                                                 "Generic Access Profile");
>
>         /*
> @@ -902,8 +917,7 @@ static void populate_gatt_service(struct btd_gatt_database *database)
>         /* Add the GATT service */
>         bt_uuid16_create(&uuid, UUID_GATT);
>         service = gatt_db_add_service(database->db, &uuid, true, 4);
> -       database->gatt_handle = database_add_record(database, UUID_GATT,
> -                                               service,
> +       database->gatt_handle = database_add_record(database, service,
>                                                 "Generic Attribute Profile");
>
>         bt_uuid16_create(&uuid, GATT_CHARAC_SERVICE_CHANGED);
> --
> 2.13.6

Applied.


-- 
Luiz Augusto von Dentz

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

end of thread, other threads:[~2017-12-04 17:48 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-04 12:10 [PATCH BlueZ 1/3] gatt: Make database_add_record detect the UUID Luiz Augusto von Dentz
2017-12-04 12:10 ` [PATCH BlueZ 2/3] gatt: Use monitor code to decode service name Luiz Augusto von Dentz
2017-12-04 12:10 ` [PATCH BlueZ 3/3] gatt: Add all services as records Luiz Augusto von Dentz
2017-12-04 17:48 ` [PATCH BlueZ 1/3] gatt: Make database_add_record detect the UUID Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).