Linux bluetooth development
 help / color / mirror / Atom feed
From: Arman Uguray <armansito@chromium.org>
To: linux-bluetooth@vger.kernel.org
Cc: Arman Uguray <armansito@chromium.org>
Subject: [PATCH BlueZ 5/8] tools/btgatt-server: Add the "services" command
Date: Fri, 28 Nov 2014 09:49:19 -0800	[thread overview]
Message-ID: <1417196962-3876-6-git-send-email-armansito@chromium.org> (raw)
In-Reply-To: <1417196962-3876-1-git-send-email-armansito@chromium.org>

This patch adds the "services" command which displayes the currently
stored services in the server database.
---
 tools/btgatt-server.c | 90 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 90 insertions(+)

diff --git a/tools/btgatt-server.c b/tools/btgatt-server.c
index c603b30..13038d1 100644
--- a/tools/btgatt-server.c
+++ b/tools/btgatt-server.c
@@ -883,6 +883,95 @@ static void cmd_heart_rate(struct server *server, char *cmd_str)
 						pdu, 4, conf_cb, NULL, NULL);
 }
 
+static void print_uuid(const bt_uuid_t *uuid)
+{
+	char uuid_str[MAX_LEN_UUID_STR];
+	bt_uuid_t uuid128;
+
+	bt_uuid_to_uuid128(uuid, &uuid128);
+	bt_uuid_to_string(&uuid128, uuid_str, sizeof(uuid_str));
+
+	printf("%s\n", uuid_str);
+}
+
+static void print_incl(struct gatt_db_attribute *attr, void *user_data)
+{
+	struct server *server = user_data;
+	uint16_t handle, start, end;
+	struct gatt_db_attribute *service;
+	bt_uuid_t uuid;
+
+	if (!gatt_db_attribute_get_incl_data(attr, &handle, &start, &end))
+		return;
+
+	service = gatt_db_get_attribute(server->db, start);
+	if (!service)
+		return;
+
+	gatt_db_attribute_get_service_uuid(service, &uuid);
+
+	printf("\t  " COLOR_GREEN "include" COLOR_OFF " - handle: "
+					"0x%04x, - start: 0x%04x, end: 0x%04x,"
+					"uuid: ", handle, start, end);
+	print_uuid(&uuid);
+}
+
+static void print_desc(struct gatt_db_attribute *attr, void *user_data)
+{
+	printf("\t\t  " COLOR_MAGENTA "descr" COLOR_OFF
+					" - handle: 0x%04x, uuid: ",
+					gatt_db_attribute_get_handle(attr));
+	print_uuid(gatt_db_attribute_get_type(attr));
+}
+
+static void print_chrc(struct gatt_db_attribute *attr, void *user_data)
+{
+	uint16_t handle, value_handle;
+	uint8_t properties;
+	bt_uuid_t uuid;
+
+	if (!gatt_db_attribute_get_char_data(attr, &handle,
+								&value_handle,
+								&properties,
+								&uuid))
+		return;
+
+	printf("\t  " COLOR_YELLOW "charac" COLOR_OFF
+					" - start: 0x%04x, value: 0x%04x, "
+					"props: 0x%02x, uuid: ",
+					handle, value_handle, properties);
+	print_uuid(&uuid);
+
+	gatt_db_service_foreach_desc(attr, print_desc, NULL);
+}
+
+static void print_service(struct gatt_db_attribute *attr, void *user_data)
+{
+	struct server *server = user_data;
+	uint16_t start, end;
+	bool primary;
+	bt_uuid_t uuid;
+
+	if (!gatt_db_attribute_get_service_data(attr, &start, &end, &primary,
+									&uuid))
+		return;
+
+	printf(COLOR_RED "service" COLOR_OFF " - start: 0x%04x, "
+				"end: 0x%04x, type: %s, uuid: ",
+				start, end, primary ? "primary" : "secondary");
+	print_uuid(&uuid);
+
+	gatt_db_service_foreach_incl(attr, print_incl, server);
+	gatt_db_service_foreach_char(attr, print_chrc, NULL);
+
+	printf("\n");
+}
+
+static void cmd_services(struct server *server, char *cmd_str)
+{
+	gatt_db_foreach_service(server->db, print_service, server);
+}
+
 static void cmd_help(struct server *server, char *cmd_str);
 
 typedef void (*command_func_t)(struct server *server, char *cmd_str);
@@ -895,6 +984,7 @@ static struct {
 	{ "help", cmd_help, "\tDisplay help message" },
 	{ "notify", cmd_notify, "\tSend handle-value notification" },
 	{ "heart-rate", cmd_heart_rate, "\tHide/Unhide Heart Rate Service" },
+	{ "services", cmd_services, "\tEnumerate all services" },
 	{ }
 };
 
-- 
2.2.0.rc0.207.ga3a616c


  parent reply	other threads:[~2014-11-28 17:49 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-11-28 17:49 [PATCH BlueZ 0/8] shared/gatt: Use gatt-db for client role Arman Uguray
2014-11-28 17:49 ` [PATCH BlueZ 1/8] shared/gatt-db: Fix bug in maximum handle check Arman Uguray
2014-11-28 17:49 ` [PATCH BlueZ 2/8] shared/gatt-db: Add helper to get service handles Arman Uguray
2014-11-28 17:49 ` [PATCH BlueZ 3/8] shared/gatt-client: Store services in gatt_db Arman Uguray
2014-12-01  9:45   ` Luiz Augusto von Dentz
2014-12-01 14:50     ` Arman Uguray
2014-12-01 16:02       ` Luiz Augusto von Dentz
2014-12-01 16:37         ` Arman Uguray
2014-12-01 17:19           ` Marcel Holtmann
2014-12-01 17:57             ` Arman Uguray
2014-12-02 10:46               ` Luiz Augusto von Dentz
2014-12-02 15:12                 ` Luiz Augusto von Dentz
2014-12-02 19:35                   ` Arman Uguray
2014-12-03  0:15                     ` Arman Uguray
2014-11-28 17:49 ` [PATCH BlueZ 4/8] shared/gatt-client: Use gatt_db in bt_gatt_register_notify Arman Uguray
2014-11-28 17:49 ` Arman Uguray [this message]
2014-11-28 17:49 ` [PATCH BlueZ 6/8] tools/btgatt-client: Use gatt-db instead of iterators Arman Uguray
2014-11-28 17:49 ` [PATCH BlueZ 7/8] unit/test-gatt: Use gatt-db for CLIENT tests Arman Uguray
2014-11-28 17:49 ` [PATCH BlueZ 8/8] shared/gatt-client: Remove GATT structs and iterators Arman Uguray
2014-12-01  9:49 ` [PATCH BlueZ 0/8] shared/gatt: Use gatt-db for client role Luiz Augusto von Dentz

Reply instructions:

You may reply publicly 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=1417196962-3876-6-git-send-email-armansito@chromium.org \
    --to=armansito@chromium.org \
    --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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox