From: "Frédéric Danis" <frederic.danis@collabora.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v3 3/5] btgatt-client: Add function to search service based on UUID
Date: Thu, 25 Jan 2024 20:08:03 +0100 [thread overview]
Message-ID: <20240125190805.1244787-4-frederic.danis@collabora.com> (raw)
In-Reply-To: <20240125190805.1244787-1-frederic.danis@collabora.com>
This is requested to pass PTS GATT/CL/GAD/BV-02-C test.
---
tools/btgatt-client.c | 69 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 69 insertions(+)
diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
index 3bcb7e1cf..99a123697 100644
--- a/tools/btgatt-client.c
+++ b/tools/btgatt-client.c
@@ -33,6 +33,7 @@
#include "src/shared/queue.h"
#include "src/shared/gatt-db.h"
#include "src/shared/gatt-client.h"
+#include "src/shared/gatt-helpers.h"
#define ATT_CID 4
@@ -1353,6 +1354,72 @@ static void cmd_set_sign_key(struct client *cli, char *cmd_str)
set_sign_key_usage();
}
+static void search_service_usage(void)
+{
+ printf("Usage: search-service <uuid>\n"
+ "e.g.:\n"
+ "\tsearch-service 1800\n");
+}
+
+static void search_service_cb(bool success, uint8_t att_ecode,
+ struct bt_gatt_result *result,
+ void *user_data)
+{
+ struct bt_gatt_iter iter;
+ uint16_t start_handle, end_handle;
+ uint128_t u128;
+ bt_uuid_t uuid;
+ char uuid_str[MAX_LEN_UUID_STR];
+
+ if (!success) {
+ PRLOG("\nService discovery failed: %s (0x%02x)\n",
+ ecode_to_string(att_ecode), att_ecode);
+ return;
+ }
+
+ if (!result || !bt_gatt_iter_init(&iter, result))
+ return;
+
+ printf("\n");
+ while (bt_gatt_iter_next_service(&iter, &start_handle, &end_handle,
+ u128.data)) {
+ bt_uuid128_create(&uuid, u128);
+ bt_uuid_to_string(&uuid, uuid_str, sizeof(uuid_str));
+ printf("Found start handle: 0x%04x, end handle: 0x%04x, "
+ "UUID: %s\n",
+ start_handle, end_handle, uuid_str);
+ }
+ PRLOG("\n");
+}
+
+static void cmd_search_service(struct client *cli, char *cmd_str)
+{
+ char *argv[2];
+ int argc = 0;
+ bt_uuid_t uuid;
+
+ if (!bt_gatt_client_is_ready(cli->gatt)) {
+ printf("GATT client not initialized\n");
+ return;
+ }
+
+ if (!parse_args(cmd_str, 1, argv, &argc) || argc != 1) {
+ search_service_usage();
+ return;
+ }
+
+ if (bt_string_to_uuid(&uuid, argv[0]) < 0) {
+ printf("Invalid UUID: %s\n", argv[0]);
+ return;
+ }
+
+ bt_gatt_discover_primary_services(bt_gatt_client_get_att(cli->gatt),
+ &uuid, 0x0001, 0xFFFF,
+ search_service_cb,
+ NULL,
+ NULL);
+}
+
static void cmd_help(struct client *cli, char *cmd_str);
typedef void (*command_func_t)(struct client *cli, char *cmd_str);
@@ -1389,6 +1456,8 @@ static struct {
"\tSet retry on security error by elevating security"},
{ "set-sign-key", cmd_set_sign_key,
"\tSet signing key for signed write command"},
+ { "search-service", cmd_search_service,
+ "\tSearch service"},
{ }
};
--
2.34.1
next prev parent reply other threads:[~2024-01-25 19:08 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-01-25 19:08 [PATCH BlueZ v3 0/5] Enhance GATT to pass PTS tests Frédéric Danis
2024-01-25 19:08 ` [PATCH BlueZ v3 1/5] shared/gatt: Prevent security level change for PTS GATT tests Frédéric Danis
2024-01-25 21:13 ` Enhance GATT to pass PTS tests bluez.test.bot
2024-01-25 19:08 ` [PATCH BlueZ v3 2/5] btgatt-client: Add command to prevent security level change Frédéric Danis
2024-01-25 19:08 ` Frédéric Danis [this message]
2024-01-25 19:08 ` [PATCH BlueZ v3 4/5] btgatt-client: Add function to search characteristics Frédéric Danis
2024-01-25 19:08 ` [PATCH BlueZ v3 5/5] btgatt-client: Add function to search all primary services Frédéric Danis
2024-01-25 22:20 ` [PATCH BlueZ v3 0/5] Enhance GATT to pass PTS tests patchwork-bot+bluetooth
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=20240125190805.1244787-4-frederic.danis@collabora.com \
--to=frederic.danis@collabora.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
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;
as well as URLs for NNTP newsgroup(s).