* [PATCH BlueZ 0/5] Enhance GATT to pass PTS tests
@ 2024-01-22 16:49 Frédéric Danis
2024-01-22 16:49 ` [PATCH BlueZ 1/5] gatt: Prevent security level change for PTS GATT tests Frédéric Danis
` (4 more replies)
0 siblings, 5 replies; 12+ messages in thread
From: Frédéric Danis @ 2024-01-22 16:49 UTC (permalink / raw)
To: linux-bluetooth
The first patch allow to prevent automatic security level change to
allow to the security error when running GATT/CL/GAR/BI-04-C using
btgatt-client.
The other patches add commands to be able to call GATT discovery
functions from btgatt-client and get their results.
Frédéric Danis (5):
gatt: Prevent security level change for PTS GATT tests
btgatt-client: Add function to search service based on UUID
btgatt-client: Add function to search characteristics
btgatt-client: Add function to search descriptors
btgatt-client: Add function to search all primary services
src/shared/att.c | 14 ++
src/shared/att.h | 1 +
src/shared/gatt-client.c | 9 ++
src/shared/gatt-client.h | 2 +
tools/btgatt-client.c | 296 +++++++++++++++++++++++++++++++++++++++
5 files changed, 322 insertions(+)
--
2.34.1
^ permalink raw reply [flat|nested] 12+ messages in thread
* [PATCH BlueZ 1/5] gatt: Prevent security level change for PTS GATT tests
2024-01-22 16:49 [PATCH BlueZ 0/5] Enhance GATT to pass PTS tests Frédéric Danis
@ 2024-01-22 16:49 ` Frédéric Danis
2024-01-22 18:13 ` Luiz Augusto von Dentz
2024-01-22 19:27 ` Enhance GATT to pass PTS tests bluez.test.bot
2024-01-22 16:49 ` [PATCH BlueZ 2/5] btgatt-client: Add function to search service based on UUID Frédéric Danis
` (3 subsequent siblings)
4 siblings, 2 replies; 12+ messages in thread
From: Frédéric Danis @ 2024-01-22 16:49 UTC (permalink / raw)
To: linux-bluetooth
Some PTS GATT tests like GATT/CL/GAR/BI-04-C request to be able to get the
security error and do not try to change the security level.
this commit adds a variable allowing to prevent to change the security
level.
---
src/shared/att.c | 14 ++++++++++++++
src/shared/att.h | 1 +
src/shared/gatt-client.c | 9 +++++++++
src/shared/gatt-client.h | 2 ++
tools/btgatt-client.c | 38 ++++++++++++++++++++++++++++++++++++++
5 files changed, 64 insertions(+)
diff --git a/src/shared/att.c b/src/shared/att.c
index 62c884b65..decc24314 100644
--- a/src/shared/att.c
+++ b/src/shared/att.c
@@ -87,6 +87,8 @@ struct bt_att {
struct sign_info *local_sign;
struct sign_info *remote_sign;
+
+ bool retry_on_sec_error;
};
struct sign_info {
@@ -786,6 +788,9 @@ static bool handle_error_rsp(struct bt_att_chan *chan, uint8_t *pdu,
*opcode = rsp->opcode;
+ if (!att->retry_on_sec_error)
+ return false;
+
/* If operation has already been marked as retry don't attempt to change
* the security again.
*/
@@ -1262,6 +1267,7 @@ struct bt_att *bt_att_new(int fd, bool ext_signed)
att = new0(struct bt_att, 1);
att->chans = queue_new();
att->mtu = chan->mtu;
+ att->retry_on_sec_error = true;
/* crypto is optional, if not available leave it NULL */
if (!ext_signed)
@@ -2042,3 +2048,11 @@ bool bt_att_has_crypto(struct bt_att *att)
return att->crypto ? true : false;
}
+
+void bt_att_set_retry_on_sec_error(struct bt_att *att, bool retry_on_sec_error)
+{
+ if (!att)
+ return;
+
+ att->retry_on_sec_error = retry_on_sec_error;
+}
diff --git a/src/shared/att.h b/src/shared/att.h
index 4aa3de87b..8ed89ba80 100644
--- a/src/shared/att.h
+++ b/src/shared/att.h
@@ -110,3 +110,4 @@ bool bt_att_set_local_key(struct bt_att *att, uint8_t sign_key[16],
bool bt_att_set_remote_key(struct bt_att *att, uint8_t sign_key[16],
bt_att_counter_func_t func, void *user_data);
bool bt_att_has_crypto(struct bt_att *att);
+void bt_att_set_retry_on_sec_error(struct bt_att *att, bool retry_on_sec_error);
diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
index 5de679c9b..b484db9db 100644
--- a/src/shared/gatt-client.c
+++ b/src/shared/gatt-client.c
@@ -3818,3 +3818,12 @@ bool bt_gatt_client_idle_unregister(struct bt_gatt_client *client,
return false;
}
+
+void bt_gatt_client_set_retry_on_sec_error(struct bt_gatt_client *client,
+ bool retry_on_sec_error)
+{
+ if (!client)
+ return;
+
+ bt_att_set_retry_on_sec_error(client->att, retry_on_sec_error);
+}
diff --git a/src/shared/gatt-client.h b/src/shared/gatt-client.h
index bccd04a62..fdb841df0 100644
--- a/src/shared/gatt-client.h
+++ b/src/shared/gatt-client.h
@@ -134,3 +134,5 @@ unsigned int bt_gatt_client_idle_register(struct bt_gatt_client *client,
bt_gatt_client_destroy_func_t destroy);
bool bt_gatt_client_idle_unregister(struct bt_gatt_client *client,
unsigned int id);
+void bt_gatt_client_set_retry_on_sec_error(struct bt_gatt_client *client,
+ bool retry_on_sec_error);
diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
index 58a03bd48..76c74c7a8 100644
--- a/tools/btgatt-client.c
+++ b/tools/btgatt-client.c
@@ -1295,6 +1295,42 @@ static void cmd_set_sign_key(struct client *cli, char *cmd_str)
set_sign_key_usage();
}
+static void set_retry_on_sec_error_usage(void)
+{
+ printf("Usage: set-retry-on-sec-error <y/n>\n"
+ "e.g.:\n"
+ "\tset-retry-on-sec-error n\n");
+}
+
+static void cmd_set_retry_on_sec_error(struct client *cli, char *cmd_str)
+{
+ char *argv[2];
+ int argc = 0;
+
+ if (!bt_gatt_client_is_ready(cli->gatt)) {
+ printf("GATT client not initialized\n");
+ return;
+ }
+
+ if (!parse_args(cmd_str, 1, argv, &argc)) {
+ printf("Too many arguments\n");
+ set_retry_on_sec_error_usage();
+ return;
+ }
+
+ if (argc < 1) {
+ set_retry_on_sec_error_usage();
+ return;
+ }
+
+ if (argv[0][0] == 'y')
+ bt_gatt_client_set_retry_on_sec_error(cli->gatt, true);
+ else if (argv[0][0] == 'n')
+ bt_gatt_client_set_retry_on_sec_error(cli->gatt, false);
+ else
+ printf("Invalid argument: %s\n", argv[0]);
+}
+
static void cmd_help(struct client *cli, char *cmd_str);
typedef void (*command_func_t)(struct client *cli, char *cmd_str);
@@ -1329,6 +1365,8 @@ static struct {
"\tGet security level on le connection"},
{ "set-sign-key", cmd_set_sign_key,
"\tSet signing key for signed write command"},
+ { "set-retry-on-sec-error", cmd_set_retry_on_sec_error,
+ "\tSet retry on security error by elevating security"},
{ }
};
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH BlueZ 2/5] btgatt-client: Add function to search service based on UUID
2024-01-22 16:49 [PATCH BlueZ 0/5] Enhance GATT to pass PTS tests Frédéric Danis
2024-01-22 16:49 ` [PATCH BlueZ 1/5] gatt: Prevent security level change for PTS GATT tests Frédéric Danis
@ 2024-01-22 16:49 ` Frédéric Danis
2024-01-22 16:49 ` [PATCH BlueZ 3/5] btgatt-client: Add function to search characteristics Frédéric Danis
` (2 subsequent siblings)
4 siblings, 0 replies; 12+ messages in thread
From: Frédéric Danis @ 2024-01-22 16:49 UTC (permalink / raw)
To: linux-bluetooth
This is requested to pass PTS GATT/CL/GAD/BV-02-C test.
---
tools/btgatt-client.c | 75 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 75 insertions(+)
diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
index 76c74c7a8..631e26879 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
@@ -1331,6 +1332,78 @@ static void cmd_set_retry_on_sec_error(struct client *cli, char *cmd_str)
printf("Invalid argument: %s\n", argv[0]);
}
+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)) {
+ printf("Too many arguments\n");
+ search_service_usage();
+ return;
+ }
+
+ if (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);
@@ -1367,6 +1440,8 @@ static struct {
"\tSet signing key for signed write command"},
{ "set-retry-on-sec-error", cmd_set_retry_on_sec_error,
"\tSet retry on security error by elevating security"},
+ { "search-service", cmd_search_service,
+ "\tSearch service"},
{ }
};
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH BlueZ 3/5] btgatt-client: Add function to search characteristics
2024-01-22 16:49 [PATCH BlueZ 0/5] Enhance GATT to pass PTS tests Frédéric Danis
2024-01-22 16:49 ` [PATCH BlueZ 1/5] gatt: Prevent security level change for PTS GATT tests Frédéric Danis
2024-01-22 16:49 ` [PATCH BlueZ 2/5] btgatt-client: Add function to search service based on UUID Frédéric Danis
@ 2024-01-22 16:49 ` Frédéric Danis
2024-01-22 16:49 ` [PATCH BlueZ 4/5] btgatt-client: Add function to search descriptors Frédéric Danis
2024-01-22 16:50 ` [PATCH BlueZ 5/5] btgatt-client: Add function to search all primary services Frédéric Danis
4 siblings, 0 replies; 12+ messages in thread
From: Frédéric Danis @ 2024-01-22 16:49 UTC (permalink / raw)
To: linux-bluetooth
This is requested to pass PTS GATT/CL/GAD/BV-05-C test.
This search characteristics based on UUID, start and end handles.
---
tools/btgatt-client.c | 88 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 88 insertions(+)
diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
index 631e26879..bb0822658 100644
--- a/tools/btgatt-client.c
+++ b/tools/btgatt-client.c
@@ -1404,6 +1404,92 @@ static void cmd_search_service(struct client *cli, char *cmd_str)
NULL);
}
+static void search_characteristics_usage(void)
+{
+ printf("Usage: search-characteristics <start_hanlde> <end_handle> "
+ "<uuid>\n"
+ "e.g.:\n"
+ "\tsearch-characteristics 0x0001 0xFFFF 1800\n");
+}
+
+static void search_characteristics_cb(bool success, uint8_t att_ecode,
+ struct bt_gatt_result *result,
+ void *user_data)
+{
+ struct bt_gatt_iter iter;
+ uint16_t handle, length;
+ const uint8_t *value;
+ int i;
+
+ if (!success) {
+ PRLOG("\nCharacteristics 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_read_by_type(&iter, &handle, &length,
+ &value)) {
+ printf("Found handle: 0x%04x value: ", handle);
+ for (i = 0; i < length; i++)
+ printf("%02x ", value[i]);
+ printf("\n");
+ }
+ PRLOG("\n");
+}
+
+static void cmd_search_characteristics(struct client *cli, char *cmd_str)
+{
+ char *argv[4];
+ int argc = 0;
+ uint16_t start_handle, end_handle;
+ char *endptr = NULL;
+ bt_uuid_t uuid;
+
+ if (!bt_gatt_client_is_ready(cli->gatt)) {
+ printf("GATT client not initialized\n");
+ return;
+ }
+
+ if (!parse_args(cmd_str, 3, argv, &argc)) {
+ printf("Too many arguments\n");
+ search_characteristics_usage();
+ return;
+ }
+
+ if (argc < 1) {
+ search_characteristics_usage();
+ return;
+ }
+
+ start_handle = strtol(argv[0], &endptr, 0);
+ if (!endptr || *endptr != '\0') {
+ printf("Invalid start handle: %s\n", argv[0]);
+ return;
+ }
+
+ end_handle = strtol(argv[1], &endptr, 0);
+ if (!endptr || *endptr != '\0') {
+ printf("Invalid end handle: %s\n", argv[1]);
+ return;
+ }
+
+ if (bt_string_to_uuid(&uuid, argv[2]) < 0) {
+ printf("Invalid UUID: %s\n", argv[2]);
+ return;
+ }
+
+ bt_gatt_read_by_type(bt_gatt_client_get_att(cli->gatt), start_handle,
+ end_handle,
+ &uuid,
+ search_characteristics_cb,
+ NULL,
+ NULL);
+}
+
static void cmd_help(struct client *cli, char *cmd_str);
typedef void (*command_func_t)(struct client *cli, char *cmd_str);
@@ -1442,6 +1528,8 @@ static struct {
"\tSet retry on security error by elevating security"},
{ "search-service", cmd_search_service,
"\tSearch service"},
+ { "search-characteristics", cmd_search_characteristics,
+ "\tSearch characteristics"},
{ }
};
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH BlueZ 4/5] btgatt-client: Add function to search descriptors
2024-01-22 16:49 [PATCH BlueZ 0/5] Enhance GATT to pass PTS tests Frédéric Danis
` (2 preceding siblings ...)
2024-01-22 16:49 ` [PATCH BlueZ 3/5] btgatt-client: Add function to search characteristics Frédéric Danis
@ 2024-01-22 16:49 ` Frédéric Danis
2024-01-22 18:15 ` Luiz Augusto von Dentz
2024-01-22 16:50 ` [PATCH BlueZ 5/5] btgatt-client: Add function to search all primary services Frédéric Danis
4 siblings, 1 reply; 12+ messages in thread
From: Frédéric Danis @ 2024-01-22 16:49 UTC (permalink / raw)
To: linux-bluetooth
This is requested to pass PTS GATT/CL/GAD/BV-06-C test.
This search descriptors based on start and end handles.
---
tools/btgatt-client.c | 79 +++++++++++++++++++++++++++++++++++++++++++
1 file changed, 79 insertions(+)
diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
index bb0822658..a7d5d76ba 100644
--- a/tools/btgatt-client.c
+++ b/tools/btgatt-client.c
@@ -1490,6 +1490,83 @@ static void cmd_search_characteristics(struct client *cli, char *cmd_str)
NULL);
}
+static void search_descriptors_usage(void)
+{
+ printf("Usage: search-descriptors <start_hanlde> <end_handle>\n"
+ "e.g.:\n"
+ "\tsearch-descriptors 0x0001 0xFFFF\n");
+}
+
+static void search_descriptors_cb(bool success, uint8_t att_ecode,
+ struct bt_gatt_result *result,
+ void *user_data)
+{
+ struct bt_gatt_iter iter;
+ uint16_t handle;
+ uint128_t u128;
+ bt_uuid_t uuid;
+ char uuid_str[MAX_LEN_UUID_STR];
+
+ if (!success) {
+ PRLOG("\nDescriptors 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_descriptor(&iter, &handle, u128.data)) {
+ bt_uuid128_create(&uuid, u128);
+ bt_uuid_to_string(&uuid, uuid_str, sizeof(uuid_str));
+ printf("Found handle: 0x%04x UUID: %s\n", handle, uuid_str);
+ }
+ PRLOG("\n");
+}
+
+static void cmd_search_descriptors(struct client *cli, char *cmd_str)
+{
+ char *argv[3];
+ int argc = 0;
+ uint16_t start_handle, end_handle;
+ char *endptr = NULL;
+
+ if (!bt_gatt_client_is_ready(cli->gatt)) {
+ printf("GATT client not initialized\n");
+ return;
+ }
+
+ if (!parse_args(cmd_str, 2, argv, &argc)) {
+ printf("Too many arguments\n");
+ search_descriptors_usage();
+ return;
+ }
+
+ if (argc < 1) {
+ search_descriptors_usage();
+ return;
+ }
+
+ start_handle = strtol(argv[0], &endptr, 0);
+ if (!endptr || *endptr != '\0') {
+ printf("Invalid start handle: %s\n", argv[0]);
+ return;
+ }
+
+ end_handle = strtol(argv[1], &endptr, 0);
+ if (!endptr || *endptr != '\0') {
+ printf("Invalid end handle: %s\n", argv[1]);
+ return;
+ }
+
+ bt_gatt_discover_descriptors(bt_gatt_client_get_att(cli->gatt),
+ start_handle, end_handle,
+ search_descriptors_cb,
+ NULL,
+ NULL);
+}
+
static void cmd_help(struct client *cli, char *cmd_str);
typedef void (*command_func_t)(struct client *cli, char *cmd_str);
@@ -1530,6 +1607,8 @@ static struct {
"\tSearch service"},
{ "search-characteristics", cmd_search_characteristics,
"\tSearch characteristics"},
+ { "search-descriptors", cmd_search_descriptors,
+ "\tSearch descriptors"},
{ }
};
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* [PATCH BlueZ 5/5] btgatt-client: Add function to search all primary services
2024-01-22 16:49 [PATCH BlueZ 0/5] Enhance GATT to pass PTS tests Frédéric Danis
` (3 preceding siblings ...)
2024-01-22 16:49 ` [PATCH BlueZ 4/5] btgatt-client: Add function to search descriptors Frédéric Danis
@ 2024-01-22 16:50 ` Frédéric Danis
4 siblings, 0 replies; 12+ messages in thread
From: Frédéric Danis @ 2024-01-22 16:50 UTC (permalink / raw)
To: linux-bluetooth
This is requested to pass PTS GATT/CL/GAD/BV-01-C test.
---
tools/btgatt-client.c | 30 +++++++++++++++++++++++-------
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
index a7d5d76ba..d097727dc 100644
--- a/tools/btgatt-client.c
+++ b/tools/btgatt-client.c
@@ -1332,13 +1332,6 @@ static void cmd_set_retry_on_sec_error(struct client *cli, char *cmd_str)
printf("Invalid argument: %s\n", argv[0]);
}
-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)
@@ -1370,6 +1363,27 @@ static void search_service_cb(bool success, uint8_t att_ecode,
PRLOG("\n");
}
+static void cmd_search_all_primary_services(struct client *cli, char *cmd_str)
+{
+ if (!bt_gatt_client_is_ready(cli->gatt)) {
+ printf("GATT client not initialized\n");
+ return;
+ }
+
+ bt_gatt_discover_all_primary_services(bt_gatt_client_get_att(cli->gatt),
+ NULL,
+ search_service_cb,
+ NULL,
+ NULL);
+}
+
+static void search_service_usage(void)
+{
+ printf("Usage: search-service <uuid>\n"
+ "e.g.:\n"
+ "\tsearch-service 1800\n");
+}
+
static void cmd_search_service(struct client *cli, char *cmd_str)
{
char *argv[2];
@@ -1603,6 +1617,8 @@ static struct {
"\tSet signing key for signed write command"},
{ "set-retry-on-sec-error", cmd_set_retry_on_sec_error,
"\tSet retry on security error by elevating security"},
+ { "search-all-primary-services", cmd_search_all_primary_services,
+ "\tSearch all primary services"},
{ "search-service", cmd_search_service,
"\tSearch service"},
{ "search-characteristics", cmd_search_characteristics,
--
2.34.1
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [PATCH BlueZ 1/5] gatt: Prevent security level change for PTS GATT tests
2024-01-22 16:49 ` [PATCH BlueZ 1/5] gatt: Prevent security level change for PTS GATT tests Frédéric Danis
@ 2024-01-22 18:13 ` Luiz Augusto von Dentz
2024-01-22 19:27 ` Enhance GATT to pass PTS tests bluez.test.bot
1 sibling, 0 replies; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2024-01-22 18:13 UTC (permalink / raw)
To: Frédéric Danis; +Cc: linux-bluetooth
Hi Frédéric,
On Mon, Jan 22, 2024 at 12:43 PM Frédéric Danis
<frederic.danis@collabora.com> wrote:
>
> Some PTS GATT tests like GATT/CL/GAR/BI-04-C request to be able to get the
> security error and do not try to change the security level.
>
> this commit adds a variable allowing to prevent to change the security
> level.
> ---
> src/shared/att.c | 14 ++++++++++++++
> src/shared/att.h | 1 +
> src/shared/gatt-client.c | 9 +++++++++
> src/shared/gatt-client.h | 2 ++
> tools/btgatt-client.c | 38 ++++++++++++++++++++++++++++++++++++++
> 5 files changed, 64 insertions(+)
>
> diff --git a/src/shared/att.c b/src/shared/att.c
> index 62c884b65..decc24314 100644
> --- a/src/shared/att.c
> +++ b/src/shared/att.c
> @@ -87,6 +87,8 @@ struct bt_att {
>
> struct sign_info *local_sign;
> struct sign_info *remote_sign;
> +
> + bool retry_on_sec_error;
Id use something like auto_retry, or perhaps just use
att_send_op->retry instead.
> };
>
> struct sign_info {
> @@ -786,6 +788,9 @@ static bool handle_error_rsp(struct bt_att_chan *chan, uint8_t *pdu,
>
> *opcode = rsp->opcode;
>
> + if (!att->retry_on_sec_error)
> + return false;
> +
> /* If operation has already been marked as retry don't attempt to change
> * the security again.
> */
> @@ -1262,6 +1267,7 @@ struct bt_att *bt_att_new(int fd, bool ext_signed)
> att = new0(struct bt_att, 1);
> att->chans = queue_new();
> att->mtu = chan->mtu;
> + att->retry_on_sec_error = true;
>
> /* crypto is optional, if not available leave it NULL */
> if (!ext_signed)
> @@ -2042,3 +2048,11 @@ bool bt_att_has_crypto(struct bt_att *att)
>
> return att->crypto ? true : false;
> }
> +
> +void bt_att_set_retry_on_sec_error(struct bt_att *att, bool retry_on_sec_error)
> +{
> + if (!att)
> + return;
> +
> + att->retry_on_sec_error = retry_on_sec_error;
> +}
> diff --git a/src/shared/att.h b/src/shared/att.h
> index 4aa3de87b..8ed89ba80 100644
> --- a/src/shared/att.h
> +++ b/src/shared/att.h
> @@ -110,3 +110,4 @@ bool bt_att_set_local_key(struct bt_att *att, uint8_t sign_key[16],
> bool bt_att_set_remote_key(struct bt_att *att, uint8_t sign_key[16],
> bt_att_counter_func_t func, void *user_data);
> bool bt_att_has_crypto(struct bt_att *att);
> +void bt_att_set_retry_on_sec_error(struct bt_att *att, bool retry_on_sec_error);
> diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c
> index 5de679c9b..b484db9db 100644
> --- a/src/shared/gatt-client.c
> +++ b/src/shared/gatt-client.c
> @@ -3818,3 +3818,12 @@ bool bt_gatt_client_idle_unregister(struct bt_gatt_client *client,
>
> return false;
> }
> +
> +void bt_gatt_client_set_retry_on_sec_error(struct bt_gatt_client *client,
> + bool retry_on_sec_error)
> +{
> + if (!client)
> + return;
> +
> + bt_att_set_retry_on_sec_error(client->att, retry_on_sec_error);
> +}
I wonder if it wouldn't be better to just have it as
bt_att_set_retry(guint op) and then set it via att_send_op->retry !=
retry; so it can be used on a per operation basis that way we can try
to have a property over D-Bus to be able to pass such tests using
bluetoothctl.
> diff --git a/src/shared/gatt-client.h b/src/shared/gatt-client.h
> index bccd04a62..fdb841df0 100644
> --- a/src/shared/gatt-client.h
> +++ b/src/shared/gatt-client.h
> @@ -134,3 +134,5 @@ unsigned int bt_gatt_client_idle_register(struct bt_gatt_client *client,
> bt_gatt_client_destroy_func_t destroy);
> bool bt_gatt_client_idle_unregister(struct bt_gatt_client *client,
> unsigned int id);
> +void bt_gatt_client_set_retry_on_sec_error(struct bt_gatt_client *client,
> + bool retry_on_sec_error);
> diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
> index 58a03bd48..76c74c7a8 100644
> --- a/tools/btgatt-client.c
> +++ b/tools/btgatt-client.c
> @@ -1295,6 +1295,42 @@ static void cmd_set_sign_key(struct client *cli, char *cmd_str)
> set_sign_key_usage();
> }
>
> +static void set_retry_on_sec_error_usage(void)
> +{
> + printf("Usage: set-retry-on-sec-error <y/n>\n"
> + "e.g.:\n"
> + "\tset-retry-on-sec-error n\n");
> +}
> +
> +static void cmd_set_retry_on_sec_error(struct client *cli, char *cmd_str)
> +{
> + char *argv[2];
> + int argc = 0;
> +
> + if (!bt_gatt_client_is_ready(cli->gatt)) {
> + printf("GATT client not initialized\n");
> + return;
> + }
> +
> + if (!parse_args(cmd_str, 1, argv, &argc)) {
> + printf("Too many arguments\n");
> + set_retry_on_sec_error_usage();
> + return;
> + }
> +
> + if (argc < 1) {
> + set_retry_on_sec_error_usage();
> + return;
> + }
> +
> + if (argv[0][0] == 'y')
> + bt_gatt_client_set_retry_on_sec_error(cli->gatt, true);
> + else if (argv[0][0] == 'n')
> + bt_gatt_client_set_retry_on_sec_error(cli->gatt, false);
> + else
> + printf("Invalid argument: %s\n", argv[0]);
> +}
> +
> static void cmd_help(struct client *cli, char *cmd_str);
>
> typedef void (*command_func_t)(struct client *cli, char *cmd_str);
> @@ -1329,6 +1365,8 @@ static struct {
> "\tGet security level on le connection"},
> { "set-sign-key", cmd_set_sign_key,
> "\tSet signing key for signed write command"},
> + { "set-retry-on-sec-error", cmd_set_retry_on_sec_error,
> + "\tSet retry on security error by elevating security"},
> { }
> };
>
> --
> 2.34.1
>
>
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH BlueZ 4/5] btgatt-client: Add function to search descriptors
2024-01-22 16:49 ` [PATCH BlueZ 4/5] btgatt-client: Add function to search descriptors Frédéric Danis
@ 2024-01-22 18:15 ` Luiz Augusto von Dentz
2024-01-23 13:16 ` Frédéric Danis
0 siblings, 1 reply; 12+ messages in thread
From: Luiz Augusto von Dentz @ 2024-01-22 18:15 UTC (permalink / raw)
To: Frédéric Danis; +Cc: linux-bluetooth
Hi Frédéric,
On Mon, Jan 22, 2024 at 12:43 PM Frédéric Danis
<frederic.danis@collabora.com> wrote:
>
> This is requested to pass PTS GATT/CL/GAD/BV-06-C test.
> This search descriptors based on start and end handles.
Is this test mandatory though? Afaik if we do support the discovery of
all procedure this becomes useless, because the stack can perform
these operations locally by using its cache.
> ---
> tools/btgatt-client.c | 79 +++++++++++++++++++++++++++++++++++++++++++
> 1 file changed, 79 insertions(+)
>
> diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
> index bb0822658..a7d5d76ba 100644
> --- a/tools/btgatt-client.c
> +++ b/tools/btgatt-client.c
> @@ -1490,6 +1490,83 @@ static void cmd_search_characteristics(struct client *cli, char *cmd_str)
> NULL);
> }
>
> +static void search_descriptors_usage(void)
> +{
> + printf("Usage: search-descriptors <start_hanlde> <end_handle>\n"
> + "e.g.:\n"
> + "\tsearch-descriptors 0x0001 0xFFFF\n");
> +}
> +
> +static void search_descriptors_cb(bool success, uint8_t att_ecode,
> + struct bt_gatt_result *result,
> + void *user_data)
> +{
> + struct bt_gatt_iter iter;
> + uint16_t handle;
> + uint128_t u128;
> + bt_uuid_t uuid;
> + char uuid_str[MAX_LEN_UUID_STR];
> +
> + if (!success) {
> + PRLOG("\nDescriptors 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_descriptor(&iter, &handle, u128.data)) {
> + bt_uuid128_create(&uuid, u128);
> + bt_uuid_to_string(&uuid, uuid_str, sizeof(uuid_str));
> + printf("Found handle: 0x%04x UUID: %s\n", handle, uuid_str);
> + }
> + PRLOG("\n");
> +}
> +
> +static void cmd_search_descriptors(struct client *cli, char *cmd_str)
> +{
> + char *argv[3];
> + int argc = 0;
> + uint16_t start_handle, end_handle;
> + char *endptr = NULL;
> +
> + if (!bt_gatt_client_is_ready(cli->gatt)) {
> + printf("GATT client not initialized\n");
> + return;
> + }
> +
> + if (!parse_args(cmd_str, 2, argv, &argc)) {
> + printf("Too many arguments\n");
> + search_descriptors_usage();
> + return;
> + }
> +
> + if (argc < 1) {
> + search_descriptors_usage();
> + return;
> + }
> +
> + start_handle = strtol(argv[0], &endptr, 0);
> + if (!endptr || *endptr != '\0') {
> + printf("Invalid start handle: %s\n", argv[0]);
> + return;
> + }
> +
> + end_handle = strtol(argv[1], &endptr, 0);
> + if (!endptr || *endptr != '\0') {
> + printf("Invalid end handle: %s\n", argv[1]);
> + return;
> + }
> +
> + bt_gatt_discover_descriptors(bt_gatt_client_get_att(cli->gatt),
> + start_handle, end_handle,
> + search_descriptors_cb,
> + NULL,
> + NULL);
> +}
> +
> static void cmd_help(struct client *cli, char *cmd_str);
>
> typedef void (*command_func_t)(struct client *cli, char *cmd_str);
> @@ -1530,6 +1607,8 @@ static struct {
> "\tSearch service"},
> { "search-characteristics", cmd_search_characteristics,
> "\tSearch characteristics"},
> + { "search-descriptors", cmd_search_descriptors,
> + "\tSearch descriptors"},
> { }
> };
>
> --
> 2.34.1
>
>
--
Luiz Augusto von Dentz
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: Enhance GATT to pass PTS tests
2024-01-22 16:49 ` [PATCH BlueZ 1/5] gatt: Prevent security level change for PTS GATT tests Frédéric Danis
2024-01-22 18:13 ` Luiz Augusto von Dentz
@ 2024-01-22 19:27 ` bluez.test.bot
1 sibling, 0 replies; 12+ messages in thread
From: bluez.test.bot @ 2024-01-22 19:27 UTC (permalink / raw)
To: linux-bluetooth, frederic.danis
[-- Attachment #1: Type: text/plain, Size: 1387 bytes --]
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=818707
---Test result---
Test Summary:
CheckPatch PASS 251.88 seconds
GitLint PASS 153.53 seconds
BuildEll PASS 42.15 seconds
BluezMake PASS 730.75 seconds
MakeCheck PASS 11.23 seconds
MakeDistcheck PASS 160.09 seconds
CheckValgrind PASS 224.46 seconds
CheckSmatch PASS 421.96 seconds
bluezmakeextell PASS 106.00 seconds
IncrementalBuild PASS 3388.99 seconds
ScanBuild WARNING 945.24 seconds
Details
##############################
Test: ScanBuild - WARNING
Desc: Run Scan Build
Output:
tools/btgatt-client.c:1571:15: warning: Null pointer passed to 1st parameter expecting 'nonnull'
end_handle = strtol(argv[1], &endptr, 0);
^~~~~~~~~~~~~~~~~~~~~~~~~~~
tools/btgatt-client.c:1893:2: warning: Value stored to 'argv' is never read
argv += optind;
^ ~~~~~~
2 warnings generated.
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [PATCH BlueZ 4/5] btgatt-client: Add function to search descriptors
2024-01-22 18:15 ` Luiz Augusto von Dentz
@ 2024-01-23 13:16 ` Frédéric Danis
0 siblings, 0 replies; 12+ messages in thread
From: Frédéric Danis @ 2024-01-23 13:16 UTC (permalink / raw)
To: Luiz Augusto von Dentz; +Cc: linux-bluetooth
Hi Luiz,
On 22/01/2024 19:15, Luiz Augusto von Dentz wrote:
> Hi Frédéric,
>
> On Mon, Jan 22, 2024 at 12:43 PM Frédéric Danis
> <frederic.danis@collabora.com> wrote:
>> This is requested to pass PTS GATT/CL/GAD/BV-06-C test.
>> This search descriptors based on start and end handles.
> Is this test mandatory though? Afaik if we do support the discovery of
> all procedure this becomes useless, because the stack can perform
> these operations locally by using its cache.
This test is optional, as tests GATT/CL/GAR/BI-10-C and
GATT/CL/GAR/BI-11-C which also needs this patch to pass.
GATT/CL/GAR/BI-10-C and GATT/CL/GAR/BI-11-C request the ability to
prevent security upgrade. This may need to add a security retry flag to
bt_gatt_read_by_type() in src/shared/gatt-helpers.{ch} to be able to
call bt_att_set_retry() introduced in the first patch of this series.
Does it seem correct?
>> ---
>> tools/btgatt-client.c | 79 +++++++++++++++++++++++++++++++++++++++++++
>> 1 file changed, 79 insertions(+)
>>
>> diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c
>> index bb0822658..a7d5d76ba 100644
>> --- a/tools/btgatt-client.c
>> +++ b/tools/btgatt-client.c
>> @@ -1490,6 +1490,83 @@ static void cmd_search_characteristics(struct client *cli, char *cmd_str)
>> NULL);
>> }
>>
>> +static void search_descriptors_usage(void)
>> +{
>> + printf("Usage: search-descriptors <start_hanlde> <end_handle>\n"
>> + "e.g.:\n"
>> + "\tsearch-descriptors 0x0001 0xFFFF\n");
>> +}
>> +
>> +static void search_descriptors_cb(bool success, uint8_t att_ecode,
>> + struct bt_gatt_result *result,
>> + void *user_data)
>> +{
>> + struct bt_gatt_iter iter;
>> + uint16_t handle;
>> + uint128_t u128;
>> + bt_uuid_t uuid;
>> + char uuid_str[MAX_LEN_UUID_STR];
>> +
>> + if (!success) {
>> + PRLOG("\nDescriptors 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_descriptor(&iter, &handle, u128.data)) {
>> + bt_uuid128_create(&uuid, u128);
>> + bt_uuid_to_string(&uuid, uuid_str, sizeof(uuid_str));
>> + printf("Found handle: 0x%04x UUID: %s\n", handle, uuid_str);
>> + }
>> + PRLOG("\n");
>> +}
>> +
>> +static void cmd_search_descriptors(struct client *cli, char *cmd_str)
>> +{
>> + char *argv[3];
>> + int argc = 0;
>> + uint16_t start_handle, end_handle;
>> + char *endptr = NULL;
>> +
>> + if (!bt_gatt_client_is_ready(cli->gatt)) {
>> + printf("GATT client not initialized\n");
>> + return;
>> + }
>> +
>> + if (!parse_args(cmd_str, 2, argv, &argc)) {
>> + printf("Too many arguments\n");
>> + search_descriptors_usage();
>> + return;
>> + }
>> +
>> + if (argc < 1) {
>> + search_descriptors_usage();
>> + return;
>> + }
>> +
>> + start_handle = strtol(argv[0], &endptr, 0);
>> + if (!endptr || *endptr != '\0') {
>> + printf("Invalid start handle: %s\n", argv[0]);
>> + return;
>> + }
>> +
>> + end_handle = strtol(argv[1], &endptr, 0);
>> + if (!endptr || *endptr != '\0') {
>> + printf("Invalid end handle: %s\n", argv[1]);
>> + return;
>> + }
>> +
>> + bt_gatt_discover_descriptors(bt_gatt_client_get_att(cli->gatt),
>> + start_handle, end_handle,
>> + search_descriptors_cb,
>> + NULL,
>> + NULL);
>> +}
>> +
>> static void cmd_help(struct client *cli, char *cmd_str);
>>
>> typedef void (*command_func_t)(struct client *cli, char *cmd_str);
>> @@ -1530,6 +1607,8 @@ static struct {
>> "\tSearch service"},
>> { "search-characteristics", cmd_search_characteristics,
>> "\tSearch characteristics"},
>> + { "search-descriptors", cmd_search_descriptors,
>> + "\tSearch descriptors"},
>> { }
>> };
>>
>> --
>> 2.34.1
>>
>>
--
Frédéric Danis
Senior Software Engineer
Collabora Ltd.
Platinum Building, St John's Innovation Park, Cambridge CB4 0DS, United Kingdom
Registered in England & Wales, no. 5513718
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: Enhance GATT to pass PTS tests
2024-01-23 14:31 [PATCH BlueZ v2 1/4] gatt: Prevent security level change for PTS GATT tests Frédéric Danis
@ 2024-01-23 16:05 ` bluez.test.bot
0 siblings, 0 replies; 12+ messages in thread
From: bluez.test.bot @ 2024-01-23 16:05 UTC (permalink / raw)
To: linux-bluetooth, frederic.danis
[-- Attachment #1: Type: text/plain, Size: 1186 bytes --]
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=819132
---Test result---
Test Summary:
CheckPatch PASS 1.79 seconds
GitLint PASS 1.16 seconds
BuildEll PASS 25.19 seconds
BluezMake PASS 728.12 seconds
MakeCheck PASS 12.08 seconds
MakeDistcheck PASS 164.05 seconds
CheckValgrind PASS 227.03 seconds
CheckSmatch PASS 328.75 seconds
bluezmakeextell PASS 107.09 seconds
IncrementalBuild PASS 2703.46 seconds
ScanBuild WARNING 956.97 seconds
Details
##############################
Test: ScanBuild - WARNING
Desc: Run Scan Build
Output:
tools/btgatt-client.c:1824:2: warning: Value stored to 'argv' is never read
argv += optind;
^ ~~~~~~
1 warning generated.
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 12+ messages in thread
* RE: Enhance GATT to pass PTS tests
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 ` bluez.test.bot
0 siblings, 0 replies; 12+ messages in thread
From: bluez.test.bot @ 2024-01-25 21:13 UTC (permalink / raw)
To: linux-bluetooth, frederic.danis
[-- Attachment #1: Type: text/plain, Size: 1186 bytes --]
This is automated email and please do not reply to this email!
Dear submitter,
Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=819996
---Test result---
Test Summary:
CheckPatch PASS 1.77 seconds
GitLint PASS 1.18 seconds
BuildEll PASS 23.97 seconds
BluezMake PASS 720.09 seconds
MakeCheck PASS 12.02 seconds
MakeDistcheck PASS 162.59 seconds
CheckValgrind PASS 227.38 seconds
CheckSmatch PASS 329.62 seconds
bluezmakeextell PASS 108.21 seconds
IncrementalBuild PASS 3305.31 seconds
ScanBuild WARNING 923.40 seconds
Details
##############################
Test: ScanBuild - WARNING
Desc: Run Scan Build
Output:
tools/btgatt-client.c:1824:2: warning: Value stored to 'argv' is never read
argv += optind;
^ ~~~~~~
1 warning generated.
---
Regards,
Linux Bluetooth
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2024-01-25 21:13 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-01-22 16:49 [PATCH BlueZ 0/5] Enhance GATT to pass PTS tests Frédéric Danis
2024-01-22 16:49 ` [PATCH BlueZ 1/5] gatt: Prevent security level change for PTS GATT tests Frédéric Danis
2024-01-22 18:13 ` Luiz Augusto von Dentz
2024-01-22 19:27 ` Enhance GATT to pass PTS tests bluez.test.bot
2024-01-22 16:49 ` [PATCH BlueZ 2/5] btgatt-client: Add function to search service based on UUID Frédéric Danis
2024-01-22 16:49 ` [PATCH BlueZ 3/5] btgatt-client: Add function to search characteristics Frédéric Danis
2024-01-22 16:49 ` [PATCH BlueZ 4/5] btgatt-client: Add function to search descriptors Frédéric Danis
2024-01-22 18:15 ` Luiz Augusto von Dentz
2024-01-23 13:16 ` Frédéric Danis
2024-01-22 16:50 ` [PATCH BlueZ 5/5] btgatt-client: Add function to search all primary services Frédéric Danis
-- strict thread matches above, loose matches on Subject: below --
2024-01-23 14:31 [PATCH BlueZ v2 1/4] gatt: Prevent security level change for PTS GATT tests Frédéric Danis
2024-01-23 16:05 ` Enhance GATT to pass PTS tests bluez.test.bot
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
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).