From patchwork Mon Jan 22 16:49:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= X-Patchwork-Id: 764724 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5AE6A5A0F3 for ; Mon, 22 Jan 2024 16:50:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705942211; cv=none; b=eAgwFGCzi4dMR37TsXoqHC/QzIfLfkc8i0xqSDZHL3x2aPvbKEeGEmMNTrLpmMke9tSoKc3iPQzBqH568p/PXOMg5ukAJ3jL11CWn8HfEmLHbApZ8M5HUux6jhydtrn6Gyfj7xAqJ9GvftrAKXPLYRbwUw40pXXrMZVCaZYFufs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705942211; c=relaxed/simple; bh=gIJATtkupiUzXndeX3DY2J5pSRzEjj+Qm08q+Oi9/Os=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=otx34QYPF6PasDcWfEIJKQ2Sp6uirQ+Tdp/vOKVEPMh6bK7bwlK633JAAYhY7OTvaW6O9XyW/yjO+etWsk4q7KqOeLyLjYJ8n6xmPA1JDlqlLdZOcyCPdeu4pqKaVoK361rBTAoYpiLY5ftNmV5+MItxTZ5jUo/Sg8JMSap9JEY= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=NKcvFhxM; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="NKcvFhxM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1705942208; bh=gIJATtkupiUzXndeX3DY2J5pSRzEjj+Qm08q+Oi9/Os=; h=From:To:Subject:Date:In-Reply-To:References:From; b=NKcvFhxM3zALoMZw4gAygBBXO0YeMe0dmOT6M4nT1x/k+zGaZZ6a4Tjk7bhQNlD/t rD7Jnxde6u6aY859ffOWSRWC7GMRWZ8PTafZXRoeOL4RIxqk53baiuDJFZZE9mWrmf meLyINb9f/NJ0nuHj1dqfVsUwK1uPVms04TcLH0yyNNdi3Xo+ZuRvYW2JL9UTUFVXo 9W93oH1KvemL1l07C+B0GStJc5UwP5YPBcMIuI+j+GNEe0uIrxqj0pfmtLNSMVxpva IGWG/Q0kc2DK4gRcmB51Celcuo+Ht/Q0ZEv19p5yBT+w8ukDqaAI7C+eRndS3pf1CK WSESJiLNbzl1w== Received: from fdanis-XPS-13-9370.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: fdanis) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 8877D3781492 for ; Mon, 22 Jan 2024 16:50:08 +0000 (UTC) From: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/5] gatt: Prevent security level change for PTS GATT tests Date: Mon, 22 Jan 2024 17:49:56 +0100 Message-Id: <20240122165000.279381-2-frederic.danis@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240122165000.279381-1-frederic.danis@collabora.com> References: <20240122165000.279381-1-frederic.danis@collabora.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 \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"}, { } }; From patchwork Mon Jan 22 16:49:57 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= X-Patchwork-Id: 765302 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 887065A0F6 for ; Mon, 22 Jan 2024 16:50:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705942212; cv=none; b=pRp7Xv3UehoymJiYJ7ek6pXn+0CuLXj5uKzXqhB8yf58H+ZrktKmPBFUUSR5KUyvJVAh1B+Wqk+GM3fk7CKoO7AVFOOJFkal2pOytdYYwNu54eG8lKd/mA8kOqM+HKCUBZY8peeqOIFHbNd5x9y1WeYziTDiOiSv4TgutOtfCAk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705942212; c=relaxed/simple; bh=fPQmdE+Oy2gu6q4gm52BqkJE2isNjgA/hC6NjUp7Om0=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=bqg6I7sx5R0v4YXIk/Vs9PcDYmx8xx2zrVMzRWI2Jm1YRiU7JTe+nUq0kyRFW4ecWJzVIG+JDMS13+MadqQrfHXHIMO2qUy5oM1caR1pglWkMHXO5pdyH4ddkwiaNhc8xKVZvc0yYvEmSsOvdrjmw5D6eFK+8rtv+s/U4HdZWqs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=sjVMTKOs; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="sjVMTKOs" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1705942209; bh=fPQmdE+Oy2gu6q4gm52BqkJE2isNjgA/hC6NjUp7Om0=; h=From:To:Subject:Date:In-Reply-To:References:From; b=sjVMTKOsxPstDTiI6PnlPPSrqHv/0Cm3EzqJziHuDI9A7FgUuoxXTxJJEk94quW8I oLFWnflcHdCsEeWZsqafuEvywW1HRzsSueErO//NBkWmX7Ll6jnhqZKDvpWV3FQWhE EFBIwllnPR3uaCkZCXPmyLyFC15YAxGTMd7iwYzkrpjeFyhFe2/Ca3JuFrDBpXFwIe tqCMs41UJCP08TcgeTQ6wcXwDmfaXAJYj6U9CDsHSj0Oc9a64ZWxJMzopauHZrACy9 T9o9nz9QCElvc5biochIWrH/sa0lPFBKaSyfPwJ+p5ftz0EPRjrN2Gfc6aQOxzwaNc xdulWAHMUbDIw== Received: from fdanis-XPS-13-9370.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: fdanis) by madrid.collaboradmins.com (Postfix) with ESMTPSA id E237E3782006 for ; Mon, 22 Jan 2024 16:50:08 +0000 (UTC) From: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 2/5] btgatt-client: Add function to search service based on UUID Date: Mon, 22 Jan 2024 17:49:57 +0100 Message-Id: <20240122165000.279381-3-frederic.danis@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240122165000.279381-1-frederic.danis@collabora.com> References: <20240122165000.279381-1-frederic.danis@collabora.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 \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"}, { } }; From patchwork Mon Jan 22 16:49:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= X-Patchwork-Id: 765301 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E6C85A104 for ; Mon, 22 Jan 2024 16:50:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705942213; cv=none; b=GDNuf4XaXdVrRXJ01aW9ZeIKcqxHbv6Cjl8GxRoBOJYGgUcpd8XkoDEMan5GOFDsMiG2IkQOktMBqKw+8Me8wQ1BytoujMtvrzIqqMsR2ec1x1utrY07Z7JCdoN1hQREsB+4gEIeMBGpaFttc+/aHQcdOKv5j6XxJBX+Al60hK8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705942213; c=relaxed/simple; bh=eGTP426tTtmM9oAuZJ87Nw94T9Av1eNGI4oqHYe62+k=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ch6unBUY/38gDKf/Ppl88UyvORN15ZeLc7SFLQ0X8oPO8gsIHuuC3lGVcidDAPxoxODWmqJ/dAgkDR3ho1b1P0KNWeN3uMrYTsZQfY99t6zWhi1+9EcyzbSNd6n1GfDQ8Y47tukKxBzCLcb/rg0QwcTiTYCYr2Bf3GxnLnNLQE0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=3YiziCbM; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="3YiziCbM" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1705942209; bh=eGTP426tTtmM9oAuZJ87Nw94T9Av1eNGI4oqHYe62+k=; h=From:To:Subject:Date:In-Reply-To:References:From; b=3YiziCbMWeTEEecJTdz6pHOpWEDXAZmswlID1N6sVCZkamdU4xxCu40gRLLLWvKz6 zEdGTPIvpACfhfq2qHZm4WiKm3p17qgA3Nzn5aooXnjc9rpoYFlXNdmsKqy7uBw8ox w1faurhpl50k/4WKuxjCN49MuDBDJ+9Ey6dEqGTavZzTaYMrois6mgnJMGenkUT3CX TOsr4jIe+lb+zISaXGgfdDnVIKNy3yJxAjNyFWAriFx9rYZ5ZYGNbkUloFFK2crO92 /WVIswWep86lTkOsdfOHKqntH+3s/X7dACr5PJ/IVbvznCEg7E8+sZYyE9bT1jlOan ug1lRacovXFuQ== Received: from fdanis-XPS-13-9370.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: fdanis) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 47B4E378200E for ; Mon, 22 Jan 2024 16:50:09 +0000 (UTC) From: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 3/5] btgatt-client: Add function to search characteristics Date: Mon, 22 Jan 2024 17:49:58 +0100 Message-Id: <20240122165000.279381-4-frederic.danis@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240122165000.279381-1-frederic.danis@collabora.com> References: <20240122165000.279381-1-frederic.danis@collabora.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 " + "\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"}, { } }; From patchwork Mon Jan 22 16:49:59 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= X-Patchwork-Id: 764723 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7E6835A103 for ; Mon, 22 Jan 2024 16:50:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705942212; cv=none; b=bGqjKdU9sAGXrxkRI2oW1tOr25MDtxaNwCMFcfMdAre2FQ/KOgAoOZOnqakYZCHiBvW8xbT25BzmCBQ6UoTHiGBEWFDQ16gfm5+248x4KpIZ3cPBLuWhEpqpDxBcXd4QBmnB/DB05eRnmeNab7CE4ZaN59v8sKLhSAEfy9LdNHQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705942212; c=relaxed/simple; bh=Hj5JqDOHqud7iRXnSOhTzvi87Bol9LHWmMYFr5ubMXE=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=oBvmeeb49wd1nRBtguvUd00ekOvDP0qfVWbZH4g4z2p2imxBYhk6gMPHZ/Ra13HGxmPKEIDiXPmOk5mz2iMKSqfNPbz7/ofzaWW3673VfiMir2d2UIsJmp0CNytCERQeaSJU9gwz2A+VVGPhHFNZuj4ghRe2gb1DsCfe0TjpKdo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=WEdapMP/; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="WEdapMP/" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1705942209; bh=Hj5JqDOHqud7iRXnSOhTzvi87Bol9LHWmMYFr5ubMXE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=WEdapMP/+OJo2De+sDgSTj3dSImKCVaHAeRw3ZpnknbizHm1zE64qG5Te+uXbQz8Y 6sQnmzYM+7i/6+QK1ZC/OZaNLOcxuO3pMvb38YQMJQU1IQQT47bXuVyFSf4R1ioIOj K1lMf8Q4dSF/58UpQ7kLqiILBPLwChY0ipUR2t9KyBEpL6ku78O94ypB8Eu1md3gs1 68Vrevdy1xK6zl1VoqgO5B++qjPnoh+W1iO8C8dLaafojxctsdC9uiuKMSEgxFGwST KGvX84P7XheyD6s0Nf1L6ElV0vWiXu0ZUDJRTQokUxv/tH9VhrloQed4hmis9dw8vf KxZI2lvzHkbqw== Received: from fdanis-XPS-13-9370.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: fdanis) by madrid.collaboradmins.com (Postfix) with ESMTPSA id A194C3782009 for ; Mon, 22 Jan 2024 16:50:09 +0000 (UTC) From: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 4/5] btgatt-client: Add function to search descriptors Date: Mon, 22 Jan 2024 17:49:59 +0100 Message-Id: <20240122165000.279381-5-frederic.danis@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240122165000.279381-1-frederic.danis@collabora.com> References: <20240122165000.279381-1-frederic.danis@collabora.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 \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"}, { } }; From patchwork Mon Jan 22 16:50:00 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= X-Patchwork-Id: 764722 Received: from madrid.collaboradmins.com (madrid.collaboradmins.com [46.235.227.194]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 17C205A78A for ; Mon, 22 Jan 2024 16:50:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=46.235.227.194 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705942214; cv=none; b=FI/ZXyNBsCtWjp4iPVAOafKfYt8TMr71FZgg4GRNMAg24mjQR4NSwhrFOA/xB0A/260tHghTWIQNQdSRq3nSmz86bqV67A1H32bfr7EogANetwImPkacPFYA/rZBqDVa+uBrCMPf0CoxVxBsH3QcoJO3Ar9Lkal4BiwwpbTkylc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1705942214; c=relaxed/simple; bh=JCKSKyIQmz8gOz1UT5T41yjPOm1tgWRNXppZHZ7xejk=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=kTOzktBytj+Vn5V8bBLb1B4lJ6NTQukNlLA5dMVPVu3xWRmzMUIdm6oszXpdx9V/eB2HR/XFHLj3rEpVRu9dzLI17myyaOIscxrmn0t8Zo7dFkxfUJ2zRR7TiepRLOvIjJ+DKDKPv2luhcuFkbcHVKh0B0Jbc2K+V5pTWdZQ/6M= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com; spf=pass smtp.mailfrom=collabora.com; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b=h4pqhnjC; arc=none smtp.client-ip=46.235.227.194 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=collabora.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=collabora.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=collabora.com header.i=@collabora.com header.b="h4pqhnjC" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1705942210; bh=JCKSKyIQmz8gOz1UT5T41yjPOm1tgWRNXppZHZ7xejk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=h4pqhnjCnHqTtYhrMubY4RcgMz8PDEJYVI75jPuvA19eKZtnW2RsTWBnokHskJi7f O+oIoU8AktQnED7Pi9R6MKKLypU0ONTc9XjMbdVc+4acnqxUqF/46xNCOmZwhVTN+v VqxFwf/c9Qf8d9Omhr/4e6GOnlO4GNejqbIv6A7PzPPpZzW9Os3ke3tdygwwUSl6vY JhKJw46y0/i9I7ri9JEO9qCWzyNPfgcXBpK2fUl9YPLNhRaVczLEVZyhSuo0naQsLc IDeVmTpmvTUA2t9Trjozl7Y0gAx93yvzHGL0fHZjXytZrYedEG2rs+UmbB9DkuTWXT To3RiO6OXMtMw== Received: from fdanis-XPS-13-9370.. (cola.collaboradmins.com [195.201.22.229]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: fdanis) by madrid.collaboradmins.com (Postfix) with ESMTPSA id 074CB3782021 for ; Mon, 22 Jan 2024 16:50:09 +0000 (UTC) From: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 5/5] btgatt-client: Add function to search all primary services Date: Mon, 22 Jan 2024 17:50:00 +0100 Message-Id: <20240122165000.279381-6-frederic.danis@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240122165000.279381-1-frederic.danis@collabora.com> References: <20240122165000.279381-1-frederic.danis@collabora.com> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 \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 \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,