From patchwork Fri Feb 9 16:46:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Istodorescu X-Patchwork-Id: 771617 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2046.outbound.protection.outlook.com [40.107.104.46]) (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 5331E7BB1B for ; Fri, 9 Feb 2024 16:46:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.104.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497201; cv=fail; b=MmdcaKnZV4CBlHuaLqwMvIeCDdVJ4NICJRqsXaFq7S6zCEoAjyA6Kpi2PuHgVkmpMbcCYhDSR57cIlxXAnWy0/raERaS77nfO30FbXuAe1dQSjc1IWPlO+VBvjHLbe6y6uQgPIwsx432EK/EbPw7tg6e2HpXexjP27OOrRP5FiM= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497201; c=relaxed/simple; bh=+e7tOTpchwwKMNgD+6yTEKru2vJwzWT1SNfz18NCRGs=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=I4YSz2u7PU9KbCxDRTVOHUVvQ3/f2dSckVKJ6x/WNFNlS7yxBg/mmp1KodiC9M5+VidpcnHjiglg6Lcroe9GSlZyPzUz713Vo1vrKaoJbes7mdWcvHK6rbIQc/vFiSqsbAxGWnYXlOMzsaWcqXgW65dO1Nk2C0RhblCOmV7NGqU= 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=j9uvsqkw; arc=fail smtp.client-ip=40.107.104.46 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="j9uvsqkw" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GW+hw6B4hE6abYERtdagJDU3RoBYPE6ZE87s6tWUtrlrpxKlAPu+9OnjizHPqH0kTZyDIg0J0JqZztbyX6//lI7AcPAyDhcbCkIK4Q2ZjQ01xAR1y0XqV9IK068My0T2f+5t7zb48lYOZzv2WCskVL25Et934o484CONEVt0pXNqS45FejQduPvUaMbCp2by9CXYI40smskvZkcvS4iiEvR99bKEMwDhyd+NtZcRG6y0VZ33yyFpdfcWkhcQBS/eyo21qIrydmv2GKudZfQt0nkX/VokLHdEQcmpCH0O6GPiwH6wJTHDP3TL01NZ11E1djEl9g6SMlOrbycf0NCVQw== 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=h1RkXAC8gdPldq0xPa/OigRjcbqLZvgpk3DedFeLgo0=; b=G2HCkxNe67jOKkpmVCaaMgtXXukNB8jWZfqurfmEco7MKvh2/3Pe7A7khE7Fn2EgRQO9gyP3Ua+E50gE0HcfNMyDGU0F+Acu4gpRFJmIAIS604gNH1TQFFIm+EQ36nU649gysJS1YcFTKt5EDb6HcHP8hdK5cwgagoTnQNxC3dB+9tR2DJUrJ8leJD2dNTEl9xFGGvZl4EAa5xUIZremOxVi1ljzJTSA9URjjwHUBcU5wxM96zpPyZiD3JWPxedNR9Hem6z8ZPoXLw8hg7D5AbOTBE9aKgpQeSOPMPsInhGoAlQG2mHhi3GzCcDsv3b5usXbUWFkBPT27SXXIrl4qQ== 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=h1RkXAC8gdPldq0xPa/OigRjcbqLZvgpk3DedFeLgo0=; b=j9uvsqkwrj/GwznGmi/OwSOvti3gvkkW2ieEw6ntvsVp279SW21lO9t+hqThtqHGIWNtgdY6xGXUMWW0GodXqaYb7YoG39FJ+UGtu8K7OB6i1MPrD26pry6suEjyQD4HFv9EumpoYCK2DLU8FKqjWV2ScwNcfbvBKZcv4e7uX0A= 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 DB8PR04MB7097.eurprd04.prod.outlook.com (2603:10a6:10:12a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.27; Fri, 9 Feb 2024 16:46:35 +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.039; Fri, 9 Feb 2024 16:46:35 +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 v2 1/6] shared/bap: Add API to convert BASE into bt_bap_base queue Date: Fri, 9 Feb 2024 18:46:25 +0200 Message-Id: <20240209164630.92208-2-andrei.istodorescu@nxp.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240209164630.92208-1-andrei.istodorescu@nxp.com> References: <20240209164630.92208-1-andrei.istodorescu@nxp.com> X-ClientProxiedBy: AS4P191CA0002.EURP191.PROD.OUTLOOK.COM (2603:10a6:20b:5d5::6) 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_|DB8PR04MB7097:EE_ X-MS-Office365-Filtering-Correlation-Id: c386a598-f13b-4bd8-376a-08dc298eada8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2cYO6ymcB/tDn14h4aA0lAOPniO41jSf5hUAnSsKoGiooBAAsnd27TEZMQIJUnPNL6fYltXHnyj1y1OCPPMvI4flqgNi734znoX3OfauGnV5z7wNY9ROhHORGKtgLQakn49hDx60UVfBShx3HU2uocUPuKHh3C7uGaAWv9sbsWqvrlOz9FkVz38WeB0lfcze7FhjbGanlEaZYh0WR8uc/EvXi6zSjG2iYEwCIjbxMBflEmc8WFm6DL6cL5s1SbIodYNOJdHxeZ1o1a4yXIYdy/yO5ojq0OFU6PofxeriQKzC6FlZOzK19fFuo2XD0JFP9JamZMozH1YROPjKGcBLMWfZOQLssrkLr607MKPPsipVjpxGBrjA1SzNA0nxNcMhbgqFzCNLkX9DXbtXCieJUnvAwCbkAeXvSwAbhq3IvmYXG6b1SD1cyyH5m11VwNSOI4F7UxpejkK++7ZvRwrmYyXy29WOqn4S5I6izF9q3Z54MiZfe0G12mSK+eOD8djziK9SY/kYHLwziyNvLDBk/z1Qvv4j+U9/XH5NacM7EjKwS9bVnSM18nnLPJpRa6B9 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)(376002)(366004)(136003)(396003)(346002)(230922051799003)(451199024)(186009)(1800799012)(64100799003)(4326008)(5660300002)(30864003)(6916009)(66556008)(66946007)(8676002)(66476007)(8936002)(44832011)(2906002)(83380400001)(26005)(36756003)(86362001)(38100700002)(1076003)(6666004)(316002)(478600001)(41300700001)(6486002)(6506007)(6512007)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: h5yqFtqFbw0t4J29pNOnAMDY12tBd9xo8g5o8pu8KTR3xNhGrKQqTy+L0Ue5rguaSS516+WXJPzq+x1HtY9H4GqnwbNmm/t1uNGCktvx9zhoyEScubmXUsDwVOTg1e5CBDNFjbwYWFu8G6f80X7hTeQAvXSQkHXJ0aAG8Ocs8xEjz888sFirwCQ1zTFD7FpaRPUjp87HV8O/xIP7hHZ4c+wQ96ABTAMnhjq8p6T/tvLqerxQLFD14q8c497yP7Eyq43EVd3uIJOvPiBO9XxGy+H7E9DeSw8SPbeO3KJQgd4bxdeUuwRp+wuehBjGAmBD7u5VBBjPesTvJLVKwgL6xaNTCxu13MSMBiAxMWPXTYhyMBrSKUCZWkDCav2A3z8IXlXXPE+F/2EVfwFmjraSKATDW/V1Ox+9WMRZgwSk11TiY7G0ORuMl861d3p/EYasE2SV/6igS5KEPrauo9Nnwv9a88LNPBj3MCJdcKSqajzqCzjlf3iJq27aG8JRrHTyIo+mLlrMIf5YjoDBiYKTBCl4m79iwCO+UvRd5npwzvW9d7LGWdND7jIwwNufQcAItNG4qdoVTvJPLjMdpSz/uwXgYb+q12UYQKwBQa5IXy6We4N4bdkEnr+7zi/ewZfJRGTX/HU8NVL5Itn164dTNNOvqsNWy6/uW1XYW/jGqloH9yGTMq4+6aX/Du78v7wbllxuoP/I8Ky6q3hU5exlUBPbThkEC3pVomHdOLRsH79ETgVC5DCvmPPH22mK04TqhyREdARc3DItqdWJEP2oNzfuD65DRCfZB3s1qreks4RYHofRC/Xw4VG9NI24542JuaHoqXdXV6lXsvjvU+r7Ms0j8E2ByEQ9aFH1CRW68PvfAvh0exaSyCMs7sip6SsFYCCZ/2dJxvqtR4pfNQk91VY4YUMxIv1HgXeGPucOld85miWvJls6X24nIzjSBg0ppS79ECA+g14Pi7w65Mm2wItrtZrZmkJ/Hs92wueIUGzxm2T4hx6udspfEl0Z+4UBIkBSsoGevRn0gjpvYJFl3/vecWx2s6tFmCtKvxQ4RPDtTgjes/XlKQ/U1W/Ty3n+lDdNMk/BeMv8tDTtkII9f6loQ/oLUuieMtxIw9sM+UNyBpJigCVjzzN3cNwSY4+LBNLnmvgoLytnMzkYWVk1pyPZzj1RFcRMnLhBSYxDmm/IOaQBkfTTjJ6R9cFlFri+UKMrJgqqswOdTmzLYCt0/XJ/QG+6YkrLnLghZ5gpJIJaIBhBMIGK3ytkisEQwQuyfC1IUtNYrUP5cpP7As3c9IGJymhqJy5s/bNn9Ez7d/2xiFMXTSQf+9JxmbesLfaBMcQtpoKQKEmQY8rPgqj/enDX7MJY0Zds8sYRggET9D3eBvKQ+Ln1OCNCmdapFEdDsvwAwY25rw9+pvbvbdq3zkn0KYIAprTFVe4GCx9tFHQaWqab2Cd9dVaR0OXpiCudCLAekvTtVhUyxO0Xfk/kyoLy7rH69xzVx/4FmrK/XHUr5TIpR9V0odrhh1D576sVmjT6FZbgLExnz4TIXc5dRinFI4OQISfBderCLLJ0DanBiQvwYSIRk2FSy2yh/BNfSBgkN9vZdpg2UI2ihHB79Q== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c386a598-f13b-4bd8-376a-08dc298eada8 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8938.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2024 16:46:35.7060 (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: t7IrKgjEFSpl91VcTD3jY8/fbUhVtroEIyhMDoTSdyYwOCi7chcCQzVQIZrebwloPGPcGO7V/RmzSaXQxlvmo4ZtSGTZwVeeLOWb/gyJ9IE= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR04MB7097 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 e26dbf9440e5..b481e4655c2d 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -282,26 +282,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; @@ -5765,7 +5745,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; @@ -5778,7 +5758,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; @@ -5795,7 +5775,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))) @@ -5833,7 +5813,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); @@ -5852,10 +5832,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; @@ -5867,12 +5847,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; @@ -6013,7 +5993,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; @@ -6031,7 +6011,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); @@ -6065,7 +6045,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; @@ -6087,7 +6067,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(); @@ -6106,3 +6086,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 Fri Feb 9 16:46:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Istodorescu X-Patchwork-Id: 771376 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2046.outbound.protection.outlook.com [40.107.104.46]) (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 DD0A484A47 for ; Fri, 9 Feb 2024 16:46:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.104.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497206; cv=fail; b=fJkOopdbwBdU1y9L9+tKPli5mvzGwjwbydeK1eTvsz43uwf1fxZWghBzmJY8nGRCl4Hslhek0Djvksp1H7guhQHl1LSuaUcmYXKY8PPUDEuvG75nVmAkZ22yd0jc5hC0NcmR4I939JOarVaZM7s/valrvafjj+CY3+Xcs1RbhrY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497206; c=relaxed/simple; bh=MV2lwYDzXA5drsR7keXNUHXumjBsMuAqmVgVPZLoPz0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=Z8E8enK9XdDx0BZ9rd73QhQcrEYFOWKAz4T/Q2khZf1rjGeL5P1KYgbWrliVDIHEIwPcCrd6XzrEPC7jvkLgwts7mMBW1OMvqLkfPBtsWYGSM/C05j5v+3MB33FWkTR3nZweTWc43POBWdpjuv6E6dXaveR+2m8TsOV047JyNrw= 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=ZY0DY1N0; arc=fail smtp.client-ip=40.107.104.46 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="ZY0DY1N0" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ELv6pAQLNV4RBVxJ2mE4gpMxsMZV5fc6hfqYpr/X5Ssx2zt8XyIQEWqiSwMY4BW0EKD9WUHN03pd3URF2gtQ6DWshMeWpzSJYHsBfvKTNRLfGayS3tFqwf6WivyjapwYuG+EkpMP9mt2SWyn+/b5JKiE5UGAHKnZiLVKNAHa+KB3u5doX0JP5XMoWaS3V4LoOt7xTHMcuqhT/PxEd7ERal9LHdob8RSl04cyoS32U4lcqujMFwIv/fYjmJvvZCfIlA+46XdAbF9pCn38Ol3DGsWSxR5bCv9hiWv5Z3/OQn1FfDNTcJ4kqPCVCVxrD4hE8/FPuWBlV/kKPeogo0O7cw== 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=5hH+EGwkcyUvZZL7fMRJGj6mqBencsEqJouEnxPT4J0=; b=I7MjJ5e002jPpD5qV+noZUmt/1mNWvmccmGjOiUg3WqNDmpLB7c7t2kBXxwu0hxF0A0aphb+AJbsqMed7vQN9VZwld1KhmeV1tfqo95Ij6rQ0bYF+S2B0XcUHf4b5PEkjQQu1jnkVIfAIjvbSPdmab9YajtWP4U4XFp4CQE5ddiH14wZC+7Ath7FxlLKb6VGobabJHee2HRI9RO7rzpjXfP5q5N/PTaw0ktFYMWWxthES0oDA2nLw7LR27LajKc35Vr1XRCRzQRNvXraySYyOvgYNki6InzH5m8tUMo9s4i0KrVTg6JuBp6PkFznJvpP5E0csbS9kZo1mTt6oC07dA== 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=5hH+EGwkcyUvZZL7fMRJGj6mqBencsEqJouEnxPT4J0=; b=ZY0DY1N0mcqL4iUXM1zqVADBlHikTHcL9HwcbWKbSIKDbi4vTnEHBhDksL/rSNaiq0f1RKwK0uOpvLHkkQiB/la6m/B4eosQkfBXLYZ5fFuqz+qlOLy2zxS/UDrN1LlWZq7fC8eIHSRSt/2AEV7Ft9KM+MN+tL6ZsU9jN+zkb58= 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 DB8PR04MB7097.eurprd04.prod.outlook.com (2603:10a6:10:12a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.27; Fri, 9 Feb 2024 16:46:37 +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.039; Fri, 9 Feb 2024 16:46:37 +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 v2 2/6] shared/bap: Add API to convert parsed BASE into pac data Date: Fri, 9 Feb 2024 18:46:26 +0200 Message-Id: <20240209164630.92208-3-andrei.istodorescu@nxp.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240209164630.92208-1-andrei.istodorescu@nxp.com> References: <20240209164630.92208-1-andrei.istodorescu@nxp.com> X-ClientProxiedBy: AS4P192CA0042.EURP192.PROD.OUTLOOK.COM (2603:10a6:20b:658::21) 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_|DB8PR04MB7097:EE_ X-MS-Office365-Filtering-Correlation-Id: 5f8fc64b-2631-453e-9e4d-08dc298eae7b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2NH/JpgthcBorFetBpLIY5L5h3cSEVGuXZYB+dEhHXX4oL/FdqZ5UHqLAq213+5tSa1Yxrf9v2eCnXosAG2HGdKaiysEFZofre7PTAHPgbHeXZCZUIhtCdUWPtZE6+n/jAK36RxPK1Ts3z7dFvJMIPTR0Qbzf4ali3+RZ2z6FkxZgvj2V0nHHSIL7k2LLWBf4i557V/4avogkxINCK/S1IdXhAUb5HhupBbJrCHP/oO4WwrO5xqnIg9l6BsARSntKbAui1dP6pvFaNSjyWP4zVIsYTjb0T0xqEnG3Smdj9ePdRIuCQ3I8TbimsRAG258+xFQWDzVCYSOEJeGhDL4iMv1ZW48Nx1LjRzHhz39SGhn/tcxr9CG3UYT190AsTPH26ydeooLpPMscXzBR1xKgR39lRj/JNCvhu8UzJ1KSrkeyMm1/Qj/Cl4AGSfLtmS1aUTgGQt+hzOIQ3IiO8vuWO4DfcjrD7FfaierL3RJk1H1ZNrfPQvQ1Yy/rzyrkXzHgnT4pOdnUbwbnNZLy1vJcq6T+t/4Mxfe3PzfqR/g/YFuXYowQqnN1Tu5hUGhXUGk 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)(376002)(366004)(136003)(396003)(346002)(230922051799003)(451199024)(186009)(1800799012)(64100799003)(4326008)(5660300002)(30864003)(6916009)(66556008)(66946007)(8676002)(66476007)(8936002)(44832011)(2906002)(83380400001)(26005)(36756003)(86362001)(38100700002)(1076003)(6666004)(316002)(478600001)(41300700001)(6486002)(6506007)(6512007)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QYxmoKEsUCEgLnllxdzQhpxKt9I3PoSHhGNIz4CTdfCfxHFdl9/Yp7tFisP7DE9+80OqbaHkPPiQjeZSpfiun4VJGfA8lYdA+QU59rojxdadWWPh1T8/iicsMCH9SzLFhQCZjUhm3bVGDgOQnO6DQXdPrQqC+4soQzBkzujwNrf8x0NNWf4ixQYAvHTbnVsLD0vz024mJo4K2X6OEzst91JatHSJZ2iX8gPMHLcO0ju8euaw2AdsoNEaxXK3ItfJMaDKLcY93BzxWwbhIshx8MFmqyACBNAWIQ1CyDjKkbII42D9qomOIPuREBTd8xhmpuvzTN9pbBqIfFoLFm+m39+hJqnnPDFJVrGqRCoVJ+uO5kOkeufBh/HqLbOFkfrpRm7621gHrhUfOwb3Li74B3FFHdQSS0MWnSrDCQttjSA1wdzJ/TP1YhkkjnvcZ4FFzkkBQtqf8XjvSFNS2VHLH9BLPXZONMEO9jdqvcmPifgOnHEmCAYlk3KwuxLFONUHY0yb4bZMmyeX6SeNzUdR/cVezW9c/GHMqG8QXhKam8MyCDAHcA9Lh03/+0xvOw8GBh/3hS2zyhIFXhnJbRimFmS83D7E2e6heBwubAPkEE7g/u/A+rkwBiIPU8D+WqyEkMr4L3oppgEgt1ABlOZgjTC9OT3kU7bbAghJmcuoU5I6aRs+CEx95jx98rbBiiQV0OJHsqI1qcAuwsUkkRRL62gYqY9Ntd35hqWLlAMit5G/9VcjYwxgKl1gdIVxsUsPKAu1BNl5WSH0VMQ+T5gIDpLrcDf/MoH/8z1lA/SgRseiitD2jOEgGbqhnH8Nda7zG9d2LktC8+VXN5DiA+hTNghLeBKC9Ev04EBQiGAkaSLQKMLNyXHdtsrMc39X27vJatuKROekzs5DN1CVYKJLrehvE9ni3YfMQcx1gqjLQ+uUSKMrYapfsNfmCfUSD+4cH0aibY/fVmVeMLerLTdpKSNpTNBiObdt66YXmLmfOuEeO4O5+/K6akexWZMq3mtTs0GqtxMZi62QbSBh3xjI3UtTllRlM5oG2eNEK53fQ0p9Cowvr1fQ+eXH2HQ+bu/9XquhtctauX9Q0agd+V4TI+OzjskmpOklrrDPLRLOrPeY3RmcSMUQ+6mOWchPFbF78xUTSdMc3tA1GdcxZRaNQNOLQszv0Uz+EZhCsozYotU49Gqt5immuTkxky8dVKQr1RLorJJnVS6nk1wOJhIuMrXzwIOaWZSYSsG96Ua2GYhRGce7/AUBlPjWZ0C3FhNjRnhFuLLfBEOSptbIuTDFnJ9BE+qIGBZVvkKmqRUmz0VvMWCN/J0dQNttaGVsaqDviOfgqq9WhApz3FWVYTThE9QzENTQg1zPPklVlPqpxk5qudx9SECDwBvHWdXQzu8OUe9mxswuF00vARQkItKc4M+YGkrp3gItGTUGDq1oIeIcxbeSClmHSGhBV1xX99FOGl5s4a4uCwTPQFuJTLrmW63pM2BQ1cNIhdOhaKleBLL0gbf0Z9Q0pp/D+YSDuVCobdt4vvNbmV3m97aQEMCcPQdqKmzD5MtrTF4ioZZwSZdpydv+7PnTyZ2uNfharbaq52qstXV0EsV72g6i3+5SUg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5f8fc64b-2631-453e-9e4d-08dc298eae7b X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8938.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2024 16:46:37.0656 (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: xpyd+I4236iqkqsfVlCg7y1hxXzUEdPeLnM9HcMo/uvYgSapETLwlCkP8ieA2OdIFl6Tmwpi3PeAf+3FJvLfNi5q3wQdXOAqfW91SZpcAMU= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR04MB7097 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 | 497 ++++++++++++++++++++++++++++++++++------------- src/shared/bap.h | 11 +- 2 files changed, 375 insertions(+), 133 deletions(-) diff --git a/src/shared/bap.c b/src/shared/bap.c index b481e4655c2d..d205632b3c80 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; @@ -3282,6 +3287,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) @@ -3433,6 +3445,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) @@ -5872,8 +5894,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 { @@ -5892,7 +5915,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; } @@ -5904,7 +5927,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, @@ -5945,8 +5968,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, @@ -5958,7 +5983,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 @@ -6112,12 +6137,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, @@ -6132,161 +6161,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); + if (!util_iov_pull_u8(&iov, &subgroup->num_bises)) 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); + 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 Fri Feb 9 16:46:27 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Istodorescu X-Patchwork-Id: 771616 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2046.outbound.protection.outlook.com [40.107.104.46]) (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 6A48686126 for ; Fri, 9 Feb 2024 16:46:46 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.104.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497208; cv=fail; b=MR+rp/mSA48mpLUwRyD0J1h+AR1lsyxcrHc2h+sAtFRfhZh6adS2AcNAwAqOk7kKCtV5t+Xsm2ifiQHm1xu50ftl5kKeG8lxx0o/1E0Wg3kBVBtOti1duH9fSC/7u9pV4UnVZGDNbq/GaT2s+x87a8ATjGTGOXl9cG8uNGEYHec= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497208; c=relaxed/simple; bh=7U1gw2BLefawatfsTkKOgZQtechyQoHuVTtaztbwxNI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=UgZRFP5i+sJqfG+rjAlH9IPsC3bU4Lf5gMihh2oU0nbkNLp33xzHhLsk1h/zbIDGDUjevB0nixO0oKXctbapV283oHCvwCDIKQtzncbp7OgDIk4g0+IVzX3mEQvX1ZtVtyB968sluW+lkwcdZx58XbwsGUoc1mo4pKsyeUpwEto= 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=KHQ5z/ay; arc=fail smtp.client-ip=40.107.104.46 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="KHQ5z/ay" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k5Z9d9S9Rox2Tli15IlwbD/v2AoX6tRXHOkQwTwz7VDVmrYEmRPJpv6zPGsR0jeXJ4U14uTEMjq0kk2zXGqUKnx7myWL8EyvqWYEurElf1xkC9N6Td6Zoq28qE0k6QlGDDDwt533IrDCE2owRZHVL7ZCBtzZEMzPGc1xfrkVU1qHPlenfguTASlTqcO9OtVu3853Ecgx+owsIKT5aIiMvw1odnB9up2FWXDAm034G2Ma7bb73YJwkXabSUI99YrleS1FEJrgArROekaRbb1TpMv8GyvnHwilQ0R4XRPOK6WpsNzbHgcrxm+3U5xHAvlYIGo4+SqAURS27XyJU142Xg== 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=azEjJVe9b8AO3pz6DYGjsSEcVGAObChAAaFX36TDUs0=; b=HdY+JHmvBE/L/xn01UDQWqBposz4eP12ZYNyeTIHQyGd7XAkBYSWKVoGp+ebA4qFmsJYX/O3Rd2k4zN10v8KjqnQX6ZWwTPJ55mRHssA9db0oB4fHwRumEUu+FwvYRcdt9hx0CFh7ZE/pLtR4y/VizqZwh0yrmJdmZ54uYKw31xZxs1U0Mp7WoEQHgGm8GBM5nPzAhoFSaXwnoeVNxsRH3LkSbKp90eBRUpdKRvb1g7s9QI7mpSjckJ9q05uKMSsX/sNgk3Cei5F6U/glAsLu+YUom6TpOvdsrYYjMn9Xyg30x5ngWetuqpJNDrwyd9wH/ERBLkUHD81Ool9wRantg== 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=azEjJVe9b8AO3pz6DYGjsSEcVGAObChAAaFX36TDUs0=; b=KHQ5z/ayMV5QSORrBjqiJLdMVbbIxKt1GCiY47I791KGD7TDtSr+OEuTgHetOE9e+yKiVLV6P0XQSUHiMilNcZNXBrYKsS74RNuW8YPU9G5ZuXTQVkjMM6VLc8AZq23U+RwjCy3xSlJhZKhqtLJgvNtgwL/KGRtm3xU4I5Aw0so= 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 DB8PR04MB7097.eurprd04.prod.outlook.com (2603:10a6:10:12a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.27; Fri, 9 Feb 2024 16:46:38 +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.039; Fri, 9 Feb 2024 16:46:38 +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 v2 3/6] btio: Check for non-zero qos before setting Date: Fri, 9 Feb 2024 18:46:27 +0200 Message-Id: <20240209164630.92208-4-andrei.istodorescu@nxp.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240209164630.92208-1-andrei.istodorescu@nxp.com> References: <20240209164630.92208-1-andrei.istodorescu@nxp.com> X-ClientProxiedBy: AS4PR09CA0011.eurprd09.prod.outlook.com (2603:10a6:20b:5e0::13) 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_|DB8PR04MB7097:EE_ X-MS-Office365-Filtering-Correlation-Id: c07690a8-a7da-474e-db3d-08dc298eaf47 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: u70FOn+nazYdOJwr4pd9xoVRgdmDzba8QMUZItVgQSdP+j/dGJKUjWJ+qZKtDNPy27rRoDgIBUlsjhfjsY4C4j2TELafepCZLprU8qts4pE/wJvTsQxJfa3Wjj6Qzonp4pmxhVLn3IiEXxZ06MvRBsmVglNRwMF/X5hgTQZPrj1JXAKUruyV0l1VTzQM9/FyeaLDuL+bq6yTk4aLjW2roGYtpl5Ta76sWCro5GY7KeqZKFYUJXDBoAJ+0l4aOtogFooJj5JXswqnw68O7W+AnzwaCmVkA01JwKlVOMy9acPQvpDV6Q4bv10+HWdd8e5a/oZ7llM43DkzlYfXBB/U8WgFjYEeQ1ZAxshFhtu+PUHXJcMNGSzchhQF13MxrpRdyi5pxgh/iZBZpXrWmAaUfLcjjB8rM/vUDuj/TgV9oMQoxn/RZEs3m3rS09l0KTLtn8DD9rcJvjsZFkqX/UH74lT/hbMdLP5anUtXn0r+Nk3x7r0WJ4SsKeXG75xU7XlkSzJFZ901vRQcwa2mTBB7aVtVdyVswCgzraEPxUetORPjvfGqVKQLbmpjNgcC8wNd 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)(376002)(366004)(136003)(396003)(346002)(230922051799003)(451199024)(186009)(1800799012)(64100799003)(4326008)(5660300002)(6916009)(66556008)(66946007)(8676002)(66476007)(8936002)(44832011)(2906002)(83380400001)(26005)(36756003)(86362001)(38100700002)(1076003)(6666004)(316002)(478600001)(41300700001)(6486002)(6506007)(6512007)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: Ty4n7OdyRLfwVNPDq9SHKxviEIge0d2wEMXZrRHstQ0SeFAQslM5NleiDzjnmWpogx+9L9Xb7pPi1xudXZJsSQMSTseNwLlvbVPQjSXs2vdagvJKUR/RSr8VHJDBSuk0FXpjcEl7FYdEVMEMhoGgGn4iHEWheRppvkWgsz/8SRM0yyiX0b/0+/iLdIuzm98/ez3wjBx9KjSVxSVYOypO2Nyv+gsjNgTNqMqYAvKm5LK8sRdaqacBC6hNrJNmpK3b3+od44cavYRVGBCErF0QYYccVxvhDhxq08SxeSO3tSBcAAGf6ftH+wD221u6PCbr12G4zMd02qSaHo5D7MFJ5eO0boJtjydkdzjKY5LdaRKWmy4AMAp52ZKyhQqntLwlMsLqs2uP9pJg2Z6onVa88kajUnA1pURTZUKdJclOdm20Lt3dWx4FFBc/sXbtn1PRk8tUkZyy6jt74v7EwI9y6AdU/sPhnB/Yxyn4MllnxOFC1ZGaJac3NALaMxggvziUpNrhHNGAtCiD2R+inNjTmFJo8NlEx3FNbDaw0GEY54+94FCPAdXMT7h7/k0DOR9/JNruOvZB2BupE6VIcGYGPIqw5JGAD2oRhguQo0yDl8/5GoNZjczbWooVeoQ3MgCv/iKZ6roTm23rNXiVi+ZCLd7LG+nDlSLaN7E3tcYqP781JGeRtMsYkNsN6gaVOB/ErMUwLIoOZO0eY+34vLZe+LkxbzsTwgI+PXPyM23UmCKvtQ/coW+LDXEdwO+5Be09/fstqCPXoMrhbifm+JfSoz2uB9GIts1SikoVAKEdiq0nK45R97xpwhlu2zhg1ukDSDRoB0MnOl2w9iKUfu068Y3qCXrmPKf3etti4kCJJCgmcg1TjHj752dC0At6asTfcu0d8tw61/I2vVPCYEU1JWH/J0geR/z1D1V3/JgAOkCcq5xV6CW8B6xWhZ0nONC6wOAbp8vCp6s2d3+M4cz0uxue/IW3pqs6XwtXNLioNYKO8gbZuvGhImCzndT1qvVRVCSW2tWMNbZ4JPJTBqlVAYSA6eCO6EtA2unJWScJR9f8ERIepBwigZissvHufc49IfYCUqq3kVPWd7JsYLqTuaMYzw2HRPimoed0ixB4IBZwVdqHEcWah2SA65iPHERv8pmqoILd6OEONPIIzczVBPklPjuMhvrRh1LAIdw7ACdW/fA0Kk3CvHgkw2Sa6zfBnMuFHnf+sFJi98myc5b6JkEt/t3vFGYCrrmZbmTLjbk164Zo5CsxYy0thUBew0j9PmvgJbKBj83KufzZ3GlXiHUhQTDYs7ZDAQ1D4Ce2bRxBUdfGBoUzKfNnQRENGTaBm5q+9uV9sjrUzn7PFcfPepDBnc4clKdGJrLdKL0JfIRtidOYtW5hAdQZeY59GJxeUf41knHpBoxEkp7yYzVMKXdnNI8ITD9orW9nLW0Z/IPQ+VwXZw0qBb8JqSiiwTZUsvNqxm19OGjdb+6b66WUsw3OL9QQhnQjZGVo9xEZe38X1WyWrlKg5l5A8+GbYCO/QlRSoXgVMtq1TxpVYY1CoNsMSuVXgx2KGKDKcGmq/CXBLF7cUZNMnJsP8su9txrwqS95XFJuSxoct3Nu/S6VMA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c07690a8-a7da-474e-db3d-08dc298eaf47 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8938.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2024 16:46:38.3511 (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: 2kiZH3H7vP3aeKvrar/IK6J7V0WCC+9koVBvQWpxZHfoFg0Alarw8tOduvmcOjhaRuVOvRKK/iVlP/H8kmjiYbSVsKOA8xEi3KSzMjJW/cY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR04MB7097 --- btio/btio.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/btio/btio.c b/btio/btio.c index d30cfcac73ee..5a07f91c7d61 100644 --- a/btio/btio.c +++ b/btio/btio.c @@ -5,7 +5,7 @@ * * Copyright (C) 2009-2010 Marcel Holtmann * Copyright (C) 2009-2010 Nokia Corporation - * Copyright 2023 NXP + * Copyright 2023-2024 NXP * * */ @@ -1981,7 +1981,9 @@ static GIOChannel *create_io(gboolean server, struct set_opts *opts, if (!sco_set(sock, opts->mtu, opts->voice, err)) goto failed; break; - case BT_IO_ISO: + case BT_IO_ISO: { + uint8_t zeroes[sizeof(opts->qos)] = {0}; + sock = socket(PF_BLUETOOTH, SOCK_SEQPACKET, BTPROTO_ISO); if (sock < 0) { ERROR_FAILED(err, "socket(SEQPACKET, ISO)", errno); @@ -1992,12 +1994,14 @@ static GIOChannel *create_io(gboolean server, struct set_opts *opts, &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; + if (memcmp(&opts->qos, zeroes, sizeof(opts->qos))) + if (!iso_set_qos(sock, &opts->qos, err)) + goto failed; if (opts->base.base_len) if (!iso_set_base(sock, &opts->base, err)) goto failed; break; + } case BT_IO_INVALID: default: g_set_error(err, BT_IO_ERROR, EINVAL, From patchwork Fri Feb 9 16:46:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Istodorescu X-Patchwork-Id: 771375 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2046.outbound.protection.outlook.com [40.107.104.46]) (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 B1BEA86ACC for ; Fri, 9 Feb 2024 16:46:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.104.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497210; cv=fail; b=LVzi758m87oKz8DwIy4TEmHVFAPGY8xIxaEcdCl4Qxaev7MabL1SBhk9sCjXR81WrucvAgHDGfUY6IEwqnMBZw571a/0uxEVrVzWwRM1nZ/IvoZC/k1jwEpuhxgK3fgeomGNDrDKtrd2bKUJOWvjrZQYnAiLSUfM7dzkR8pcvh0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497210; c=relaxed/simple; bh=9AgvRW9E9j/T0/niKnjjtAbJmFEM0i5AaSqgVjbj14k=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=Ce8gRhS5pyS/T4siW6r1PO6ez6rIHCBZ0W+hgx84yHPZH1hT+NegSozxHc6Th3QQtUGjBPelGpK8IQW1rXtKyDXRDeDlPuNxVmwAUHypsXv1ZWKSZLGMMDcxByI7u93q7xlL60YziHkE/zTmxwmrVYZVuOegQreezTh5e5ejMGc= 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=XFvMAm/V; arc=fail smtp.client-ip=40.107.104.46 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="XFvMAm/V" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QKQ63fZqOdsdV3+buI28CN5aNuHrCQhxqOTSSlV+apqOaOP9wlF7FU+xSQDPqoXP3jwW7qy5UODUBJsgVBJrlDkqp35PO6gnIUQbqkZf9XFXga8EsOsU/djZ/A4KoTXTGhFtVXcfjQM6a41f4qJwJb33ddDA1qguUcalex0N85r0g3To5wkfMFOSoiYBG1V0fsy+0tjvsy2ERlumLkOKM5zS0LlQwn1tLG4eIAafRkWa7kSB5cKPNJAEq4aBx5hjpZEoREv0IVQLzWkgACaU51bEpJL4GoarDB7u4vfFvKpsQ3C8kAyyOnC1QEnhD39LceTbr32u2A1X1DyJ8rnSwA== 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=PYr688Ib2JVhhXeoAn7QdQJt1/iKVAu1wTwXXGrbKaM=; b=QzKDdGBWGd7ZeB/RqS2u0dFVXZqKnP+DzrrlGipy7JqMr+c+E/Z/e2+DvyugEO/1LH87ie3tYfdIFk7NoRytaxLyNVWItX1e3CpJxyTB4TysMr0ttAeHg1MSvuWk7xv12OMoaTUQi2J8MzEqAbkWRHOFKzwF2x9pWE3nS3/uvFP/bsx6J1L1RwIcQQTeHcDTrQqpbRGbhflbCjdVPXb24fWb90TFomDTOmkU6DTZtydA1CX+9374/CoBXiMFN1OyKUuffWjwmwBvjKUrqb1UQPOXY0XT21Yer1wGT610mweEgiA0iAONR4J+KCLMmA16+RzmMbZOJzNJJz1dLRtRQQ== 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=PYr688Ib2JVhhXeoAn7QdQJt1/iKVAu1wTwXXGrbKaM=; b=XFvMAm/ViJzVTpm0DQlwyjEJKsc/TKxCAg8khRJLd1kpWeylIwL1WlLy3WFafTEIuha2E1hIWLcCWMQN9mfEx2hG39rNF9ecHYjZ2m/pA7KK5FMiiLXXDpHAXh8Oa1mIpnp5o6BTmXQ7+80EGonVDIe9VyfbuPI+wYq/UmJ1w/0= 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 DB8PR04MB7097.eurprd04.prod.outlook.com (2603:10a6:10:12a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.27; Fri, 9 Feb 2024 16:46:39 +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.039; Fri, 9 Feb 2024 16:46:39 +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 v2 4/6] shared/bap: Add Broadcast QOS copy functions Date: Fri, 9 Feb 2024 18:46:28 +0200 Message-Id: <20240209164630.92208-5-andrei.istodorescu@nxp.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240209164630.92208-1-andrei.istodorescu@nxp.com> References: <20240209164630.92208-1-andrei.istodorescu@nxp.com> X-ClientProxiedBy: AS4P190CA0035.EURP190.PROD.OUTLOOK.COM (2603:10a6:20b:5d1::11) 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_|DB8PR04MB7097:EE_ X-MS-Office365-Filtering-Correlation-Id: 504cba22-e16a-4d0b-db41-08dc298eb029 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rwtZk78GV2Kw3m1Zl7R5PDf1cWG2rGJRqBGEYHISwLIk596ByKBcFaRRHX7FpQQ3L0bRvEMOUZ5QNWbksDjW7iNZ2W/tlevVWYCICACsJv84M57KYGMfAOmULTe6pUzh+fB0NiZc+m5Lm4QaL9fD+d7olGj1yS0OnVsJScMuJUi6rfukyWeWasx/z59oa4+0m37n/BUDA/pGgfj7mx0PT3ghke/pXGw+MBmJKyUkvp76m8+nUcEC5RpkHCsMCjgKTxD9rbkQpCGmk/xP4k/mkAbgaSjHLYTxsi/UH2UJc3Bsh2Dij7d+VKWVkVoVKvjYQt+HKSDiSwI+EOy/UqyIbi5hsWzW01xMUfIZYhj5M/M5ovWD8s9Reb1ySqjQbx77ZOrp1SPymdZl0GBJBhxRw6VRawfqYGM3wlh04bYEH2wrkRqlKWvqDi7DryGlAk9g33MBlAzSA2Z2myIhsYlg4EuslSzcilR06SCFoLIl+6VpI7bo5L1bjY84+N62k8GN847J1NKIEGKW+6EMcDOLpN+luMSAkJrWrrWGFfeFKMtfu3MW8FBxbxxUo2P8uczk 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)(376002)(366004)(136003)(396003)(346002)(230922051799003)(451199024)(186009)(1800799012)(64100799003)(4326008)(5660300002)(6916009)(66556008)(66946007)(8676002)(66476007)(8936002)(44832011)(2906002)(26005)(36756003)(86362001)(38100700002)(1076003)(6666004)(316002)(478600001)(41300700001)(6486002)(6506007)(6512007)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: HTZFv1LARMNHBvT7jzhp4Hg7JsymRhYB4iiHB9O58zxTiEXOXJ86tcw5Dvs/3sgfh2bYu7DpJKHirmsTTeRjHl+JCXcEhZsdWaTfp2VFkgjjDAWKSjd4r8nfol3kWskl2E67luCuKfVM6hzqLxrgUwAoIzz9A207AhYQhIrG5UwnJCLZrPhsUWU58lX5eAUBtbm4G6dl6yG9mNgWzWhSOm02HVDVjdSdGVq0piEnBqsY0uQTeyem43XTxSxT83RzJFnfD89k96oCIdrXHrmvecyWL0D/P2AHa3BLcztKuZsExoa+akPjuqeCmM6wD2hCXXDGRtte+vCTQJjBQx369T8TcVNVsbY4pyz8a4heItgxYpi/WUCQ5Yukvq7GWWdlpOgQcu/wVsjCxo6tOrCVeZrKqUL8+jsH0rI9dXrbOYjFqs6hHc2AB9bGPBF46iy1Xpq29qUW3jr5ghdvOx/yuaP10reQj6pHVHK0tsCZ69OxO4DiqQa1Zae6nq5/skPFUGDPEqZUz08czXe0qJnY8K7botSNIOhtScera9TDzlrCIzqo1oOdrR4j4/6/H9jB0O8OCuCECDnjP+4G5+gEXRZSIbXqFs3mc9614KNGgY0LkW1KlKOTj9QkCBtAcgXzM3w9tKUSq0EAQv98tEpTU5S9Zn/kAA6iK3GTARWFnocrQmb0PuYgSDjkAY6lpX7ca4fuiOvC90KbS72mdvgk2MsMI+lnMdDxxEKHqItTDYF89WjeSuo+kDKeodJyZaMPIwQME4v/SDBegqrCin7i4bEa3K96ZGBRbAMZ+GLK9vE0dXOK3JBA2+/AW8SjpOo6cL2I15lWAyRSeSqW7BFvtcUcOmhgDWxHarTfT1koAO7vYkQNTis4xMqluu2ocWljo3q1BwtyRLK5mEppTPU0tPpfTi7tfZE8Tr72ZZ8AUmKDzftcJUF55Zns8ykFElsWdpsyD1ge1bSrCbwQtQ67VKbD16LToN/YcAX6Z9xGUEgRwCzRcIxEV85ywzLCCwMEFbB5dEyNWVtqVC9GzwljQuTeEY1mjc7djPDPV/HkkItVWQjkKt7em3KNExMaK2hHAORQ6CJp2y7p4Y8sfCxqdhmW+Uk/7Q329KSyL1W+bFQwJzwxz7dvaiqM9yn3B/i17KMIhcfonNJ4MstrL3lhNau+LBiJz+09oPQr2132T0ks8O+4Z+jTY8aRgg2eN1b8+oGIenJIM2DoSUhTg/07lmmvlbmOMItPqgcFUt850yI6zHr9wsbtlUnsvm8Z3mm/Rt3RCwYIaZ2VPSWtiOlf5brnuvPzXDjs5zLNpI3qTNxeVufKD+DGDOsM7SyYif4f2YNme9/coU1pdJpjadqyakPSx8ax6U92tLj5MDRf42sAg9ihw4TsUsfYNXB6BNg2eMTcrYhv8Ar640Vzw83qFqFuVBB6V8ya6yrVkGQA4oQ5NibPyeqRWVYAaGqI5YqOyiMr3ZfXQJfABKAEBvRxQ8VGkLZw+Ts4ZXV4MUEVgvRJf7PIRviYhWO0AcD9kcCriQ017wo464aKn4FP+NoRFoQJJ1MOErUGUgQhv6oemRWrrkN53AA6hynAnY6/g8KAa3pjRJ7kN5Wd/5kP7EtRKQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 504cba22-e16a-4d0b-db41-08dc298eb029 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8938.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2024 16:46:39.8263 (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: kwvSnD360B+jO5ZyB2Qp/ZHzMTMacgtwpaEbS839PJitb76IvNSK6t5nccnrahtJxfM68I0Sn2on600QR+wV7YEH5q4wkkWnA7/1VSLL5rs= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR04MB7097 BAP works with bt_bap_qos structures and kernel with bt_iso_qos. These functions are utilitary functions to allow jumping easily from one structure to another. --- src/shared/bap.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/shared/bap.h | 4 ++++ 2 files changed, 48 insertions(+) diff --git a/src/shared/bap.c b/src/shared/bap.c index d205632b3c80..b88fc60842a3 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -6527,3 +6527,47 @@ void bt_bap_parse_bis(void *data, void *user_data) queue_foreach(subgroup->bises, bis_to_pac, subgroup); cleanup_subgroup(subgroup); } + +void bt_bap_bcast_qos_iso_to_bap(struct bt_bap_qos *bap_qos, + struct bt_iso_qos *iso_qos) +{ + bap_qos->bcast.big = iso_qos->bcast.big; + bap_qos->bcast.bis = iso_qos->bcast.bis; + bap_qos->bcast.sync_factor = iso_qos->bcast.sync_factor; + bap_qos->bcast.packing = iso_qos->bcast.packing; + bap_qos->bcast.framing = iso_qos->bcast.framing; + bap_qos->bcast.encryption = iso_qos->bcast.encryption; + if (bap_qos->bcast.bcode && bap_qos->bcast.bcode->iov_base) + memcpy(bap_qos->bcast.bcode->iov_base, iso_qos->bcast.bcode, + bap_qos->bcast.bcode->iov_len); + bap_qos->bcast.options = iso_qos->bcast.options; + bap_qos->bcast.skip = iso_qos->bcast.skip; + bap_qos->bcast.sync_timeout = iso_qos->bcast.sync_timeout; + bap_qos->bcast.sync_cte_type = iso_qos->bcast.sync_cte_type; + bap_qos->bcast.mse = iso_qos->bcast.mse; + bap_qos->bcast.timeout = iso_qos->bcast.timeout; + memcpy(&bap_qos->bcast.io_qos, &iso_qos->bcast.out, + sizeof(struct bt_iso_io_qos)); +} + +void bt_bap_bcast_qos_bap_to_iso(struct bt_iso_qos *iso_qos, + struct bt_bap_qos *bap_qos) +{ + iso_qos->bcast.big = bap_qos->bcast.big; + iso_qos->bcast.bis = bap_qos->bcast.bis; + iso_qos->bcast.sync_factor = bap_qos->bcast.sync_factor; + iso_qos->bcast.packing = bap_qos->bcast.packing; + iso_qos->bcast.framing = bap_qos->bcast.framing; + iso_qos->bcast.encryption = bap_qos->bcast.encryption; + if (bap_qos->bcast.bcode && bap_qos->bcast.bcode->iov_base) + memcpy(iso_qos->bcast.bcode, bap_qos->bcast.bcode->iov_base, + bap_qos->bcast.bcode->iov_len); + iso_qos->bcast.options = bap_qos->bcast.options; + iso_qos->bcast.skip = bap_qos->bcast.skip; + iso_qos->bcast.sync_timeout = bap_qos->bcast.sync_timeout; + iso_qos->bcast.sync_cte_type = bap_qos->bcast.sync_cte_type; + iso_qos->bcast.mse = bap_qos->bcast.mse; + iso_qos->bcast.timeout = bap_qos->bcast.timeout; + memcpy(&iso_qos->bcast.out, &bap_qos->bcast.io_qos, + sizeof(struct bt_iso_io_qos)); +} diff --git a/src/shared/bap.h b/src/shared/bap.h index aed3bf52b8d9..968257651766 100644 --- a/src/shared/bap.h +++ b/src/shared/bap.h @@ -354,4 +354,8 @@ 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); +void bt_bap_bcast_qos_iso_to_bap(struct bt_bap_qos *bap_qos, + struct bt_iso_qos *iso_qos); +void bt_bap_bcast_qos_bap_to_iso(struct bt_iso_qos *iso_qos, + struct bt_bap_qos *bap_qos); From patchwork Fri Feb 9 16:46:29 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Istodorescu X-Patchwork-Id: 771615 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2046.outbound.protection.outlook.com [40.107.104.46]) (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 334757E59F for ; Fri, 9 Feb 2024 16:46:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.104.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497213; cv=fail; b=qF5Yh5BixSsWTa5NGZJmHZmeilMMRu6Cmr9cL8xj8GSTxB98C6b/ohm8IsGApRDEG0FYq/ZDqNp6xrwYf3ZoXMQIFnkHVcXmVJ7FtkjGie2BN+oiwyFKjJWT5Pk7uqFSCpi6GrwOQuUVsSdrOXakIMwkTEzPOqWjn0hD4oTpTSY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497213; c=relaxed/simple; bh=fKeBvX9xp3YbYUl1YnHhEcG43ovfHQ3yOuq/B/F2inQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=fw6Ny6wnIfxLbZK+eFgKbcXvV872CeDd2eLjxEaj4T8JQuVBUNvQ4jEChC1gSmhol5z8dyT0z9Lj12ECRKuz0hPs5S7T8d4tUl81JpFSFoOsSYlmqSrCec9UcsuoYN/TVIze0xrUPC7we8qOgkkOay6WPC67tA+dFFydLQgRnZE= 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=oo5swO/Q; arc=fail smtp.client-ip=40.107.104.46 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="oo5swO/Q" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MKe9H5mDSbLU13uFT1wKRjz25TilsTjvQFG/frDr6k+TGxAowEpfbyF14vOIEKSbs+YDwNK5U+Be8nVUASMeKa15UVBYyl+9b/TsSvJgTk7Rxtf5yeVllciOuFR04ZgSHR0XdVjBHobF9V5xTmr7+JAr17/81MlH9gurBKOmDnKAw+OwFXPULQeVARJGGlnaLKS5cHbe3ICkWTwvOB8uWV8dHY3olnDJSXQoaDjuvSMyyuW531GMavUwsYZ8rdyfbpUmlLJSW0pbgFRa2lmPHAJjU5JlFu12wlyibWxYTES4Te+NpjOpv47Oy7uNI/ev5eJA3lRM5fD6Ou/KQj8tRg== 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=DPqFH8xxB03ODnk1cfVPQ9CScjGW50e6NQYYAvKsHDw=; b=Ik+XF46u5oQ35PjYcM76aRTSPYqjnrSl1J4tW5u4zPIfDq0Bsfd1+aAmXH1qtDRTNuVfB/RKiivLTCWxkTIPcbUXGvoP9FQhky58tsEu55VWki05f4f7EVnLHE7gs28+1z7ePZeksV78bfFJia5GhJ2GQecE2wQgzwKhpFllyVmpDnBhOnToBN+gwPx46iQ2/mNQI9qRzFGzxfx9lDk0fpQUDsXe9nRVEAFGyJv4MZhA4NVeMQAHo3LYPZH2yYfQQRcMHa1gOjIlAEbAmSDW5ZxBcSulgB0oi5gwZf1waOYGuv2xAAvK3AqxVbQ2utrsD1EcRAv2TDserPX+2wJHmA== 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=DPqFH8xxB03ODnk1cfVPQ9CScjGW50e6NQYYAvKsHDw=; b=oo5swO/QhR3Yzs+uQ5g0GCG5EWjzM6mSzJYhNYUWtUv6maw3cgUyW+IvFuJcY/aIHVdSzOfBG10lUId6o8fBEwloe3cEaMVFAV9XGt8+otR215AVy+1jxt3frMD/fizX0nfuXbAX+rFo/+j36zd0aAHkLLh8r/+1EdOVxWYVJWE= 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 DB8PR04MB7097.eurprd04.prod.outlook.com (2603:10a6:10:12a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.27; Fri, 9 Feb 2024 16:46:41 +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.039; Fri, 9 Feb 2024 16:46:41 +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 v2 5/6] bap: Do PA Sync for each BAP Broadcast source discovered Date: Fri, 9 Feb 2024 18:46:29 +0200 Message-Id: <20240209164630.92208-6-andrei.istodorescu@nxp.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240209164630.92208-1-andrei.istodorescu@nxp.com> References: <20240209164630.92208-1-andrei.istodorescu@nxp.com> X-ClientProxiedBy: AS4PR09CA0015.eurprd09.prod.outlook.com (2603:10a6:20b:5e0::20) 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_|DB8PR04MB7097:EE_ X-MS-Office365-Filtering-Correlation-Id: c1143b4f-d8be-4aca-c4c1-08dc298eb100 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: rSK73Dz21VVHC3XQ6uU6aVmqnETpiWOiJ9acivb4hJh0rAnhTs/kxseMtsyJHtTJr7pTT3W7Yc9Ilx02iCy3dhb0dxsQ9OFezvWQxpV47ywKysRkzKXYi2ZZavD8WX384q0QFwB1g6OdvxLqF2r1vUvqmApmgkZoTU4QcSZ0iJrqljaVjuUCOaC9q2FZpkZ4WacMq1KcWNrPV8pC02Cvd/kGUHa+UtaL33WseztdQ8CfUSTyeOowCb8ctn2tQBfZ4IufqBaWEzeWPC8YHShbDGeKXNasleklMK96AHwz/+h8ZTGS3Kue4VJVNGH5TvZrf8nBWRaBReXK1zfcpf1WfqxFdDDrpn1CZAUPkeIeIZqOiA0T1WTHr/dW/U51zl6iH0ZhTdTmlQ4yn4RTOLGiJiZesE5Bj/tqjMxlrzYW8n5F08dh3n362ptTJJL5CyZ+KQ+v/sVPhFlJWP+uyNe24L/4jUTjBkIofgvUUmOEvddU0AR+QrNxpqZGYv9yYPAWKOe4RAp0+LsawpDersPZxS0EOttx6/Xh2my4pvCjnppW8c9ngkvTVzPwJSZElQI6 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)(376002)(366004)(136003)(396003)(346002)(230922051799003)(451199024)(186009)(1800799012)(64100799003)(4326008)(5660300002)(30864003)(6916009)(66556008)(66946007)(8676002)(66476007)(8936002)(44832011)(2906002)(83380400001)(26005)(36756003)(86362001)(38100700002)(1076003)(6666004)(316002)(478600001)(41300700001)(6486002)(6506007)(6512007)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 1j8cbrYDiyKMnP7rHODOrEGxtObUrrqIzdf1F4Hy0FHAwvQTii4wkhclmWIeXWVPqDRJx5f39s06Bg+z/Hv/tcXTv1B39qeDKktxpt/ipuW9ULc6wIquITXGmTjxOC3ZnzpvcsPBELh0tC37gNXQU5dmNuv4odeQYISDySyQ+weQXHfbO3OuPsSlHVZroi3katkfxTnLlz/WG7RC7ZKXiV1kDV28MTqHcW00DHVszBpU+b3WKcHOvBOl8pYGCrU2aOo1dfa0uWaGC1+pBBgPdwsW5oW41fRld7Olsk9jI5hwo9cXnE7EMXW2239ycJY0oBNc5M+lhMENTwQXnKWtpBFlcTnjzO7cGPXyXb9UVz69OJBxgFSK0JHrdug8DvfJsDlo6+cxlmPehme0CWei+hReuc7h/HfrsC4A8l6bmg3hAjTlyZrC7+Ok7P99I2HSfmiANoTr4IltUs0BT3SAvbG0iABi6yWKvX8bUghq6pjP9HZgtHCr2KLbAGomNVtSTn3BfeVr5aDcSeaWQtdD++/dkoR4+HxSZOZtVj7L2yolvj37V2njU93YXwdlSf4Xhpqra95RDIx3qDrU1prE9NBDYKV4IXVgXsbtHglJs96Q83KccrBu9KUsooefg+7yLJYEopsGasvF82Nqp615NVivg5xVAuCXpBMMGBX08b2maNwsZS7/1GUN1cvGGuIcTtcUcAqBg3bSzF7mnHayvPM5Jt5DDtc9Vc5YKJwvEkG1TwdGH3Mb21/gVibzQRL5tRCV/1WAGg3hFnMtvBswrb4wyCefRac8XOjKF4BRywGSo2L1aeT4a/Vf/dErA/b2T3jcegm32LRiSRTGT3nYTvEM54R2menHGGcRU/iEzyzmfbthgWYd7ZZ5mxj23p9Mdm7LX2zIQpsP4jfDfa5igas3oGfZ3HoBmlj8IGNNt/hJmfSFy9XI7r6q/w4MEYDy4dIn1z1b/KndsCCphUcHwUvr3aVg6V5JHxEU1xvxn7L4h9gFFPKz7CE2W4ZslDFZ9TM5OywYYr+vAmObYoXJpo0gPVlxCyQOgn+lrLBgjIj6H8C1YjxXXnfDdZp8kvWwfNLVww8hQwNCKLimb10ui3QMUGfG8DH+TFLnQKEna4k//VhjcIvcY35vpDIhMvn0zuR+r0D4D3oBQaW0G0ROy6xU2b3zBwgoeUXYcxodVzT9IgiUVyKre+2RJfLcNOFQGoK/P+1yQ2n9tD2/qZhpp/ZBeIKbvIn/F3b7PmTJC/CCDt8iOOgBZTY8iLkTJhQRah4G/Q+OQvRyqJ/lRplNl1fxHu1ngaPkXDngrW2g5FB/qRK0rHjtjkhdI6BCptiR02+9QSDMue/nrvr1oWRQzxiR6IXP0msHcm5ePaQ0uK0rFAv9oyFy8157JD5VfAgh8rlKaG1bQV+YiHUAnplXMrCM8t1QnzFkK7iQk4SdgbtaaKzKxEKTYkOLCVkGdZN+jA/g72cZC/JBC854COFgFvcwSViW4PxRZZ+YxppnH9ekHOjNEDs+p8EKyWGbzZKsCbpoAIpd00uvBNxxVeFC+CIUABM/sF0qFJFzN0/MpKHBBjXNGEg7es1xJIazNGKG9Va4q6I5y1Bx0dnv3iZtQQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c1143b4f-d8be-4aca-c4c1-08dc298eb100 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8938.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2024 16:46:41.3171 (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: 8J4XTKq7QsIi0qSLcmVb0ONmlvpD0J5AXz99FaHSChb0Jh5JFPUomAdrwoXMeRt7+yPPQdoA2WiLNqL8RlkZ7I6c+XscjEGZMKWvmWf4/2M= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR04MB7097 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 | 308 +++++++++++++------------------------------ 1 file changed, 95 insertions(+), 213 deletions(-) diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index 88c93127bea0..61fb124b62c2 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -422,113 +422,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) { @@ -948,12 +841,36 @@ static DBusMessage *set_configuration(DBusConnection *conn, DBusMessage *msg, setup = setup_new(ep); + /* For BAP Broadcast Sink QOS comes from the kernel and it should be set + * in the setup before taking user's new values. + */ + if (bt_bap_pac_get_type(ep->lpac) == BT_BAP_BCAST_SINK) { + GError *gerr = NULL; + struct bt_iso_qos qos; + + bt_io_get(ep->data->listen_io, &gerr, + BT_IO_OPT_QOS, &qos, + BT_IO_OPT_INVALID); + bt_bap_bcast_qos_iso_to_bap(&setup->qos, &qos); + } + if (setup_parse_configuration(setup, &props) < 0) { DBG("Unable to parse configuration"); setup_free(setup); 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 +894,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 +923,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 +1800,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 +1816,26 @@ 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; + /* Send back to the kernel the updated QOS */ + if (!bt_io_set(data->listen_io, &err, + BT_IO_OPT_QOS, qos, + BT_IO_OPT_INVALID)) { + error("bt_io_set: %s", err->message); + g_error_free(err); + } - 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 +1899,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 +2284,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 +2328,26 @@ 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)); + /* TODO: Check that there is no other PA Sync in progress already. + * If there is another PA Sync controller procedure in progress this + * one will fail. + */ + 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_INVALID); + if (!data->listen_io) { + error("%s", err->message); + g_error_free(err); + } + return 0; } From patchwork Fri Feb 9 16:46:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrei Istodorescu X-Patchwork-Id: 771374 Received: from EUR03-DBA-obe.outbound.protection.outlook.com (mail-dbaeur03on2046.outbound.protection.outlook.com [40.107.104.46]) (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 99FBC126F06 for ; Fri, 9 Feb 2024 16:46:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.104.46 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497215; cv=fail; b=jPLf3WbShFd+lWWfnWI0277HRDAAAYcpxf+78uhO/0o7ItRMkzFTUbhpMAyMCyVqd5qSRxKU67yBB+P8zNEVsWIipBwjWXOvxy3HehqVRx9+tC7BAL9W62leYQOrzGlPR7VsJvsf9uMkCQ0ArT6QOpTLxkRwaMtv7Q9WbNKU5A0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1707497215; c=relaxed/simple; bh=bBi5mN66fkTzjuhyXVL8Nq50saerbfEEFcjF6jbmP8E=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=ppWzKjE4fqEF08vj87pN816C5EdmsUtmhInDisy2WAJibOQERDn/WuV6MOPxzLeSwwDzlLVKIV2QfHzw8PKwbYaeUWfwJKO/L0jDn/mUNS8ZotZb3qUURICi5Au+wFHiQZgMnCsnHtqR64BIxhkhH5BN6Nc4UXv00qrm2b/oRhk= 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=UKgROV/z; arc=fail smtp.client-ip=40.107.104.46 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="UKgROV/z" ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=UY+redvzZALpVCjRw6dgpVVfp/eLXLmHYGBBTCY/sbOmisOtVJVx7cUtF3QscCnSJ/0Ofd/cX+ZSWAOaPCWn99QU18c5ib0vbAI6ndJO/RIatuqa4mqt8IHauShPzE4Tho8MBD+8t/684S87+6b6mJhPz4y9fncJsqKOimOQ8GNVM9upTpavITZrlFs7gjyd8yHOJ43orHAMMpgDQ9B6PwAIWRCn6FWfJX0yNmOEyK+KXiJEmAo+8N4zCFQ1acemDYSjDeL7mEdjMT+o4qVbZb3emPPrdhFe+hoBctNCYAWDyYWJX70LnbFW51AaP7a0YIx6VFcqTkY+YOihqgQuBw== 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=8HuAAlUU+zSyLx2bY5+syPkkfHG5MJ3Z2no3alS9v44=; b=jHJppixAW1oxiy10fCquZ4jdDiztUxI/pjHZOZZUZVuJmZg8CUOo/0DatkWvFRGzPqI2laNZyHTjdnI/H/QImiv3+p/K+u+P7pM6x0jJHwtU3w05YqOAOKa4OujUshKQHxpIYeea4C4HAZxd+Tc7z6pMdLIQV76Klrpi10eOc2rRWUdxrBE6xmk/Ooa/GdN27SQgTAz0e5k0qzR8xjhJ5ZSCrrxJDtFdSQSbTM/rcKs5TpzwYabepS39k4Pj3AmLceKgFJkoCU3EHmioX9OfGNUZvulbRtclxtHUpipvG3So5Lzjpdz74H5q1PZUsaOk7OgzneJSOkuwJEJUd0Sv+g== 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=8HuAAlUU+zSyLx2bY5+syPkkfHG5MJ3Z2no3alS9v44=; b=UKgROV/zBW38v5uQeM/MtGDpRct0Uk8jo0ac5mLcGkZobzPHfyD5wJseJc7K7KvfVcnsJ/6boRf34GZzQ0PTAUxfu+wXexThYGaHTOEeJhrROxKk2w4x7BDPBj6pyDhPDqELSW0N9yq1nxsfBz9V2TXT6ss+9p3E44YrSPOXMw4= 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 DB8PR04MB7097.eurprd04.prod.outlook.com (2603:10a6:10:12a::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7270.27; Fri, 9 Feb 2024 16:46:42 +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.039; Fri, 9 Feb 2024 16:46:42 +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 v2 6/6] shared/bap: Remove stream double configuration Date: Fri, 9 Feb 2024 18:46:30 +0200 Message-Id: <20240209164630.92208-7-andrei.istodorescu@nxp.com> X-Mailer: git-send-email 2.40.1 In-Reply-To: <20240209164630.92208-1-andrei.istodorescu@nxp.com> References: <20240209164630.92208-1-andrei.istodorescu@nxp.com> X-ClientProxiedBy: AS4PR09CA0009.eurprd09.prod.outlook.com (2603:10a6:20b:5e0::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_|DB8PR04MB7097:EE_ X-MS-Office365-Filtering-Correlation-Id: fcb08887-e1d5-4b19-5c54-08dc298eb1e8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vWMS7GQ3M/hbcIiwjb1w83NCMvHjRK4dw8dpN9Wok85WxpkOkyySAzqJwDjPMYY+IPp8tf9srMzKK7xyZjatu16n++33sSqkcAE3Vuy2W3/kU8i+Js7oJI8PjsCOo5rfgLFxErRsLo3rgcO0XkeGOAJKzi7eZyqLXJkrRfnJnmfz4oIVQTM4l5I75ZlqkoZtuVpP7uyMt0Bf34EIhu/Hj2x0HPUiaX1GEZwmnLfeFZJmPHfc1AZ3o26snWLILsWw3UMDv+eFAEIg23809OuZY87GR3Swa0rzZDyolMacrWp9hYn/4Se1TvOX0qcWKky5eRca0GasbNQ4ZQSn49RbNeaM7GlI5RqSfszwG7a7Nfnz+qH3l44RgHarBd8BzaM4KkQA9WXBpcmV/TD1AjPbIchz4eNJIfvv7EC0YCyTFyBMX26hLTI/zNt9cHxoGFWi1mzznOEBLA5UBxYCvSMX6vnD84KhS+K5D6mkPdYdo90Sjr1GocysxSdUYC85oDQHnLW3niL9Xu6nW13jjFPVAqjcn2oFhoA2mQsQIuP2E69YNIzgOM5IcNIUQDFrEEub 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)(376002)(366004)(136003)(396003)(346002)(230922051799003)(451199024)(186009)(1800799012)(64100799003)(4326008)(4744005)(5660300002)(6916009)(66556008)(66946007)(8676002)(66476007)(8936002)(44832011)(2906002)(83380400001)(26005)(36756003)(86362001)(38100700002)(1076003)(6666004)(316002)(478600001)(41300700001)(6486002)(6506007)(6512007)(2616005); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: QwV5NfnmEFWHNtTQbA+cOpg4hB9RgX8fMGPe8VPX07JPusoY1T6y6Y4BbptpAbnrg7LdF6/VIcAhbeV606EScU0llzJefPDhd0Cq2BCnDchq6mn4Fund++3mGOGbWjPhqKMfCo2DTFBc/Bk2plT3f0OtGNER0PwWNP/0BBtEF+ASnN43DfmGbslfCj1r+CFPbmsEisQ9tUY9mf9bZO8b/mDccqEkoa/EGNMm7uEB6K4Wrf4zeXQNO7UAFkONcUDJTPMCkIUgQKT/9PNKze8hWU0ytJkpwvHih9rh0nRfhmbLu7H76Be/+tQpI3OSZx00Ln2/15dQSbzBkTII3DABQj2LX5YZqmE1dJg7chx2VIW50H23vJG8aaCNIQ0Oq/nAFVT7bdiOEKhzGlM21GNdL/19twXsLVksgq+wzaJWpQCZuNwP567xFEriFR8J9IWKGXNQlqzs+PSR1Y7AmS5N2eYIKY+f4pStR9PP6c30wKBfRuQudBVtdQMIUye3k1fXVJPvU0eEHgfzWfpTpg18eevyMCdQExA6xwWRZhAd6EkW2wrSFq0YsXqamkHwfIt4SxJpJGZgRIeCPHFo3zCQewwAdcIFc8aOyC1R6qu8CjCct14fFQGxfG0zZlQSn0cjU1z2pTzmAaSic5rHRFjsQwqsvpctXEZnCzej/DMhVlulLzW4tdB26m57+gUcTzzvXsf/fvopFllhx2mSguwuRFRQIISO3E8Tl1XqTxzdRe3UyZOyfU2l56rrDDbuknwdbuPSo2Q2gSyA4cp1sVoaOuSaiyS8vuFAaiIzdOeAh9Ht2Df3OYwaA1M2KYEKOnhiO+p62dk8sWfDBbbgDovfoW2NjxBIyktQ/lMw+sOu+kKOAIje5XjHb3GpTrwRByk7uRrZ9fMXLcUYkTS24Zdh3sB52bcq8SfktTyyeq4mrMEPPM8bs4ugQcb1v2Nib5YmmQ7S6zByZUw2AQPiU7vufFpjclP5z2qhTFYVX+yRBlOxDuNpzAWduT7L2Q2Tf6ntDL2YNImqBTQmce1TDVB1hUavtN+zMsGGyGQlYnDLU+YxnnB/Og68YtEN1TUchzSdzIWuMiNtkzKUud2+MBjozhlMsNLV/OMDHOD3txggWMUjNGf4Fp2wyeVExLzPG4X0tHfdNvkAVS9VCMqlxd1qqjqvVbPanY39U/eUuMGB7eyEyaXXwOKwrQN3jMxUKtwNQ3lSyckus0HPFQKsUew+b3wVp17PsDxX+NSUFRC4ZCPOmwY8B1kKwnrBaFRH5JGjzifOmseIN9YGdN2gOcWzwBcBKk4L88BIo0JBpplll9HDJQV37gs0gjV/FJbImWTU2ZnzemZHIFlP2e/7Y7iNUIKlss/66xXYJdebEBeGuoqM7uIxkUVTWzACP7Z2sLIGAPVvtnwH6qmtvsBKtBiSk0+dErWfO6dm6k4oC2sV5GDNkzwxp8fnMeMCuZELeUby96Am+BmG8fYtTO3cnRy/zpBw/ozVi04e+n+cDdDbrvnaR+ni/7lUXCcypCGw65EmBW1T1JsBNOus7FU3kqDem0JC/oqua/3o+E20ldcrXqYoZdZ+17MB8ecZILxNiZgigB9Qc4LsdEa8RY+qPbdFRQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fcb08887-e1d5-4b19-5c54-08dc298eb1e8 X-MS-Exchange-CrossTenant-AuthSource: AM9PR04MB8938.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Feb 2024 16:46:42.7557 (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: 9IkF+uPTZzVx0yMLKOYDqWpC4pWpdHaBXjEQtvX9v7ffhl6uEV/K4ONg7tZvMNQgff76ZwJfDwIIMbEiLpS0+dCdVY1ZtSiMivH2hlIwCAc= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB8PR04MB7097 The stream configuration is done in bt_bap_stream_set_user_data. This will be cleaned in a later patch. --- src/shared/bap.c | 6 ------ 1 file changed, 6 deletions(-) diff --git a/src/shared/bap.c b/src/shared/bap.c index b88fc60842a3..133711e99d71 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -1677,12 +1677,6 @@ static unsigned int bap_bcast_config(struct bt_bap_stream *stream, bt_bap_stream_func_t func, void *user_data) { 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; }