From patchwork Wed Oct 4 15:31:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 13408910 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 B6BC3E7C4D0 for ; Wed, 4 Oct 2023 15:32:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233504AbjJDPcO (ORCPT ); Wed, 4 Oct 2023 11:32:14 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233499AbjJDPcN (ORCPT ); Wed, 4 Oct 2023 11:32:13 -0400 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2072.outbound.protection.outlook.com [40.107.241.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80C46BF for ; Wed, 4 Oct 2023 08:32:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m5fg71bgnGXpD5l9y8XrHCcpdwuiZFNFMjszyrDnFRs62LN8gLRwmUTq/3fFn/3DGhyyLSqfH7rd4Ngcikepz29EiLgghoTd9aY9zFiMu/4Zqz82Xl3zH0sroYMR/igX8lgwJ3PO2DdCu8Ejy0qu0WPS5iKU1WUahPTFsXZcsIMD09/mi9QZVeM+d/0a04gCYCTV/LUaPr9OuhXAx0SftX913694sNc/GBbdrwlaD9+k7nVLLF6sJLb411rlgDCgF4myJjyS1kUZuoMQoOw5o8EBlOLmt2fVMArfU7bG9srIq3JerF7IRP2/egI7yubu6h+c64rF8Cj3155y6nOtcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=MduW7ptBFfkMrM8Xi2votwl069/7yHTmERVsEOqtTJU=; b=WRY05t7Lov9eLBVZmHq5kverE+wY7h0NEhSDujZ+a2kjs/1X5YLLBHyUocprFcQ7FhtLlmYhZ9gBLdE3KUmdLAYKhSd1H6RBJMduVUUMN+7zx/xpptUNDOgTnxaKF5RMSWYWLu+UkAeeIDRN/F84rAVCuEkywcSfAzLtt1y/+/kBPbJ5mTCPNbP8ev9S4F3NNSSyjCN4h1zC+UNoypJe/Lpe4I7sMncgsqmTS/uSWaqC8SIbiaKZ/YL3+93AqcOaTHiRB7o9qPd7BqnehkfJcSWlcjkUAF6GAi0TiWZ6+hnTMBsfqwF7vWCfz+kKiTKrwaxwZwvW544fxpzhepmBsg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=MduW7ptBFfkMrM8Xi2votwl069/7yHTmERVsEOqtTJU=; b=FImgO1X3q6pA6iyws4HNYI+Kk/rg6XU/NR7vGE7EfCl3UWwDq36F327GcO/IH5TC94HjoDw7SlO2q6ZUl8u+Dbzl+kgwDmh2Ca/PysFc008cyCKBJu0RyG+PQBWkP/2V6lCVvR4yp+ZmbfarPpaGmupuWGzlsBVQAbP2jRIg7d0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) by PA4PR04MB7790.eurprd04.prod.outlook.com (2603:10a6:102:cc::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.33; Wed, 4 Oct 2023 15:32:07 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7763:779b:1a89:47da]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7763:779b:1a89:47da%3]) with mapi id 15.20.6838.033; Wed, 4 Oct 2023 15:32:07 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, silviu.barbulescu@nxp.com, vlad.pruteanu@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Iulia Tanasescu Subject: [PATCH BlueZ 1/4] btio: Bind listener to bcaster addr based on dst opt Date: Wed, 4 Oct 2023 18:31:47 +0300 Message-Id: <20231004153150.3051-2-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231004153150.3051-1-iulia.tanasescu@nxp.com> References: <20231004153150.3051-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: VI1PR0902CA0050.eurprd09.prod.outlook.com (2603:10a6:802:1::39) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|PA4PR04MB7790:EE_ X-MS-Office365-Filtering-Correlation-Id: 5008703f-31dd-40ed-0621-08dbc4ef116c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 3QECC0UyzF2lYvcV9AMQfk86A38s3V87GNcH+OChlGdCNKzQJT9rVWx0Zq6hLrJTFrT1s/diyv42zopSBXuCcfaZlpPK/V0fBpO0LMqzeRtIYGkSQBYKAEvI+pW5tP0c1O5mns6GkTHYs9BrKSl2xavrqSq22A2D0kUfzbSWdwAqKbp61xiFb27pOhzo5ix8rDprV7tFJmlql/54ndu/LTdLgVZcWhnvBwW46tTiICus18CqyEcaBMLDTOi98wj3aMnkZ/iW3SNHsjuIomitZjLvqnxqFJLO1rguvHUJEccnpdn8LwMFcMKOPqexLa3NWK1ZQp6NC8hnV4xBuVQQBu/vWySTxkmSVZ59HmIRT3a84lVp0RipE18+qGq/r7VqEOnXkjHQJrq3CE1IShwGvKMhCxcPpdOIeYsYZh3Zfeqr+tIWfdnEwJB7vMPBBusI79gzr2EmnmXLYn/YgXlaQJYSeoOeAS85DVkYR46lfwGg5WP8lVeHRKeKOAv7EI3g0uHGjZWfAfImiZxPg3Cpxm2VSCt1pyjq/kgW1tp6SXLv06zTrjv4DXJ1/nGzYdxX8TVofv2Zkni5FYEGfLd6r99RWppW95Up5rxfBsn6TgthFYAUDgfVEOUwyUGkOqUF X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR04MB8898.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(39860400002)(376002)(346002)(136003)(366004)(230922051799003)(451199024)(1800799009)(64100799003)(186009)(2013699003)(6486002)(6512007)(6506007)(478600001)(6666004)(38100700002)(86362001)(66476007)(2906002)(6916009)(4326008)(83380400001)(2616005)(26005)(1076003)(41300700001)(36756003)(66556008)(66946007)(8936002)(44832011)(5660300002)(316002)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: MS/9ffbZvBlEkQIPyEjGg/FhLu7uWxsPfMTzXXLgJvfZdLTkUVhBRC3Og2sfWelrSgKKKD5VI2lOxfLgYDrYvJhovoxVuW/BRZi/hw19l+QmIYBY5gbn0UtpMSRnoYLwf4AVMbD2t8FauD11WTcRk5/OZi06Nksb3u6CMpLm+xG1vC7Koi6xZCwrh5ht+MN6jqir+gTeHnEa8nMUye4D8VHJ5rn1oD1SMP7JXK/WZQjpHtVT8itSH7vx5zb+ZQKpe7Q+lwo+VnEzcslq1ED/gwNbBz8oKxKcV7HeMkq8xwVvmsqDzXk94aqI+z+ahsZCquJsOSX3uqQvnVHRvO2iOp6ILBuT4qHeAjQuRVnApkTyVFFl7JA0AI2q+Z0or16kyADWOj/+BqwIaWvdiavd0YAKPCDr9tbeVGgHs4jKdxe+lGKNm0+DG6hcAD2YPH8O89yRCdATrR8E02nAaLh9c7SLVfogEPHzVv2VE50SqgJhkiS07Cvz1Bp8AG9WUIv/PfFpgTI5p8f8pvyDyvrnsih9bfG4x9/jPY0D+XEYWVQ3jT8CZ0XpxdIE18PDVPNsmZhmvERJ5xyra2JjbI/B5WoWmlPnFSwNCHiDeV3ja0M2n43TetSA5Jxz6BqtfCueDE28/tW4x1EfuQZW9nEZgh/QLdlLSu8FEfxAQ2fij7j3lqqRbLpiUT0x+FFfA873kCZZt9gratxh+f22DSTdjWSms9l/RFRjLbo66dujaa1tp/hKdpnq0V9ZaFr7WrEpG3qj71xW3X3jU3boYOxLJZ0qMWEKOOSKcJyc2GzV78/hKdSnWNt3hY76D127YfHRSmJE+4f80DkB0WuE0t23PfkHsb9o4Ys7ejFIv5Zx/1OmxFLQO+wRvOjpXA+xNbhUidolEdLiEUcpb3oQSRAdmzdnjxwpV1N29+yslZwNrc9nhHLFZ1mgiyopYnuriSClyPmg7LF8LrAqMCrOPIRW1gPPXErsfc7bOWRIM5HDPtVq2hF1ojgoR33NFi2w46mMW1e06DedHG22QE/B46hRRFDpi7ZM5av5/gM2xZmXEXnfRJtgbOEBK/8ni5L6TXjEB5Rwvz4/c/QLuJ4e1Z0ASswfARPZSYVvcvSUx7yHYvYEnCewZ4tOCNkVx4l4RpROmBEHaIg+vlugik19AfJDCaKMhZW8sGPypZXZizdK6LZuoEkEW3XDvw1HUtrveu/7BhuB56Ych5UAwXEWCnpTc9ElSZ8atPWaD71LsKGKx9zahyb4LbpijVAA0pZpOqrVNZHw3OklnOMQmPIi+sWPWNAkzNIZKwoPA585HwxoUt+NWPIC0zqQtwlIlse9sZAnPk8QN5btqGUWCwXHUWQaUKYq3VKx4K5gc4CDX1YmC8FXd0AcFyxNtKx5DyliqmrF6SsYvVfK+ZElwHf86hpyM9hgx921M+Jmxnu0NvoKHueesRkXtib9cWgq/WFI+2tJjblpmJRRjl9mQaPRIRlsMlvf14ItvKbVFbG7jCTYIcQROykvSD7gO6rOgDhnhpkaaueo8acYVQah6uEBcmV7Am0tuAtpHc4aHgbZGl8uILbCKP3dCY6m3pHrTLQWYMi3yQhA2dGK+fGvZ9TKxLQL+w== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5008703f-31dd-40ed-0621-08dbc4ef116c X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2023 15:32:07.3072 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: /PD+MXNEgDBoKlkK9YgybczacMTZfGkSKm8wCBYND7GHXejMEgbjCIOAxmnaepxE+sUNTJI4JcMxcb+QCAZ9oQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7790 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This updates the btio module to decide whether to bind a listening socket to a broadcaster address or not, by looking at the dst address. --- btio/btio.c | 24 ++++++++++++++---------- profiles/audio/bap.c | 4 ++-- 2 files changed, 16 insertions(+), 12 deletions(-) diff --git a/btio/btio.c b/btio/btio.c index c6d056b89..d45b8240d 100644 --- a/btio/btio.c +++ b/btio/btio.c @@ -774,16 +774,21 @@ static int sco_bind(int sock, const bdaddr_t *src, GError **err) return 0; } -static int iso_bind(int sock, const bdaddr_t *src, uint8_t src_type, - const bdaddr_t *dst, uint8_t dst_type, - uint8_t bc_sid, uint8_t num_bis, - uint8_t *bis, GError **err) +static int iso_bind(int sock, bool server, const bdaddr_t *src, + uint8_t src_type, const bdaddr_t *dst, + uint8_t dst_type, uint8_t bc_sid, + uint8_t num_bis, uint8_t *bis, + GError **err) { struct sockaddr_iso *addr = NULL; size_t addr_len; int ret = 0; - if (num_bis) + /* If this is an ISO listener and the destination address + * is not BDADDR_ANY, the listener should be bound to the + * broadcaster address + */ + if (server && bacmp(dst, BDADDR_ANY)) addr_len = sizeof(*addr) + sizeof(*addr->iso_bc); else addr_len = sizeof(*addr); @@ -798,7 +803,7 @@ static int iso_bind(int sock, const bdaddr_t *src, uint8_t src_type, bacpy(&addr->iso_bdaddr, src); addr->iso_bdaddr_type = src_type; - if (num_bis) { + if (addr_len > sizeof(*addr)) { bacpy(&addr->iso_bc->bc_bdaddr, dst); addr->iso_bc->bc_bdaddr_type = dst_type; addr->iso_bc->bc_sid = bc_sid; @@ -1930,10 +1935,9 @@ static GIOChannel *create_io(gboolean server, struct set_opts *opts, return NULL; } - if (iso_bind(sock, &opts->src, opts->src_type, - &opts->dst, opts->dst_type, - opts->bc_sid, opts->bc_num_bis, - opts->bc_bis, err) < 0) + if (iso_bind(sock, server, &opts->src, opts->src_type, + &opts->dst, opts->dst_type, opts->bc_sid, + opts->bc_num_bis, opts->bc_bis, err) < 0) goto failed; if (!iso_set_qos(sock, &opts->qos, err)) goto failed; diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index d70ad872e..cab68f779 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -1566,9 +1566,9 @@ static void bap_listen_io(struct bap_data *data, struct bt_bap_stream *stream, BT_IO_OPT_SOURCE_BDADDR, btd_adapter_get_address(adapter), BT_IO_OPT_DEST_BDADDR, - device_get_address(data->device), + BDADDR_ANY, BT_IO_OPT_DEST_TYPE, - device_get_le_address_type(data->device), + BDADDR_LE_PUBLIC, BT_IO_OPT_MODE, BT_IO_MODE_ISO, BT_IO_OPT_QOS, qos, BT_IO_OPT_INVALID); From patchwork Wed Oct 4 15:31:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 13408911 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 7EE4EE7C4D4 for ; Wed, 4 Oct 2023 15:32:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233508AbjJDPcP (ORCPT ); Wed, 4 Oct 2023 11:32:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33282 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233495AbjJDPcO (ORCPT ); Wed, 4 Oct 2023 11:32:14 -0400 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2072.outbound.protection.outlook.com [40.107.241.72]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 585D3C4 for ; Wed, 4 Oct 2023 08:32:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fAt0ehYI8QBw2rOcqV70FOuG+ng2KOjC0FjhuQGH1RfzPj324HgtVQQBbMMJjtwtpoppcTFavRcI67TJMcHSqnJAi9ZO8HZ+NKuy2Fqw2nCYF0X+LbyBbho5N0AEtZm8/5TN+86XyCatzOMmshCvtwPe4HRAFuRJOskwiiWMFgLgEnxPmCXbVafu9I9BqN6HzMxZpX8LbANHhe7wxonsGJXdhuKpclhr1jewggJxmoPWxtnh0Q9GCgFsJM9T8b2DoQPttU5EbYQmmI2pcFMQB6Mf7vDy6HkO5xUCzmpuuXksHI5/58pCXh4LM3DX7f609fCxmsLmNRJs++3FAu1vIQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=XDVmGNFMaPG9C7QtsB0jzOLSXgDA5uxPcW8KfqSpvVc=; b=KMtSltrg+/QIKaYkSjGqjx+JdgzAZ2RI1MfHIpVcGhl3kFye9JR+JHCP9zNokhBWDlYAuHTREt22BSA1+fDgVh/1a2KJpF5t0YVwvgGvSS32cee1MjgEfQEqMZjUXC7m/ZqO7rG8cXpWQivQaXTV8riIBySkgBE7FMPUvWac+1m98IPYTz4ulhlb5sB7y/JusbCBrRD9wolk/ZbJuwU87QPvYDsa7hKbXGnTTtjjWztH+YPJeSrHYMKYums0rKC4OP9PloKVN8D04iYyzotWFQtTcnY1k0ZBZnheMq6L64joeO27lTq96U6Jm1xd9R4RBPRxhM/DDuriL9hYqYzf7w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XDVmGNFMaPG9C7QtsB0jzOLSXgDA5uxPcW8KfqSpvVc=; b=mhCF80T1cJhIq+N51QHJBYkOKnls1LEF11jofb5Uq8iVvsC0BiDuOFFhgrq1/jLMPJ9dUA2u00moslg5WHT9ht0SQ9ZyA5kgCeh6LBEwNLxUmzrnBo3+J0qKUlZOtQPikk9u+L8UfQl+lP9MbXE4dK9lDQmb/We8+2z73QrzPd0= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) by PA4PR04MB7790.eurprd04.prod.outlook.com (2603:10a6:102:cc::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.33; Wed, 4 Oct 2023 15:32:10 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7763:779b:1a89:47da]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7763:779b:1a89:47da%3]) with mapi id 15.20.6838.033; Wed, 4 Oct 2023 15:32:10 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, silviu.barbulescu@nxp.com, vlad.pruteanu@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Iulia Tanasescu Subject: [PATCH BlueZ 2/4] hciemu: Add support for setting emulator bdaddr Date: Wed, 4 Oct 2023 18:31:48 +0300 Message-Id: <20231004153150.3051-3-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231004153150.3051-1-iulia.tanasescu@nxp.com> References: <20231004153150.3051-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: VI1PR0202CA0024.eurprd02.prod.outlook.com (2603:10a6:803:14::37) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|PA4PR04MB7790:EE_ X-MS-Office365-Filtering-Correlation-Id: 84c2579a-4ba3-4317-de1e-08dbc4ef133c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: d2JDcb8oM/6VpRxJ0ALlwGyvNiSs6VBukYmNGt7CbmY8HG93NTP7cf6oFm4hdMiyCNQyWAY+P5MBWgBHeTbdu7bZOtAoHFqhfw56tTuxFt9RrH82FzS70DTcs2CeuSAFMB83J7QdlrGZxnZlbROjvdjxYym/tSKgOUMHHgtrWe4YpP0NDD0j/Wq7gArkQYdv+ZgffXG1WEnrN1nAmRGyi9JvReZqHi1MekIyScxql3YSIJUDN+LlxuoF8XrMI8z/LLhmmnVz/D0XrYM92UFGWdBNWcnUPynbjEa57ZLywAMd0nLWVwcYPVAbpvCootKzWzGJak+2QTERsburUMDLdVfniZWkqr3AOruamAVDd5TiRpC2OAjCJQtKbnXxEpSn5af3yfJaoBe53DGNTwA8h5Xswr8P/W4QBH6tiH64NzLq1k5Hu8UmkcjDy8Jnyd0z2gmIINwPBysTX32MwAktbIej3YDj/s47CTBxYV4g0dA6Hpat0MtCT2+EW09Er2oSjwILnFTr2WR2Wr4B1T2mKnVvapuORPq4C1NxJV4PFR/hNraTZ71n9hIgwmjVO7Nb X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR04MB8898.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(39860400002)(376002)(346002)(136003)(366004)(230922051799003)(451199024)(1800799009)(64100799003)(186009)(6486002)(6512007)(6506007)(478600001)(6666004)(38100700002)(86362001)(66476007)(2906002)(6916009)(4326008)(2616005)(26005)(1076003)(41300700001)(36756003)(66556008)(66946007)(8936002)(44832011)(5660300002)(316002)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: o20Jvv7pwM5HFpFnJvQkmFaNeCl8QmLEUKV5dOwNiyME0m/f8Vm9Q7jssSa39pjK3n43iEg+SAFycnLgYxINAHWc9xDr49prrSCc0gpTM7AbcIEfMoU7IRWZSVL/N+iMeKeJaZJFbwYXt9/Wlu4mRYmH5KQXqcKiU77ha9k9TcH9j9YxjqHr/lnJZN4t9zOY5qO0VVElZ9yfio6Pqm+HO6rObdYFqf5YCrd+SwOj3FLfiIvdQggVqKoqEIDDm06D32+avJapM8DXg8feYpKJ5Bqy8sC3JZZ3o0UdtTNHbtWxsBmBjDkuENQq8IQv7P/mXyBrbX+p+ZMZxEgpVbZiPdvaLj+R5Q4bKg9cjk61Uzy1Gk5jdvVit9xAtPFhlYiIybaVXrdAmUMnbYyKyXBoMBkM0/eaiqUk8/4lHS45gdoE8SGnFllCwGXEwSsnqHTZbAtbqGtX7GZ8Bzqt1VDoaPupsMhziKlnpKt0ahdPoS4v8nlrnNgl70rD0EzxdazlsQL4l1EGtK8IIK857Hg/UQ+heSFYivbsKLw/v7fU4PHQXf0PDtuEfxXsmsvPDKLlktpF/pghGFypQn96Vc+fkJTtrdgpYADFfpkHGrwixXv2DUhUpIPdJWSlz3FVqHg+Exv0+G81wW630ShmwURm72HfQuyk4s3n3TdaZmbMwobMiNxPUqtuRErQBrsXwsZeP2TTBLmkGlxsoa0UnGq2C0KpH88yJt4RKpmujJq/bckVTVbLsT+JKSMSBm5pYVclWeul40MAY68/vzGbH68j++ZRyffTGNDgcXcuvcIkywNaOWjcgLwZ79TD5Yqs9lMRDULodT+SRA0DAeJ2b51dm/ESrrrzi11Rie8jLwLlGRxgznKGiSPdwejVXSaevC6HTz1jYOMserIKj4VNzE4ohvH1y47PPER3sUGdw7uE57TMXG1O5cde8T2ISBFIRFKDZom4NzMQN3OHSfy7qjOwPLAmuT8GMW+aAIWjmEHzpRR6E5P8UnXLRYi5wFLQ2LO43/Gtkbkc8S75ednwUBrjFqpsGnExfpJ6ddyi5r5mm+1mdEPf/t7ou1JBtAqYxcN4V6jGcaFPRreHs+IWc3VbrBEzpGqHFrZVYfWtTCs9BjmaCNffJADeHeF93R83C7XHBMiZNwE11Vp/28mNF+dlw35sx5okKvVuXg0EtndJzzB3APvy+UhXSvpe8Db+juuhW+laR5thP1ZkHLyG2QkfSN1SVbWy4KmvTGHimbb9SgJ5z041gchE0Ev6cYcF3y3CvbSXuYVmVTKllV6+24qv+c5TX2jOQKjmlRbfrZSpAeg6Gg3PKaKr6Mlez3ns+aPoj/vqKZqgkDizV/hwcoFfs63zXK/tRhnIz4YPzmIxdWrSMCnzoxCCBxHG9MCV3QPBLBSxOgZiIXkbyeUuBUVQD2AdYcUo16Wa5nMKMcPg/u5sZfHCRaEZDjikvrcHHYlbb++VSDMHe8IVpbMnk3WTP33mQW/SNRuqC/Z/difbD6vvnEmysGoASepY36lv2S10hhIhz9aINSrU9H3ayWu4hlrn4ZfDi2WwAiVD95j1rwYoOhIcFFSp1v+0wdhw7wj5n8olyj49K7F/7fYX5W4EtA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 84c2579a-4ba3-4317-de1e-08dbc4ef133c X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2023 15:32:10.3035 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: DC3HUYRUCxHutIsa/RQbhqkq8waR53AoCKq3nLV0B0tGm/Py44N04qcj96VKcCFl0gxSAr7oPLDQvSd74OqjFg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7790 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds support for the user to explicitly set a desired bdaddr to a client emulator. --- emulator/hciemu.c | 9 +++++++++ emulator/hciemu.h | 2 ++ 2 files changed, 11 insertions(+) diff --git a/emulator/hciemu.c b/emulator/hciemu.c index 25874ded5..f13b4bda1 100644 --- a/emulator/hciemu.c +++ b/emulator/hciemu.c @@ -550,6 +550,15 @@ const uint8_t *hciemu_client_bdaddr(struct hciemu_client *client) return btdev_get_bdaddr(client->dev); } +bool hciemu_set_client_bdaddr(struct hciemu_client *client, + const uint8_t *bdaddr) +{ + if (!client) + return NULL; + + return btdev_set_bdaddr(client->dev, bdaddr); +} + const uint8_t *hciemu_get_client_bdaddr(struct hciemu *hciemu) { struct hciemu_client *client; diff --git a/emulator/hciemu.h b/emulator/hciemu.h index 3449eae41..dba920fdd 100644 --- a/emulator/hciemu.h +++ b/emulator/hciemu.h @@ -39,6 +39,8 @@ void hciemu_unref(struct hciemu *hciemu); struct hciemu_client *hciemu_get_client(struct hciemu *hciemu, int num); struct bthost *hciemu_client_host(struct hciemu_client *client); const uint8_t *hciemu_client_bdaddr(struct hciemu_client *client); +bool hciemu_set_client_bdaddr(struct hciemu_client *client, + const uint8_t *bdaddr); typedef void (*hciemu_debug_func_t)(const char *str, void *user_data); typedef void (*hciemu_destroy_func_t)(void *user_data); From patchwork Wed Oct 4 15:31:49 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 13408912 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 745B1E7C4CE for ; Wed, 4 Oct 2023 15:32:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233518AbjJDPcX (ORCPT ); Wed, 4 Oct 2023 11:32:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34010 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233495AbjJDPcW (ORCPT ); Wed, 4 Oct 2023 11:32:22 -0400 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2089.outbound.protection.outlook.com [40.107.241.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB503C9 for ; Wed, 4 Oct 2023 08:32:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=eKx8FTN6OhFCLsqEL3ibB/0MnFKcazfydRfvOUhz0b1NFrF/DE6z2LBRm6Zjl4CcY/OzmLYpLrOr0shuui+FXopdR4x0CHRdFdErgD/Qhi5Zzz1nKws9GU+yD7fMWYlwTJoYHHYhevXZJw5F7f5Ovf+VRvjFJ22THf29VOiSQ7R1Jjc/uCQ7sRbEjNQMiucQLCmEXcuNu30hCdi07OcxvHfB8gSnxqqsG32PfP6hsTTHZCs+IHbXVTEF4Klgu8TFPZWpPBqOoIjXZa/iuVcs9MeLjW2Tlo7ctFxUOKh6AEjBGiTmwVHBvILhs8/dWjDFNNuMWFd9Axi5HrLKEuO5Tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CHq6qJsCjeE/MxMfVNowA2Q8cHRC7JAXM72tjGyGsEg=; b=QJ3sHKZ2mcPwQ9mX8I1jSBbR0t+DS27TGG08n1qBy855GV2jZgzv3wbxjomdScSZLdpIWodC5rKXHl2d/m6ClzmgE9CHAAAcX+/TFYFMW1u2gO9Ad4TxAfKXeVuQvibndAR36lQjT9lLn8IZFFRp0sdwAnnOW3vCkUsc+8/YlWgK5IHWEheF5zx4xDFSE533i/wfEaf096rmXbPsZa7HsvKeydS56+YjzOWzuKJdYMMWyz0qHZCOABbap4YykHsD7dKKFMlkkWNgmK+Qe41Mdw49DF1hOH8ckQoGBIx1Mfy6w662MCyKSDA5nKJGk3f5f+rmpme454LiRoJ6VZXtaQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CHq6qJsCjeE/MxMfVNowA2Q8cHRC7JAXM72tjGyGsEg=; b=Az1RrBXSqyi8xsvuXnLVyaBorIskXemC2ziuwbPX/4GQ4s968pnw+t/o8WsKjQzcb8iWLJX2wuDM4zWm4mXbvNRy4qdJo8rwjUyR/+laOgVSxu18vubs20UQ94nCh3bc0PHu1HoEuoTXsFMA4u6fk4VaYydTuLEylJf2/FoCioY= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) by PA4PR04MB7790.eurprd04.prod.outlook.com (2603:10a6:102:cc::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.33; Wed, 4 Oct 2023 15:32:13 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7763:779b:1a89:47da]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7763:779b:1a89:47da%3]) with mapi id 15.20.6838.033; Wed, 4 Oct 2023 15:32:13 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, silviu.barbulescu@nxp.com, vlad.pruteanu@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Iulia Tanasescu Subject: [PATCH BlueZ 3/4] shared/bass: Add miscellaneous fixes Date: Wed, 4 Oct 2023 18:31:49 +0300 Message-Id: <20231004153150.3051-4-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231004153150.3051-1-iulia.tanasescu@nxp.com> References: <20231004153150.3051-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: VI1P195CA0067.EURP195.PROD.OUTLOOK.COM (2603:10a6:802:59::20) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|PA4PR04MB7790:EE_ X-MS-Office365-Filtering-Correlation-Id: 37efa8cf-b324-4d32-3a7b-08dbc4ef14f8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: SrbjfiuvZB+AbZ7t+tbNsDhIyn9E/mbJdOu3L0lOgkzO7GxBOr1sFjft0uy/5G2gEMcDY9c+ZE8zpm1ukj9UDgU5kP9qJoiK6nYQe/D7OAp53vY8HtIEWqTJ6ZIa2QTC4cuDp2L7pvhluLQmUVrJ4o7Dnl3F99QihEP79+aIQsaUl21axjk7CHKJFq5D551LkuwAokLj8DlyJKqA4ARtcqXPIy1xQSqN5GAbwT805u8Dh/9UGluqWew4vxRogsEsS6iuZnnbV8f9DTPZADCp6z9txmeo3b1SIEiJXoC11UsNTwQfHRkJiNHdkSESq1daQKachLt91lkM0ol6mLqVtL2oKk9SYkOGpARMJ7AwCPCRzGluw/5X86C/cDmhhyyQPwAtWoeJknO5km7OxIsDPZJL+zUj551S0OeVoJ0Br5HaFHYXd/iqpKhSrfkO9nKyEiwYWaHMEIRjZlidlZ42eVhQe1miicrnNRsThbB6vKqiBOZOawScYKR71LtGcSUQJ1QZqWaG0+2VCbe3dWaxO/ZUPHpJTlS35FxgeAN7JUJjMuRCZr4a5D+WEe62c9W6 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR04MB8898.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(39860400002)(376002)(346002)(136003)(366004)(230922051799003)(451199024)(1800799009)(64100799003)(186009)(6486002)(6512007)(6506007)(478600001)(6666004)(38100700002)(86362001)(66476007)(2906002)(6916009)(4326008)(83380400001)(2616005)(26005)(1076003)(41300700001)(36756003)(66556008)(66946007)(8936002)(44832011)(5660300002)(316002)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: tzeuL2u/mf8PJjJsbMZi/Wm6Jbic8k+5IVVrV4BKQiIPziM6rjEO31aSULCm8rYp0vxlYqSZAWBcOdJOQ9QNnPA19YqNMwrUpf6meyXVcwesAukgSIp1DDJMzXDF8u1eM6tK0Ogf+yPls9Hm9m7M4qmWEF4zM3r6XuBIknaul1DJc4qnLM+H6peOW/hLhN84rYfbRVQE0pvPtKqThwe60G4Y2YMYIdl5yclf2r+nitc8wXVZ+e+vQq6cY/IIsJ8d5TpQ7/On3Rntm3SgOupk2Cj+g2jfXwCsFU+IijoKIWlby8hWq0fWH2lzrmkNEfbWUCLh4qOwXm+tcxUOwVpgj7Egvd+90FH5UYsCiDITrlq4hnNKclAw2y5ZKf4ovnOFV7w+aLbPEpP7TizY+0Lcz8qCELrUK7HQ+YprhUa/JxB/hWWBGeebf7R0ghBfYnjvTZ72/9dtOk+lmv9EpTNo6ONhu1O4CqMoWgluJuaeC69GZvzcXlUUeze03Gvjn66Otn2480LZjvJHtRScqrWdOFSmrYtls0ZKHCzH8zjRVgUMKvTVvpu7K2WsFYLI94lVhm4cy+aMBl2Vda7RhBskVBNZGRmniNlv1H9Iby1PTSwxtAdihkHHiugupv5Vd0zSF3rFm7hw5iqa/J18KuTVKKKwg53uGoIFj6oX11/aArIvPGifkVhbZIswpSccq6d6CL0i3+0b0qnG5hwEUyPtv7XnlFklNdcYhLrdLUrjj2U/bScoocJOH3B2N9oO+ZR7Bjh5doMI5jjXntw+Gfm4YTyQaIHLgiSkDnR/5bgIn5vCnUe3tf/VIK93p6m85kRVM0qloOaty3ZsIOQ9V1XLUEq0Wfdem/gBv0gGq1dk/p3wEJUZeEmyIt9FRQji5LGba3184l2KGlyOrrVsjlSGWb+Nw4qK2gEJQGqa7RhuC8hZ3v5CS7f9WIphLvAYM+C0HrfpaTh7BswlpdiH5XmyOiKLrABWzCO9gsGmpzBiqyV934GNcQq7UU5UO0dwdwc0inOd6ItY5QqbqyAN+qXLFvCxtLgK2TlvVV2koCHA0axh7OEBXMA/1kOFCu6KZvto0FoWehIyUPsHjCeoqnOoWTA2qf7hylvzxnN2CH93ZAnh35VU1V/ZhYbfk0zEmJvIhgbFF7viEMpUxEFv+GuqaWsc+ZJ54qhvY0VyDO54unnRICS5tCqs1hpHs6ha8zZRSffBEYBFqTicZnLUqV5kLq9wjhOGUacEAEl704HCXhPi26g4JX40cAE1XLz3j6V6nPv9xqAHfTjl74gIHIC2iiS0Kms2/zeB/G54G3mLs/ZdTG158cZP7PSo02prpGf1mg6cL+YplEyc0qwWtVthZvdL5XkxHQNtcodH3vv+orzcCuItq387mMe2bQNqzyOyRF9gzlPBkGTdrY5RpznWtszYSV+qP0veepgLSC996wi1FHMDO8nUj9N+jT2mb/h5HeyZV5NTiAW3sOfhZ/ZWkrZ9dMMc9y/l696AXhMXk1x7t7ZLRmjcoHfjzGto3VEJ5d13z3Xyy7V4VXdMZVqYvS6g4AeIdZREbNEqmjGqAc1LAodBZvpmaYncjyibWYQhm7XfnPeBiVXMD4W/WT3Ebg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 37efa8cf-b324-4d32-3a7b-08dbc4ef14f8 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2023 15:32:13.2383 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: Sa4wMAos+/D840aEkJfQmCb8ECGDWzVp7evx8hIhFjtyTywoX+Mfj2NZWSfDU3k9E0m7JBTj7NoqQs1Y2fBPWQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7790 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This introduces miscellaneous BASS updates and fixes discovered during PTS testing. --- src/shared/bass.c | 179 +++++++++++++++++++++++++++++++++++----------- src/shared/bass.h | 1 + 2 files changed, 140 insertions(+), 40 deletions(-) diff --git a/src/shared/bass.c b/src/shared/bass.c index 86dab03e3..288e1c7c5 100644 --- a/src/shared/bass.c +++ b/src/shared/bass.c @@ -504,8 +504,7 @@ static void bass_handle_remote_scan_stopped_op(struct bt_bass *bass, struct iovec *iov, struct bt_att *att) { - if (opcode == BT_ATT_OP_WRITE_REQ) - gatt_db_attribute_write_result(attrib, id, 0x00); + gatt_db_attribute_write_result(attrib, id, 0x00); } static void bass_handle_remote_scan_started_op(struct bt_bass *bass, @@ -515,8 +514,7 @@ static void bass_handle_remote_scan_started_op(struct bt_bass *bass, struct iovec *iov, struct bt_att *att) { - if (opcode == BT_ATT_OP_WRITE_REQ) - gatt_db_attribute_write_result(attrib, id, 0x00); + gatt_db_attribute_write_result(attrib, id, 0x00); } static bool bass_src_id_match(const void *data, const void *match_data) @@ -536,6 +534,7 @@ static void bass_handle_remove_src_op(struct bt_bass *bass, { struct bt_bass_remove_src_params *params; struct bt_bcast_src *bcast_src; + int att_err = 0; /* Get Remove Source command parameters */ params = util_iov_pull_mem(iov, sizeof(*params)); @@ -546,33 +545,31 @@ static void bass_handle_remove_src_op(struct bt_bass *bass, if (!bcast_src) { /* No source matches the written source id */ - if (opcode == BT_ATT_OP_WRITE_REQ) - gatt_db_attribute_write_result(attrib, id, - BT_BASS_ERROR_INVALID_SOURCE_ID); - - return; + att_err = BT_BASS_ERROR_INVALID_SOURCE_ID; + goto done; } /* Ignore if server is synchronized to the PA * of the source */ if (bcast_src->sync_state == BT_BASS_SYNCHRONIZED_TO_PA) - return; + goto done; /* Ignore if server is synchronized to any BIS * of the source */ for (int i = 0; i < bcast_src->num_subgroups; i++) if (bcast_src->subgroup_data[i].bis_sync) - return; + goto done; /* Accept the operation and remove source */ queue_remove(bass->ldb->bcast_srcs, bcast_src); gatt_db_attribute_notify(bcast_src->attr, NULL, 0, att); bass_bcast_src_free(bcast_src); - if (opcode == BT_ATT_OP_WRITE_REQ) - gatt_db_attribute_write_result(attrib, id, 0x00); +done: + gatt_db_attribute_write_result(attrib, id, + att_err); } static bool bass_src_attr_match(const void *data, const void *match_data) @@ -692,6 +689,21 @@ static void connect_cb(GIOChannel *io, GError *gerr, free(notify_data); } +static bool bass_trigger_big_sync(struct bt_bcast_src *bcast_src) +{ + for (int i = 0; i < bcast_src->num_subgroups; i++) { + struct bt_bass_subgroup_data *data = + &bcast_src->subgroup_data[i]; + + if (data->pending_bis_sync && + data->pending_bis_sync != BIS_SYNC_NO_PREF) + return true; + } + + return false; +} + + static void confirm_cb(GIOChannel *io, gpointer user_data) { struct bt_bcast_src *bcast_src = user_data; @@ -729,12 +741,17 @@ static void confirm_cb(GIOChannel *io, gpointer user_data) /* BIG is not encrypted. Try to synchronize */ bcast_src->enc = BT_BASS_BIG_ENC_STATE_NO_ENC; - if (!bt_io_bcast_accept(bcast_src->pa_sync_io, - connect_cb, bcast_src, NULL, &gerr)) { - DBG(bcast_src->bass, "bt_io_accept: %s", gerr->message); - g_error_free(gerr); + if (bass_trigger_big_sync(bcast_src)) { + if (!bt_io_bcast_accept(bcast_src->pa_sync_io, + connect_cb, bcast_src, NULL, &gerr)) { + DBG(bcast_src->bass, "bt_io_accept: %s", + gerr->message); + g_error_free(gerr); + } + return; } - return; + + goto notify; } /* BIG is encrypted. Wait for Client to provide the Broadcast_Code */ @@ -773,6 +790,60 @@ static struct bt_bass *bass_get_session(struct bt_att *att, struct gatt_db *db, return bass; } +static bool bass_validate_bis_sync(uint8_t num_subgroups, + struct iovec *iov) +{ + uint32_t bis_sync_state; + uint32_t bitmask = 0U; + uint8_t *meta_len; + + for (int i = 0; i < num_subgroups; i++) { + util_iov_pull_le32(iov, &bis_sync_state); + + if (bis_sync_state != BIS_SYNC_NO_PREF) + for (int bis_idx = 0; bis_idx < 31; bis_idx++) { + if (bis_sync_state & (1 << bis_idx)) { + if (bitmask & (1 << bis_idx)) + return false; + + bitmask |= (1 << bis_idx); + } + } + + meta_len = util_iov_pull_mem(iov, + sizeof(*meta_len)); + util_iov_pull_mem(iov, *meta_len); + } + + return true; +} + +static bool bass_validate_add_src_params(uint8_t *value, size_t len) +{ + struct bt_bass_add_src_params *params; + struct iovec iov = { + .iov_base = (void *)value, + .iov_len = len, + }; + + params = util_iov_pull_mem(&iov, sizeof(*params)); + + if (params->pa_sync > PA_SYNC_NO_PAST) + return false; + + if (params->addr_type > 0x01) + return false; + + if (params->sid > 0x0F) + return false; + + if (!bass_validate_bis_sync(params->num_subgroups, + &iov)) + return false; + + return true; +} + static void bass_handle_add_src_op(struct bt_bass *bass, struct gatt_db_attribute *attrib, uint8_t opcode, @@ -791,9 +862,13 @@ static void bass_handle_add_src_op(struct bt_bass *bass, uint8_t bis[ISO_MAX_NUM_BIS]; uint8_t *notify_data; size_t notify_data_len; + uint8_t addr_type; + + gatt_db_attribute_write_result(attrib, id, 0x00); - if (opcode == BT_ATT_OP_WRITE_REQ) - gatt_db_attribute_write_result(attrib, id, 0x00); + /* Ignore operation if parameters are invalid */ + if (!bass_validate_add_src_params(iov->iov_base, iov->iov_len)) + return; /* Allocate a new broadcast source */ bcast_src = malloc(sizeof(*bcast_src)); @@ -856,10 +931,8 @@ static void bass_handle_add_src_op(struct bt_bass *bass, bcast_src->id = src_id; /* Populate broadcast source fields from command parameters */ - if (*(uint8_t *)util_iov_pull_mem(iov, sizeof(bcast_src->addr_type))) - bcast_src->addr_type = BDADDR_LE_RANDOM; - else - bcast_src->addr_type = BDADDR_LE_PUBLIC; + bcast_src->addr_type = *(uint8_t *)util_iov_pull_mem(iov, + sizeof(bcast_src->addr_type)); bacpy(&bcast_src->addr, (bdaddr_t *)util_iov_pull_mem(iov, sizeof(bdaddr_t))); @@ -919,7 +992,13 @@ static void bass_handle_add_src_op(struct bt_bass *bass, data->meta_len), data->meta_len); } - if (pa_sync != PA_SYNC_NO_SYNC && num_bis > 0) { + if (pa_sync != PA_SYNC_NO_SYNC) { + /* Convert to three-value type */ + if (bcast_src->addr_type) + addr_type = BDADDR_LE_RANDOM; + else + addr_type = BDADDR_LE_PUBLIC; + /* If requested by client, try to synchronize to the source */ io = bt_io_listen(NULL, confirm_cb, bcast_src, NULL, &err, BT_IO_OPT_SOURCE_BDADDR, @@ -927,7 +1006,7 @@ static void bass_handle_add_src_op(struct bt_bass *bass, BT_IO_OPT_DEST_BDADDR, &bcast_src->addr, BT_IO_OPT_DEST_TYPE, - bcast_src->addr_type, + addr_type, BT_IO_OPT_MODE, BT_IO_MODE_ISO, BT_IO_OPT_QOS, &iso_qos, BT_IO_OPT_ISO_BC_SID, bcast_src->sid, @@ -944,7 +1023,7 @@ static void bass_handle_add_src_op(struct bt_bass *bass, bcast_src->listen_io = io; g_io_channel_ref(bcast_src->listen_io); - if (!bcast_src->bises) + if (num_bis > 0 && !bcast_src->bises) bcast_src->bises = queue_new(); } else { for (int i = 0; i < bcast_src->num_subgroups; i++) @@ -988,9 +1067,8 @@ static void bass_handle_set_bcast_code_op(struct bt_bass *bass, socklen_t len; struct bt_iso_qos qos; GError *gerr = NULL; - - if (opcode == BT_ATT_OP_WRITE_REQ) - gatt_db_attribute_write_result(attrib, id, 0x00); + uint8_t *notify_data; + size_t notify_data_len; /* Get Set Broadcast Code command parameters */ params = util_iov_pull_mem(iov, sizeof(*params)); @@ -1001,13 +1079,29 @@ static void bass_handle_set_bcast_code_op(struct bt_bass *bass, if (!bcast_src) { /* No source matches the written source id */ - if (opcode == BT_ATT_OP_WRITE_REQ) - gatt_db_attribute_write_result(attrib, id, + gatt_db_attribute_write_result(attrib, id, BT_BASS_ERROR_INVALID_SOURCE_ID); return; } + gatt_db_attribute_write_result(attrib, id, 0x00); + + if (!bass_trigger_big_sync(bcast_src)) { + bcast_src->enc = BT_BASS_BIG_ENC_STATE_DEC; + + notify_data = bass_build_notif_from_bcast_src(bcast_src, + ¬ify_data_len); + + gatt_db_attribute_notify(bcast_src->attr, + (void *)notify_data, + notify_data_len, + bt_bass_get_att(bcast_src->bass)); + + free(notify_data); + return; + } + /* Try to sync to the source using the * received broadcast code */ @@ -1091,10 +1185,8 @@ static void bass_bcast_audio_scan_cp_write(struct gatt_db_attribute *attrib, /* Validate written command length */ if (!bass_check_cp_command_len(value, len)) { - if (opcode == BT_ATT_OP_WRITE_REQ) { - gatt_db_attribute_write_result(attrib, id, - BT_ERROR_WRITE_REQUEST_REJECTED); - } + gatt_db_attribute_write_result(attrib, id, + BT_ERROR_WRITE_REQUEST_REJECTED); return; } @@ -1110,10 +1202,8 @@ static void bass_bcast_audio_scan_cp_write(struct gatt_db_attribute *attrib, } /* Send error response if unsupported opcode was written */ - if (opcode == BT_ATT_OP_WRITE_REQ) { - gatt_db_attribute_write_result(attrib, id, - BT_BASS_ERROR_OPCODE_NOT_SUPPORTED); - } + gatt_db_attribute_write_result(attrib, id, + BT_BASS_ERROR_OPCODE_NOT_SUPPORTED); } static bool bass_src_match_attrib(const void *data, const void *match_data) @@ -1459,6 +1549,15 @@ bool bt_bass_attach(struct bt_bass *bass, struct bt_gatt_client *client) return true; } +bool bt_bass_set_att(struct bt_bass *bass, struct bt_att *att) +{ + if (!bass) + return false; + + bass->att = att; + return true; +} + static void bass_detached(void *data, void *user_data) { struct bt_bass_cb *cb = data; diff --git a/src/shared/bass.h b/src/shared/bass.h index b3f83b32e..c4b5b76ba 100644 --- a/src/shared/bass.h +++ b/src/shared/bass.h @@ -131,5 +131,6 @@ struct bt_bass *bt_bass_new(struct gatt_db *ldb, struct gatt_db *rdb, bool bt_bass_set_user_data(struct bt_bass *bass, void *user_data); void bt_bass_unref(struct bt_bass *bass); bool bt_bass_attach(struct bt_bass *bass, struct bt_gatt_client *client); +bool bt_bass_set_att(struct bt_bass *bass, struct bt_att *att); void bt_bass_detach(struct bt_bass *bass); void bt_bass_add_db(struct gatt_db *db, const bdaddr_t *adapter_bdaddr); From patchwork Wed Oct 4 15:31:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 13408913 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 30127E7C4D4 for ; Wed, 4 Oct 2023 15:32:25 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233495AbjJDPc0 (ORCPT ); Wed, 4 Oct 2023 11:32:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34072 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233523AbjJDPcZ (ORCPT ); Wed, 4 Oct 2023 11:32:25 -0400 Received: from EUR02-VI1-obe.outbound.protection.outlook.com (mail-vi1eur02on2089.outbound.protection.outlook.com [40.107.241.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D6E1ABD for ; Wed, 4 Oct 2023 08:32:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XBrEU3Y2E86JkXiLy6cY5B+p6DzzqEjgoEo68UdQQDgOxv+m+88lfCw1NExllsuhn+6blxyYJFjk+TQZVYWNNfzmRSTCFSHCGPjMMRF6IC00kNQ4LaAe3LGI0uC7suBbWbfy4EHuFLk0uHayO/lSQS6km/J1YzBqDpdGL19ueyPzzXhD/BwwuRewGgCt5Fa9fJJDIN+bR9ZzkHJwzyY2eCX1uFYD2cAWL6wsgNISvg08DAqMHs1GCm1ZJks6glpP5g+ZowHSc230CTh3sSlxXgtaS3/RwTFI5hO2bJyZufDnlh8uSx8CGnqN+zhMOMIz+uzYxHpmGrs5QKZH6ktikA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=vEPpdqhuq9g/mY5mmM01Vp3t/co5CyYSqwh/DYBBQ4k=; b=mbTzXjVnaH6FHJR9CRCahxNxAyo2DS+lIdZTvTney7KysMHaU+mtZg5YLRVo+4cFmqNJbRASx9fHL0MOZ1sDSCNUrKBuxOoINDmed886kRaAEZv158WjoRJvwpwCtCV/xUjiimyCSl6UcgngYF+6hQIy2iZkC4npk6NkQqk9aDkjmc1iz/IDC2PXXKNi/cQtX8vohImFqC4VVWzjuk2ESdbTbbFZgQERex8p8Mrd5dxaSXzut1FSKmVPVi7UCH1K5GJnEoKV6di8ldarqZU2XiViAvNd6Qw/NMxqh5a0TbDyB21R1GL3mIomImNBk9Gobp5zhnpb9K8vnYOSRAq8kw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector2; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=vEPpdqhuq9g/mY5mmM01Vp3t/co5CyYSqwh/DYBBQ4k=; b=rUASf2e0LaAlNub2M387D28NZMHBZEILB6rK0AaYQptKhw3q6OVz3icOIeac2JRaStuWttL8Hi+q0V8GEOi8xRh0RppMcrZYbsTpFYjfOuAwQF+WOd3zWkStGgoZO+CPG/aTPdMKKv3bhBKqOKDnQzTGd/eUficlVBxZVtmdQVE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) by PA4PR04MB7790.eurprd04.prod.outlook.com (2603:10a6:102:cc::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6838.33; Wed, 4 Oct 2023 15:32:17 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7763:779b:1a89:47da]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7763:779b:1a89:47da%3]) with mapi id 15.20.6838.033; Wed, 4 Oct 2023 15:32:17 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, silviu.barbulescu@nxp.com, vlad.pruteanu@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Iulia Tanasescu Subject: [PATCH BlueZ 4/4] test-bass: Add unit tests for the SPE suite Date: Wed, 4 Oct 2023 18:31:50 +0300 Message-Id: <20231004153150.3051-5-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231004153150.3051-1-iulia.tanasescu@nxp.com> References: <20231004153150.3051-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: VI1PR07CA0283.eurprd07.prod.outlook.com (2603:10a6:800:130::11) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|PA4PR04MB7790:EE_ X-MS-Office365-Filtering-Correlation-Id: 02e93b51-8d14-4a20-8f03-08dbc4ef172f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: XUeGoD9o20TMyjzFp+a2qYuIceQeOFTJefukbaHnIoqVbDbTaCI5s9G4N5XvorkfCha5ZJYi7b6zXVCyRlGu7tJ/4ZpWLkmVv0fLsMbcuBnvAlFNOmhfUXQzU2LUwk1cYhgvaDWBKA+daK1B9OlygT2DGn1HkpgFWZyNDHP9NijbER33zopmyBdvLoyjfx++rL1ePgVtjc/+b5GKzetxtyFxX8NiMxcry14P42o4cUvqo49PCRjQce4dxVmyUIumJmaVqvj5sfnDT00Sr++Rq8yFHJ0Mo5RUBBB7ZRYoM6nRkC2UwZRCCK1TT299zIfzUhSAyZP8LxQZPv/ZePzFdrm3b7yc8/A7PuuDfX6fn1Eb+1xe2Xpm4Sz54C/KTvsBBvWji+DJ+Ilthu+Bv5H2VNf58fauwhgVPRwQnHW5dJocMleJZKB+LpvbQuCGmWKtx3YedKQixcYIUeLTuJjD65WBOl68QwoWXjBAtjfJH6jFqdwN/+bNGBtXIDPyMTcd8b3J/UDioYPuiIuZG8B8/Ab0fgU1LblqeFc1c9G52BRYob7AHizdpoMLbG+3MMpb X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR04MB8898.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230031)(396003)(39860400002)(376002)(346002)(136003)(366004)(230922051799003)(451199024)(1800799009)(64100799003)(186009)(6486002)(6512007)(6506007)(478600001)(6666004)(38100700002)(86362001)(30864003)(66476007)(2906002)(6916009)(4326008)(83380400001)(2616005)(26005)(1076003)(41300700001)(36756003)(66556008)(66946007)(8936002)(44832011)(5660300002)(316002)(8676002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 9HLlVwhPpgwiGP0aNAfLvTWLVORIxSU+BUiEzokh5Up6AUcMYQg6mz4ujlM2D6sSIFh37+SIg75twfvIMnyf2vOALX4ShNI1Ptfbz0ZGFwObZSvvogmHqwiVQShB11v4T/Ou6b4M8ltz3F/6+FTayvic7nu9hB0BjBnqBdwiUO3YIa8vX6R0fwirZ2/KkAIR3S6+AgZOCRRHY4BV2ODrBlDjGudSJeOx5WWhGBh2pBkFZQOwazydrcdyNwo6EM1ZfBF3U/spPCynCzCQ8RcnDLfukKrgHUVupGDPF1VYdv4FR6pd+iEhqbZohDGxnIpb2mxu2kwMJa6CYQz+ROTno8xumJX/cYzv53fGZqoB+5N/L9SvN44BK7s86FtJ8tE775jivzH0PnGMPxqxQEna3tWA1aRMs6hLrvkYfYp/Z2BkKdHZNCeC5YDjqG08UF5hmyOmj9vNbYGmanfifihdvUSdaMWnltDIHC3yTirkPa7wmah0rUyJVMBOKSuF/RdKmznQDkfVLyWzgbShP6+73P0SjVEv2bAclSREKe8xsmc2KmvjXjSfKxKUlGPb8D01Z1dG5/q+Zgvrf9VaQRVqQTYRN878ZfhlxSFDQINzs1UGIKWExJW8myTsCpIzIUrEqC1N4QGbGlwFHqOFleWHO2Zp5qoZKoPNPQFij5CsAIePasOjxU3MK8CDK2f7chycuAtwQp+Cd60BL75kPIw4C/JYhoLkpjBcAOVoTeD6d+0H9tD9K1d4KrKAYJ3L1Qihf2IPvzqhsLidxz4NA23zfngtvzkv6piriDb7q+Vy9uXeryNYAT4azR1xdvC+8gAl0Leoa+NZ2iwd9vNI3iXzC4lubNOYFF3QsOVlxW6FPlFm4gqrsBNm7OnvXpZRVu5j2YCBNZaXhldldRhGtVh5CPXkY6VhWoH9LAUIcPxYupuSsligbE27xAsx5r6VlpdknJf3+9xQg4eR0CDrN5BYGjWlXDBcDe6BltD/c9+KfYxx5cIY5fpNvSNJlk/LnC4nUFtIwk6IZF3krcIaIh6tHuk6mfgprQND0d3fa56zGpLDbVeLNaqdqd3DFn7q3aCiBSEnCX0e4aOhSDwqGRN29AoLUT87oTxiBOsBDE1gOPn11up0Q3FxcplTijVJPpQjhGbey4BodbrHOk2oTtrOyv0OpcFHDABCGWszRR0cejMpkTnvZ+0DF1ZIIH0njPup1JDwKg51fz+0/Xhp/opiX9aeNla/TAX8whUF84khR7Sf9us6ruNbQNlEkPRFNOvzUEnLQrH5lXPECZkt2Ql8z0w8ldBEZiqTWMDpL52JBOa+a6X6dHN/mE2mxZ6ZUxgFJz3ygRCvPB8kRnHPz6G45M1nO+6TAEA9Yh47lVNo0QnJXPxUMh7RZsPpI/5Y2HEtK0Of3ALj0oIfPdnZ0ojE90PXDPNpp9f79Cvx8g0U3Q223IM7XiNkzmxFhcXGfmtPdB3Vfx3Tjvn5nptdASJciqwFqFiq3IlJrtmUjsZFIBdJfW5+fswaUbOAbWbS6OFwOOr/k01yG3prTvs3y0JIk11Bls3fv9GBUaauw/NXEPlDWXrvrcI/ACv5JvKTLFUZ7s9xEwdXygxSyCsBND9YOg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 02e93b51-8d14-4a20-8f03-08dbc4ef172f X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 04 Oct 2023 15:32:17.0513 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: jmAQPxujFdUuENDGrBPw2vY/3IMzUMjIu0pppMSaJ5o1PwhQ9d1a6ZD4dEVFa0Ck+zqethaSXUUlRMRHA0A0Iw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA4PR04MB7790 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds BASS unit tests for the Service Procedures Error Handling suite. Some unit tests require the BASS Server to synchronize to a broadcast source, as instructed by a BASS Client. For this, a testing framework was added similar to the one used by iso-tester, to emulate hardware. --- Makefile.am | 7 +- unit/test-bass.c | 781 ++++++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 775 insertions(+), 13 deletions(-) diff --git a/Makefile.am b/Makefile.am index 30db74a0c..088f5aaef 100644 --- a/Makefile.am +++ b/Makefile.am @@ -581,7 +581,12 @@ unit_test_bap_LDADD = src/libshared-glib.la \ unit_tests += unit/test-bass -unit_test_bass_SOURCES = unit/test-bass.c $(btio_sources) +unit_test_bass_SOURCES = unit/test-bass.c $(btio_sources) monitor/bt.h \ + emulator/hciemu.h emulator/hciemu.c \ + emulator/vhci.h emulator/vhci.c \ + emulator/btdev.h emulator/btdev.c \ + emulator/bthost.h emulator/bthost.c \ + emulator/smp.c unit_test_bass_LDADD = src/libshared-glib.la \ lib/libbluetooth-internal.la $(GLIB_LIBS) diff --git a/unit/test-bass.c b/unit/test-bass.c index 2ab61f760..4407bb4d3 100644 --- a/unit/test-bass.c +++ b/unit/test-bass.c @@ -18,13 +18,22 @@ #include #include +#include + #include #include "lib/bluetooth.h" #include "lib/uuid.h" +#include "lib/mgmt.h" + +#include "monitor/bt.h" +#include "emulator/bthost.h" +#include "emulator/hciemu.h" + #include "src/shared/util.h" #include "src/shared/io.h" #include "src/shared/tester.h" +#include "src/shared/mgmt.h" #include "src/shared/queue.h" #include "src/shared/att.h" #include "src/shared/gatt-db.h" @@ -39,6 +48,9 @@ struct test_data { struct queue *ccc_states; size_t iovcnt; struct iovec *iov; + struct mgmt *mgmt; + uint16_t mgmt_index; + struct hciemu *hciemu; }; struct ccc_state { @@ -190,16 +202,397 @@ struct ccc_state { DISC_BCAST_AUDIO_SCAN_CP, \ BASS_READ_CHAR_DESC +/* ATT: Write Request (0x12) len 4 + * Handle: 0x0004 Type: Client Characteristic Configuration (0x2902) + * Data: 0100 + * Notification (0x01) + * ATT: Write Response (0x13) len 0 + * ATT: Write Request (0x12) len 4 + * Handle: 0x0007 Type: Client Characteristic Configuration (0x2902) + * Data: 0100 + * Notification (0x01) + * ATT: Write Response (0x13) len 0 + */ +#define BASS_WRITE_CHAR_DESC \ + IOV_DATA(0x12, 0x04, 0x00, 0x01, 0x00), \ + IOV_DATA(0x13), \ + IOV_DATA(0x12, 0x07, 0x00, 0x01, 0x00), \ + IOV_DATA(0x13) + +/* ATT: Read Request (0x0a) len 2 + * Handle: 0x0003 Type: Broadcast Receive State (0x2bc8) + * ATT: Read Response (0x0b) len 0 + * Handle: 0x0003 Broadcast Receive State (0x2bc8) + * ATT: Read Request (0x0a) len 2 + * Handle: 0x0006 Type: Broadcast Receive State (0x2bc8) + * ATT: Read Response (0x0b) len 0 + * Handle: 0x0006 Broadcast Receive State (0x2bc8) + */ +#define BASS_READ_BCAST_RECV_STATE_CHARS \ + IOV_DATA(0x0a, 0x03, 0x00), \ + IOV_DATA(0x0b), \ + IOV_DATA(0x0a, 0x06, 0x00), \ + IOV_DATA(0x0b) + +#define BASS_CP_WRITE_CMD(_op, _args...) \ + IOV_DATA(0x52, 0x09, 0x00, _op, _args) + +#define BASS_CP_WRITE_REQ(_op, _args...) \ + IOV_DATA(0x12, 0x09, 0x00, _op, _args) + +/* ATT: Write Command (0x52) len 19 + * Handle: 0x0009 Type: Broadcast Audio Scan Control Point (0x2bc7) + * Data: 0401693C4572685526613465597073275455 + * Opcode: Set Broadcast_Code + * Source_ID: 1 + * Broadcast_Code: 0x55542773705965346126556872453c69 + * ATT: Write Command (0x52) len 2 + * Handle: 0x0009 Type: Broadcast Audio Scan Control Point (0x2bc7) + * Data: 0501 + * Opcode: Remove Source + * Source_ID: 1 + */ +#define IGNORE_INVALID_SRC_ID \ + EXCHANGE_MTU, \ + BASS_FIND_BY_TYPE_VALUE, \ + DISC_BASS_CHAR, \ + BASS_FIND_INFO, \ + BASS_WRITE_CHAR_DESC, \ + BASS_READ_BCAST_RECV_STATE_CHARS, \ + BASS_CP_WRITE_CMD(0x04, 0x01, 0x69, 0x3C, 0x45, 0x72, 0x68, \ + 0x55, 0x26, 0x61, 0x34, 0x65, 0x59, 0x70, \ + 0x73, 0x27, 0x54, 0x55), \ + IOV_NULL, \ + BASS_CP_WRITE_CMD(0x05, 0x01) + +/* ATT: Write Command (0x52) len 26 + * Handle: 0x0009 Type: Broadcast Audio Scan Control Point (0x2bc7) + * Data: 0200F2698BE807C0003412000610270200000000000000000000 + * Opcode: Add Source + * Advertiser_Address_Type: Public Device or Public Identity Address + * Advertiser_Address: c0:07:e8:8b:69:f2 + * Advertising_SID: 0x00 + * Broadcast_ID: 0x001234 + * PA_Sync: 0x06 (Reserved for Future Use) + * PA_Interval: 0x2710 + * Num_Subgroups: 2 + * Subgroup #0: + * BIS_Sync: 00000000000000000000000000000000 + * Metadata_Length: 0 + * Subgroup #1: + * BIS_Sync: 00000000000000000000000000000000 + * Metadata_Length: 0 + * ATT: Write Command (0x52) len 26 + * Handle: 0x0009 Type: Broadcast Audio Scan Control Point (0x2bc7) + * Data: 0205F2698BE807C0003412000210270200000000000000000000 + * Opcode: Add Source + * Advertiser_Address_Type: 0x05 (Reserved for Future Use) + * Advertiser_Address: c0:07:e8:8b:69:f2 + * Advertising_SID: 0x00 + * Broadcast_ID: 0x001234 + * PA_Sync: Synchronize to PA (PAST not available) + * PA_Interval: 0x2710 + * Num_Subgroups: 2 + * Subgroup #0: + * BIS_Sync: 00000000000000000000000000000000 + * Metadata_Length: 0 + * Subgroup #1: + * BIS_Sync: 00000000000000000000000000000000 + * Metadata_Length: 0 + * ATT: Write Command (0x52) len 26 + * Handle: 0x0009 Type: Broadcast Audio Scan Control Point (0x2bc7) + * Data: 0200F2698BE807C0003412000210270201000000000100000000 + * Opcode: Add Source + * Advertiser_Address_Type: Public Device or Public Identity Address + * Advertiser_Address: c0:07:e8:8b:69:f2 + * Advertising_SID: 0x00 + * Broadcast_ID: 0x001234 + * PA_Sync: Synchronize to PA (PAST not available) + * PA_Interval: 0x2710 + * Num_Subgroups: 2 + * Subgroup #0: + * BIS_Sync: 00000000000000000000000000000001 + * Metadata_Length: 0 + * Subgroup #1: + * BIS_Sync: 00000000000000000000000000000001 + * Metadata_Length: 0 + */ +#define ADD_SRC_INVALID_PARAMS \ + EXCHANGE_MTU, \ + BASS_FIND_BY_TYPE_VALUE, \ + DISC_BASS_CHAR, \ + BASS_FIND_INFO, \ + BASS_WRITE_CHAR_DESC,\ + BASS_READ_BCAST_RECV_STATE_CHARS, \ + BASS_CP_WRITE_CMD(0x02, 0x00, 0xF2, 0x69, 0x8B, 0xE8, 0x07, 0xC0, \ + 0x00, 0x34, 0x12, 0x00, 0x06, 0x10, 0x27, 0x02, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00), \ + IOV_NULL, \ + BASS_CP_WRITE_CMD(0x02, 0x05, 0xF2, 0x69, 0x8B, 0xE8, 0x07, 0xC0, \ + 0x00, 0x34, 0x12, 0x00, 0x02, 0x10, 0x27, 0x02, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00), \ + IOV_NULL, \ + BASS_CP_WRITE_CMD(0x02, 0x05, 0xF2, 0x69, 0x8B, 0xE8, 0x07, 0xC0, \ + 0x3F, 0x34, 0x12, 0x00, 0x02, 0x10, 0x27, 0x02, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, \ + 0x00, 0x00), \ + IOV_NULL, \ + BASS_CP_WRITE_CMD(0x02, 0x00, 0xF2, 0x69, 0x8B, 0xE8, 0x07, 0xC0, \ + 0x00, 0x34, 0x12, 0x00, 0x02, 0x10, 0x27, 0x02, \ + 0x01, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, \ + 0x00, 0x00) + +/* ATT: Write Request (0x12) len 3 + * Handle: 0x0009 Type: Broadcast Audio Scan Control Point (0x2bc7) + * Data: FF + * Opcode: 0xff (Reserved For Future Use) + * ATT: Error Response (0x01) len 4 + * Write Request (0x12) + * Handle: 0x0009 + * Error: Opcode Not Supported (0x80) + */ +#define OPCODE_NOT_SUPPORTED \ + EXCHANGE_MTU, \ + BASS_FIND_BY_TYPE_VALUE, \ + DISC_BASS_CHAR, \ + BASS_FIND_INFO, \ + BASS_WRITE_CHAR_DESC,\ + BASS_READ_BCAST_RECV_STATE_CHARS, \ + BASS_CP_WRITE_REQ(0xFF), \ + IOV_DATA(0x01, 0x12, 0x09, 0x00, 0x80) + +/* ATT: Write Command (0x52) len 26 + * Handle: 0x0009 Type: Broadcast Audio Scan Control Point (0x2bc7) + * Data: 0200F2698BE807C000F5D983021027010000000000 + * Opcode: Add Source + * Advertiser_Address_Type: Public Device or Public Identity Address + * Advertiser_Address: c0:07:e8:8b:69:f2 + * Advertising_SID: 0x00 + * Broadcast_ID: 0x83d9f5 + * PA_Sync: Synchronize to PA (PAST not available) + * PA_Interval: 0x2710 + * Num_Subgroups: 1 + * Subgroup #0: + * BIS_Sync: 00000000000000000000000000000000 + * Metadata_Length: 0 + * ATT: Handle Value Notification (0x1b) len 22 + * Handle: 0x0003 Type: Broadcast Receive State (0x2bc8) + * Data: 0100F2698BE807C000F5D9830200010000000000 + * Source_ID: 0x01 + * Source_Address_Type: Public Device or Public Identity Address + * Source_Address: c0:07:e8:8b:69:f2 + * Source_Adv_SID: 0x00 + * Broadcast_ID: 0x83d9f5 + * PA_Sync_State: Synchronized to PA + * BIG_Encryption: Not encrypted + * Num_Subgroups: 1 + * Subgroup #0: + * BIS_Sync State: 00000000000000000000000000000000 + * Metadata_Length: 0 + * ATT: Read Request (0x0a) len 2 + * Handle: 0x0003 Type: Broadcast Receive State (0x2bc8) + * ATT: Read Response (0x0b) len 20 + * Handle: 0x0003 Broadcast Receive State (0x2bc8) + * Source_ID: 0x01 + * Source_Address_Type: Public Device or Public Identity Address + * Source_Address: c0:07:e8:8b:69:f2 + * Source_Adv_SID: 0x00 + * Broadcast_ID: 0x83d9f5 + * PA_Sync_State: Synchronized to PA + * BIG_Encryption: Not encrypted + * Num_Subgroups: 1 + * Subgroup #0: + * BIS_Sync State: 00000000000000000000000000000000 + * Metadata_Length: 0 + * ATT: Write Request (0x12) len 2 + * Handle: 0x0009 Type: Broadcast Audio Scan Control Point (0x2bc7) + * Data: 0501 + * Opcode: Remove Source + * Source_ID: 1 + * ATT: Write Response (0x13) len 0 + * Handle: 0x0009 Type: Broadcast Audio Scan Control Point (0x2bc7) + */ +#define RM_SRC_WHILE_SYNC \ + EXCHANGE_MTU, \ + BASS_FIND_BY_TYPE_VALUE, \ + DISC_BASS_CHAR, \ + BASS_FIND_INFO, \ + BASS_WRITE_CHAR_DESC, \ + BASS_READ_BCAST_RECV_STATE_CHARS, \ + BASS_CP_WRITE_CMD(0x02, 0x00, 0xF2, 0x69, 0x8B, 0xE8, 0x07, 0xC0, \ + 0x00, 0xF5, 0xD9, 0x83, 0x02, 0x10, 0x27, 0x01, \ + 0x00, 0x00, 0x00, 0x00, 0x00), \ + IOV_DATA(0x1b, 0x03, 0x00, 0x01, 0x00, 0xF2, 0x69, 0x8B, 0xE8, \ + 0x07, 0xC0, 0x00, 0xF5, 0xD9, 0x83, 0x02, 0x00, 0x01, \ + 0x00, 0x00, 0x00, 0x00, 0x00), \ + IOV_DATA(0x0a, 0x03, 0x00), \ + IOV_DATA(0x0b, 0x01, 0x00, 0xF2, 0x69, 0x8B, 0xE8, 0x07, 0xC0, 0x00, \ + 0xF5, 0xD9, 0x83, 0x02, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, \ + 0x00), \ + BASS_CP_WRITE_REQ(0x05, 0x01), \ + IOV_DATA(0x13) + +/* ATT: Write Request (0x12) len 5 + * Handle: 0x0009 Type: Broadcast Audio Scan Control Point (0x2bc7) + * Data: 006dfe + * Opcode: Remote Scan Stopped + * Extra Data: 0xfe6d + * ATT: Error Response (0x01) len 4 + * Write Request (0x12) + * Handle: 0x0009 + * Error: Write Request Rejected (0xFC) + * ATT: Write Request (0x12) len 5 + * Handle: 0x0009 Type: Broadcast Audio Scan Control Point (0x2bc7) + * Data: 006dfe + * Opcode: Remote Scan Started + * Extra Data: 0xa2c2 + * ATT: Error Response (0x01) len 4 + * Write Request (0x12) + * Handle: 0x0009 + * Error: Write Request Rejected (0xFC) + * ATT: Write Request (0x12) len 25 + * Handle: 0x0009 Type: Broadcast Audio Scan Control Point (0x2bc7) + * Data: 0200F2698BE807C0003412000210270100000000000000 + * Opcode: Add Source + * Advertiser_Address_Type: Public Device or Public Identity Address + * Advertiser_Address: c0:07:e8:8b:69:f2 + * Advertising_SID: 0x00 + * Broadcast_ID: 0x001234 + * PA_Sync: Synchronize to PA (PAST not available) + * PA_Interval: 0x2710 + * Num_Subgroups: 1 + * Subgroup #0: + * BIS_Sync: 00000000000000000000000000000001 + * Metadata_Length: 0 + * Extra Data: 0x0000 + * ATT: Error Response (0x01) len 4 + * Write Request (0x12) + * Handle: 0x0009 + * Error: Write Request Rejected (0xFC) + * ATT: Write Request (0x12) len 13 + * Handle: 0x0009 Type: Broadcast Audio Scan Control Point (0x2bc7) + * Data: 03000210270100000000001500 + * Opcode: Modify Source + * Source_ID: 0x00 + * PA_Sync: Synchronize to PA (PAST not available) + * PA_Interval: 0x2710 + * Num_Subgroups: 1 + * Subgroup #0: + * BIS_Sync: 00000000000000000000000000000001 + * Metadata_Length: 0 + * Extra Data: 0x0015 + * ATT: Error Response (0x01) len 4 + * Write Request (0x12) + * Handle: 0x0009 + * Error: Write Request Rejected (0xFC) + * ATT: Write Request (0x12) len 20 + * Handle: 0x0009 Type: Broadcast Audio Scan Control Point (0x2bc7) + * Data: 0400B803EAC6AFBB65A25A41F153056802010000 + * Opcode: Set Broadcast_Code + * Source_ID: 0x00 + * Broadcast_Code: 0x0102680553f1415aa265bbafc6ea03b8 + * Extra Data: 0x0000 + * ATT: Error Response (0x01) len 4 + * Write Request (0x12) + * Handle: 0x0009 + * Error: Write Request Rejected (0xFC) + * ATT: Write Request (0x12) len 4 + * Handle: 0x0009 Type: Broadcast Audio Scan Control Point (0x2bc7) + * Data: 05008F13 + * Opcode: Remove Source + * Source_ID: 0x00 + * Extra Data: 0x138f + * ATT: Error Response (0x01) len 4 + * Write Request (0x12) + * Handle: 0x0009 + * Error: Write Request Rejected (0xFC) + */ +#define INVALID_LEN \ + EXCHANGE_MTU, \ + BASS_FIND_BY_TYPE_VALUE, \ + DISC_BASS_CHAR, \ + BASS_FIND_INFO, \ + BASS_WRITE_CHAR_DESC,\ + BASS_READ_BCAST_RECV_STATE_CHARS, \ + BASS_CP_WRITE_REQ(0x00, 0x6D, 0xFE), \ + IOV_DATA(0x01, 0x12, 0x09, 0x00, 0xFC), \ + BASS_CP_WRITE_REQ(0x01, 0xC2, 0xA2), \ + IOV_DATA(0x01, 0x12, 0x09, 0x00, 0xFC), \ + BASS_CP_WRITE_REQ(0x02, 0x00, 0xF2, 0x69, 0x8B, 0xE8, 0x07, 0xC0, \ + 0x00, 0x34, 0x12, 0x00, 0x02, 0x10, 0x27, 0x01, \ + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00), \ + IOV_DATA(0x01, 0x12, 0x09, 0x00, 0xFC), \ + BASS_CP_WRITE_REQ(0x03, 0x00, 0x02, 0x10, 0x27, 0x01, 0x00, 0x00, \ + 0x00, 0x00, 0x00, 0x15, 0x00), \ + IOV_DATA(0x01, 0x12, 0x09, 0x00, 0xFC), \ + BASS_CP_WRITE_REQ(0x04, 0x00, 0xB8, 0x03, 0xEA, 0xC6, 0xAF, 0xBB, \ + 0x65, 0xA2, 0x5A, 0x41, 0xF1, 0x53, 0x05, 0x68, \ + 0x02, 0x01, 0x00, 0x00), \ + IOV_DATA(0x01, 0x12, 0x09, 0x00, 0xFC), \ + BASS_CP_WRITE_REQ(0x05, 0x00, 0x8F, 0x13), \ + IOV_DATA(0x01, 0x12, 0x09, 0x00, 0xFC) + +/* ATT: Write Request (0x12) len 20 + * Handle: 0x0009 Type: Broadcast Audio Scan Control Point (0x2bc7) + * Data: 0400B803EAC6AFBB65A25A41F153056802010000 + * Opcode: Set Broadcast_Code + * Source_ID: 0x05 + * Broadcast_Code: 0x0102680553f1415aa265bbafc6ea03b + * ATT: Error Response (0x01) len 4 + * Write Request (0x12) + * Handle: 0x0009 + * Error: Invalid Source ID (0x81) + * ATT: Write Request (0x12) len 4 + * Handle: 0x0009 Type: Broadcast Audio Scan Control Point (0x2bc7) + * Data: 005 + * Opcode: Remove Source + * Source_ID: 0x05 + * ATT: Error Response (0x01) len 4 + * Write Request (0x12) + * Handle: 0x0009 + * Error: Invalid Source ID (0x81) + */ +#define INVALID_SRC_ID \ + EXCHANGE_MTU, \ + BASS_FIND_BY_TYPE_VALUE, \ + DISC_BASS_CHAR, \ + BASS_FIND_INFO, \ + BASS_WRITE_CHAR_DESC, \ + BASS_READ_BCAST_RECV_STATE_CHARS, \ + BASS_CP_WRITE_REQ(0x04, 0x05, 0xB8, 0x03, 0xEA, 0xC6, 0xAF, 0xBB, \ + 0x65, 0xA2, 0x5A, 0x41, 0xF1, 0x53, 0x05, 0x68, \ + 0x02, 0x01), \ + IOV_DATA(0x01, 0x12, 0x09, 0x00, 0x81), \ + BASS_CP_WRITE_REQ(0x05, 0x05), \ + IOV_DATA(0x01, 0x12, 0x09, 0x00, 0x81) + +static const uint8_t client_bdaddr[] = {0xF2, 0x69, 0x8B, 0xE8, 0x07, 0xC0}; + +static const uint8_t set_iso_socket_param[] = { + 0x3e, 0xe0, 0xb4, 0xfd, 0xdd, 0xd6, 0x85, 0x98, /* UUID - ISO Socket */ + 0x6a, 0x49, 0xe0, 0x05, 0x88, 0xf1, 0xba, 0x6f, + 0x01, /* Action - enable */ +}; + +static const uint8_t reset_iso_socket_param[] = { + 0x3e, 0xe0, 0xb4, 0xfd, 0xdd, 0xd6, 0x85, 0x98, /* UUID - ISO Socket */ + 0x6a, 0x49, 0xe0, 0x05, 0x88, 0xf1, 0xba, 0x6f, + 0x00, /* Action - disable */ +}; + #define iov_data(args...) ((const struct iovec[]) { args }) -#define define_test(name, function, _cfg, args...) \ +#define define_test(name, pre_setup, setup, function, teardown, \ + post_teardown, args...) \ do { \ const struct iovec iov[] = { args }; \ static struct test_data data; \ data.iovcnt = ARRAY_SIZE(iov_data(args)); \ data.iov = util_iov_dup(iov, ARRAY_SIZE(iov_data(args))); \ - tester_add(name, &data, NULL, function, \ - test_teardown); \ + tester_add_full(name, &data, pre_setup, setup, function, \ + teardown, post_teardown, 0, NULL, NULL); \ } while (0) static void test_complete_cb(const void *user_data) @@ -287,11 +680,282 @@ done: gatt_db_attribute_read_result(attrib, id, ecode, value, len); } +static void gatt_ccc_write_cb(struct gatt_db_attribute *attrib, + unsigned int id, uint16_t offset, + const uint8_t *value, size_t len, + uint8_t opcode, struct bt_att *att, + void *user_data) +{ + struct test_data *data = (void *)user_data; + struct ccc_state *ccc_state; + uint16_t val; + uint8_t ecode = 0; + + if (!value || len > 2) { + ecode = BT_ATT_ERROR_INVALID_ATTRIBUTE_VALUE_LEN; + goto done; + } + + if (offset > 2) { + ecode = BT_ATT_ERROR_INVALID_OFFSET; + goto done; + } + + if (len == 1) + val = *value; + else + val = get_le16(value); + + ccc_state = get_ccc_state(data, gatt_db_attribute_get_handle(attrib)); + if (!ccc_state) + return; + + /* If value is identical, then just succeed */ + if (val == ccc_state->value) + goto done; + + ccc_state->value = val; + +done: + gatt_db_attribute_write_result(attrib, id, ecode); +} + +static void gatt_notify_cb(struct gatt_db_attribute *attrib, + struct gatt_db_attribute *ccc, + const uint8_t *value, size_t len, + struct bt_att *att, void *user_data) +{ + struct test_data *data = user_data; + struct ccc_state *ccc_state; + + ccc_state = find_ccc_state(data, gatt_db_attribute_get_handle(ccc)); + if (!ccc_state || !(ccc_state->value & 0x0001)) + return; + + bt_gatt_server_send_notification(data->server, + gatt_db_attribute_get_handle(attrib), + value, len, false); +} + +static void set_iso_socket_callback(uint8_t status, uint16_t length, + const void *param, void *user_data) +{ + if (status != MGMT_STATUS_SUCCESS) { + tester_print("ISO socket feature could not be enabled"); + return; + } + + tester_print("ISO socket feature is enabled"); +} + +static void read_info_callback(uint8_t status, uint16_t length, + const void *param, void *user_data) +{ + struct test_data *data = (void *)user_data; + const struct mgmt_rp_read_info *rp = param; + char addr[18]; + uint16_t manufacturer; + uint32_t supported_settings, current_settings; + + tester_print("Read Info callback"); + tester_print(" Status: 0x%02x", status); + + if (status || !param) { + tester_pre_setup_failed(); + return; + } + + ba2str(&rp->bdaddr, addr); + manufacturer = btohs(rp->manufacturer); + supported_settings = btohl(rp->supported_settings); + current_settings = btohl(rp->current_settings); + + tester_print(" Address: %s", addr); + tester_print(" Version: 0x%02x", rp->version); + tester_print(" Manufacturer: 0x%04x", manufacturer); + tester_print(" Supported settings: 0x%08x", supported_settings); + tester_print(" Current settings: 0x%08x", current_settings); + tester_print(" Class: 0x%02x%02x%02x", + rp->dev_class[2], rp->dev_class[1], rp->dev_class[0]); + tester_print(" Name: %s", rp->name); + tester_print(" Short name: %s", rp->short_name); + + if (strcmp(hciemu_get_address(data->hciemu), addr)) { + tester_pre_setup_failed(); + return; + } + + tester_pre_setup_complete(); +} + +static void index_added_callback(uint16_t index, uint16_t length, + const void *param, void *user_data) +{ + struct test_data *data = (void *)user_data; + + tester_print("Index Added callback"); + tester_print(" Index: 0x%04x", index); + + data->mgmt_index = index; + + mgmt_send(data->mgmt, MGMT_OP_READ_INFO, data->mgmt_index, 0, NULL, + read_info_callback, data, NULL); +} + +static void index_removed_callback(uint16_t index, uint16_t length, + const void *param, void *user_data) +{ + struct test_data *data = (void *)user_data; + + tester_print("Index Removed callback"); + tester_print(" Index: 0x%04x", index); + + if (index != data->mgmt_index) + return; + + mgmt_unregister_index(data->mgmt, data->mgmt_index); + + mgmt_unref(data->mgmt); + data->mgmt = NULL; + + tester_post_teardown_complete(); +} + +static void read_index_list_callback(uint8_t status, uint16_t length, + const void *param, void *user_data) +{ + struct test_data *data = (void *)user_data; + struct hciemu_client *client; + + tester_print("Read Index List callback"); + tester_print(" Status: 0x%02x", status); + + if (status || !param) { + tester_pre_setup_failed(); + return; + } + + mgmt_register(data->mgmt, MGMT_EV_INDEX_ADDED, MGMT_INDEX_NONE, + index_added_callback, data, NULL); + + mgmt_register(data->mgmt, MGMT_EV_INDEX_REMOVED, MGMT_INDEX_NONE, + index_removed_callback, data, NULL); + + data->hciemu = hciemu_new(HCIEMU_TYPE_BREDRLE52); + if (!data->hciemu) { + tester_warn("Failed to setup HCI emulation"); + tester_pre_setup_failed(); + return; + } + + client = hciemu_get_client(data->hciemu, 0); + + if (!hciemu_set_client_bdaddr(client, client_bdaddr)) { + tester_warn("Failed to setup HCI emulation"); + tester_pre_setup_failed(); + return; + } + + tester_print("New hciemu instance created"); +} + +static void test_pre_setup(const void *test_data) +{ + struct test_data *data = (void *)test_data; + + data->mgmt = mgmt_new_default(); + if (!data->mgmt) { + tester_warn("Failed to setup management interface"); + tester_pre_setup_failed(); + return; + } + + mgmt_send(data->mgmt, MGMT_OP_SET_EXP_FEATURE, MGMT_INDEX_NONE, + sizeof(set_iso_socket_param), set_iso_socket_param, + set_iso_socket_callback, NULL, NULL); + + mgmt_send(data->mgmt, MGMT_OP_READ_INDEX_LIST, MGMT_INDEX_NONE, 0, NULL, + read_index_list_callback, data, NULL); +} + +static void test_post_teardown(const void *test_data) +{ + struct test_data *data = (void *)test_data; + + mgmt_send(data->mgmt, MGMT_OP_SET_EXP_FEATURE, MGMT_INDEX_NONE, + sizeof(reset_iso_socket_param), reset_iso_socket_param, + NULL, NULL, NULL); + + hciemu_unref(data->hciemu); + data->hciemu = NULL; +} + +static void client_connectable_complete(uint16_t opcode, uint8_t status, + const void *param, uint8_t len, + void *user_data) +{ + if (opcode != BT_HCI_CMD_LE_SET_EXT_ADV_ENABLE) + return; + + tester_print("Client set connectable status 0x%02x", status); + + if (status) + tester_setup_failed(); + else + tester_setup_complete(); +} + +static void setup_powered_callback(uint8_t status, uint16_t length, + const void *param, void *user_data) +{ + struct test_data *data = (void *)user_data; + struct hciemu_client *client; + struct bthost *host; + uint8_t bcode[16] = {0x00}; + + if (status != MGMT_STATUS_SUCCESS) { + tester_setup_failed(); + return; + } + + tester_print("Controller powered on"); + + client = hciemu_get_client(data->hciemu, 0); + host = hciemu_client_host(client); + bthost_set_cmd_complete_cb(host, client_connectable_complete, + data); + bthost_set_ext_adv_params(host); + bthost_set_ext_adv_enable(host, 0x01); + + bthost_set_pa_params(host); + bthost_set_pa_enable(host, 0x01); + bthost_create_big(host, 1, 0x00, bcode); +} + +static void setup_powered(const void *test_data) +{ + struct test_data *data = (void *)test_data; + unsigned char param[] = { 0x01 }; + + tester_print("Powering on controller"); + + mgmt_send(data->mgmt, MGMT_OP_SET_SSP, data->mgmt_index, + sizeof(param), param, NULL, NULL, NULL); + + mgmt_send(data->mgmt, MGMT_OP_SET_LE, data->mgmt_index, + sizeof(param), param, NULL, NULL, NULL); + + mgmt_send(data->mgmt, MGMT_OP_SET_POWERED, data->mgmt_index, + sizeof(param), param, + setup_powered_callback, data, NULL); +} + static void test_server(const void *user_data) { struct test_data *data = (void *)user_data; struct bt_att *att; struct io *io; + bdaddr_t adapter_bdaddr = {{0, 0, 0, 0, 0, 0}}; io = tester_setup_io(data->iov, data->iovcnt); g_assert(io); @@ -306,12 +970,22 @@ static void test_server(const void *user_data) data->db = gatt_db_new(); g_assert(data->db); - gatt_db_ccc_register(data->db, gatt_ccc_read_cb, NULL, - NULL, data); + gatt_db_ccc_register(data->db, gatt_ccc_read_cb, gatt_ccc_write_cb, + gatt_notify_cb, data); - data->bass = bt_bass_new(data->db, NULL, BDADDR_ANY); + if (data->hciemu) + memcpy(&adapter_bdaddr, + hciemu_get_central_bdaddr(data->hciemu), + sizeof(adapter_bdaddr)); + + data->bass = bt_bass_new(data->db, NULL, &adapter_bdaddr); g_assert(data->bass); + bt_bass_set_att(data->bass, att); + bt_bass_attach(data->bass, NULL); + + bt_bass_set_debug(data->bass, print_debug, "bt_bass:", NULL); + data->server = bt_gatt_server_new(data->db, att, 64, 0); g_assert(data->server); @@ -346,8 +1020,8 @@ static void test_sggit(void) * handle range of the request. The IUT reports all BASS * characteristics. */ - define_test("BASS/SR/SGGIT/SER/BV-01-C", test_server, NULL, - DISC_BASS_SER); + define_test("BASS/SR/SGGIT/SER/BV-01-C", NULL, NULL, test_server, + test_teardown, NULL, DISC_BASS_SER); /* BASS/SR/SGGIT/CHA/BV-01-C [Service GGIT - * Broadcast Audio Scan Control Point] @@ -359,8 +1033,8 @@ static void test_sggit(void) * handle range of the request. The IUT reports one instance of the * Broadcast Audio Scan Control Point characteristic. */ - define_test("BASS/SR/SGGIT/CHA/BV-01-C", test_server, NULL, - DISC_BCAST_AUDIO_SCAN_CP); + define_test("BASS/SR/SGGIT/CHA/BV-01-C", NULL, NULL, test_server, + test_teardown, NULL, DISC_BCAST_AUDIO_SCAN_CP); /* BASS/SR/SGGIT/CHA/BV-02-C [Service GGIT - * Broadcast Receive State] @@ -383,8 +1057,90 @@ static void test_sggit(void) * The IUT sends an ATT_Read_Response to the Lower Tester for each * ATT_Read_Request. */ - define_test("BASS/SR/SGGIT/CHA/BV-02-C", test_server, NULL, - DISC_BCAST_RECV_STATE); + define_test("BASS/SR/SGGIT/CHA/BV-02-C", NULL, NULL, test_server, + test_teardown, NULL, DISC_BCAST_RECV_STATE); +} + +static void test_spe(void) +{ + /* BASS/SR/SPE/BI-01-C [Ignore Invalid Source ID] + * + * Test Purpose: + * Verify that the BASS Server IUT does not respond to a control point + * procedure call that uses an invalid Source_ID parameter. + * + * Pass verdict: + * The IUT does not send a notification of the Broadcast Receive State + * characteristic. + */ + define_test("BASS/SR/SPE/BI-01-C", NULL, NULL, test_server, + test_teardown, NULL, IGNORE_INVALID_SRC_ID); + + /* BASS/SR/SPE/BI-03-C [Add Source - Ignore Invalid Values] + * + * Test Purpose: + * Verify that the BASS Server IUT ignores Add Source control point + * procedure calls that include an RFU or Invalid parameter. + * + * Pass verdict: + * The IUT does not send a notification of the Broadcast Receive State + * characteristic. + */ + define_test("BASS/SR/SPE/BI-03-C", NULL, NULL, test_server, + test_teardown, NULL, ADD_SRC_INVALID_PARAMS); + + /* BASS/SR/SPE/BI-04-C [Opcode Not Supported] + * + * Test Purpose: + * Verify that the BASS Server IUT returns an Opcode Not Supported error + * response when the opcode written is not supported by the IUT or is + * within a range that is reserved for future use being written to the + * Broadcast Audio Scan Control Point. + * + * Pass verdict: + * The IUT sends an error response of OPCODE NOT SUPPORTED. + */ + define_test("BASS/SR/SPE/BI-04-C", NULL, NULL, test_server, + test_teardown, NULL, OPCODE_NOT_SUPPORTED); + + /* BASS/SR/SPE/BI-05-C [Remove Source While Synchronized to a Source] + * + * Test Purpose: + * Verify that the BASS Server IUT, if synchronized to PA and/or BIS, + * does not accept the Remove Source operation request. + * + * Pass verdict: + * The IUT does not send a notification to the Lower Tester for the + * Broadcast Receive State characteristic. + */ + define_test("BASS/SR/SPE/BI-05-C", test_pre_setup, setup_powered, + test_server, test_teardown, test_post_teardown, + RM_SRC_WHILE_SYNC); + + /* BASS/SR/SPE/BI-06-C [Invalid Length] + * + * Test Purpose: + * Verify that the BASS Server IUT rejects writing of an opcode with + * an invalid length. + * + * Pass verdict: + * The IUT rejects the opcode. + */ + define_test("BASS/SR/SPE/BI-06-C", NULL, NULL, test_server, + test_teardown, NULL, INVALID_LEN); + + /* BASS/SR/SPE/BI-07-C [Invalid Source ID] + * + * Test Purpose: + * Verify that the BASS Server IUT returns an error when a control + * point procedure passing an invalid Source_ID parameter is called. + * + * Pass verdict: + * The IUT sends an ATT Error Response with the Error Code set to + * Invalid Source_ID. + */ + define_test("BASS/SR/SPE/BI-07-C", NULL, NULL, test_server, + test_teardown, NULL, INVALID_SRC_ID); } int main(int argc, char *argv[]) @@ -392,6 +1148,7 @@ int main(int argc, char *argv[]) tester_init(&argc, &argv); test_sggit(); + test_spe(); return tester_run(); }