From patchwork Sun May 28 17:39:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 686651 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 849D4C7EE2E for ; Sun, 28 May 2023 17:39:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229543AbjE1Rjf (ORCPT ); Sun, 28 May 2023 13:39:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46928 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229485AbjE1Rje (ORCPT ); Sun, 28 May 2023 13:39:34 -0400 Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EDC4D8 for ; Sun, 28 May 2023 10:39:21 -0700 (PDT) Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id DA38C240028 for ; Sun, 28 May 2023 19:39:18 +0200 (CEST) Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4QTm9y1lCwz6tm4; Sun, 28 May 2023 19:39:18 +0200 (CEST) From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ 1/4] iso-tester: Add tests for AC configuration reconnect Date: Sun, 28 May 2023 17:39:13 +0000 Message-Id: <502997002ac9d4a76593aa4ba8237b7fb803c701.1685283364.git.pav@iki.fi> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Add test for reconnecting a CIG with two CIS, either both with same peer or with different peers. ISO Reconnect AC 6(i) - Success ISO Reconnect AC 6(ii) - Success --- Notes: The intent here was to trigger the kernel to send Remove CIG and Set CIG Parameters in the wrong order, but it doesn't hit the right timing in the emulator. It occurs on real hardware when BlueZ recreates multiple CIS at the same time. This can occur because Remove CIG is sent via hci_sync queue and queueing its request may be delayed until hci_cmd_sync_work runs, whereas Set CIG Parameters request is queued directly via hci_send_cmd. However, these tests were useful to have, as they hit Create CIS timing issues if Set CIG Parameters is moved to hci_sync. tools/iso-tester.c | 39 ++++++++++++++++++++++++++++++--------- 1 file changed, 30 insertions(+), 9 deletions(-) diff --git a/tools/iso-tester.c b/tools/iso-tester.c index 63c37bd52..776d87fc1 100644 --- a/tools/iso-tester.c +++ b/tools/iso-tester.c @@ -839,6 +839,15 @@ static const struct iso_client_data connect_ac_6i = { .defer = true, }; +static const struct iso_client_data reconnect_ac_6i = { + .qos = AC_6i_1, + .qos_2 = AC_6i_2, + .expect_err = 0, + .mcis = true, + .defer = true, + .disconnect = true, +}; + static const struct iso_client_data connect_ac_6ii = { .qos = AC_6ii_1, .qos_2 = AC_6ii_2, @@ -847,6 +856,15 @@ static const struct iso_client_data connect_ac_6ii = { .defer = true, }; +static const struct iso_client_data reconnect_ac_6ii = { + .qos = AC_6ii_1, + .qos_2 = AC_6ii_2, + .expect_err = 0, + .mcis = true, + .defer = true, + .disconnect = true, +}; + static const struct iso_client_data connect_ac_7i = { .qos = AC_7i_1, .qos_2 = AC_7i_2, @@ -1626,7 +1644,7 @@ static void iso_send(struct test_data *data, GIOChannel *io) iso_recv(data, io); } -static void setup_connect(struct test_data *data, uint8_t num, GIOFunc func); +static void test_connect(const void *test_data); static gboolean iso_connect_cb(GIOChannel *io, GIOCondition cond, gpointer user_data); @@ -1642,7 +1660,7 @@ static gboolean iso_disconnected(GIOChannel *io, GIOCondition cond, if (data->reconnect) { data->reconnect = false; - setup_connect(data, 0, iso_connect_cb); + test_connect(data->test_data); return FALSE; } @@ -1885,17 +1903,12 @@ static void test_connect(const void *test_data) setup_connect_many(data, n, num, func); } -static void setup_reconnect(struct test_data *data, uint8_t num, GIOFunc func) -{ - data->reconnect = true; - setup_connect(data, num, func); -} - static void test_reconnect(const void *test_data) { struct test_data *data = tester_get_data(); - setup_reconnect(data, 0, iso_connect_cb); + data->reconnect = true; + test_connect(test_data); } static void test_defer(const void *test_data) @@ -2410,6 +2423,14 @@ int main(int argc, char *argv[]) setup_powered, test_connect2_seq); + test_iso2("ISO Reconnect AC 6(i) - Success", &reconnect_ac_6i, + setup_powered, + test_reconnect); + + test_iso2("ISO Reconnect AC 6(ii) - Success", &reconnect_ac_6ii, + setup_powered, + test_reconnect); + test_iso("ISO Broadcaster - Success", &bcast_16_2_1_send, setup_powered, test_bcast); test_iso("ISO Broadcaster Encrypted - Success", &bcast_enc_16_2_1_send, From patchwork Sun May 28 17:39:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 686747 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5FB20C7EE2F for ; Sun, 28 May 2023 17:39:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229533AbjE1Rjg (ORCPT ); Sun, 28 May 2023 13:39:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46930 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229496AbjE1Rje (ORCPT ); Sun, 28 May 2023 13:39:34 -0400 Received: from mout01.posteo.de (mout01.posteo.de [185.67.36.141]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6FA85E4 for ; Sun, 28 May 2023 10:39:21 -0700 (PDT) Received: from submission (posteo.de [185.67.36.169]) by mout01.posteo.de (Postfix) with ESMTPS id F0051240029 for ; Sun, 28 May 2023 19:39:18 +0200 (CEST) Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4QTm9y4Cz8z6txq; Sun, 28 May 2023 19:39:18 +0200 (CEST) From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ 2/4] btdev: fix inactive CIG configurable status Date: Sun, 28 May 2023 17:39:14 +0000 Message-Id: <1788d43df1a572539158d133f8d330e36340d7fe.1685283364.git.pav@iki.fi> In-Reply-To: <502997002ac9d4a76593aa4ba8237b7fb803c701.1685283364.git.pav@iki.fi> References: <502997002ac9d4a76593aa4ba8237b7fb803c701.1685283364.git.pav@iki.fi> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org CIG shall not be configurable after the first Create CIS until Remove CIG is issued (Core v5.3 Vol 6 Part B Sec. 4.5.14.3). We currently have it configurable in the inactive state (Create CIS done and all CIS closed), which is incorrect. Track CIG state and allow reconfigure only in nonexistent/configured state, i.e., when no CIS have been created yet. --- emulator/btdev.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index f9260511a..98d7af99e 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -105,6 +105,7 @@ struct le_ext_adv { struct le_cig { struct bt_hci_cmd_le_set_cig_params params; struct bt_hci_cis_params cis[CIS_SIZE]; + bool activated; } __attribute__ ((packed)); struct btdev { @@ -5864,29 +5865,24 @@ static int cmd_set_cig_params(struct btdev *dev, const void *data, goto done; } + /* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E + * page 2553 + * + * If the Host issues this command when the CIG is not in the + * configurable state, the Controller shall return the error + * code Command Disallowed (0x0C). + */ + if (dev->le_cig[cig_idx].activated) { + rsp.params.status = BT_HCI_ERR_COMMAND_DISALLOWED; + goto done; + } + rsp.params.status = BT_HCI_ERR_SUCCESS; rsp.params.cig_id = cmd->cig_id; for (i = 0; i < cmd->num_cis; i++) { - struct btdev_conn *iso; - rsp.params.num_handles++; rsp.handle[i] = cpu_to_le16(make_cis_handle(cig_idx, i)); - - /* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E - * page 2553 - * - * If the Host issues this command when the CIG is not in the - * configurable state, the Controller shall return the error - * code Command Disallowed (0x0C). - */ - iso = queue_find(dev->conns, match_handle, - UINT_TO_PTR(le16_to_cpu(rsp.handle[i]))); - if (iso) { - rsp.params.status = BT_HCI_ERR_COMMAND_DISALLOWED; - i = 0; - goto done; - } } memcpy(&dev->le_cig[cig_idx], data, len); @@ -6006,6 +6002,8 @@ static int cmd_create_cis_complete(struct btdev *dev, const void *data, evt.cig_id = le_cig->params.cig_id; evt.cis_id = le_cig->cis[cis_idx].cis_id; + le_cig->activated = true; + le_meta_event(iso->link->dev, BT_HCI_EVT_LE_CIS_REQ, &evt, sizeof(evt)); } From patchwork Sun May 28 17:39:15 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 686748 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BFBCDC7EE29 for ; Sun, 28 May 2023 17:39:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229566AbjE1Rje (ORCPT ); Sun, 28 May 2023 13:39:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229453AbjE1Rje (ORCPT ); Sun, 28 May 2023 13:39:34 -0400 Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6F00FDC for ; Sun, 28 May 2023 10:39:21 -0700 (PDT) Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id 66EE2240101 for ; Sun, 28 May 2023 19:39:19 +0200 (CEST) Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4QTm9y6f1vz6tm4; Sun, 28 May 2023 19:39:18 +0200 (CEST) From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ 3/4] btdev: check LE Create CIS error conditions Date: Sun, 28 May 2023 17:39:15 +0000 Message-Id: <8846153ed22812ecf49ac33c994b97650018f2d6.1685283364.git.pav@iki.fi> In-Reply-To: <502997002ac9d4a76593aa4ba8237b7fb803c701.1685283364.git.pav@iki.fi> References: <502997002ac9d4a76593aa4ba8237b7fb803c701.1685283364.git.pav@iki.fi> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Check LE Create CIS input parameter are valid and return correct status codes (Core v5.3 Vol 4 Part E Sec. 7.8.99). On current bluetooth-next kernel, this results to ISO AC 6(i) - Success Failed ISO AC 7(i) - Success Failed ISO AC 8(i) - Success Failed ISO AC 9(i) - Success Failed ISO AC 11(i) - Success Failed as in these tests the kernel is sending new Create CIS commands before it has seen all events from the previous, which is not allowed: < HCI Command: LE Create Co.. (0x08|0x0064) plen 9 #129 [hci0] Number of CIS: 2 CIS Handle: 257 ACL Handle: 42 CIS Handle: 258 ACL Handle: 42 > HCI Event: Command Status (0x0f) plen 4 #130 [hci0] LE Create Connected Isochronous Stream (0x08|0x0064) ncmd 1 Status: Success (0x00) > HCI Event: LE Meta Event (0x3e) plen 29 #131 [hci0] LE Connected Isochronous Stream Established (0x19) Status: Success (0x00) Connection Handle: 257 ... < HCI Command: LE Setup Is.. (0x08|0x006e) plen 13 #132 [hci0] ... > HCI Event: Command Complete (0x0e) plen 6 #133 [hci0] LE Setup Isochronous Data Path (0x08|0x006e) ncmd 1 ... < HCI Command: LE Create Co.. (0x08|0x0064) plen 5 #134 [hci0] Number of CIS: 1 CIS Handle: 258 ACL Handle: 42 > HCI Event: Command Status (0x0f) plen 4 #135 [hci0] LE Create Connected Isochronous Stream (0x08|0x0064) ncmd 1 Status: ACL Connection Already Exists (0x0b) > HCI Event: LE Meta Event (0x3e) plen 29 #136 [hci0] LE Connected Isochronous Stream Established (0x19) Status: Success (0x00) Connection Handle: 258 ... The emulator uses Already Exists error code here, not Command Disallowed, since the Established events are logically generated immediately after the first status event, even though the kernel hasn't yet processed them. --- emulator/btdev.c | 38 ++++++++++++++++++++++++++++++++++++++ monitor/bt.h | 1 + 2 files changed, 39 insertions(+) diff --git a/emulator/btdev.c b/emulator/btdev.c index 98d7af99e..08506c66e 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -5903,6 +5903,38 @@ static int cmd_set_cig_params_test(struct btdev *dev, const void *data, static int cmd_create_cis(struct btdev *dev, const void *data, uint8_t len) { + const struct bt_hci_cmd_le_create_cis *cmd = data; + int i, j; + + for (i = 0; i < cmd->num_cis; i++) { + const struct bt_hci_cis *cis = &cmd->cis[i]; + struct btdev_conn *acl; + struct btdev_conn *iso; + int cig_idx, cis_idx; + + /* Check for errors (Core v5.3 Vol 4 Part E Sec. 7.8.99) */ + for (j = 0; j < i; j++) + if (cis->cis_handle == cmd->cis[j].cis_handle) + return -EINVAL; + + cig_idx = parse_cis_handle(le16_to_cpu(cis->cis_handle), + &cis_idx); + if (cig_idx < 0) + return -ENOENT; + if (cis_idx >= dev->le_cig[cig_idx].params.num_cis) + return -ENOENT; + + acl = queue_find(dev->conns, match_handle, + UINT_TO_PTR(le16_to_cpu(cis->acl_handle))); + if (!acl) + return -ENOENT; + + iso = queue_find(dev->conns, match_handle, + UINT_TO_PTR(le16_to_cpu(cis->cis_handle))); + if (iso) + return -EEXIST; + } + cmd_status(dev, BT_HCI_ERR_SUCCESS, BT_HCI_CMD_LE_CREATE_CIS); return 0; @@ -7142,6 +7174,12 @@ static const struct btdev_cmd *run_cmd(struct btdev *btdev, case -EPERM: status = BT_HCI_ERR_COMMAND_DISALLOWED; break; + case -EEXIST: + status = BT_HCI_ERR_CONN_ALREADY_EXISTS; + break; + case -ENOENT: + status = BT_HCI_ERR_UNKNOWN_CONN_ID; + break; default: status = BT_HCI_ERR_UNSPECIFIED_ERROR; break; diff --git a/monitor/bt.h b/monitor/bt.h index b99ada0b2..37fcdaeaa 100644 --- a/monitor/bt.h +++ b/monitor/bt.h @@ -3713,6 +3713,7 @@ struct bt_hci_evt_le_big_info_adv_report { #define BT_HCI_ERR_AUTH_FAILURE 0x05 #define BT_HCI_ERR_PIN_OR_KEY_MISSING 0x06 #define BT_HCI_ERR_MEM_CAPACITY_EXCEEDED 0x07 +#define BT_HCI_ERR_CONN_ALREADY_EXISTS 0x0b #define BT_HCI_ERR_COMMAND_DISALLOWED 0x0c #define BT_HCI_ERR_UNSUPPORTED_FEATURE 0x11 #define BT_HCI_ERR_INVALID_PARAMETERS 0x12 From patchwork Sun May 28 17:39:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 686652 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id F1937C77B7E for ; Sun, 28 May 2023 17:39:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229528AbjE1Rje (ORCPT ); Sun, 28 May 2023 13:39:34 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46904 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229473AbjE1Rjd (ORCPT ); Sun, 28 May 2023 13:39:33 -0400 Received: from mout02.posteo.de (mout02.posteo.de [185.67.36.142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6EE52D9 for ; Sun, 28 May 2023 10:39:21 -0700 (PDT) Received: from submission (posteo.de [185.67.36.169]) by mout02.posteo.de (Postfix) with ESMTPS id B3AE9240101 for ; Sun, 28 May 2023 19:39:19 +0200 (CEST) Received: from customer (localhost [127.0.0.1]) by submission (posteo.de) with ESMTPSA id 4QTm9z1wKwz6txs; Sun, 28 May 2023 19:39:19 +0200 (CEST) From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ 4/4] test-runner: enable no_hash_pointers=1 Date: Sun, 28 May 2023 17:39:16 +0000 Message-Id: <4275efc32fd4e63ffb25ee53fde2d24d5a60e6d7.1685283364.git.pav@iki.fi> In-Reply-To: <502997002ac9d4a76593aa4ba8237b7fb803c701.1685283364.git.pav@iki.fi> References: <502997002ac9d4a76593aa4ba8237b7fb803c701.1685283364.git.pav@iki.fi> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Set no_hash_pointers=1 to avoid printk printing "___ptrval___" for %p. This happens with test-runner since the kernel is not running long enough to gather entropy and so refuses to print addresses, and makes debugging harder. As test-runner is only used for testing and debugging, pointer hashing is not needed. --- tools/test-runner.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tools/test-runner.c b/tools/test-runner.c index 8b18f848a..d74bb1087 100644 --- a/tools/test-runner.c +++ b/tools/test-runner.c @@ -247,7 +247,7 @@ static void start_qemu(void) snprintf(cmdline, sizeof(cmdline), "console=ttyS0,115200n8 earlyprintk=serial " - "rootfstype=9p " + "no_hash_pointers=1 rootfstype=9p " "rootflags=trans=virtio,version=9p2000.u " "acpi=off pci=noacpi noapic quiet ro init=%s " "TESTHOME=%s TESTDBUS=%u TESTDAEMON=%u "