Received: by 2002:a05:7412:bbc7:b0:fc:a2b0:25d7 with SMTP id kh7csp2970892rdb; Tue, 6 Feb 2024 03:28:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IEll42FuDwB6eD2we6uc/pw2TeuhJxmQBeb2hNUwYJjUhVwjzbCgPpDSH6L8jrH48EiV/VW X-Received: by 2002:a17:90b:4ac5:b0:296:5f38:cbd0 with SMTP id mh5-20020a17090b4ac500b002965f38cbd0mr2074384pjb.44.1707218916761; Tue, 06 Feb 2024 03:28:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1707218916; cv=pass; d=google.com; s=arc-20160816; b=TpqcSw25TUGcncRDb15NWQNzH2C+lCMATN7I9HxkTv0Ri7jOm/WpN9zbPqpGht4nSh PdGLjv99VXYH7IbOJVNi2mVsfpuUGTM54w6F0H5rsxI2M4zRoskicVFfA6zPwSjjTZmA rWDz3nvIBekK04QGgcyfwoFPQ0tpN2uIsWAkDzBRyw7SJQoJhe20cKZdH9Mrbsglnr4a sbk1sZjJgBBemo5wmClkzlmqzCeZPVthmxb5NfbTKbsza17qeltnAPfgVgi2+BcAmXoJ 2zm1bWJN1zTIVCvdyPaqcMR3sYD2Ue0bM64pIGkJyuXXaKI4slYhAUrvmNKGk2WV2kqe Slbg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=riW7EeI8OECOgAenero5ITEDGImFGvu0KHKPV2OCq9E=; fh=Q65neXCOXWRl+M9/QlxNWhKxW6r9xLFFn6egAoCLenY=; b=toCBAjLanJgzGBdzr+CDGNRuQ3k/V/8RlcmAJ8hAugb3zPTFIx6PPl5DlS/ZjyOZkl NtkBnjSq4O3dZpnBrf45iXBqbjf4RtgYxzNc0GPuo9oPAmFtjwZZWwErw3VW0s+8qyKN Rr21OlkgMNJOF05Wx01VH5N2JNLkgcUUhPHTJDSBxjPO2Ve2a1RAYoC6ZfqCcb4qo9Vk 12elP3OkExs/rM7SLTe3kIlPcPpcb6dI3BqNa9NIeqhcm7pzMhAgBGWctl5hHLIymP/Q xdDpbix1b9yqiRqV8N9BxRvd6iaVyn+Gt4Bk0CF4YTO4C1fsRkdMt9J9ciWfm/ac/2pA R4HQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=v0yd.nl); spf=pass (google.com: domain of linux-bluetooth+bounces-1632-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-1632-linux.lists.archive=gmail.com@vger.kernel.org" X-Forwarded-Encrypted: i=2; AJvYcCUNkfL68enkvLlrI9rpsqw/WsaxRZNVfkvZPJlt5VPtWMECCnXCbWmiHSKRdnK31S/48r5ReFUZ4Wx8CMOuHicTym10OEoHEGYw89oB/Q== Return-Path: Received: from sy.mirrors.kernel.org (sy.mirrors.kernel.org. [147.75.48.161]) by mx.google.com with ESMTPS id cl21-20020a17090af69500b00291f211c3eesi994415pjb.54.2024.02.06.03.28.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 06 Feb 2024 03:28:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-1632-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) client-ip=147.75.48.161; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=v0yd.nl); spf=pass (google.com: domain of linux-bluetooth+bounces-1632-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.48.161 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-1632-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sy.mirrors.kernel.org (Postfix) with ESMTPS id 586C0B23071 for ; Tue, 6 Feb 2024 11:23:59 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C9E5912F37D; Tue, 6 Feb 2024 11:23:17 +0000 (UTC) X-Original-To: linux-bluetooth@vger.kernel.org Received: from mout-p-101.mailbox.org (mout-p-101.mailbox.org [80.241.56.151]) (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 AE4A212D152 for ; Tue, 6 Feb 2024 11:23:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=80.241.56.151 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707218597; cv=none; b=ejcgrm5NqH0uQIw4P0y0H/BpqzEU4/Jdgz3uneKpgUZxAo+yfbvkHtdkUVXOw6lBkFBfVH6/dlvgxrmqXseLpHk2Yz3wsOGD11hddbFPKvRgQrpOtKZ1AdtzjHCY2gCipgq8UzhbYiWtzyQq5o6t8XeuUFkmNlGmypS+6OUFVzs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707218597; c=relaxed/simple; bh=DnMD8gUxu30juBFpQz9aXRAA2HnRTVzZQ4qj1UTY0js=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ECG0t20fwY1vYGI07IWACsTLPhueo3Jz7G3cV6d3YsQmdTDcoLueVx0n+j0uBDI7VpkbahJUyYi/k1vT7xXxY/hmQjFi3HAtmi3t5FKQloT43wi3eKCR/6JhRgwjFRmDijdgZrQdDB+MeMYxsFISirSCrLXgsgWT7YsxFQCVFkU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=v0yd.nl; spf=pass smtp.mailfrom=v0yd.nl; arc=none smtp.client-ip=80.241.56.151 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=v0yd.nl Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=v0yd.nl Received: from smtp202.mailbox.org (smtp202.mailbox.org [IPv6:2001:67c:2050:b231:465::202]) (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) by mout-p-101.mailbox.org (Postfix) with ESMTPS id 4TTgpl5LN1z9swV; Tue, 6 Feb 2024 12:23:11 +0100 (CET) From: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= To: linux-bluetooth@vger.kernel.org, Luiz Augusto von Dentz Cc: =?UTF-8?q?Jonas=20Dre=C3=9Fler?= Subject: [PATCH BlueZ v2 4/4] mgmt-tester: Add a test for connecting sequentially Date: Tue, 6 Feb 2024 12:22:53 +0100 Message-ID: <20240206112253.76446-5-verdre@v0yd.nl> In-Reply-To: <20240206112253.76446-1-verdre@v0yd.nl> References: <20240206112253.76446-1-verdre@v0yd.nl> Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: 4TTgpl5LN1z9swV The kernel was recently changed to only connect to ACL devices sequentially (see kernel commit "Bluetooth: hci_conn: Only do ACL connections sequentially"), similar to how it already behaves for LE devices. Add some testing for this behavior to mgmt-tester and make sure that new "HCI Create Connection" commands only get sent after the previous "Pair Device" MGMT command has failed. --- tools/mgmt-tester.c | 106 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 106 insertions(+) diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c index 767cd5cda..ac3045e13 100644 --- a/tools/mgmt-tester.c +++ b/tools/mgmt-tester.c @@ -12767,6 +12767,103 @@ static void test_hci_devcd(const void *test_data) tester_wait(test->dump_data->timeout + 1, verify_devcd, NULL); } +static const struct generic_data sequential_connect = { + .setup_settings = settings_powered_bondable, + .pin = pair_device_pin, + .pin_len = sizeof(pair_device_pin), + .client_pin = pair_device_pin, + .client_pin_len = sizeof(pair_device_pin), +}; + +struct pair_devices_data { + struct test_data *test_data; + unsigned int n_conn_failed_evts; + unsigned int n_create_conn_cmds; +}; + +static void pair_device_command_callback(uint8_t status, uint16_t length, + const void *param, void *user_data) +{ + struct pair_devices_data *pd_data = user_data; + + if (status != MGMT_STATUS_CONNECT_FAILED) { + tester_warn("Unexpected status got %d expected %d", + status, MGMT_STATUS_CONNECT_FAILED); + tester_test_failed(); + free(pd_data); + return; + } + + tester_print("Connect failed for Pair Device"); + + pd_data->n_conn_failed_evts++; + if (pd_data->n_conn_failed_evts != pd_data->n_create_conn_cmds) { + tester_test_failed(); + free(pd_data); + return; + } + + if (pd_data->n_conn_failed_evts == 3) { + test_condition_complete(pd_data->test_data); + free(pd_data); + } +} + +static bool connect_multiple_create_conn(const void *data, uint16_t len, + void *user_data) +{ + struct pair_devices_data *pd_data = user_data; + const uint8_t *status = data; + + if (*status == 0) { + tester_print("Create connection finished"); + + pd_data->n_create_conn_cmds++; + if (pd_data->n_conn_failed_evts != pd_data->n_create_conn_cmds - 1) { + tester_test_failed(); + free(pd_data); + } + } else { + tester_print("Create connection failed: 0x%02x", *status); + tester_test_failed(); + free(pd_data); + } + + return true; +} + +static void test_sequential_connect(const void *test_data) +{ + struct test_data *data = tester_get_data(); + struct pair_devices_data *pd_data; + static uint8_t param[8] = { + 0x31, 0xAB, 0xCD, 0x32, 0x34, 0x73, /* random bdaddr so we fail to connect */ + BDADDR_BREDR, + 0x03, /* NoInputNoOutput */ + }; + + pd_data = new0(struct pair_devices_data, 1); + pd_data->test_data = data; + pd_data->n_conn_failed_evts = 0; + pd_data->n_create_conn_cmds = 0; + + hciemu_add_hook(data->hciemu, HCIEMU_HOOK_POST_CMD, + BT_HCI_CMD_CREATE_CONN, + connect_multiple_create_conn, pd_data); + + mgmt_send_nowait(data->mgmt, MGMT_OP_PAIR_DEVICE, data->mgmt_index, + sizeof(param), param, + pair_device_command_callback, pd_data, NULL); + param[2] = 0x09; /* change bdaddr a bit */ + mgmt_send_nowait(data->mgmt, MGMT_OP_PAIR_DEVICE, data->mgmt_index, + sizeof(param), param, + pair_device_command_callback, pd_data, NULL); + param[2] = 0x10; /* change bdaddr a bit */ + mgmt_send_nowait(data->mgmt, MGMT_OP_PAIR_DEVICE, data->mgmt_index, + sizeof(param), param, + pair_device_command_callback, pd_data, NULL); +} + int main(int argc, char *argv[]) { tester_init(&argc, &argv); @@ -14932,5 +15029,14 @@ int main(int argc, char *argv[]) test_bredrle_full("HCI Devcoredump - Dump Timeout", &dump_timeout, NULL, test_hci_devcd, 3); + /* Sequential connect + * Setup: Power on + * Run: Try connecting to multiple devices + * Expect: Connects time out sequentially + */ + test_bredrle_full("Sequential connect", + &sequential_connect, NULL, + test_sequential_connect, 7); + return tester_run(); } -- 2.43.0