From patchwork Thu Jan 25 19:08:01 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: 766050 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 25B8A130E25 for ; Thu, 25 Jan 2024 19:08:15 +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=1706209698; cv=none; b=RJhKV2Hc9VfuD91lEzdbGo9IybIsJlEIy35QiJ+4Oa/ZECR4DGAv21yp0gFz/Ehv5UNatGCqMXNntYSGouJ9ZQvn+8KUjUjTia0C5k06kRJW0ivlkODBZCyT4UbzHNBG8COjzuw9J1nOvzansgx/HqNrSunaIvO7M86Ti7RFoyY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706209698; c=relaxed/simple; bh=WdBUdqcKOux8RTVoIpwaJ5u983v55MMB+x+pK+1qM9Q=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=ZAl5WDRIXr67OCDMK9AQvB1qF/EiJLv9C6x4vdhUrTnUC/sfNRNRgmZEktT+bCqGowDe6iZKosvbupPkyyUWKSkW27m7jocs99EvLpbez4DfIcdj6OyzcihSpe/FlMz39QowSzlaf3TCWB4SGBYKBZX224zfMZ7P1hHdbgOHuv8= 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=Ty1aywMT; 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="Ty1aywMT" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706209694; bh=WdBUdqcKOux8RTVoIpwaJ5u983v55MMB+x+pK+1qM9Q=; h=From:To:Subject:Date:In-Reply-To:References:From; b=Ty1aywMThFWY7HxOozT3KwxYr/ohfW679OoejYdvFNdCS7gxIwjUsqAzbOiL8u9OA koPTOofyx+kZfOCo4W5qZXLO0CiwUPJ6gw8f1a8NTENEqK0kNbSk/MG1rEJcMjn5nF L92WvXkxM3KFcuXO38Q24M0pPVVaZ3P2itOljbdbSvkygdyD3WFt1R1WXGYcWXmeNR n4v/i9wKjohOclFZhf0pHRPuh5dKHWux43NjB6FAKjlxXrGpD7FIezRdh/Q7RrnXDQ GwSiaiJ9Nrgh5Ux3NfvDCopKMxaBMTnYwuLd45Uu/6m057p82zradFj/x3810Fi9g9 +mkIgzbsP4sAA== 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 4FCCB3781F89 for ; Thu, 25 Jan 2024 19:08:14 +0000 (UTC) From: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3 1/5] shared/gatt: Prevent security level change for PTS GATT tests Date: Thu, 25 Jan 2024 20:08:01 +0100 Message-Id: <20240125190805.1244787-2-frederic.danis@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240125190805.1244787-1-frederic.danis@collabora.com> References: <20240125190805.1244787-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 the ability to prevent to change the security level for an operation. --- src/shared/att.c | 26 ++++++++++++++++++++++++++ src/shared/att.h | 1 + src/shared/gatt-client.c | 19 +++++++++++++++++++ src/shared/gatt-client.h | 3 +++ 4 files changed, 49 insertions(+) diff --git a/src/shared/att.c b/src/shared/att.c index 62c884b65..485ef071b 100644 --- a/src/shared/att.c +++ b/src/shared/att.c @@ -2042,3 +2042,29 @@ bool bt_att_has_crypto(struct bt_att *att) return att->crypto ? true : false; } + +bool bt_att_set_retry(struct bt_att *att, unsigned int id, bool retry) +{ + struct att_send_op *op; + + if (!id) + return false; + + op = queue_find(att->req_queue, match_op_id, UINT_TO_PTR(id)); + if (op) + goto done; + + op = queue_find(att->ind_queue, match_op_id, UINT_TO_PTR(id)); + if (op) + goto done; + + op = queue_find(att->write_queue, match_op_id, UINT_TO_PTR(id)); + +done: + if (!op) + return false; + + op->retry = !retry; + + return true; +} diff --git a/src/shared/att.h b/src/shared/att.h index 4aa3de87b..6fd78636e 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); +bool bt_att_set_retry(struct bt_att *att, unsigned int id, bool retry); diff --git a/src/shared/gatt-client.c b/src/shared/gatt-client.c index 5de679c9b..6340bcd85 100644 --- a/src/shared/gatt-client.c +++ b/src/shared/gatt-client.c @@ -3818,3 +3818,22 @@ bool bt_gatt_client_idle_unregister(struct bt_gatt_client *client, return false; } + +bool bt_gatt_client_set_retry(struct bt_gatt_client *client, + unsigned int id, + bool retry) +{ + struct request *req; + + if (!client || !id) + return false; + + req = queue_find(client->pending_requests, match_req_id, + UINT_TO_PTR(id)); + if (!req) + return false; + + bt_att_set_retry(client->att, req->att_id, retry); + + return true; +} diff --git a/src/shared/gatt-client.h b/src/shared/gatt-client.h index bccd04a62..63cf99500 100644 --- a/src/shared/gatt-client.h +++ b/src/shared/gatt-client.h @@ -134,3 +134,6 @@ 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); +bool bt_gatt_client_set_retry(struct bt_gatt_client *client, + unsigned int id, + bool retry); From patchwork Thu Jan 25 19:08:02 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: 766051 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 88C6913399E for ; Thu, 25 Jan 2024 19:08:16 +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=1706209698; cv=none; b=n1SlqxU7NHNdzeQSndLVZ74W+4UwrJrUpTvVTMZUS2PTmGzJqpHGnQy/n3p2XB4Ep0ebadsdoAYLKg6wzWBEwh2MKiftEeLxgI5qDQ/DniPjfIYK0OmqPSuoAN+fyJAb4XZ296FdANy7rjGrIPsIMKmLhbu7p+h1RQeDeAEc/0w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706209698; c=relaxed/simple; bh=HzGzbnE/z4iKIte/jzMHhTp803l+ZrpBDBSWSeqH0mk=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=stVWV+XeGEduZrjm3jfHnjzaXPQmnz4ohO4ICwtCdkO/nejXGOfDihTWvLHgvAJ7ee0aaZbxNV4fHoQGpwkGIZnes/qubwS9qwbaZKglx2AsQvrvIJ561Pj88tIymAhvlrwApC7lZO/MfxBTdT9gLWR3W7rCINeHtuhzrPb2tEI= 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=KBKlnPOj; 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="KBKlnPOj" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706209694; bh=HzGzbnE/z4iKIte/jzMHhTp803l+ZrpBDBSWSeqH0mk=; h=From:To:Subject:Date:In-Reply-To:References:From; b=KBKlnPOjCBWsOYUgqtM3PaVCIvAt/hScNnFnESc2oLL8dlc61b2rySp8Wrf+CCGEv hV5oAGZhE13SDEyvZUgn+ngo6kYZPjPUODyR/sEjltT5/Gf7/EMsdY8nKv2vd46DDl na31uAVScaoWKmc2WmFNHDDYs4pnpcM0xhtjFIw5vhwZBB7nLb5lE8AaxrNzTdo/lI OUCVXE4Y4/d8c2tf+clep/rkeFOn93y4Sj06Wu30jrA+UC7QAsJ2I1AgbeOS0RSRai T/6XY5HBH+eWQvrXPz6CTmn5m+0XCLFs0IJ1PJlJTjKtx48CQcpQIgkGbrD+kMrplq ceBPlAit3IKQw== 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 A64383782021 for ; Thu, 25 Jan 2024 19:08:14 +0000 (UTC) From: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3 2/5] btgatt-client: Add command to prevent security level change Date: Thu, 25 Jan 2024 20:08:02 +0100 Message-Id: <20240125190805.1244787-3-frederic.danis@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240125190805.1244787-1-frederic.danis@collabora.com> References: <20240125190805.1244787-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 the ability to prevent to change the security level. --- tools/btgatt-client.c | 84 ++++++++++++++++++++++++++++++++++++------- 1 file changed, 72 insertions(+), 12 deletions(-) diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c index 58a03bd48..3bcb7e1cf 100644 --- a/tools/btgatt-client.c +++ b/tools/btgatt-client.c @@ -57,6 +57,7 @@ struct client { struct bt_gatt_client *gatt; unsigned int reliable_session_id; + bool sec_retry; }; static void print_prompt(void) @@ -172,6 +173,7 @@ static struct client *client_create(int fd, uint16_t mtu) fprintf(stderr, "Failed to allocate memory for client\n"); return NULL; } + cli->sec_retry = true; cli->att = bt_att_new(fd, false); if (!cli->att) { @@ -488,6 +490,7 @@ static void cmd_read_multiple(struct client *cli, char *cmd_str) char *argv[512]; int i; char *endptr = NULL; + unsigned int id; if (!bt_gatt_client_is_ready(cli->gatt)) { printf("GATT client not initialized\n"); @@ -514,9 +517,12 @@ static void cmd_read_multiple(struct client *cli, char *cmd_str) } } - if (!bt_gatt_client_read_multiple(cli->gatt, value, argc, - read_multiple_cb, NULL, NULL)) + id = bt_gatt_client_read_multiple(cli->gatt, value, argc, + read_multiple_cb, NULL, NULL); + if (!id) printf("Failed to initiate read multiple procedure\n"); + else if (!cli->sec_retry) + bt_gatt_client_set_retry(cli->gatt, id, false); free(value); } @@ -558,6 +564,7 @@ static void cmd_read_value(struct client *cli, char *cmd_str) int argc = 0; uint16_t handle; char *endptr = NULL; + unsigned int id; if (!bt_gatt_client_is_ready(cli->gatt)) { printf("GATT client not initialized\n"); @@ -575,9 +582,12 @@ static void cmd_read_value(struct client *cli, char *cmd_str) return; } - if (!bt_gatt_client_read_value(cli->gatt, handle, read_cb, - NULL, NULL)) + id = bt_gatt_client_read_value(cli->gatt, handle, read_cb, + NULL, NULL); + if (!id) printf("Failed to initiate read value procedure\n"); + else if (!cli->sec_retry) + bt_gatt_client_set_retry(cli->gatt, id, false); } static void read_long_value_usage(void) @@ -592,6 +602,7 @@ static void cmd_read_long_value(struct client *cli, char *cmd_str) uint16_t handle; uint16_t offset; char *endptr = NULL; + unsigned int id; if (!bt_gatt_client_is_ready(cli->gatt)) { printf("GATT client not initialized\n"); @@ -616,9 +627,12 @@ static void cmd_read_long_value(struct client *cli, char *cmd_str) return; } - if (!bt_gatt_client_read_long_value(cli->gatt, handle, offset, read_cb, - NULL, NULL)) + id = bt_gatt_client_read_long_value(cli->gatt, handle, offset, read_cb, + NULL, NULL); + if (!id) printf("Failed to initiate read long value procedure\n"); + else if (!cli->sec_retry) + bt_gatt_client_set_retry(cli->gatt, id, false); } static void write_value_usage(void) @@ -659,6 +673,7 @@ static void cmd_write_value(struct client *cli, char *cmd_str) uint8_t *value = NULL; bool without_response = false; bool signed_write = false; + unsigned int id; if (!bt_gatt_client_is_ready(cli->gatt)) { printf("GATT client not initialized\n"); @@ -740,10 +755,13 @@ static void cmd_write_value(struct client *cli, char *cmd_str) goto done; } - if (!bt_gatt_client_write_value(cli->gatt, handle, value, length, + id = bt_gatt_client_write_value(cli->gatt, handle, value, length, write_cb, - NULL, NULL)) + NULL, NULL); + if (!id) printf("Failed to initiate write procedure\n"); + else if (!cli->sec_retry) + bt_gatt_client_set_retry(cli->gatt, id, false); done: free(value); @@ -789,6 +807,7 @@ static void cmd_write_long_value(struct client *cli, char *cmd_str) int length; uint8_t *value = NULL; bool reliable_writes = false; + unsigned int id; if (!bt_gatt_client_is_ready(cli->gatt)) { printf("GATT client not initialized\n"); @@ -863,11 +882,14 @@ static void cmd_write_long_value(struct client *cli, char *cmd_str) } } - if (!bt_gatt_client_write_long_value(cli->gatt, reliable_writes, handle, + id = bt_gatt_client_write_long_value(cli->gatt, reliable_writes, handle, offset, value, length, write_long_cb, - NULL, NULL)) + NULL, NULL); + if (!id) printf("Failed to initiate long write procedure\n"); + else if (!cli->sec_retry) + bt_gatt_client_set_retry(cli->gatt, id, false); free(value); } @@ -999,12 +1021,18 @@ done: value, length, write_long_cb, NULL, NULL); - if (!cli->reliable_session_id) + if (!cli->reliable_session_id) { printf("Failed to proceed prepare write\n"); - else + } else { + if (!cli->sec_retry) + bt_gatt_client_set_retry(cli->gatt, + cli->reliable_session_id, + false); + printf("Prepare write success.\n" "Session id: %d to be used on next write\n", cli->reliable_session_id); + } free(value); } @@ -1236,6 +1264,36 @@ static void cmd_get_security(struct client *cli, char *cmd_str) printf("Security level: %u\n", level); } +static void set_security_retry_usage(void) +{ + printf("Usage: set-security-retry \n" + "e.g.:\n" + "\tset-security-retry n\n"); +} + +static void cmd_set_security_retry(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) || argc != 1) { + set_security_retry_usage(); + return; + } + + if (argv[0][0] == 'y') + cli->sec_retry = true; + else if (argv[0][0] == 'n') + cli->sec_retry = false; + else + printf("Invalid argument: %s\n", argv[0]); +} + static bool convert_sign_key(char *optarg, uint8_t key[16]) { int i; @@ -1327,6 +1385,8 @@ static struct { "\tSet security level on le connection"}, { "get-security", cmd_get_security, "\tGet security level on le connection"}, + { "set-security-retry", cmd_set_security_retry, + "\tSet retry on security error by elevating security"}, { "set-sign-key", cmd_set_sign_key, "\tSet signing key for signed write command"}, { } From patchwork Thu Jan 25 19:08:03 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: 766903 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 C29571339B5 for ; Thu, 25 Jan 2024 19:08:16 +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=1706209698; cv=none; b=cpDAg1Bvi6Bna2YySLj9sqLyfJvKHFACXtvsrkF5yLKx7uekxGlPxkEV+bnDmWve9vKTeB1ZUBC1qMTU7vqstbzro/b1JCa38MO/Mmnh/zd+M6a2cYK/4jNm6+cmWraQfATLAMI3eQ2nC7x0fbc2sX+MPZ4BC6BdWeApZ/jNrnM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706209698; c=relaxed/simple; bh=LmNYPxbyewhVFnClXjrGP4+mfa7j8oKqiQCqFrnbb40=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=Lxjf+LfSj3u1MiZ4+G0zosimrp15NCq3ghOr7KgHy+D3V9B9onxHkn/7vU/Cc3NfIm/fhK2UiwGPAF/YgfEz6YFawm5SD6xvf58oOp7tEAT61zeufj3mVgl93ksracL9e0FpQVM23wt/gAqPaD+F1d/PmhrvFs3jwApjlvmJ6nw= 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=CaJQDRyt; 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="CaJQDRyt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706209695; bh=LmNYPxbyewhVFnClXjrGP4+mfa7j8oKqiQCqFrnbb40=; h=From:To:Subject:Date:In-Reply-To:References:From; b=CaJQDRytx3eoQOFpN6yNFqA3hPiX2zePWLTVQm2Y3joNewrQKr8xbpfdHZDYGUk/L w8HNmmZhhn53DIScVq2x2Yudz7lvY0BpmdzMQDmROPMlyLAmVaWTb1L9sYXd3Zrkf9 jIK3qsTU9fCaRivmH0VMXXRslcSHm6cNaK/+KrEIPNepKozkEVA7LxdR73krc3RsfH WEgq3mKja6bUAEL7XZH9k+wFmjZg0uCvvLrXHYC4O96lSN8e56UTLbU2IlxKmF3M/L hsDAkgPkxWqz/CtzpSRxbnnhVHyXkFONTB9MLW1au+WJXYz6fOC5yeBW9+6yqZqHiX /BGpNCBJOkDnw== 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 020EB3782031 for ; Thu, 25 Jan 2024 19:08:14 +0000 (UTC) From: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= 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 Message-Id: <20240125190805.1244787-4-frederic.danis@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240125190805.1244787-1-frederic.danis@collabora.com> References: <20240125190805.1244787-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 | 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 \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"}, { } }; From patchwork Thu Jan 25 19:08:04 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: 766902 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 201E11339A3 for ; Thu, 25 Jan 2024 19:08:16 +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=1706209698; cv=none; b=b20zTvXd4MA8Laya2aoIriUyH9flK403FyMQQtscGY1mp483IXzod8e8Qf+B5wPuuahA3bcX6fBtNT0X1mxWqNoFZ6dMEtf+Boecc0k3WNHvLTufLkVPNyo3PWZs8pNcOPGNmABpH9YROeGQ3eurWkJ6HvSwYyyYXi8n8K4u77o= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706209698; c=relaxed/simple; bh=FC+9pgSINxVbv8TKyD9qVRj5fjcBXeSQmgiihqqgTVE=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=QAC4fF1cjGwisuI71zISq6P97RWUMhIJuU/zlAkZ0VnIttrsbmRRo7CRg4SXhraAFh/pKUJ0bA+rAwWFIRDvJ7TzyrjpmP55HncPBQnDJvz+JBMdLrGrWBwPEGKhhkujIjX82B3cEElanmkr698hdIBCFtpyPQUQF9elrDM7fAY= 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=vzUO/9ar; 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="vzUO/9ar" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706209695; bh=FC+9pgSINxVbv8TKyD9qVRj5fjcBXeSQmgiihqqgTVE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=vzUO/9ar8sdWhSTMBMfoO7v+UoLde+Hr4btcoGtHzsBpZaAmD/zr0+dIpplSCa/Ju cufyt1A05yx0dIMspRwXk3Evq3fxrtZwoPlOVYDEzXRXqb+TNFqDqCcNeTE98R48l0 3OKeStJw9Uqv4EslZ4w4zNE2oQujrgXWLafVP8d+cm5+nobMEI0ufsVTXMOicaK194 zBJ0oEfPalsYmWPB0KVE/T5dopgrsqTCsGBtmd6//VSWvY0MAVuEiNaThusgiP7Vs4 BusnlwSDm2uRj+i/Vp3DiVt68K3/qBf1qe8MdJpn4rAUUNeAHhGmnZdL6UEdwYHcm+ Ts+Fe03ofW7kQ== 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 567A33782033 for ; Thu, 25 Jan 2024 19:08:15 +0000 (UTC) From: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3 4/5] btgatt-client: Add function to search characteristics Date: Thu, 25 Jan 2024 20:08:04 +0100 Message-Id: <20240125190805.1244787-5-frederic.danis@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240125190805.1244787-1-frederic.danis@collabora.com> References: <20240125190805.1244787-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 | 82 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/tools/btgatt-client.c b/tools/btgatt-client.c index 99a123697..04fd3ce0f 100644 --- a/tools/btgatt-client.c +++ b/tools/btgatt-client.c @@ -1420,6 +1420,86 @@ 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) || argc != 3) { + 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); @@ -1458,6 +1538,8 @@ static struct { "\tSet signing key for signed write command"}, { "search-service", cmd_search_service, "\tSearch service"}, + { "search-characteristics", cmd_search_characteristics, + "\tSearch characteristics"}, { } }; From patchwork Thu Jan 25 19:08:05 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: 766049 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 5A5A51353F5 for ; Thu, 25 Jan 2024 19:08:19 +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=1706209700; cv=none; b=Nl6/ewGSaitJEibbNVFBGf9z5YP24oiOumWA83QymURbEY8GF7dYco0GrquzswAiq2R8T0PYWkdXDGa64vod2lvBYqth7fURBopeKp49sDy7Z5hw1L2/zUdrWaA0ZEfeDjmPks98XhhK+tcIgjz+ngyvL5u08j0nBvd8wWZ30q8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706209700; c=relaxed/simple; bh=TR9FeCKfGpogbwWXGekAInfxeqoCMmoY+xr575x32gE=; h=From:To:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version:Content-Type; b=eXNoIoT8QECO0B4kz9bhI0R5pMefwrdTc7o8TVGlkbU6jgRpWr2SIHOek3o04rnEKlWPpvH20xSpvQCSGPuOr9/F0ixh1P3sCZTBPpXYk7nXZBQnr4Nbf0qtskSwMXMdzNOG/IkaQC2g6vaev+IlpLcwbtXVRF53CYNYU0KUA/Q= 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=myg7jpfg; 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="myg7jpfg" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1706209695; bh=TR9FeCKfGpogbwWXGekAInfxeqoCMmoY+xr575x32gE=; h=From:To:Subject:Date:In-Reply-To:References:From; b=myg7jpfgsSeC8eWD9hb/H5AC73/jdYAAhaDkGGpnAJDTXnA/t4Nowad49kK4cX12f dTYq3rgBFkfL7bPOR0y89rG57lzFLkLp+PEmKqrQcV/Qh/DlT4H+zzI5u2HvVyoCny KIjdRWHS9IOy+FJSyhAMw96vgd4YpY7Koo8dFvMe1KP6sPuhCj8Ypx9/c6fSYeAjU9 b8+C7Ix+Ve3q5VseO7de7eCQjBJQsV+F+1HnyCI2R4CJoGhsWNjbsC/5yM/iQ5ncC6 AyDKJeog8Ld7A6dmenrqVIIAKBk0zbft8yR61BMLyQSD+rFcTlLUtYVZ6LOZMc2R2Z r/sNxbN002ItA== 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 ABC003782053 for ; Thu, 25 Jan 2024 19:08:15 +0000 (UTC) From: =?utf-8?q?Fr=C3=A9d=C3=A9ric_Danis?= To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ v3 5/5] btgatt-client: Add function to search all primary services Date: Thu, 25 Jan 2024 20:08:05 +0100 Message-Id: <20240125190805.1244787-6-frederic.danis@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20240125190805.1244787-1-frederic.danis@collabora.com> References: <20240125190805.1244787-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 04fd3ce0f..b47914da3 100644 --- a/tools/btgatt-client.c +++ b/tools/btgatt-client.c @@ -1354,13 +1354,6 @@ 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 \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) @@ -1392,6 +1385,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]; @@ -1536,6 +1550,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-all-primary-services", cmd_search_all_primary_services, + "\tSearch all primary services"}, { "search-service", cmd_search_service, "\tSearch service"}, { "search-characteristics", cmd_search_characteristics,