From patchwork Wed Feb 7 12:23:06 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Istodorescu X-Patchwork-Id: 770677 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2082.outbound.protection.outlook.com [40.107.105.82]) (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 8632D59B72 for ; Wed, 7 Feb 2024 12:23:18 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.105.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707308601; cv=fail; b=jYLHyVFBfHqpJU4F2xcZL+ztPvcfNe4REp806GaIencAMUBABXl4YUoMn+xXwwkiajcP96iUqKNJDz0hRGJZXX6Ba5JIiphuwNA4x7QEK7H2BlmxD1PeA8t+z4CBO8LxXActcMvyl7Cmtpz3x4uzaCHfJlgBHdFItVWMFVgcawE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707308601; c=relaxed/simple; bh=yPSjGWuBlkwXVKOEuEKptm2LSK8+DKTdRtqFdPQVOnI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=qUnZO4li5L2HrlcVwKaA09yT5LBiCOoVejAHFuo95N0t1C76D+Va0ow39nzRzemS27xHVgCjvC3ZYXXVlzL9KBNkMTpADrJIZANyGKU1btNR99Rt8SqwWMzB+0ajtCZ3NaevAoGsawcPzQjqdK7GILWScJt3rr54vyinnQziyfM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b=mhDQMYR5; arc=fail smtp.client-ip=40.107.105.82 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="mhDQMYR5" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=BBR1wa1gBZK/nhtmdUMKp3V3bIn1aVNZtyPClSeX/wjFoGv2kj0PMyY/1X2/pE2wO76z4pn9lGzA16BI5uGffnM/3CUm+vJ+LIt8S6s8UksNggrDsy7VyKKcqJsN/IuElzedl0g2fRzgleie4J6zVqDB7sZYm4F7E7MDX2yPYwdmk8DfIL4K1RTGbNjnA0V2jytTb4Jyd7+oZ81Z10xRzalfOYQITW2pOPs3FSzNiqX0D9lWuU/qPWez7CtP7xj0c3nhAtJKNqXxpdnb+P8TPqLMSbtE5ffOqFStTr/sp1U2wy29l2BTjWccJgxJ9UCfu83wzabZtN0dHznpql9+UA== 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=nt2e3M/HGvjvTO+q/RgTxDpRrwCsg2D4eblXxQdY8Bk=; b=EGjCikYrW5HInH3/Y/gOsMzMJzp6cN4db2Ydb2yDJf9oefieBhzI8dlyBlb3uiROwcVDo/6UBMPSH8UQv98dNyWDcH0gaY7rDvPEtbhN/JdHnp9ftsD4r9tYIwZIrszKp/w1wXHu8oUKos1D/qWavvw3oXAgxa6GfYXfEh0ES44MKkfMGO5N1Es5gMYzhJjofx1XKEsRMhQEXFGVzKQLAjXMoJHUAqMYdszqkGx6DBplkhFIIeiXGNV1N6lsH5y1RD7Uev9F3NiZIQbMeZK3LFlHY7P5Bl6XBXMKpHaDBsVr5Ke0OE9XNh+7tYXkQ5yB7/ULv4lPV2lnTv/8n3Q8HA== 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=nt2e3M/HGvjvTO+q/RgTxDpRrwCsg2D4eblXxQdY8Bk=; b=mhDQMYR5UeoFqlNDdEkhefL6iclkGdjcXMpY4fgZ7RQG9r4iN3/NSoOaBkxXXHEMKZTYXe59CtBZ8kPWCB7pEyS4gO1E65iQG/H4Zn1xzThEpQ4oc89ZArtO8S4H+FTIEhM3y71rrApO3b1/yF790Y1fZFOq7LpgyoERknxRRIw= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM9PR04MB8938.eurprd04.prod.outlook.com (2603:10a6:20b:409::20) by GVXPR04MB9851.eurprd04.prod.outlook.com (2603:10a6:150:118::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.36; Wed, 7 Feb 2024 12:23:14 +0000 Received: from AM9PR04MB8938.eurprd04.prod.outlook.com ([fe80::bbd0:4409:3f0e:afdd]) by AM9PR04MB8938.eurprd04.prod.outlook.com ([fe80::bbd0:4409:3f0e:afdd%4]) with mapi id 15.20.7249.035; Wed, 7 Feb 2024 12:23:14 +0000 From: Andrei Istodorescu To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, mihai-octavian.urzica@nxp.com, silviu.barbulescu@nxp.com, vlad.pruteanu@nxp.com, iulia.tanasescu@nxp.com, Andrei Istodorescu Subject: [PATCH BlueZ 1/3] shared/bap: Add API to convert BASE into bt_bap_base queue Date: Wed, 7 Feb 2024 14:23:06 +0200 Message-Id: <20240207122308.26457-2-andrei.istodorescu@nxp.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240207122308.26457-1-andrei.istodorescu@nxp.com> References: <20240207122308.26457-1-andrei.istodorescu@nxp.com> X-ClientProxiedBy: AM9P192CA0013.EURP192.PROD.OUTLOOK.COM (2603:10a6:20b:21d::18) To AM9PR04MB8938.eurprd04.prod.outlook.com (2603:10a6:20b:409::20) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8938:EE_|GVXPR04MB9851:EE_ X-MS-Office365-Filtering-Correlation-Id: 3e6841be-35c3-4b64-3607-08dc27d78e64 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 9DlsZjDdznrfh4Onyy2jI6PteorBrU6QGCg2rTS6sWeIg90sWxJM+ENkK8xCsgEkqBCcrZGy0Rcf8/IiBJlSuBgaDzsPUfTPBlOB5I+unRWVNUj6pezMTW+PEaXeCs+dENPzatTdEHs1wJQNGY9YshTaTzvlE2PM1QoIVBAuvC+IQlBH2vcHylzs6lYDoBVEGWaJv8eEWqcp+8xXmF1lfQJSNWnpAWjxPt0Zix3aoOt0RGlxzmJxRnqSlV66RHgr8EBXnX2+lKH/v8cBPlC2F+OG/w0axgbzaJJm7IFFOClbHs8cXJ+090vSwzNeHbHf6MCdlOQQS2k5ztxGL4LWhJB5X38CmOuT6nsOgfNjb0v7EfThy0IwIsohifTsPj7U7hLdSctSco+2/NrRbi3Js1MXsYEoAOo5rzk/2aPoP4Ck6ic6u1EwhxTblAA9k7uQ+ltdcK/ERVphL/Qcepv3AVFmP1C0TgiyaKNP4cDRnwfag0oAENEUPfU6+Gf6M1ufu+ozPtmlN4qA2LhC/T5TLCFG9lz2OQD9cbb7nTxlniqQUwRfj9H5EZ5mcnYHecDL X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR04MB8938.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(39860400002)(346002)(396003)(366004)(376002)(136003)(230922051799003)(1800799012)(64100799003)(186009)(451199024)(6666004)(6506007)(38100700002)(83380400001)(26005)(86362001)(41300700001)(1076003)(2616005)(8676002)(6512007)(4326008)(8936002)(36756003)(30864003)(478600001)(2906002)(5660300002)(6486002)(66556008)(6916009)(66946007)(66476007)(316002)(44832011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Y3S1CznRRKtvs91RHFVau/HLKBcQBqtB/VpWeyifLtLpc2mUwLCmSvhoB8XILnOaNR7aRhYWz9jLiaJa2DJ/X71Hz33GySvz8pZGYElfTynufMEBZZaGmQYzptxjvJLNV5U0DE8ErFlgHX7i9LKteXI0NzFdm/Np8eZ4Iw3ZM0q2fsiswrACM2za+qejjDsJy7lJbeLjeWn/XkeYqHtxe1bnSRqBIFbLePc3ksygIrSaYN6YJVSKPChw2RUTMuBTQ8R5V39KBJRDVsEftssl/cUhDZU1u0AeVH4NxCoJZE90wIS7lLunUGSFBF4BCRRTDPCnWDWv+Hyk04xjFSkoJVdkpHHgF82tq+zZIgzy8XHK8lSFoD2RMS9RMB7sjo6xwQHkeJBX+LiVC+7O+cI86A0B1v/pJFEvNsKIrkYp5aWeTzLlDhrisfO78/VOMG8vVPw1xRrjHFOD1+/yacheEu0lo/bOun0WpzhX9Bbx1E0Xmn2w4d4eKe9NSLD6kZSQ1f1bN7VghyokJEakia2hnrCca37Ig3KVn+e+QYtRz0zXzqgqxSwOJXRgmCV84IEczel8yx/iIB0CxQMugjyEdQP8O4AOr9Lfel0Fh16UEr29K2v90jHf7VNrczQwd1KpR3GK34ky1faPWAs7aUFLsXkyYBmeNf/YUgeO0KbIicrXB0e/Ix7k9aUN8ybyOLPEiM75yDb+AUo0N9qExmPV5rBw0ZBBCjl+RXwCRBqnxgilIweSl15InSiOHTJqIJe1ufNwMiralwae3eiJHp+ftvCJTTxMIbKFi4h4UbXxH3Pjbm3SMKgmM8fTSzZ7KHmExJK+rGeb6fgw1EQ9F9VRuJtAQ570LD/42i3FT3xvDAQrPAu5ZRXM4i7Wz6KSRAK19uWLoe0uFkS2MgC3FY11+AfWJu5/hp9vWpXMlMuhe3n115TWR6FRDJAkwDGVSYcyd5shShj7aA0oyErDbF5a7F7RFWz3OTzq6+QW73ourv/Tt3q1TqnA0o+8pC9hrJPk3UNKab6902Ivyrk/16wMBjS01b83n6zCx+70FUjyIev61ArjHLbarBCE4/52p592e5UWZWEflyAPnQuwU4B5JavwT8Gk7jDm/q/o/s/8h/0sf+pK3H5tTQb2JZeJZY8BWxMlvBNjbkucNTY/AWDIHpsHF+cuC+FAyOYZ1XcvrQQnzuenIp9lFD4nybiTDaRtUF73zhvwOcL7BXadx/mtk6EzdbvXry5oG1WZrHgJHStF6S4gigQLe4hnsCcQIW0zailRqfyyUkGyDKpaz6nKwIo9QYxPbxkBXFivpwV8YjlNDXEA+6fwDXjMnWtjTdz3JFxtqJPSbctj+vQWpYlwb+JXQDXEs0fmf6fV4dpDO3y5e7TIH2Ud9mifgmTIkoZaZG/BG6WUxiyAZg7yYiNtx9okwgZK2spilQsiZeXkb3cTcc5TqZWDetZRzoBrhnr5aIbb8FCKxzAJ500jyuZK0bfc872j41pKZtA7Z58npxVH0kxDMjjDctEpoEyOklo9aMwyr5QG5GeDSc9JL1+WGVGMkz02G185S9MUl919Y5Pj4sVD+2tl8142C7HRrnWKofGJOo0tdHMfxDXy/7TWQQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3e6841be-35c3-4b64-3607-08dc27d78e64 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8938.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2024 12:23:14.1638 (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: pskNDJ9apiKxMvnrGd+bNcdzEVspbArGwAynNeDx5hstZsD48Dk9eM3Lk2hOD3I3Wjrd+XZVUdoT7+yNv5DoIGeLw0tlnmSw47h5MBAEzQA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB9851 Create public function to read the BASE bytes and populate a bt_bap_base structure for further processing. --- src/shared/bap.c | 250 ++++++++++++++++++++++++++++++++++++++++------- src/shared/bap.h | 27 +++++ 2 files changed, 244 insertions(+), 33 deletions(-) diff --git a/src/shared/bap.c b/src/shared/bap.c index 00d211c15ddf..aa78b1b74fbb 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -255,26 +255,6 @@ struct bt_pacs_context { uint16_t src; } __packed; -struct bt_base { - uint8_t big_id; - uint32_t pres_delay; - uint8_t next_bis_index; - struct queue *subgroups; -}; - -struct bt_subgroup { - uint8_t index; - struct bt_bap_codec codec; - struct iovec *caps; - struct iovec *meta; - struct queue *bises; -}; - -struct bt_bis { - uint8_t index; - struct iovec *caps; -}; - /* Contains local bt_bap_db */ static struct queue *bap_db; static struct queue *bap_cbs; @@ -5536,7 +5516,7 @@ void bt_bap_update_bcast_source(struct bt_bap_pac *pac, static void destroy_base_bis(void *data) { - struct bt_bis *bis = data; + struct bt_bap_bis *bis = data; if (!bis) return; @@ -5549,7 +5529,7 @@ static void destroy_base_bis(void *data) static void generate_bis_base(void *data, void *user_data) { - struct bt_bis *bis = data; + struct bt_bap_bis *bis = data; struct iovec *base_iov = user_data; uint8_t cc_length = bis->caps->iov_len; @@ -5566,7 +5546,7 @@ static void generate_bis_base(void *data, void *user_data) static void generate_subgroup_base(void *data, void *user_data) { - struct bt_subgroup *sgrp = data; + struct bt_bap_subgroup *sgrp = data; struct iovec *base_iov = user_data; if (!util_iov_push_u8(base_iov, queue_length(sgrp->bises))) @@ -5604,7 +5584,7 @@ static void generate_subgroup_base(void *data, void *user_data) queue_foreach(sgrp->bises, generate_bis_base, base_iov); } -static struct iovec *generate_base(struct bt_base *base) +static struct iovec *generate_base(struct bt_bap_base *base) { struct iovec *base_iov = new0(struct iovec, 0x1); @@ -5623,10 +5603,10 @@ static struct iovec *generate_base(struct bt_base *base) return base_iov; } -static void add_new_bis(struct bt_subgroup *subgroup, +static void add_new_bis(struct bt_bap_subgroup *subgroup, uint8_t bis_index, struct iovec *caps) { - struct bt_bis *bis = new0(struct bt_bis, 1); + struct bt_bap_bis *bis = new0(struct bt_bap_bis, 1); bis->index = bis_index; @@ -5638,12 +5618,12 @@ static void add_new_bis(struct bt_subgroup *subgroup, queue_push_tail(subgroup->bises, bis); } -static void add_new_subgroup(struct bt_base *base, +static void add_new_subgroup(struct bt_bap_base *base, struct bt_bap_stream *stream) { struct bt_bap_pac *lpac = stream->lpac; - struct bt_subgroup *sgrp = new0( - struct bt_subgroup, 1); + struct bt_bap_subgroup *sgrp = new0( + struct bt_bap_subgroup, 1); uint16_t cid = 0; uint16_t vid = 0; @@ -5784,7 +5764,7 @@ static struct iovec *extract_diff_caps( static void set_base_subgroup(void *data, void *user_data) { struct bt_bap_stream *stream = data; - struct bt_base *base = user_data; + struct bt_bap_base *base = user_data; /* BIS specific codec capabilities */ struct iovec *bis_caps; @@ -5802,7 +5782,7 @@ static void set_base_subgroup(void *data, void *user_data) } else { /* Verify if a subgroup has the same metadata */ const struct queue_entry *entry; - struct bt_subgroup *subgroup = NULL; + struct bt_bap_subgroup *subgroup = NULL; bool same_meta = false; for (entry = queue_get_entries(base->subgroups); @@ -5836,7 +5816,7 @@ static void set_base_subgroup(void *data, void *user_data) static void destroy_base_subgroup(void *data) { - struct bt_subgroup *subgroup = data; + struct bt_bap_subgroup *subgroup = data; if (!subgroup) return; @@ -5858,7 +5838,7 @@ static void destroy_base_subgroup(void *data) */ struct iovec *bt_bap_stream_get_base(struct bt_bap_stream *stream) { - struct bt_base base; + struct bt_bap_base base; struct iovec *base_iov; base.subgroups = queue_new(); @@ -5877,3 +5857,207 @@ struct iovec *bt_bap_stream_get_base(struct bt_bap_stream *stream) return base_iov; } + +static void cleanup_bis(void *data) +{ + struct bt_bap_bis *bis = data; + + if (bis->caps) + util_iov_free(bis->caps, 1); +} + +static void cleanup_subgroup(struct bt_bap_subgroup *subgroup) +{ + if (!subgroup) + return; + + if (subgroup->meta) + util_iov_free(subgroup->meta, 1); + + if (subgroup->caps) + util_iov_free(subgroup->caps, 1); + + queue_destroy(subgroup->bises, cleanup_bis); + + if (subgroup) + free(subgroup); +} + +bool bt_bap_parse_base(struct bt_bap *bap, void *data, size_t len, + util_debug_func_t func, struct bt_bap_base *base) +{ + uint8_t num_subgroups; + uint8_t num_bis; + + struct iovec iov = { + .iov_base = data, + .iov_len = len, + }; + util_debug(func, NULL, "BASE len %ld", len); + if (!base) + return false; + + if (!util_iov_pull_le24(&iov, &base->pres_delay)) + return false; + util_debug(func, NULL, "PresentationDelay %d", base->pres_delay); + + if (!util_iov_pull_u8(&iov, &base->num_subgroups)) + return false; + util_debug(func, NULL, "NumSubgroups %d", base->num_subgroups); + num_subgroups = base->num_subgroups; + + for (int sg = 0; sg < num_subgroups; sg++) { + struct bt_bap_subgroup *sub_group = new0( + struct bt_bap_subgroup, 1); + uint8_t caps_len, metaLen; + uint8_t *hexstream; + + sub_group->subgroup_index = sg; + + util_debug(func, NULL, "Subgroup #%d", sg); + sub_group->bap = bap; + sub_group->bises = queue_new(); + + if (!util_iov_pull_u8(&iov, &num_bis)) { + cleanup_subgroup(sub_group); + goto fail; + } + util_debug(func, NULL, "NumBis %d", num_bis); + sub_group->num_bises = num_bis; + + memcpy(&sub_group->codec, util_iov_pull_mem(&iov, + sizeof(struct bt_bap_codec)), sizeof(struct bt_bap_codec)); + util_debug(func, NULL, "%s: ID %d CID 0x%2.2x VID 0x%2.2x", + "Codec", sub_group->codec.id, sub_group->codec.cid, + sub_group->codec.vid); + if (!util_iov_pull_u8(&iov, &caps_len)) { + cleanup_subgroup(sub_group); + goto fail; + } + + util_debug(func, NULL, "CC Len %d", caps_len); + + /* + * Copy the Codec Specific configurations from base + */ + sub_group->caps = new0(struct iovec, 1); + util_iov_memcpy(sub_group->caps, iov.iov_base, caps_len); + util_debug(func, NULL, "subgroup caps len %ld", + sub_group->caps->iov_len); + + for (int i = 0; caps_len > 1; i++) { + struct bt_ltv *ltv = util_iov_pull_mem(&iov, + sizeof(*ltv)); + uint8_t *caps; + + if (!ltv) { + util_debug(func, NULL, "Unable to parse %s", + "Capabilities"); + cleanup_subgroup(sub_group); + goto fail; + } + + util_debug(func, NULL, "%s #%u: len %u type %u", + "CC", i, ltv->len, ltv->type); + + caps = util_iov_pull_mem(&iov, ltv->len - 1); + if (!caps) { + util_debug(func, NULL, "Unable to parse %s", + "CC"); + cleanup_subgroup(sub_group); + goto fail; + } + util_hexdump(' ', caps, ltv->len - 1, func, NULL); + + caps_len -= (ltv->len + 1); + } + + if (!util_iov_pull_u8(&iov, &metaLen)) { + cleanup_subgroup(sub_group); + goto fail; + } + util_debug(func, NULL, "Metadata Len %d", metaLen); + + sub_group->meta = new0(struct iovec, 1); + sub_group->meta->iov_len = metaLen; + sub_group->meta->iov_base = iov.iov_base; + + hexstream = util_iov_pull_mem(&iov, metaLen); + if (!hexstream) { + cleanup_subgroup(sub_group); + goto fail; + } + util_hexdump(' ', hexstream, metaLen, func, NULL); + + for (int bis_sg = 0; bis_sg < sub_group->num_bises; bis_sg++) { + struct bt_bap_bis *bis; + uint8_t caps_len; + uint8_t crt_bis; + + if (!util_iov_pull_u8(&iov, &crt_bis)) { + cleanup_subgroup(sub_group); + goto fail; + } + util_debug(func, NULL, "BIS #%d", crt_bis); + + bis = new0(struct bt_bap_bis, 1); + bis->index = crt_bis; + + if (!util_iov_pull_u8(&iov, &caps_len)) { + cleanup_subgroup(sub_group); + goto fail; + } + util_debug(func, NULL, "CC Len %d", caps_len); + + bis->caps = new0(struct iovec, 1); + bis->caps->iov_len = caps_len; + util_iov_memcpy(bis->caps, iov.iov_base, caps_len); + util_debug(func, NULL, "bis caps len %ld", + bis->caps->iov_len); + + for (int i = 0; caps_len > 1; i++) { + struct bt_ltv *ltv = util_iov_pull_mem(&iov, + sizeof(*ltv)); + uint8_t *caps; + + if (!ltv) { + util_debug(func, NULL, "Unable to parse %s", + "Capabilities"); + cleanup_subgroup(sub_group); + goto fail; + } + + util_debug(func, NULL, "%s #%u: len %u type %u", + "CC", i, ltv->len, ltv->type); + + caps = util_iov_pull_mem(&iov, ltv->len - 1); + if (!caps) { + util_debug(func, NULL, + "Unable to parse %s", "CC"); + cleanup_subgroup(sub_group); + goto fail; + } + util_hexdump(' ', caps, ltv->len - 1, func, + NULL); + + caps_len -= (ltv->len + 1); + } + + queue_push_tail(sub_group->bises, bis); + } + + queue_push_tail(base->subgroups, sub_group); + } + return true; + +fail: + while (!queue_isempty(base->subgroups)) { + struct bt_bap_subgroup *subGroup = + queue_peek_head(base->subgroups); + cleanup_subgroup(subGroup); + base->num_subgroups--; + } + util_debug(func, NULL, "Unable to parse %s", "Base"); + + return false; +} diff --git a/src/shared/bap.h b/src/shared/bap.h index 2c3550921f07..b13fef688da3 100644 --- a/src/shared/bap.h +++ b/src/shared/bap.h @@ -98,6 +98,29 @@ struct bt_bap_qos { }; }; +struct bt_bap_base { + uint32_t pres_delay; + uint8_t big_id; + uint8_t num_subgroups; + uint8_t next_bis_index; + struct queue *subgroups; +}; + +struct bt_bap_subgroup { + uint8_t subgroup_index; + struct bt_bap *bap; + uint8_t num_bises; + struct bt_bap_codec codec; + struct iovec *caps; + struct iovec *meta; + struct queue *bises; +}; + +struct bt_bap_bis { + uint8_t index; + struct iovec *caps; +}; + typedef void (*bt_bap_ready_func_t)(struct bt_bap *bap, void *user_data); typedef void (*bt_bap_destroy_func_t)(void *user_data); typedef void (*bt_bap_debug_func_t)(const char *str, void *user_data); @@ -323,3 +346,7 @@ void bt_bap_update_bcast_source(struct bt_bap_pac *pac, bool bt_bap_pac_bcast_is_local(struct bt_bap *bap, struct bt_bap_pac *pac); struct iovec *bt_bap_stream_get_base(struct bt_bap_stream *stream); + +bool bt_bap_parse_base(struct bt_bap *bap, void *data, size_t len, + util_debug_func_t func, struct bt_bap_base *base); + From patchwork Wed Feb 7 12:23:07 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Istodorescu X-Patchwork-Id: 771025 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2082.outbound.protection.outlook.com [40.107.105.82]) (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 6BAD559B7F for ; Wed, 7 Feb 2024 12:23:21 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.105.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707308604; cv=fail; b=eBRM66r3mCmSAlTWsGGBh5M74ozXMMw8To/9fbKoxHDub5GlBJ9u4JqP2GsXY/I08lBDSUVTSn5NEYXGBIADNU27ZBB9eiSAtLUu5LK3ara9VSdir+NhZ/hznLSnv0ARn1fRVUmCOdS1TyJyziMZEZnYLCoYaGw1f68BVGo/cqI= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707308604; c=relaxed/simple; bh=4iZUinHFJm9PUlCoBD356fBc5vGJVcAt9pB9ejc3dn0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=O83EXP06A51B9XcnJ/p7iOd6A/xDQv+HxjdIfdjVyoYCkJwd+Ifce3H1Ou6ZnyYu4zNdRQIbP1qDtSo+E5U17Laa6MNJwJO0/Dq8z9+fpcF0NFW0S2U00QjPR6DMENwVD7eR4MczJX9St9wH00DZjTgRlfSEUWhYZtQYgzHjjsM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b=m8Q0+HtD; arc=fail smtp.client-ip=40.107.105.82 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="m8Q0+HtD" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=jwuQqVNIBxt7bCd/kSkKloDk2cwWXnEC/zbTcL3eyErY97VePsTcc/v6Eb42tzONxUBN0+ABMz46blLvgwl07U87sHgQ6JKHlu4jZhtCQs9PyZphXCtoj6vkkWx77WRkyjHf6lJXrgt3nrG3jBBRVF6QfoahWb/OGSc4sBoe4jT4JiRzsX1LwF7/eA+m8/o9pwkgkkJ6+l5SWK6I1kAjMGAweQkGZbevye/PE2pdptQyF4E8qN5etqf03hl/SSiBDhQbI0ZOJgBJQhKAsYecKbF/n5G9w3EWyep10Y4+QyatZcjamQ7rSLOBSZ70SMJTjZawn2kyjbLPkoQoZuvWrQ== 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=BZwaK20WX7LvnujAkA0F50ez8kq6qrgNF1cPvThyhj4=; b=EtBlZ29HzJanT70BfrJp3muozR2c2ryZyGvtiHoVzNV70mvBqe3lsqKCXmzf5lhIeULZSt3uzQCS78Q/PfrMKlkefAV5X2H7mQ+CFUZW+3WT+u+OVUOFVu2D1bqDs76bItl09CK/vZ0wlPzRiF3PYX36Lz6GwOVXkYaA1azZBgQKzAjbgDv27pI89n53J1V6cYEH8qULMAYTzCYrgHe3n+kxWhNneez3JN/OgdPIqLKVC2HDb2/aBelOsi9A/8nHDiJ3zyApFmxEBHdUBRx1c1R6iH5WY2LZwuqA+nOj8yubI0956PN0pnzuBEBZZKq1AdN1GCILwKIbJ1tUqSpcuA== 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=BZwaK20WX7LvnujAkA0F50ez8kq6qrgNF1cPvThyhj4=; b=m8Q0+HtDxOkYOSRbEfm3YE9nylN3LvtwN3kK+K5si27qtF3DHlI78DrLcu6+F+ejRG/ZUBcGVhwFf5q0CVg5WHsLr+BJZxE5W21O/+jEtrhVJhOI80DVTQSieqGI14J4BE7p2rF6Ez6qvAk2UcDj5PEVGUD4da0g79+hRQSH/OU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM9PR04MB8938.eurprd04.prod.outlook.com (2603:10a6:20b:409::20) by GVXPR04MB9851.eurprd04.prod.outlook.com (2603:10a6:150:118::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.36; Wed, 7 Feb 2024 12:23:15 +0000 Received: from AM9PR04MB8938.eurprd04.prod.outlook.com ([fe80::bbd0:4409:3f0e:afdd]) by AM9PR04MB8938.eurprd04.prod.outlook.com ([fe80::bbd0:4409:3f0e:afdd%4]) with mapi id 15.20.7249.035; Wed, 7 Feb 2024 12:23:15 +0000 From: Andrei Istodorescu To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, mihai-octavian.urzica@nxp.com, silviu.barbulescu@nxp.com, vlad.pruteanu@nxp.com, iulia.tanasescu@nxp.com, Andrei Istodorescu Subject: [PATCH BlueZ 2/3] shared/bap: Add API to convert parsed BASE into pac data Date: Wed, 7 Feb 2024 14:23:07 +0200 Message-Id: <20240207122308.26457-3-andrei.istodorescu@nxp.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240207122308.26457-1-andrei.istodorescu@nxp.com> References: <20240207122308.26457-1-andrei.istodorescu@nxp.com> X-ClientProxiedBy: AM9P193CA0007.EURP193.PROD.OUTLOOK.COM (2603:10a6:20b:21e::12) To AM9PR04MB8938.eurprd04.prod.outlook.com (2603:10a6:20b:409::20) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8938:EE_|GVXPR04MB9851:EE_ X-MS-Office365-Filtering-Correlation-Id: 4b580d9e-35cd-42ba-3e4c-08dc27d78f56 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JI5HnOcNwEcK6DU7ZtI2/u/pJKe7lIPmQtotPoJFOmDZJVxnbtbFkUe7U/EKC4ePlC0KHKNoik1dphlU4CpkC6JlYIkq/KcGAQdUUlpO+oouyeLeq7rJQtZN0neDlF5o3wNH/Dp9UjzsU5aaBg5nZaCtKh0XcZKapLH4GBnrkGe+M1a0NjtB576GT6jGZIRloEvt1DDM6ybOYHqwVff1xTsBuDquYejnBRZLE9WooSijezFc8zKsWjEy6ug3sxbynSONmwCx87BLCTgMrZRdAIO6vq6CIuuj37mByLEZOxLoixsekhZmz5y+0fYJ+iPL+q+EujRF5ZXQ63SnRUa/qZ97ziidmL4v1Ucl88+d9gnsJBWy3/32TaOjRxVWU3STll4lc32XF0CJWKrNALxwPpkjiwT+C8yrKmN+7GpU9SijNCrfqYFcfMbrrYuWkEBdn3fU2KDNktXZ+1oRoabxJSmVQN2WzEfTt43qxMuo6Mk6o6koM18HKJj/4Lq+ZKdTOk9gOu8M43TIOYiwz2VkcXDtyw0frQeEM7sukethrQ8GsQmNBG/3577Yj4aZ8FxF X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR04MB8938.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(39860400002)(346002)(396003)(366004)(376002)(136003)(230922051799003)(1800799012)(64100799003)(186009)(451199024)(6666004)(6506007)(38100700002)(83380400001)(26005)(86362001)(41300700001)(1076003)(2616005)(8676002)(6512007)(4326008)(8936002)(36756003)(30864003)(478600001)(2906002)(5660300002)(6486002)(66556008)(6916009)(66946007)(66476007)(316002)(44832011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ASKzjW0bHejdM976emfi+Mj42nJanSaZrOlB1K9LWwORtEyFW2wHCTNUZ928ER1XV6ViOmhwI/eyWUUllG6BnLS3umcBfo3NivPgoCZ/P2L8ESjHRcqGhikI5AykNHvwmUEMNPII17lBDlPHxeAcKteBGrFD/l5fNEaaVdCOgBbPb9CrbPfTtS8Af17bcQt6swi5QqMglKcEQsdKsL3r6VXAVUNROu7SAlI1PMTdtj2hbO3F1ZgTk62qIJ1DcGuq1EDEmSC3olwCOrq3sOelVZ4v2r4fnbAFtTzPPSqCguGv0KL9xIubWbAlt2Wj06Zv5LopN2xchJGbQFbhjLTk6h//ZeMuZt/zKEFkWA+g3CpUK6GTqrhL6MqnMQRpZu6dQrjPKy2q5RlfYKjqpFIr/rYeVdoPHX2p+oJZr+NgyGjRRKTLk83gFa5uPXEUHJexGjSGED8dyBAOn9wTx2np5LgReJ8S/rlUbl/NQenfFnAZ5Qs3/hRzgkVBi+ENwI+suQABAFwnZWIlHUKC1Dz4sS7qRal6XqgbBNu8Z8NG/4I/wLhrxF/HluxmJC7cXtPoRB3o/XIwrI94UcyNUS35D3LCHBIxJBfnpPoIjLTvtGgCg966bSmB/iR/xyseRorQM1GOsXJsQpkKUvbF9WbEc5imvrwA1QWLPM9csyd1VaK23vOFH1RBl6lPe0bU6iu314nfKDC8axz2zyLrnJAeQPdsX6s2OJdnVMlPFL1890XR43YVEKVOfRn6VEVzey23kxphnnacW0/lzx0ax95o3lD/PFg/l2HAuI/7PgpQaVmNOJ2sxthPo88j9HcjXJ8sGSaoHVvc5EmvUd89umSRSKO0tAebdZHwGT7V5V9MNZ92DXjUmDW8IwYrUwg4ZTHcG65TxPFu83rs59i+bFVlu5uBACk78tXuNiu+gIhuK556IzQRIcQv8zJJlFeHE8vl8EIWnn0u7MVs8iyLJ+QaPAf6K8A/PJkeZO66S9heEO8GMGANpodvrH0e29MDCRCz0Q1yRR/dR3dUxcBrTA6S2M+QoGOXolgEXmuRPRvKwek5wpU6gB01+EJYqdT9g0+YaxlC1NK1Ztm8TbxnJ49+K9vQZ7GPIvvW+wgcQW16UkbFlQtCkjBqq/68EXHepx08zT8fm+vsHrmJ7wEm/T/tLyMtF4sMLfpSSahaIiqdm8hriKLjiHg4366O3JMu3F/oD4oMRClpm+jTSQGrAfJ5R7ZUMFZ5Kv51eBMZ1vpw5bOADQE7IrcCpvdz3ggZoU2lUAyqT86CdUGOwUkmpB6fJns32HqDywlFqEWzcjoDLHfxLuYPH4HfMaro51flFb90hHoaWViIbKocFUSovtbqEMPQXSMiFEw1bgMAOmiQeLxSSJiECpFjF63ywwvGr10mZfITPO1GlUXeqZFQ6c8X8teBjyrmG/wO/jq7b+JE1zwXeFeNFRjVJVhgh1e/XT7W8nqtrN3Twdc2bHlaRIqxzf7ckcPUDV2deN0ioqw2+oC8ox7qL6TQrvL0lRaVQ6YFnVbytiRjQRRPmeA0IucpObRD1arRjndddreIARyZRpHa7z5b1VXNpcebAF9SIehJmYgdPTGtO+FsHc7GVg5zWw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4b580d9e-35cd-42ba-3e4c-08dc27d78f56 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8938.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2024 12:23:15.7425 (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: JevQRZTk0MXPFx30lpou+hFH/wG6gF3dO3yqJ51yZy/r6NkTsTrJy9prwt+9zKDTPA9nWVb/dQ/x6LHiPGdwhXZ+bIEmmB4hzyS0hSL38gs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB9851 Create one remote endpoint for each BIS present in the BASE which matches the local sink capabilities. Add API to get the PAC metadata and capabilities. --- src/shared/bap.c | 502 ++++++++++++++++++++++++++++++++++------------- src/shared/bap.h | 11 +- 2 files changed, 375 insertions(+), 138 deletions(-) diff --git a/src/shared/bap.c b/src/shared/bap.c index aa78b1b74fbb..09f681688cc7 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -48,6 +48,11 @@ #define BAP_PROCESS_TIMEOUT 10 +#define BAP_FREQ_LTV_TYPE 1 +#define BAP_DURATION_LTV_TYPE 2 +#define BAP_CHANNEL_ALLOCATION_LTV_TYPE 3 +#define BAP_FRAME_LEN_LTV_TYPE 4 + struct bt_bap_pac_changed { unsigned int id; bt_bap_pac_func_t added; @@ -2655,6 +2660,13 @@ static void bap_add_broadcast_source(struct bt_bap_pac *pac) static void bap_add_broadcast_sink(struct bt_bap_pac *pac) { queue_push_tail(pac->bdb->broadcast_sinks, pac); + + /* Update local PACS for broadcast sink also, when registering an + * endpoint + */ + pacs_add_sink_location(pac->bdb->pacs, pac->qos.location); + pacs_add_sink_supported_context(pac->bdb->pacs, + pac->qos.supported_context); } static void notify_pac_added(void *data, void *user_data) @@ -2806,6 +2818,16 @@ struct bt_bap_pac_qos *bt_bap_pac_get_qos(struct bt_bap_pac *pac) return &pac->qos; } +struct iovec *bt_bap_pac_get_data(struct bt_bap_pac *pac) +{ + return pac->data; +} + +struct iovec *bt_bap_pac_get_metadata(struct bt_bap_pac *pac) +{ + return pac->metadata; +} + uint8_t bt_bap_stream_get_type(struct bt_bap_stream *stream) { if (!stream) @@ -4631,11 +4653,6 @@ unsigned int bt_bap_stream_config(struct bt_bap_stream *stream, return req->id; case BT_BAP_STREAM_TYPE_BCAST: stream->qos = *qos; - if (stream->lpac->type == BT_BAP_BCAST_SINK) { - if (data) - stream_config(stream, data, NULL); - stream_set_state(stream, BT_BAP_STREAM_STATE_CONFIG); - } return 1; } @@ -5643,8 +5660,9 @@ static void add_new_subgroup(struct bt_bap_base *base, struct bt_ltv_match { uint8_t l; - uint8_t *v; + void *data; bool found; + uint32_t data32; }; struct bt_ltv_search { @@ -5663,7 +5681,7 @@ static void match_ltv(size_t i, uint8_t l, uint8_t t, uint8_t *v, if (ltv_match->l != l) return; - if (!memcmp(v, ltv_match->v, l)) + if (!memcmp(v, ltv_match->data, l)) ltv_match->found = true; } @@ -5675,7 +5693,7 @@ static void search_ltv(size_t i, uint8_t l, uint8_t t, uint8_t *v, ltv_match.found = false; ltv_match.l = l; - ltv_match.v = v; + ltv_match.data = v; util_ltv_foreach(ltv_search->iov->iov_base, ltv_search->iov->iov_len, &t, @@ -5716,8 +5734,10 @@ static bool compare_ltv(struct iovec *iov1, } struct bt_ltv_extract { - struct iovec *result; struct iovec *src; + void *value; + uint8_t len; + struct iovec *result; }; static void extract_ltv(size_t i, uint8_t l, uint8_t t, uint8_t *v, @@ -5729,7 +5749,7 @@ static void extract_ltv(size_t i, uint8_t l, uint8_t t, uint8_t *v, ltv_match.found = false; ltv_match.l = l; - ltv_match.v = v; + ltv_match.data = v; /* Search each BIS caps ltv in subgroup caps * to extract the one that are BIS specific @@ -5883,12 +5903,16 @@ static void cleanup_subgroup(struct bt_bap_subgroup *subgroup) free(subgroup); } +static void print_ltv(size_t i, uint8_t l, uint8_t t, uint8_t *v, + void *user_data) +{ + util_debug(user_data, NULL, "CC #%zu: l:%u t:%u", i, l, t); + util_hexdump(' ', v, l, user_data, NULL); +} + bool bt_bap_parse_base(struct bt_bap *bap, void *data, size_t len, util_debug_func_t func, struct bt_bap_base *base) { - uint8_t num_subgroups; - uint8_t num_bis; - struct iovec iov = { .iov_base = data, .iov_len = len, @@ -5903,161 +5927,369 @@ bool bt_bap_parse_base(struct bt_bap *bap, void *data, size_t len, if (!util_iov_pull_u8(&iov, &base->num_subgroups)) return false; - util_debug(func, NULL, "NumSubgroups %d", base->num_subgroups); - num_subgroups = base->num_subgroups; + util_debug(func, NULL, "Number of Subgroups: %d", base->num_subgroups); - for (int sg = 0; sg < num_subgroups; sg++) { - struct bt_bap_subgroup *sub_group = new0( + for (int idx = 0; idx < base->num_subgroups; idx++) { + struct bt_bap_subgroup *subgroup = new0( struct bt_bap_subgroup, 1); - uint8_t caps_len, metaLen; - uint8_t *hexstream; - sub_group->subgroup_index = sg; + subgroup->index = idx; - util_debug(func, NULL, "Subgroup #%d", sg); - sub_group->bap = bap; - sub_group->bises = queue_new(); + util_debug(func, NULL, "Subgroup #%d", idx); + subgroup->bap = bap; + subgroup->bises = queue_new(); - if (!util_iov_pull_u8(&iov, &num_bis)) { - cleanup_subgroup(sub_group); - goto fail; - } - util_debug(func, NULL, "NumBis %d", num_bis); - sub_group->num_bises = num_bis; - - memcpy(&sub_group->codec, util_iov_pull_mem(&iov, - sizeof(struct bt_bap_codec)), sizeof(struct bt_bap_codec)); - util_debug(func, NULL, "%s: ID %d CID 0x%2.2x VID 0x%2.2x", - "Codec", sub_group->codec.id, sub_group->codec.cid, - sub_group->codec.vid); - if (!util_iov_pull_u8(&iov, &caps_len)) { - cleanup_subgroup(sub_group); + if (!util_iov_pull_u8(&iov, &subgroup->num_bises)) goto fail; - } - util_debug(func, NULL, "CC Len %d", caps_len); + util_debug(func, NULL, "Number of BISes: %d", + subgroup->num_bises); - /* - * Copy the Codec Specific configurations from base - */ - sub_group->caps = new0(struct iovec, 1); - util_iov_memcpy(sub_group->caps, iov.iov_base, caps_len); - util_debug(func, NULL, "subgroup caps len %ld", - sub_group->caps->iov_len); - - for (int i = 0; caps_len > 1; i++) { - struct bt_ltv *ltv = util_iov_pull_mem(&iov, - sizeof(*ltv)); - uint8_t *caps; - - if (!ltv) { - util_debug(func, NULL, "Unable to parse %s", - "Capabilities"); - cleanup_subgroup(sub_group); - goto fail; - } + memcpy(&subgroup->codec, util_iov_pull_mem(&iov, + sizeof(struct bt_bap_codec)), + sizeof(struct bt_bap_codec)); + util_debug(func, NULL, "Codec: ID %d CID 0x%2.2x VID 0x%2.2x", + subgroup->codec.id, subgroup->codec.cid, + subgroup->codec.vid); - util_debug(func, NULL, "%s #%u: len %u type %u", - "CC", i, ltv->len, ltv->type); + /* BASE Level 2 */ + /* Read Codec Specific Configuration */ + subgroup->caps = new0(struct iovec, 1); + if (!util_iov_pull_u8(&iov, (void *)&subgroup->caps->iov_len)) + goto fail; - caps = util_iov_pull_mem(&iov, ltv->len - 1); - if (!caps) { - util_debug(func, NULL, "Unable to parse %s", - "CC"); - cleanup_subgroup(sub_group); - goto fail; - } - util_hexdump(' ', caps, ltv->len - 1, func, NULL); + util_iov_memcpy(subgroup->caps, + util_iov_pull_mem(&iov, + subgroup->caps->iov_len), + subgroup->caps->iov_len); - caps_len -= (ltv->len + 1); - } + /* Print Codec Specific Configuration */ + util_debug(func, NULL, "CC len: %ld", + subgroup->caps->iov_len); + util_ltv_foreach(subgroup->caps->iov_base, + subgroup->caps->iov_len, NULL, print_ltv, func); - if (!util_iov_pull_u8(&iov, &metaLen)) { - cleanup_subgroup(sub_group); + /* Read Metadata */ + subgroup->meta = new0(struct iovec, 1); + if (!util_iov_pull_u8(&iov, (void *)&subgroup->meta->iov_len)) goto fail; - } - util_debug(func, NULL, "Metadata Len %d", metaLen); - sub_group->meta = new0(struct iovec, 1); - sub_group->meta->iov_len = metaLen; - sub_group->meta->iov_base = iov.iov_base; + util_iov_memcpy(subgroup->meta, + util_iov_pull_mem(&iov, + subgroup->meta->iov_len), + subgroup->meta->iov_len); - hexstream = util_iov_pull_mem(&iov, metaLen); - if (!hexstream) { - cleanup_subgroup(sub_group); - goto fail; - } - util_hexdump(' ', hexstream, metaLen, func, NULL); + /* Print Metadata */ + util_debug(func, NULL, "Metadata len: %i", + (uint8_t)subgroup->meta->iov_len); + util_hexdump(' ', subgroup->meta->iov_base, + subgroup->meta->iov_len, func, NULL); - for (int bis_sg = 0; bis_sg < sub_group->num_bises; bis_sg++) { + /* BASE Level 3 */ + for (int bis_sg = 0; bis_sg < subgroup->num_bises; bis_sg++) { struct bt_bap_bis *bis; - uint8_t caps_len; - uint8_t crt_bis; - if (!util_iov_pull_u8(&iov, &crt_bis)) { - cleanup_subgroup(sub_group); + bis = new0(struct bt_bap_bis, 1); + if (!util_iov_pull_u8(&iov, &bis->index)) goto fail; - } - util_debug(func, NULL, "BIS #%d", crt_bis); - bis = new0(struct bt_bap_bis, 1); - bis->index = crt_bis; + util_debug(func, NULL, "BIS #%d", bis->index); - if (!util_iov_pull_u8(&iov, &caps_len)) { - cleanup_subgroup(sub_group); + /* Read Codec Specific Configuration */ + bis->caps = new0(struct iovec, 1); + if (!util_iov_pull_u8(&iov, + (void *)&bis->caps->iov_len)) goto fail; - } - util_debug(func, NULL, "CC Len %d", caps_len); - bis->caps = new0(struct iovec, 1); - bis->caps->iov_len = caps_len; - util_iov_memcpy(bis->caps, iov.iov_base, caps_len); - util_debug(func, NULL, "bis caps len %ld", + util_iov_memcpy(bis->caps, + util_iov_pull_mem(&iov, + bis->caps->iov_len), bis->caps->iov_len); - for (int i = 0; caps_len > 1; i++) { - struct bt_ltv *ltv = util_iov_pull_mem(&iov, - sizeof(*ltv)); - uint8_t *caps; - - if (!ltv) { - util_debug(func, NULL, "Unable to parse %s", - "Capabilities"); - cleanup_subgroup(sub_group); - goto fail; - } - - util_debug(func, NULL, "%s #%u: len %u type %u", - "CC", i, ltv->len, ltv->type); - - caps = util_iov_pull_mem(&iov, ltv->len - 1); - if (!caps) { - util_debug(func, NULL, - "Unable to parse %s", "CC"); - cleanup_subgroup(sub_group); - goto fail; - } - util_hexdump(' ', caps, ltv->len - 1, func, - NULL); - - caps_len -= (ltv->len + 1); - } + /* Print Codec Specific Configuration */ + util_debug(func, NULL, "CC Len: %d", + (uint8_t)bis->caps->iov_len); + util_ltv_foreach(bis->caps->iov_base, + bis->caps->iov_len, NULL, print_ltv, + func); - queue_push_tail(sub_group->bises, bis); + queue_push_tail(subgroup->bises, bis); } - queue_push_tail(base->subgroups, sub_group); + queue_push_tail(base->subgroups, subgroup); } return true; fail: - while (!queue_isempty(base->subgroups)) { - struct bt_bap_subgroup *subGroup = - queue_peek_head(base->subgroups); - cleanup_subgroup(subGroup); - base->num_subgroups--; - } util_debug(func, NULL, "Unable to parse %s", "Base"); return false; } + +static void bap_sink_get_allocation(size_t i, uint8_t l, uint8_t t, + uint8_t *v, void *user_data) +{ + uint32_t location32; + + if (!v) + return; + + memcpy(&location32, v, l); + *((uint32_t *)user_data) = le32_to_cpu(location32); +} + +/* + * This function compares PAC Codec Specific Capabilities, with the Codec + * Specific Configuration LTVs received in the BASE of the BAP Source. The + * result is accumulated in data32 which is a bitmask of types. + */ +static void check_pac_caps_ltv(size_t i, uint8_t l, uint8_t t, uint8_t *v, + void *user_data) +{ + struct bt_ltv_match *compare_data = user_data; + uint8_t *bis_v = compare_data->data; + + switch (t) { + case BAP_FREQ_LTV_TYPE: + { + uint16_t mask = *((uint16_t *)v); + + mask = le16_to_cpu(mask); + if (mask & (1 << (bis_v[0] - 1))) + compare_data->data32 |= 1<data32 |= 1<= min) && + (frame_len <= max)) + compare_data->data32 |= 1<data; + struct bt_ltv_match compare_data; + + compare_data.data = v; + + /* Search inside local PAC's caps for LTV of type t */ + util_ltv_foreach(pac_caps->iov_base, pac_caps->iov_len, &t, + check_pac_caps_ltv, &compare_data); + + local_data->data32 |= compare_data.data32; +} + +static void bap_sink_check_level3_ltv(size_t i, uint8_t l, uint8_t t, + uint8_t *v, void *user_data) +{ + struct bt_ltv_extract *merge_data = user_data; + + merge_data->value = v; + merge_data->len = l; +} + +static void bap_push_ltv(struct iovec *output, uint8_t l, uint8_t t, void *v) +{ + l++; + iov_append(output, 1, &l); + iov_append(output, 1, &t); + iov_append(output, l - 1, v); +} + +static void bap_sink_check_level2_ltv(size_t i, uint8_t l, uint8_t t, + uint8_t *v, void *user_data) +{ + struct bt_ltv_extract *merge_data = user_data; + + merge_data->value = NULL; + util_ltv_foreach(merge_data->src->iov_base, + merge_data->src->iov_len, + &t, + bap_sink_check_level3_ltv, user_data); + + /* If the LTV at level 2 was found at level 3 add the one from level 3, + * otherwise add the one at level 2 + */ + if (merge_data->value) + bap_push_ltv(merge_data->result, merge_data->len, + t, merge_data->value); + else + bap_push_ltv(merge_data->result, l, t, v); +} + +static void check_local_pac(void *data, void *user_data) +{ +#define Codec_Specific_Configuration_Check_Mask (\ + (1<data; + const struct bt_bap_pac *pac = data; + + /* Keep searching for a matching PAC if one wasn't found + * in previous PAC element + */ + if (compare_data->found == false) { + struct bt_ltv_match bis_compare_data = { + .data = pac->data, + .data32 = 0, /* LTVs bitmask result */ + .found = false + }; + + /* loop each BIS LTV */ + util_ltv_foreach(bis_data->iov_base, bis_data->iov_len, NULL, + check_source_ltv, &bis_compare_data); + + /* We have a match if all selected LTVs have a match */ + if ((bis_compare_data.data32 & + Codec_Specific_Configuration_Check_Mask) == + Codec_Specific_Configuration_Check_Mask) + compare_data->found = true; + } +} + +static void bap_sink_match_allocation(size_t i, uint8_t l, uint8_t t, + uint8_t *v, void *user_data) +{ + struct bt_ltv_match *data = user_data; + uint32_t location32; + + if (!v) + return; + + memcpy(&location32, v, l); + + /* If all the bits in the received bitmask are found in + * the local bitmask then we have a match + */ + if ((le32_to_cpu(location32) & data->data32) == + le32_to_cpu(location32)) + data->found = true; + else + data->found = false; +} + +static bool bap_check_bis(struct bt_bap_db *ldb, struct iovec *bis_data) +{ + struct bt_ltv_match compare_data = {}; + + /* Check channel allocation against the PACS location. + * If we don't have a location set we can accept any BIS location. + * If the BIS doesn't have a location set we also accept it + */ + compare_data.found = true; + + if (ldb->pacs->sink_loc_value) { + uint8_t type = BAP_CHANNEL_ALLOCATION_LTV_TYPE; + + compare_data.data32 = ldb->pacs->sink_loc_value; + util_ltv_foreach(bis_data->iov_base, bis_data->iov_len, &type, + bap_sink_match_allocation, &compare_data); + } + + /* Check remaining LTVs against the PACs list */ + if (compare_data.found) { + compare_data.data = bis_data; + compare_data.found = false; + queue_foreach(ldb->broadcast_sinks, check_local_pac, + &compare_data); + } + + return compare_data.found; +} + +static void bis_to_pac(void *data, void *user_data) +{ + struct bt_bap_bis *bis = data; + struct bt_bap_subgroup *subgroup = user_data; + struct bt_bap_pac *pac_source_bis; + struct bt_bap_endpoint *ep; + int err = 0; + struct bt_bap_pac_qos bis_qos = {0}; + uint8_t type = 0; + struct bt_ltv_extract merge_data = {0}; + + merge_data.src = bis->caps; + merge_data.result = new0(struct iovec, 1); + + /* Create a Codec Specific Configuration with LTVs at level 2 (subgroup) + * overwritten by LTVs at level 3 (BIS) + */ + util_ltv_foreach(subgroup->caps->iov_base, + subgroup->caps->iov_len, + NULL, + bap_sink_check_level2_ltv, &merge_data); + + /* Check each BIS Codec Specific Configuration LTVs against our Codec + * Specific Capabilities and if the BIS matches create a PAC with it + */ + if (bap_check_bis(subgroup->bap->ldb, merge_data.result) == false) + goto cleanup; + + DBG(subgroup->bap, "Matching BIS %i", bis->index); + + /* Create a QoS structure based on the received BIS information to + * specify the desired channel for this BIS/PAC + */ + type = BAP_CHANNEL_ALLOCATION_LTV_TYPE; + util_ltv_foreach(merge_data.result->iov_base, + merge_data.result->iov_len, &type, + bap_sink_get_allocation, &bis_qos.location); + + /* Create a remote PAC */ + pac_source_bis = bap_pac_new(subgroup->bap->rdb, NULL, + BT_BAP_BCAST_SOURCE, &subgroup->codec, &bis_qos, + merge_data.result, subgroup->meta); + + err = asprintf(&pac_source_bis->name, "%d", bis->index); + + if (err < 0) { + DBG(subgroup->bap, "error in asprintf"); + goto cleanup; + } + + /* Add remote source endpoint */ + if (!subgroup->bap->rdb->broadcast_sources) + subgroup->bap->rdb->broadcast_sources = queue_new(); + queue_push_tail(subgroup->bap->rdb->broadcast_sources, pac_source_bis); + + queue_foreach(subgroup->bap->pac_cbs, notify_pac_added, pac_source_bis); + /* Push remote endpoint with direction sink */ + ep = bap_endpoint_new_broadcast(subgroup->bap->rdb, BT_BAP_BCAST_SINK); + + if (ep) + queue_push_tail(subgroup->bap->remote_eps, ep); + +cleanup: + util_iov_free(merge_data.result, 1); +} + +/* + * Parse each subgroup, check if we can create PACs from its BISes and then + * clear the subgroup data. + */ +void bt_bap_parse_bis(void *data, void *user_data) +{ + struct bt_bap_subgroup *subgroup = data; + + queue_foreach(subgroup->bises, bis_to_pac, subgroup); + cleanup_subgroup(subgroup); +} diff --git a/src/shared/bap.h b/src/shared/bap.h index b13fef688da3..aed3bf52b8d9 100644 --- a/src/shared/bap.h +++ b/src/shared/bap.h @@ -4,7 +4,7 @@ * BlueZ - Bluetooth protocol stack for Linux * * Copyright (C) 2022 Intel Corporation. All rights reserved. - * Copyright 2023 NXP + * Copyright 2023-2024 NXP * */ @@ -101,13 +101,13 @@ struct bt_bap_qos { struct bt_bap_base { uint32_t pres_delay; uint8_t big_id; - uint8_t num_subgroups; uint8_t next_bis_index; + uint8_t num_subgroups; struct queue *subgroups; }; struct bt_bap_subgroup { - uint8_t subgroup_index; + uint8_t index; struct bt_bap *bap; uint8_t num_bises; struct bt_bap_codec codec; @@ -198,6 +198,10 @@ uint16_t bt_bap_pac_get_context(struct bt_bap_pac *pac); struct bt_bap_pac_qos *bt_bap_pac_get_qos(struct bt_bap_pac *pac); +struct iovec *bt_bap_pac_get_data(struct bt_bap_pac *pac); + +struct iovec *bt_bap_pac_get_metadata(struct bt_bap_pac *pac); + uint8_t bt_bap_stream_get_type(struct bt_bap_stream *stream); struct bt_bap_stream *bt_bap_pac_get_stream(struct bt_bap_pac *pac); @@ -349,4 +353,5 @@ struct iovec *bt_bap_stream_get_base(struct bt_bap_stream *stream); bool bt_bap_parse_base(struct bt_bap *bap, void *data, size_t len, util_debug_func_t func, struct bt_bap_base *base); +void bt_bap_parse_bis(void *data, void *user_data); From patchwork Wed Feb 7 12:23:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Istodorescu X-Patchwork-Id: 770676 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2082.outbound.protection.outlook.com [40.107.105.82]) (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 8B54A5A0EC for ; Wed, 7 Feb 2024 12:23:24 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.105.82 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707308607; cv=fail; b=Yeef9GhdVy7GxYAS8HI6+54A5mG6bKVwBS+FDYmCgw5OZtWZAAOYkB3+l90rSmkckMRVNui2HorzQ6J3IJu88B9KAPy7H5zsW3m7cxwtZ4UJuOuJVGCuU1auKgKppjS7X7fvIQ4Af/zWmc1Kbx4F+ntF6j3nZ6q0bY3WAhUUEfw= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707308607; c=relaxed/simple; bh=Uy+DC9nM8GHlUw4eRb8hIc0ddPqYr/Fc7jqqqqSNcr8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=InS9LYXPRkJQjNv1tqBzPrylOHJWg8i6R/QQVqMIvhbyb//eK5PtpX6pRz+T/zQDUymOkihAjt1ISJw7KoQmrr4/DAMdtddp4xiszDJp6hBkXXnefcKhI8KxrPiJTsAK73Jnkh0QrrP6BqXpojmnpLLQtQ8mteXfYb21PDVlmHY= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b=WE//ykNX; arc=fail smtp.client-ip=40.107.105.82 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=nxp.com header.i=@nxp.com header.b="WE//ykNX" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MBLR2IKkCVeujrWiWcCtiVeRK5gui3GzfHkftKHrApmb/+QyfkWU/EPfc8+d9y67CTNKr/s0ZWBvy/bDMG/Y3v3sI5pEQwarv43sH8n8SiQmWifr3WyfMx7mmxQj3jCASeJfJ/PuJxaRqnm9LoNgZbWkkXOe+OYrviiXWsxfqHJhnOu6HY4VxzR89PYPLlbUxuGuF/Va54pHlRyn1q2YhZBj4C3cR9A50HrtEh1ypluarOHjfaYDifcMb2SRRsaNDXHbs3vS33taaO5u9yy+1CrRnuPKZ+YzAIQo3xZC9yk6qWk5t3gMbaST4LXH6Eyy2K8YIb3fr22MnX+x6ENJkA== 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=xwlNumKxkfLFSc2D9C1IxG48P7ocd2n3SvZo6bEF1uk=; b=bU3VKhTQmRfExXU/X0jHkRelpJgT3PT8pZfZuVJ5kNGw9LfM5p6AulyxVkWSWIhCXMtha7aENP7FScIqCnZCw4+L9kr/r1Js4F959+pTTJ2iepf1sRpoQth/+zbmW6kN/HUFNFlmnVp3EiKCKWmWQkqaXpoRmbVGYFkYmyhQMJdakVErrd7v5wnmflRbeYcpqF9pRIkRNWGHdVdo3lmV9SHKcIZhhF4+bpEn3Sp+tednjCH5IStTWtyfHVxVKd/YniCdzoOZxj4CJKdin9l3rJvodR/azCJsqmeLG+a5gGbVohbdRrcPaghUDFJB8zrokIEjsnwZ8GcBS5WKh9IKLg== 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=xwlNumKxkfLFSc2D9C1IxG48P7ocd2n3SvZo6bEF1uk=; b=WE//ykNXytBhgkOolfKrXLgWEOUeFweVaudsq4G2txHX4+lvx9UkXE1K1W5J6jl+7jkb1q0m81fRa3c43XCWFpl4qmapBRa2xcU3Ml0hZVNX0u1wrqTKxdd+VRmdvAK6DCjOK4If1Sy9wBuZsEvG52V9a0HLsL2dJTPfjaLwATk= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AM9PR04MB8938.eurprd04.prod.outlook.com (2603:10a6:20b:409::20) by GVXPR04MB9851.eurprd04.prod.outlook.com (2603:10a6:150:118::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7249.36; Wed, 7 Feb 2024 12:23:17 +0000 Received: from AM9PR04MB8938.eurprd04.prod.outlook.com ([fe80::bbd0:4409:3f0e:afdd]) by AM9PR04MB8938.eurprd04.prod.outlook.com ([fe80::bbd0:4409:3f0e:afdd%4]) with mapi id 15.20.7249.035; Wed, 7 Feb 2024 12:23:17 +0000 From: Andrei Istodorescu To: linux-bluetooth@vger.kernel.org Cc: luiz.dentz@gmail.com, mihai-octavian.urzica@nxp.com, silviu.barbulescu@nxp.com, vlad.pruteanu@nxp.com, iulia.tanasescu@nxp.com, Andrei Istodorescu Subject: [PATCH BlueZ 3/3] bap: Do PA Sync for each BAP Broadcast source discovered Date: Wed, 7 Feb 2024 14:23:08 +0200 Message-Id: <20240207122308.26457-4-andrei.istodorescu@nxp.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240207122308.26457-1-andrei.istodorescu@nxp.com> References: <20240207122308.26457-1-andrei.istodorescu@nxp.com> X-ClientProxiedBy: AM0PR04CA0090.eurprd04.prod.outlook.com (2603:10a6:208:be::31) To AM9PR04MB8938.eurprd04.prod.outlook.com (2603:10a6:20b:409::20) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AM9PR04MB8938:EE_|GVXPR04MB9851:EE_ X-MS-Office365-Filtering-Correlation-Id: b4db5ed4-7dec-4f76-5a29-08dc27d79022 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: e533MLbjiqD5fBcgjPbriSz3SIYUUWevO0nXTkmjf8bW00uBt0M1Od8ZxSo0zEII4FkVbHmesfnvhEyxUtY+3T1NV3t9PgJf8bw94qse2M+FaFHQ1iafCcBqwObdp4iXrj87ZOQ5tFurQcFCfVUszjiKTDUTWoEMCzmN4Fh5VzxU8OjG35gB12MZbROyXRRdcmhbvuDrWMGE5aOLGt6LMdacUDJPNePJKseOauZYMfYNo4PuPTbwTi+o7lvH2kZR7SaPgqm5EdrtHDS+5r2tXIYe02z34URCBKw/2I0P6L5KC8+6JnJ0RVQhh0Zq3XjbmMwXvjohzxBK6wOVCKdGEkIYUvUJ/6AMEl4GZBxleuv6kocLnyjwgKijwkRCix5j1XV7r5FBdTUmr6aIbUOyAc+d0PYkBAEXykrEF4KeXhPEgR/Br5L1ojQR/zoa6OsMdJjnVMBPhqeMQ064iMSMwXarYwD2nyPL818jrdZYduw1W0r6To2HY3TC7SWdIBQV+3ED1MgtpJNbYgmGL2uWmwgcYz/q8Kvamsbys4ZH9l2hNbsnMbRKH4z4PD3FJH54 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AM9PR04MB8938.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(39860400002)(346002)(396003)(366004)(376002)(136003)(230922051799003)(1800799012)(64100799003)(186009)(451199024)(6666004)(6506007)(38100700002)(83380400001)(26005)(86362001)(41300700001)(1076003)(2616005)(8676002)(6512007)(4326008)(8936002)(36756003)(30864003)(478600001)(2906002)(5660300002)(6486002)(66556008)(6916009)(66946007)(66476007)(316002)(44832011); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: o7GGEivphfmJGr31yUj9Roo76Ror5qYajYHzHwPX3zUZyrut5g2mdMD/z2vuneagdaJDPVXIwUsrUagfhRlxRRkM86e8gAnRTeIwKqhycsluLv/0uRH18YTBxM1pFrq/fsPkbHcEI7xbwCtifxdrMCWqH1ed/5SNHLmu76UREGj+CHCw2cwqt7+8UdnXo7TVJezFqeZvQqWyVMNP+F+abHchhGgdRZBDr1HIy4DBrRsvB9/lm7O6CGZ4zwyxrLGqS79tEDeS/AjtrDQlNyBkABD5jtYycW7kICduOwrG6h9RDj/RgVL48iAlf+JZe5j5jNeESYyYyIOp7nTWs6W+xxWtByI/D1RqoA40e0jt3SLcO7IjpXp71UiwRjHkN5ZERfsXcSAvibwoRhZg/bXJwL7pA6AxGZXujridNzbDG5U/T2GDDW/3MShSryy8TsvJLLl9yVc+3P/QDrGNQsE8cgg5SPeCW/hjvdCqle2ViA0zq3bZPxvwzkqT1Ban7b8NoYUDrwoSDR+yxCygqo2a0nnlmPfx9w8GMBbaeL7z0P4nc+Rp4r+P50MQG8i3DrTmLYcaAMWTVKbVtfw3L3cu8Uycb2BUVsbroqM+rcS/BtqnGXtHU8w+nS6ZQ4XnvngpuM0iul48wyAYr+PexB8u3LSbX5ersaOqzOlcFLWvRsH2JyBbwhS8IOf+qJns7D8tmrcNFr7+VDs7eli/5uqBz1b/FNASzx+rx5Go6bPI08HId1A5Db7em4WrAGlb/lA9aujNHDRj5rlZjsrM+ssiiyFR4E4pSehojeT/vuZMuAyye+KM4Bqwy6Thmu0YH8ebFO7a+nrSAkuEyOf4dhAmBy6mTuInDQUjQsWyeFwJR2oob+b1PcPDSf5SjnS9Db/QRtrqApwmXv1cUKBjP4aPexZ0a4K6JlpcLJHB3nqtwwcG3RBsZNBNmbqEwfWbI9s4kdLIQyiJRWROXeudCnND6BF7QBdWzwQ+8V/a0XXlhF6z2XgoZDQuG7k/jcBfd+cPfmm5e8vKwJRHUbr3Br8y692JynSCeI7VUf1L+135Awfly39eHD6H1jPF9bgNu0uPl9qNW/OM0EL2GqYldoLeB88zU16GSAuJu8x9lRi/cD9nRc0JWN7BjrvMRvBoBI1y3czgOKOGSr+DnjiIE0BMEdL0Yek2NZAVQYfUT7aNcmV6z07hmsqDsMlImfzL//l/7hPfiaLM30mOfJfzsa9EZfGAuvhrHzQiyVvV6Z/goHmf/i4E3SGPYMFvgj9kv82X5FC5/+DYOjAxdb3VUOnPnNavO8ZEQiQe21gNhAmF5WLGgJPpDh3H6NMzChgT4HMIHjjPvkl2LANxRrYrhuFG/7zF3Nv7vi7/3hpvB1/pNprHW2SdAJ1j9xsmdqv30E4cWvj7czW9RMRros9pOrMRNC6GwsGmOKoiRE8MvDxdGuLFlqkP3bxnMxidNq9ypk8T3qQXIxUswWSjmtkyFn7eG1+u+B3tmiidA8AsK3fHjn8YtIEUDEgoPwt5H7Mkjl0Ryh6idKCsqCpnKkEODJ0nWdlBruNUZ39dz4Vul0d7kJxebdONX54nNBQKu7C+bj0Y9MFXTAlAkHp0alc32dy90g== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b4db5ed4-7dec-4f76-5a29-08dc27d79022 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8938.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Feb 2024 12:23:17.0957 (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: oDLtIwTJXaOSjXwxeSNzBQKNb563MEsnArBUelWuWxTPX3XHW+swXHrIserQkY5YfKppYXIZEqy4fGVqOxV/6t0NcIm+n0iu01Ox6J8c7FA= X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB9851 After discovering a BAP Broadcast Source do a short PA sync first to learn the BASE. After discovering the BASE check how many BISes are matching the sink capabilities and create endpoints for them. Allow user to configure one endpoint using "SetConfiguration" causing BIG synchronization to the corresponding BIS; also this results in creating a stream and the corresponding transport. --- profiles/audio/bap.c | 324 +++++++++++++++---------------------------- 1 file changed, 110 insertions(+), 214 deletions(-) diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index 88c93127bea0..8646eae2ed20 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -105,6 +105,44 @@ struct bap_data { void *user_data; }; +/* Structure holding the parameters for periodic train and BIG + * synchronization + */ +static struct bt_iso_qos bap_sink_sync_parameters = { + .bcast = { + .big = BT_ISO_QOS_BIG_UNSET, + .bis = BT_ISO_QOS_BIS_UNSET, + /* HCI_LE_Periodic_Advertising_Create_Sync */ + .options = 0x00, + .skip = 0x0000, + .sync_timeout = 0x4000, + .sync_cte_type = 0x00, + /* HCI_LE_BIG_Create_Sync */ + .encryption = 0x00, + .bcode = {0x00}, + .mse = 0x00, + .timeout = 0x4000, + /* to remove from kernel check */ + .sync_factor = 0x07, + .packing = 0x00, + .framing = 0x00, + .in = { + .interval = 10000, + .latency = 10, + .sdu = 40, + .phy = 0x02, + .rtn = 2, + }, + .out = { + .interval = 10000, + .latency = 10, + .sdu = 40, + .phy = 0x02, + .rtn = 2, + } + } +}; + static struct queue *sessions; static bool bap_data_set_user_data(struct bap_data *data, void *user_data) @@ -422,113 +460,6 @@ static int parse_array(DBusMessageIter *iter, struct iovec *iov) return 0; } -static bool parse_base(void *data, size_t len, util_debug_func_t func, - uint32_t *presDelay, uint8_t *numSubgroups, uint8_t *numBis, - struct bt_bap_codec *codec, struct iovec **caps, - struct iovec **meta) -{ - struct iovec iov = { - .iov_base = data, - .iov_len = len, - }; - - uint8_t capsLen, metaLen; - struct iovec cc; - struct iovec metadata; - - if (presDelay) { - if (!util_iov_pull_le24(&iov, presDelay)) - return false; - util_debug(func, NULL, "PresentationDelay %d", *presDelay); - } - - if (numSubgroups) { - if (!util_iov_pull_u8(&iov, numSubgroups)) - return false; - util_debug(func, NULL, "NumSubgroups %d", *numSubgroups); - } - - if (numBis) { - if (!util_iov_pull_u8(&iov, numBis)) - return false; - util_debug(func, NULL, "NumBis %d", *numBis); - } - - if (codec) { - codec = util_iov_pull_mem(&iov, sizeof(*codec)); - if (!codec) - return false; - util_debug(func, NULL, "%s: ID %d CID 0x%2.2x VID 0x%2.2x", - "Codec", codec->id, codec->cid, codec->vid); - } - - if (!util_iov_pull_u8(&iov, &capsLen)) - return false; - util_debug(func, NULL, "CC Len %d", capsLen); - - if (!capsLen) - return false; - - cc.iov_len = capsLen; - cc.iov_base = util_iov_pull_mem(&iov, capsLen); - if (!cc.iov_base) - return false; - - if (caps) { - if (*caps) - util_iov_free(*caps, 1); - - *caps = util_iov_dup(&cc, 1); - } - - for (int i = 0; capsLen > 1; i++) { - struct bt_ltv *ltv = util_iov_pull_mem(&cc, sizeof(*ltv)); - uint8_t *caps; - - if (!ltv) { - util_debug(func, NULL, "Unable to parse %s", - "Capabilities"); - return false; - } - - util_debug(func, NULL, "%s #%u: len %u type %u", - "CC", i, ltv->len, ltv->type); - - caps = util_iov_pull_mem(&cc, ltv->len - 1); - if (!caps) { - util_debug(func, NULL, "Unable to parse %s", - "CC"); - return false; - } - util_hexdump(' ', caps, ltv->len - 1, func, NULL); - - capsLen -= (ltv->len + 1); - } - - if (!util_iov_pull_u8(&iov, &metaLen)) - return false; - util_debug(func, NULL, "Metadata Len %d", metaLen); - - if (!metaLen) - return false; - - metadata.iov_len = metaLen; - metadata.iov_base = util_iov_pull_mem(&iov, metaLen); - if (!metadata.iov_base) - return false; - - if (meta) { - if (*meta) - util_iov_free(*meta, 1); - - *meta = util_iov_dup(&metadata, 1); - } - - util_hexdump(' ', metadata.iov_base, metaLen, func, NULL); - - return true; -} - static int parse_io_qos(const char *key, int var, DBusMessageIter *iter, struct bt_bap_io_qos *qos) { @@ -954,6 +885,17 @@ static DBusMessage *set_configuration(DBusConnection *conn, DBusMessage *msg, return btd_error_invalid_args(msg); } + /* For BAP Broadcast Sink, the capabilities and metadata are coming + * from the source's BIS, which are present in the remote PAC + */ + if (bt_bap_pac_get_type(ep->lpac) == BT_BAP_BCAST_SINK) { + util_iov_free(setup->caps, 1); + setup->caps = util_iov_dup(bt_bap_pac_get_data(ep->rpac), 1); + util_iov_free(setup->metadata, 1); + setup->metadata = util_iov_dup( + bt_bap_pac_get_metadata(ep->rpac), 1); + } + setup->stream = bt_bap_stream_new(ep->data->bap, ep->lpac, ep->rpac, &setup->qos, setup->caps); @@ -977,95 +919,27 @@ static DBusMessage *set_configuration(DBusConnection *conn, DBusMessage *msg, break; case BT_BAP_STREAM_TYPE_BCAST: /* No message sent over the air for broadcast */ - if (bt_bap_pac_get_type(ep->lpac) == BT_BAP_BCAST_SINK) - setup->msg = dbus_message_ref(msg); - else { + if (bt_bap_pac_get_type(ep->lpac) == BT_BAP_BCAST_SOURCE) setup->base = bt_bap_stream_get_base(setup->stream); - setup->id = 0; } + setup->id = 0; if (ep->data->service) service_set_connecting(ep->data->service); return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); - } return NULL; } -static void update_bcast_qos(struct bt_iso_qos *qos, - struct bt_bap_qos *bap_qos) -{ - bap_qos->bcast.big = qos->bcast.big; - bap_qos->bcast.bis = qos->bcast.bis; - bap_qos->bcast.sync_factor = qos->bcast.sync_factor; - bap_qos->bcast.packing = qos->bcast.packing; - bap_qos->bcast.framing = qos->bcast.framing; - bap_qos->bcast.encryption = qos->bcast.encryption; - bap_qos->bcast.options = qos->bcast.options; - bap_qos->bcast.skip = qos->bcast.skip; - bap_qos->bcast.sync_timeout = qos->bcast.sync_timeout; - bap_qos->bcast.sync_cte_type = qos->bcast.sync_cte_type; - bap_qos->bcast.mse = qos->bcast.mse; - bap_qos->bcast.timeout = qos->bcast.timeout; - bap_qos->bcast.io_qos.interval = qos->bcast.in.interval; - bap_qos->bcast.io_qos.latency = qos->bcast.in.latency; - bap_qos->bcast.io_qos.phy = qos->bcast.in.phy; - bap_qos->bcast.io_qos.sdu = qos->bcast.in.sdu; - bap_qos->bcast.io_qos.rtn = qos->bcast.in.rtn; - if (!bap_qos->bcast.bcode) - bap_qos->bcast.bcode = new0(struct iovec, 1); - util_iov_memcpy(bap_qos->bcast.bcode, qos->bcast.bcode, - sizeof(qos->bcast.bcode)); -} - static void iso_bcast_confirm_cb(GIOChannel *io, GError *err, void *user_data) { struct bap_setup *setup = user_data; - struct bap_ep *ep = setup->ep; - struct bap_data *data = ep->data; - struct bt_iso_qos qos; - struct bt_iso_base base; - char address[18]; int fd; - struct iovec *base_io; - uint32_t presDelay; - uint8_t numSubgroups; - uint8_t numBis; - struct bt_bap_codec codec; - - bt_io_get(io, &err, - BT_IO_OPT_DEST, address, - BT_IO_OPT_QOS, &qos, - BT_IO_OPT_BASE, &base, - BT_IO_OPT_INVALID); - if (err) { - error("%s", err->message); - g_error_free(err); - goto drop; - } - g_io_channel_ref(io); - btd_service_connecting_complete(data->service, 0); - DBG("BCAST ISO: sync with %s (BIG 0x%02x BIS 0x%02x)", - address, qos.bcast.big, qos.bcast.bis); - - update_bcast_qos(&qos, &setup->qos); - - base_io = new0(struct iovec, 1); - util_iov_memcpy(base_io, base.base, base.base_len); - - parse_base(base_io->iov_base, base_io->iov_len, bap_debug, - &presDelay, &numSubgroups, &numBis, - &codec, &setup->caps, &setup->metadata); - - /* Update pac with BASE information */ - bt_bap_update_bcast_source(ep->rpac, &codec, setup->caps, - setup->metadata); - setup->id = bt_bap_stream_config(setup->stream, &setup->qos, - setup->caps, NULL, NULL); - - bt_bap_stream_set_user_data(setup->stream, ep->path); + /* listen channel is not needed anymore */ + g_io_channel_unref(setup->io); + setup->io = NULL; fd = g_io_channel_unix_get_fd(io); @@ -1074,26 +948,43 @@ static void iso_bcast_confirm_cb(GIOChannel *io, GError *err, void *user_data) g_io_channel_set_close_on_unref(io, FALSE); return; } - - - return; - -drop: - g_io_channel_shutdown(io, TRUE, NULL); - } static void iso_pa_sync_confirm_cb(GIOChannel *io, void *user_data) { GError *err = NULL; + struct bap_data *data = user_data; + struct bt_iso_base base; + struct bt_bap_base base_s; + struct bt_iso_qos qos; - if (!bt_io_bcast_accept(io, iso_bcast_confirm_cb, - user_data, NULL, &err, BT_IO_OPT_INVALID)) { - error("bt_io_bcast_accept: %s", err->message); + btd_service_connecting_complete(data->service, 0); + + bt_io_get(io, &err, + BT_IO_OPT_BASE, &base, + BT_IO_OPT_QOS, &qos, + BT_IO_OPT_INVALID); + if (err) { + error("%s", err->message); g_error_free(err); g_io_channel_shutdown(io, TRUE, NULL); + return; } + /* The PA Sync channel becomes the new listen_io. + * It will be later used to listen for a BIS io. + */ + g_io_channel_unref(data->listen_io); + data->listen_io = io; + g_io_channel_ref(io); + + /* Analyze received BASE data and create remote media endpoints for each + * matching BIS + */ + base_s.subgroups = queue_new(); + bt_bap_parse_base(data->bap, base.base, base.base_len, bap_debug, + &base_s); + queue_foreach(base_s.subgroups, bt_bap_parse_bis, NULL); } static bool match_data_bap_data(const void *data, const void *match_data) @@ -1934,12 +1825,11 @@ static void setup_listen_io(struct bap_data *data, struct bt_bap_stream *stream, data->listen_io = io; } -static void setup_listen_io_broadcast(struct bap_data *data, +static void setup_accept_io_broadcast(struct bap_data *data, struct bap_setup *setup, struct bt_bap_stream *stream, struct bt_iso_qos *qos) { - GIOChannel *io; GError *err = NULL; struct sockaddr_iso_bc iso_bc_addr; @@ -1951,29 +1841,18 @@ static void setup_listen_io_broadcast(struct bap_data *data, DBG("stream %p", stream); - /* If IO already set skip creating it again */ - if (bt_bap_stream_get_io(stream) || data->listen_io) - return; - - io = bt_io_listen(NULL, iso_pa_sync_confirm_cb, setup, NULL, &err, - BT_IO_OPT_SOURCE_BDADDR, - btd_adapter_get_address(data->adapter), - BT_IO_OPT_DEST_BDADDR, - device_get_address(data->device), - BT_IO_OPT_DEST_TYPE, - btd_device_get_bdaddr_type(data->device), - BT_IO_OPT_MODE, BT_IO_MODE_ISO, - BT_IO_OPT_QOS, &qos->bcast, - BT_IO_OPT_ISO_BC_NUM_BIS, iso_bc_addr.bc_num_bis, - BT_IO_OPT_ISO_BC_BIS, iso_bc_addr.bc_bis, - BT_IO_OPT_INVALID); - if (!io) { - error("%s", err->message); + if (!bt_io_bcast_accept(data->listen_io, + iso_bcast_confirm_cb, + setup, NULL, &err, + BT_IO_OPT_ISO_BC_NUM_BIS, + iso_bc_addr.bc_num_bis, BT_IO_OPT_ISO_BC_BIS, + iso_bc_addr.bc_bis, BT_IO_OPT_INVALID)) { + error("bt_io_bcast_accept: %s", err->message); g_error_free(err); } - setup->io = io; - data->listen_io = io; + setup->io = data->listen_io; + data->listen_io = NULL; } static void setup_create_ucast_io(struct bap_data *data, struct bap_setup *setup, @@ -2037,7 +1916,7 @@ done: if (bt_bap_pac_get_type(setup->ep->lpac) == BT_BAP_BCAST_SOURCE) setup_connect_io_broadcast(data, setup, stream, &iso_qos); else - setup_listen_io_broadcast(data, setup, stream, &iso_qos); + setup_accept_io_broadcast(data, setup, stream, &iso_qos); } static void setup_create_io(struct bap_data *data, struct bap_setup *setup, @@ -2422,6 +2301,7 @@ static int bap_bcast_probe(struct btd_service *service) struct btd_gatt_database *database = btd_adapter_get_database(adapter); struct bap_data *data = btd_service_get_user_data(service); char addr[18]; + GError *err = NULL; ba2str(device_get_address(device), addr); @@ -2465,7 +2345,23 @@ static int bap_bcast_probe(struct btd_service *service) bt_bap_set_user_data(data->bap, service); - bt_bap_new_bcast_source(data->bap, device_get_path(device)); + DBG("Create PA sync with this source"); + data->listen_io = bt_io_listen(NULL, iso_pa_sync_confirm_cb, data, + NULL, &err, + BT_IO_OPT_SOURCE_BDADDR, + btd_adapter_get_address(data->adapter), + BT_IO_OPT_DEST_BDADDR, + device_get_address(data->device), + BT_IO_OPT_DEST_TYPE, + btd_device_get_bdaddr_type(data->device), + BT_IO_OPT_MODE, BT_IO_MODE_ISO, + BT_IO_OPT_QOS, &bap_sink_sync_parameters, + BT_IO_OPT_INVALID); + if (!data->listen_io) { + error("%s", err->message); + g_error_free(err); + } + return 0; }