From patchwork Sat Aug 19 13:31:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 13358620 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 C8AC7EE49A5 for ; Sat, 19 Aug 2023 13:33:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232805AbjHSNdY (ORCPT ); Sat, 19 Aug 2023 09:33:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjHSNdY (ORCPT ); Sat, 19 Aug 2023 09:33:24 -0400 Received: from meesny.iki.fi (meesny.iki.fi [IPv6:2001:67c:2b0:1c1::201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36113F58C for ; Sat, 19 Aug 2023 06:31:34 -0700 (PDT) Received: from monolith.lan (91-152-120-101.elisa-laajakaista.fi [91.152.120.101]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pav) by meesny.iki.fi (Postfix) with ESMTPSA id 4RSflf4ktXzyPG; Sat, 19 Aug 2023 16:31:26 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1692451886; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=QFzl1Q1pyyM4DuuxOqyyoJaMaJEA7LV10cSwcwZSSf0=; b=YWVrFMnMmF2OKUkfPRAvFyqI80ucjHn0ZIxbpipk6xGa0NFm2rsmd9irEjV3n6l/yeSjZE ocfGyICULHqXv4JvPVWUtHakGpNMpI4cmXeW+4fP6cP1oGBWsPkNjrYb/vUR3WMH3VIswk EYhG3N32ekOi0WlDtNPP+U0oNCKiWvI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1692451886; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=QFzl1Q1pyyM4DuuxOqyyoJaMaJEA7LV10cSwcwZSSf0=; b=ydeKb607BviIae4m6cBOvbzuSgY5Rmb/niwHK7F9WiKdjqfY7r7hRRJLPlMFchPMdEvOGS WP2vpuE4QN0C/Sz5pTikGH97sbqaM7JtgauzaGx8CcrJ00D6gUcTsNoxz3CNaqWUSw1Pcz boBv+KVcU1ygxI1Rs7sYit0Tc5XTrlk= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1692451886; a=rsa-sha256; cv=none; b=PlNDE+EmU5wN+ZmX74QDZrrnFhrdcj962fDwNh5Wrl3bMSdOH+w72AnlzdY96gcL0mz46d 60kAwWbpFdpE6vcmcjXOnD8EgiFm4Fx2GhPwZMvzqOMheADj+ga+6JlmrkbWaQDt1NbOzi S57Q2IG2d+ZGLhTqFrz9hzFVZNQjC6k= From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ 1/4] vhci: Add function to pause processing input from vhci Date: Sat, 19 Aug 2023 16:31:20 +0300 Message-ID: X-Mailer: git-send-email 2.41.0 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Add function to pause (temporarily) reading data from vhci. This can be used to synchronously pause handling of btdev commands from the kernel. --- emulator/vhci.c | 9 +++++++++ emulator/vhci.h | 1 + 2 files changed, 10 insertions(+) diff --git a/emulator/vhci.c b/emulator/vhci.c index ecf1db3c7..c6a5caa5e 100644 --- a/emulator/vhci.c +++ b/emulator/vhci.c @@ -178,6 +178,15 @@ void vhci_close(struct vhci *vhci) vhci_destroy(vhci); } +bool vhci_pause_input(struct vhci *vhci, bool paused) +{ + if (paused) + return io_set_read_handler(vhci->io, NULL, NULL, NULL); + else + return io_set_read_handler(vhci->io, vhci_read_callback, vhci, + NULL); +} + struct btdev *vhci_get_btdev(struct vhci *vhci) { if (!vhci) diff --git a/emulator/vhci.h b/emulator/vhci.h index 68eae4c4a..12c4b55a0 100644 --- a/emulator/vhci.h +++ b/emulator/vhci.h @@ -31,3 +31,4 @@ int vhci_set_emu_opcode(struct vhci *vhci, uint16_t opcode); int vhci_set_force_static_address(struct vhci *vhci, bool enable); int vhci_force_devcd(struct vhci *vhci, const void *data, size_t len); int vhci_read_devcd(struct vhci *vhci, void *buf, size_t size); +bool vhci_pause_input(struct vhci *vhci, bool paused); From patchwork Sat Aug 19 13:31:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 13358622 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 AC977EE49A5 for ; Sat, 19 Aug 2023 13:33:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232816AbjHSNdj (ORCPT ); Sat, 19 Aug 2023 09:33:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43844 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjHSNdi (ORCPT ); Sat, 19 Aug 2023 09:33:38 -0400 Received: from meesny.iki.fi (meesny.iki.fi [IPv6:2001:67c:2b0:1c1::201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A8E381A2B6 for ; Sat, 19 Aug 2023 06:31:34 -0700 (PDT) Received: from monolith.lan (91-152-120-101.elisa-laajakaista.fi [91.152.120.101]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pav) by meesny.iki.fi (Postfix) with ESMTPSA id 4RSflg1CmHzyd2; Sat, 19 Aug 2023 16:31:27 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1692451887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1wBO73R9ff7gSKgLy3qUisXiLGhrcRmdpR547QojgoA=; b=iP8hssisP/DndwDrJRwS3Q2MEyunAp7eIUWkz2xjmGcB0yOi9ewsWZW+OyWbaTQMCAEqM2 bTCc8kzeylD4AGuEau1rh8DqI8eUdccw88d8qM/OlB801MlowWaHpKgxyCFEasQobocux8 ZUVuFnQIR1HFCfqX7Yvi9cn45+8Ak6g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1692451887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=1wBO73R9ff7gSKgLy3qUisXiLGhrcRmdpR547QojgoA=; b=IXgKYnUA9aXp0RrVRmKiBD+sfSXbFzvu89rgJaOojKw7B0zHLTxYICsNuNChbOUdffxSIf vP/w91Cgydiypd3y2+BzCQzemgMqWUwDumcSBPSKqi04HYNDelVSvtEBZPUWsrg5LY5ZDN Khp3O+r2cCLJmehFboBdT8fExpmu6RU= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1692451887; a=rsa-sha256; cv=none; b=SVScu7nbldfmyl7YKkQ7JloFQMmmSkgsDO8HdU1OfpPS91nd0Ealj2WTS2f6+VBx3EySQy YOVU42aOdNz1AAVOlxGAjrpnzkSuh8N3E2rg8ezgDUeltWEsJ7uLfpc3t/2QtXcBSdMGE0 eqSsfbpdhc/nzfZ0xNtTYmKL/n+DhPc= From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ 2/4] hciemu: Add hciemu_flush_client_events for ordering VHCI vs bthost Date: Sat, 19 Aug 2023 16:31:21 +0300 Message-ID: <70e5ea48b34f3fdb339e92faf4ceb0fefff91f53.1692451184.git.pav@iki.fi> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org bthost commands execute with a delay because events may be sitting in the socketpair queues. This makes it difficult to ensure, when writing tests, that certain bthost commands have been handled, before any new events from VHCI are processed. To make event ordering possible, add a function that flushes client bthost/btdev socketpair queues, before processing any new VHCI events. This is done by pausing VHCI input processing until the kernel socketpair queues are empty. --- emulator/hciemu.c | 54 +++++++++++++++++++++++++++++++++++++++++++++++ emulator/hciemu.h | 3 +++ 2 files changed, 57 insertions(+) diff --git a/emulator/hciemu.c b/emulator/hciemu.c index dcfed9be7..0b5847c27 100644 --- a/emulator/hciemu.c +++ b/emulator/hciemu.c @@ -21,6 +21,7 @@ #include #include #include +#include #include @@ -41,6 +42,7 @@ struct hciemu_client { guint start_source; guint host_source; guint source; + int sock[2]; }; struct hciemu { @@ -54,6 +56,8 @@ struct hciemu { hciemu_debug_func_t debug_callback; hciemu_destroy_func_t debug_destroy; void *debug_data; + + unsigned int flush_id; }; struct hciemu_command_hook { @@ -338,6 +342,9 @@ static struct hciemu_client *hciemu_client_new(struct hciemu *hciemu, return NULL; } + client->sock[0] = sv[0]; + client->sock[1] = sv[1]; + client->source = create_source_btdev(sv[0], client->dev); client->host_source = create_source_bthost(sv[1], client->host); client->start_source = g_idle_add(start_host, client); @@ -435,6 +442,9 @@ void hciemu_unref(struct hciemu *hciemu) queue_destroy(hciemu->post_command_hooks, destroy_command_hook); queue_destroy(hciemu->clients, hciemu_client_destroy); + if (hciemu->flush_id) + g_source_remove(hciemu->flush_id); + vhci_close(hciemu->vhci); free(hciemu); @@ -744,3 +754,47 @@ bool hciemu_del_hook(struct hciemu *hciemu, enum hciemu_hook_type type, return btdev_del_hook(dev, hook_type, opcode); } + +static bool client_is_pending(const void *data, const void *match_data) +{ + struct hciemu_client *client = (struct hciemu_client *)data; + int used, i; + + if (!client->source || !client->host_source) + return false; + + for (i = 0; i < 2; ++i) { + if (!ioctl(client->sock[i], TIOCOUTQ, &used) && used > 0) + return true; + if (!ioctl(client->sock[i], TIOCINQ, &used) && used > 0) + return true; + } + + return false; +} + +static gboolean flush_client_events(gpointer user_data) +{ + struct hciemu *hciemu = user_data; + + if (queue_find(hciemu->clients, client_is_pending, NULL)) + return TRUE; + + hciemu->flush_id = 0; + + util_debug(hciemu->debug_callback, hciemu->debug_data, "vhci: resume"); + if (hciemu->vhci) + vhci_pause_input(hciemu->vhci, false); + + return FALSE; +} + +void hciemu_flush_client_events(struct hciemu *hciemu) +{ + if (hciemu->flush_id || !hciemu->vhci) + return; + + util_debug(hciemu->debug_callback, hciemu->debug_data, "vhci: pause"); + vhci_pause_input(hciemu->vhci, true); + hciemu->flush_id = g_idle_add(flush_client_events, hciemu); +} diff --git a/emulator/hciemu.h b/emulator/hciemu.h index 3a06ca578..3449eae41 100644 --- a/emulator/hciemu.h +++ b/emulator/hciemu.h @@ -48,6 +48,9 @@ bool hciemu_set_debug(struct hciemu *hciemu, hciemu_debug_func_t callback, struct vhci *hciemu_get_vhci(struct hciemu *hciemu); struct bthost *hciemu_client_get_host(struct hciemu *hciemu); +/* Process pending client events before new VHCI events */ +void hciemu_flush_client_events(struct hciemu *hciemu); + const char *hciemu_get_address(struct hciemu *hciemu); uint8_t *hciemu_get_features(struct hciemu *hciemu); From patchwork Sat Aug 19 13:31:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 13358623 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 A32D1EE49A8 for ; Sat, 19 Aug 2023 13:33:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232824AbjHSNdk (ORCPT ); Sat, 19 Aug 2023 09:33:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjHSNdk (ORCPT ); Sat, 19 Aug 2023 09:33:40 -0400 Received: from meesny.iki.fi (meesny.iki.fi [195.140.195.201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDE99255E2 for ; Sat, 19 Aug 2023 06:31:34 -0700 (PDT) Received: from monolith.lan (91-152-120-101.elisa-laajakaista.fi [91.152.120.101]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pav) by meesny.iki.fi (Postfix) with ESMTPSA id 4RSflg22pVzydv; Sat, 19 Aug 2023 16:31:27 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1692451887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uHkOP8ei0C/7dI72g+L6LTwouMqiFz34F6ZsMFxBN1s=; b=M2bYqHV9Ts/snNT86/tljL8RyEWldOmutr1hRwplsMzZbKk23eUxajhJn7uLgLiOQchpNQ 0v3GsEFGQ5r5yQw9UJNdPZWgtFwfEfqj/Bxhsa0LYtbmXUyO7mAKy2U7OscIhS0BRiV8nV I3QUN+NbFm5CAM1VJ2PXNE5bhgUyk1U= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1692451887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=uHkOP8ei0C/7dI72g+L6LTwouMqiFz34F6ZsMFxBN1s=; b=u1EeQDYz22XY8b8BH9rUjfX18MzDrjrYopzbsuQ8l4GZA1Ysv2x5DbTd2XZB2GUn/MJzsf VkuiaJhYUubx+n/9Zq9W6glMFsiBDCKBZeyYSlAKcgx9ZskQ2Fh54q/0x6QT+NWbeStOVM NOw/jomMS8LqvddOP+LsAXHD5DaCSPs= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1692451887; a=rsa-sha256; cv=none; b=ie08uD0FHpUFJ1TwCsmGER78yn5TqwLumYNdiUidTcxGVRfDeOc1pLPxxwFMqRlBZv+tZr BdXnayPq5tfwdLygVmyVB4Mso1SHm3BiPfqXoKcOpnMsEIwLLbotmSKG6DHjWCDLelurlg lVl/ORwTzj7Ak30VeOTN2qJZe8U8b7o= From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ 3/4] sco-tester: add test for ACL disconnect before SCO established Date: Sat, 19 Aug 2023 16:31:22 +0300 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Simulate ACL being disconnected before SCO is established. Kernel shall not crash. eSCO ACL Disconnect - Failure Link: https://lore.kernel.org/linux-bluetooth/00000000000013b93805fbbadc50@google.com/ --- Notes: Current bluetooth-next/master crashes, similarly as what syzbot says. tools/sco-tester.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/tools/sco-tester.c b/tools/sco-tester.c index f3de42c7b..ecc65e092 100644 --- a/tools/sco-tester.c +++ b/tools/sco-tester.c @@ -800,6 +800,36 @@ static void test_connect_simult_disc(const void *test_data) test_connect(test_data); } +static bool hook_acl_disc(const void *msg, uint16_t len, void *user_data) +{ + const struct bt_hci_evt_conn_complete *ev = msg; + struct test_data *data = tester_get_data(); + struct bthost *bthost; + + tester_print("Disconnect ACL"); + + bthost = hciemu_client_get_host(data->hciemu); + bthost_hci_disconnect(bthost, le16_to_cpu(ev->handle), 0x13); + + hciemu_flush_client_events(data->hciemu); + + return true; +} + +static void test_connect_acl_disc(const void *test_data) +{ + struct test_data *data = tester_get_data(); + + /* ACL disconnected before SCO is established seen. + * Kernel shall not crash, but <= 6.5-rc5 crash. + */ + hciemu_add_hook(data->hciemu, HCIEMU_HOOK_POST_EVT, + BT_HCI_EVT_CONN_COMPLETE, + hook_acl_disc, NULL); + + test_connect(test_data); +} + int main(int argc, char *argv[]) { tester_init(&argc, &argv); @@ -826,6 +856,10 @@ int main(int argc, char *argv[]) &connect_failure_reset, setup_powered, test_connect_simult_disc); + test_sco("eSCO ACL Disconnect - Failure", + &connect_failure_reset, setup_powered, + test_connect_acl_disc); + test_sco_11("SCO CVSD 1.1 - Success", &connect_success, setup_powered, test_connect); From patchwork Sat Aug 19 13:31:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Pauli Virtanen X-Patchwork-Id: 13358621 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 49E32EE49A5 for ; Sat, 19 Aug 2023 13:33:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232812AbjHSNdd (ORCPT ); Sat, 19 Aug 2023 09:33:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229436AbjHSNdc (ORCPT ); Sat, 19 Aug 2023 09:33:32 -0400 Received: from meesny.iki.fi (meesny.iki.fi [IPv6:2001:67c:2b0:1c1::201]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 974031A2A8 for ; Sat, 19 Aug 2023 06:31:34 -0700 (PDT) Received: from monolith.lan (91-152-120-101.elisa-laajakaista.fi [91.152.120.101]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: pav) by meesny.iki.fi (Postfix) with ESMTPSA id 4RSflg30FMzyfN; Sat, 19 Aug 2023 16:31:27 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1692451887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2CeyuORkRww/CWbLS26iE+78V82b5y9/EStIhVviNYA=; b=Z5NGIEHowI8I2Bm48J5yOVN4+3uEiGKi28rdzEYxIHB3+OWlHqsX27hDcVY2x6nvRZkyq/ rwEH54lPZZbCN3CZuCWQELFA8RPN0SDbH/kC+et8glLdBrCV8QYbd8EqtjuLaFcpK3JMFU dnjTf3GwndNL1sDaI0ddjLlVMFAcMpg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=iki.fi; s=meesny; t=1692451887; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=2CeyuORkRww/CWbLS26iE+78V82b5y9/EStIhVviNYA=; b=y2cvH4Uz2DbRMVrgQf95Fq1g3jexyLhcX7FNZqCSMojPmVjoPjEVCH4/PiBvjy3QcyHzcL z8/gPZSs51ZiwndB9iOEssSLRnytoCI5hSocygdo4BOpwOpJWbUrdD+y0CT7+V/xlndmt1 yGtcznSb6/ifE0xf7VaWLsIhHBnNgIg= ARC-Authentication-Results: i=1; ORIGINATING; auth=pass smtp.auth=pav smtp.mailfrom=pav@iki.fi ARC-Seal: i=1; s=meesny; d=iki.fi; t=1692451887; a=rsa-sha256; cv=none; b=sS7pkbBeh/gwfiHjQPUt9/AuSIVGJvE3qlBndACbNXWAikj3z/cjCqDobZxAl3m5SsKYT3 B0Vk1FO/mUmPRzs6o1NO2YXkM5ZkVuyzcpEFzUq5SyzRDAFvAEQsu42CVtiPKO3SPEOd1O Lr+qe6bcPNWhtFZQZ5ZDd8kUVCB/06w= From: Pauli Virtanen To: linux-bluetooth@vger.kernel.org Cc: Pauli Virtanen Subject: [PATCH BlueZ 4/4] iso-tester: add test for ACL disconnect before ISO created Date: Sat, 19 Aug 2023 16:31:23 +0300 Message-ID: <444c48235fb02ac68871236ce669fd02b4a4736d.1692451184.git.pav@iki.fi> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Simulate ACL being disconnected when connecting ISO, before LE Create CIS got sent. The kernel shall indicate connection failure for the ISO socket immediately when the ACL is gone, since connecting the ISO can no longer proceed. ISO Connect ACL Disconnect - Failure --- Notes: Current bluetooth-next/master kernel fails this. tools/iso-tester.c | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/tools/iso-tester.c b/tools/iso-tester.c index b1a2afba0..48c8ab52a 100644 --- a/tools/iso-tester.c +++ b/tools/iso-tester.c @@ -2628,6 +2628,40 @@ static void test_connect_suspend(const void *test_data) trigger_force_suspend((void *)test_data); } +static bool hook_acl_disc(const void *msg, uint16_t len, void *user_data) +{ + const uint8_t *msg_data = msg; + const struct bt_hci_evt_le_enhanced_conn_complete *ev; + struct test_data *data = tester_get_data(); + struct bthost *bthost; + + if (msg_data[0] != BT_HCI_EVT_LE_ENHANCED_CONN_COMPLETE) + return true; + + ev = (void *) &msg_data[1]; + + tester_print("Disconnect ACL"); + + bthost = hciemu_client_get_host(data->hciemu); + bthost_hci_disconnect(bthost, le16_to_cpu(ev->handle), 0x13); + + hciemu_flush_client_events(data->hciemu); + + return true; +} + +static void test_connect_acl_disc(const void *test_data) +{ + struct test_data *data = tester_get_data(); + + /* ACL disconnected before ISO is created */ + hciemu_add_hook(data->hciemu, HCIEMU_HOOK_POST_EVT, + BT_HCI_EVT_LE_META_EVENT, + hook_acl_disc, NULL); + + test_connect(test_data); +} + static void test_bcast(const void *test_data) { struct test_data *data = tester_get_data(); @@ -2850,6 +2884,10 @@ int main(int argc, char *argv[]) setup_powered, test_connect2); + test_iso("ISO Connect ACL Disconnect - Failure", &connect_suspend, + setup_powered, + test_connect_acl_disc); + test_iso("ISO Defer Send - Success", &connect_16_2_1_defer_send, setup_powered, test_connect);