Linux-Bluetooth Archive on lore.kernel.org
 help / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH v2 6/8] client: Enable setting attribute handles
Date: Wed, 30 Jan 2019 15:54:22 +0200
Message-ID: <20190130135424.2091-6-luiz.dentz@gmail.com> (raw)
In-Reply-To: <20190130135424.2091-1-luiz.dentz@gmail.com>

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

This emulates application setting their attribute handles.
---
 client/gatt.c       | 11 ++++++++++-
 client/main.c       | 13 +++++++------
 src/gatt-database.c | 24 +++++++++++++++++++-----
 3 files changed, 36 insertions(+), 12 deletions(-)

diff --git a/client/gatt.c b/client/gatt.c
index b29e68136..42fe795d7 100644
--- a/client/gatt.c
+++ b/client/gatt.c
@@ -1410,6 +1410,9 @@ void gatt_register_service(DBusConnection *conn, GDBusProxy *proxy,
 	service->path = g_strdup_printf("%s/service%p", APP_PATH, service);
 	service->primary = primary;
 
+	if (argc > 2)
+		service->handle = atoi(argv[2]);
+
 	if (g_dbus_register_interface(conn, service->path,
 					SERVICE_INTERFACE, NULL, NULL,
 					service_properties, service,
@@ -1693,7 +1696,7 @@ static gboolean chrc_notify_acquired_exists(const GDBusPropertyTable *property,
 }
 
 static const GDBusPropertyTable chrc_properties[] = {
-	{ "Handle", "s", chrc_get_handle, chrc_set_handle, NULL },
+	{ "Handle", "q", chrc_get_handle, chrc_set_handle, NULL },
 	{ "UUID", "s", chrc_get_uuid, NULL, NULL },
 	{ "Service", "o", chrc_get_service, NULL, NULL },
 	{ "Value", "ay", chrc_get_value, NULL, NULL },
@@ -2289,6 +2292,9 @@ void gatt_register_chrc(DBusConnection *conn, GDBusProxy *proxy,
 	chrc->flags = g_strsplit(argv[2], ",", -1);
 	chrc->authorization_req = attr_authorization_flag_exists(chrc->flags);
 
+	if (argc > 3)
+		chrc->handle = atoi(argv[3]);
+
 	if (g_dbus_register_interface(conn, chrc->path, CHRC_INTERFACE,
 					chrc_methods, NULL, chrc_properties,
 					chrc, chrc_free) == FALSE) {
@@ -2555,6 +2561,9 @@ void gatt_register_desc(DBusConnection *conn, GDBusProxy *proxy,
 	desc->path = g_strdup_printf("%s/desc%p", desc->chrc->path, desc);
 	desc->flags = g_strsplit(argv[2], ",", -1);
 
+	if (argc > 3)
+		desc->handle = atoi(argv[3]);
+
 	if (g_dbus_register_interface(conn, desc->path, DESC_INTERFACE,
 					desc_methods, NULL, desc_properties,
 					desc, desc_free) == FALSE) {
diff --git a/client/main.c b/client/main.c
index a4647f334..07c8ec008 100644
--- a/client/main.c
+++ b/client/main.c
@@ -2619,22 +2619,23 @@ static const struct bt_shell_menu gatt_menu = {
 						"Register profile to connect" },
 	{ "unregister-application", NULL, cmd_unregister_app,
 						"Unregister profile" },
-	{ "register-service", "<UUID>", cmd_register_service,
+	{ "register-service", "<UUID> [handle]", cmd_register_service,
 					"Register application service."  },
 	{ "unregister-service", "<UUID/object>", cmd_unregister_service,
 					"Unregister application service" },
-	{ "register-includes", "<UUID>", cmd_register_includes,
+	{ "register-includes", "<UUID> [handle]", cmd_register_includes,
 					"Register as Included service in." },
 	{ "unregister-includes", "<Service-UUID><Inc-UUID>",
 			cmd_unregister_includes,
 				 "Unregister Included service." },
-	{ "register-characteristic", "<UUID> <Flags=read,write,notify...> "
-					, cmd_register_characteristic,
-					"Register application characteristic" },
+	{ "register-characteristic",
+			"<UUID> <Flags=read,write,notify...> [handle]",
+			cmd_register_characteristic,
+			"Register application characteristic" },
 	{ "unregister-characteristic", "<UUID/object>",
 				cmd_unregister_characteristic,
 				"Unregister application characteristic" },
-	{ "register-descriptor", "<UUID> <Flags=read,write...>",
+	{ "register-descriptor", "<UUID> <Flags=read,write...> [handle]",
 					cmd_register_descriptor,
 					"Register application descriptor" },
 	{ "unregister-descriptor", "<UUID/object>",
diff --git a/src/gatt-database.c b/src/gatt-database.c
index b159786ea..cca70c947 100644
--- a/src/gatt-database.c
+++ b/src/gatt-database.c
@@ -1843,17 +1843,16 @@ static bool parse_handle(GDBusProxy *proxy, uint16_t *handle)
 {
 	DBusMessageIter iter;
 
+	*handle = 0;
+
 	/* Handle property is optional */
-	if (!g_dbus_proxy_get_property(proxy, "Handle", &iter)) {
-		*handle = 0;
+	if (!g_dbus_proxy_get_property(proxy, "Handle", &iter))
 		return true;
-	}
-
 
 	if (dbus_message_iter_get_arg_type(&iter) != DBUS_TYPE_UINT16)
 		return false;
 
-	dbus_message_iter_get_basic(&iter, &handle);
+	dbus_message_iter_get_basic(&iter, handle);
 
 	return true;
 }
@@ -2634,6 +2633,7 @@ static bool database_add_desc(struct external_service *service,
 {
 	uint16_t handle;
 	bt_uuid_t uuid;
+	char str[MAX_LEN_UUID_STR];
 
 	if (!parse_handle(desc->proxy, &handle)) {
 		error("Failed to read \"Handle\" property of descriptor");
@@ -2662,6 +2662,10 @@ static bool database_add_desc(struct external_service *service,
 		write_handle(desc->proxy, handle);
 	}
 
+	bt_uuid_to_string(&uuid, str, sizeof(str));
+
+	DBG("handle 0x%04x UUID %s", handle, str);
+
 	return true;
 }
 
@@ -2795,6 +2799,7 @@ static bool database_add_chrc(struct external_service *service,
 {
 	uint16_t handle;
 	bt_uuid_t uuid;
+	char str[MAX_LEN_UUID_STR];
 	const struct queue_entry *entry;
 
 	if (!parse_handle(chrc->proxy, &handle)) {
@@ -2832,6 +2837,10 @@ static bool database_add_chrc(struct external_service *service,
 		write_handle(chrc->proxy, handle);
 	}
 
+	bt_uuid_to_string(&uuid, str, sizeof(str));
+
+	DBG("handle 0x%04x UUID %s", handle, str);
+
 	/* Handle the descriptors that belong to this characteristic. */
 	for (entry = queue_get_entries(service->descs); entry;
 							entry = entry->next) {
@@ -2863,6 +2872,7 @@ static bool database_add_service(struct external_service *service)
 	bool primary;
 	uint16_t handle;
 	const struct queue_entry *entry;
+	char str[MAX_LEN_UUID_STR];
 
 	if (!parse_uuid(service->proxy, &uuid)) {
 		error("Failed to read \"UUID\" property of service");
@@ -2895,6 +2905,10 @@ static bool database_add_service(struct external_service *service)
 		write_handle(service->proxy, handle);
 	}
 
+	bt_uuid_to_string(&uuid, str, sizeof(str));
+
+	DBG("handle 0x%04x UUID %s", handle, str);
+
 	database_add_includes(service);
 
 	entry = queue_get_entries(service->chrcs);
-- 
2.17.2


  parent reply index

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-01-30 13:54 [PATCH v2 1/8] doc/gatt-api: Add Handle property Luiz Augusto von Dentz
2019-01-30 13:54 ` [PATCH v2 2/8] shared/gatt-db: Allow passing 0 as handle to gatt_db_insert_* Luiz Augusto von Dentz
2019-01-30 13:54 ` [PATCH v2 3/8] gatt: Implement Handle property Luiz Augusto von Dentz
2019-01-30 13:54 ` [PATCH v2 4/8] gatt: Write back the handle to " Luiz Augusto von Dentz
2019-01-30 13:54 ` [PATCH v2 5/8] client: Enable Handle property for GATT attributes Luiz Augusto von Dentz
2019-01-30 13:54 ` Luiz Augusto von Dentz [this message]
2019-01-30 13:54 ` [PATCH v2 7/8] client: Enable list-attributes to print local attributes Luiz Augusto von Dentz
2019-01-30 13:54 ` [PATCH v2 8/8] client: Don't expose pointer value in attribute path Luiz Augusto von Dentz
2019-01-31 12:17 ` [PATCH v2 1/8] doc/gatt-api: Add Handle property Luiz Augusto von Dentz

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190130135424.2091-6-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

Linux-Bluetooth Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/linux-bluetooth/0 linux-bluetooth/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 linux-bluetooth linux-bluetooth/ https://lore.kernel.org/linux-bluetooth \
		linux-bluetooth@vger.kernel.org linux-bluetooth@archiver.kernel.org
	public-inbox-index linux-bluetooth


Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.linux-bluetooth


AGPL code for this site: git clone https://public-inbox.org/ public-inbox