From patchwork Fri Nov 15 10:38:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 13876074 Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2040.outbound.protection.outlook.com [40.107.249.40]) (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 7409F38DD8 for ; Fri, 15 Nov 2024 10:38:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.249.40 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731667121; cv=fail; b=oPmf3Ahfl3ttnCrD0KsJXxBv5W2mhzD0nK3T+zHdtLhLgFfDRiek++ZumzXj2jFH5EGRZVL9DrIEB8QYHxVpMaROapRmOEgQaJKzEogcxkGN+gV6X8Zq6pijJPNdBCxGhPglbZ5rKBjktzvrZ8WMOan1rirqOQkdjedKl8kUH8c= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731667121; c=relaxed/simple; bh=m28VM6DA+DilLnVF6Lk6E9AEeQHfliCXjOU7SrY7JEw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=jD4u+Iusp5WIQLQg5iUjhM/+vxYVHBb0y2bxDRXAfTtFLJLMUv0qOheH6UJM22W3UxC9ZIxQa0PYTjYiab38zGk04mk0UnuFOMMTqpjwhpQvVtgp8gGblfv3G/4S6X0A5pkd3BJodIgzhhYKyXd9bQxieADlKlFE6cycXWwfs3A= 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 (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=c/POaCuj; arc=fail smtp.client-ip=40.107.249.40 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 (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="c/POaCuj" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=Qtb2yEP8tRI5FWMcHITaThdoLOPZ5rX+Z9aGFkjtAYhBOyEjPHpazzWdZRp0DfCrthK8EnKz1iW7tHepJpQi6kF3tfdZwstAR+Pr8KwHb1uJCzy8X2iLBsrQZTIVfeiqnFkdTmoJRhlMjw2UOXl6mcGexRYXQ9pk2IUDoOY2c7OkwAPdnLxNyMv5quQlvDF2DAbHEq0wKE4rzUUboqowv2XzGzlgNAQl+R2bQFZ2CSmQSPtN6C46OqW7rZbCZTS7K9laX2BWq7w1Oi64vjbPadWg8lkLOURNGq/EbDOn/q7bRCdEKm62nmsO+gjY4ZmXbZzaWdDQQ6L7l8bKigEzPw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=1e6yq9wTQl0b4bwm84/QNH7vvqpqKKqo/ggy/t5EbRA=; b=nZJBKj9JPvWVUYd7wm/VXV3LWSLBtEvPq5AcYFR05Uky7jN1mWGC9SIZ9XYNMs6I8G9fDKcPBxX5Nwq8e50xfdob64FyeLeBgMBJ0XStRNpLFM2pUlYzdodOGD6dbcKNfZCjsN7NqswiHZMgHZCIeeyQFDTFWJ8joJVQHFmP5xcygMD+GqEER4mMfZcCCEpNspKrIoKrcQxuOkQAFOSrKLBMTWu95KanKlMazJD4n4r+Aqpkc3v9RG1EJ/Z/eosDQ3p58wTYbpLm3zpM0wBloQ+d80OdIeR4YPu1VRRTE7NXS5+IU167LvrsI+g0S/w9RdjTZNT0QVirzV/VLWlp4A== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=1e6yq9wTQl0b4bwm84/QNH7vvqpqKKqo/ggy/t5EbRA=; b=c/POaCujHMUrm2CLPgWyJ9yJGqjeFiw08n5THF0n8Imv03g8wOLTcZhejDe7e06MzchvyqLz/VNyEFZcw8ON6VVfbJyH2M0g8gDbJv8POAtTo82s78JyQ6KJ/TmRSuozYvGxV3IaFD9Dd8H0H1AtLSzDBgSsg2xJmCTVdvOk477ybJRiRTMYFPxmA1JGYOY/93kWqNBYi1dCXRWJ41H7LV/JF2d0fYQMfCd4f6zuHu7doVbF4zPDd5Y3i1ZWKvn6F/ugv0OcBK4pfzfkFc76KXReVc57M1kvHumSUMoe/FbjljO5gnYJoKqgEd6YpIACP5DCTscWgJtA3Dv121xPGA== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) by DU2PR04MB8776.eurprd04.prod.outlook.com (2603:10a6:10:2e3::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8158.19; Fri, 15 Nov 2024 10:38:36 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::5e22:869c:33c:9654]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::5e22:869c:33c:9654%4]) with mapi id 15.20.8158.017; Fri, 15 Nov 2024 10:38:36 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Iulia Tanasescu Subject: [PATCH BlueZ 1/6] bap: Rework parse_base Date: Fri, 15 Nov 2024 12:38:19 +0200 Message-ID: <20241115103825.19761-2-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241115103825.19761-1-iulia.tanasescu@nxp.com> References: <20241115103825.19761-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AM0PR02CA0181.eurprd02.prod.outlook.com (2603:10a6:20b:28e::18) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) 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: AS8PR04MB8898:EE_|DU2PR04MB8776:EE_ X-MS-Office365-Filtering-Correlation-Id: b4f013da-519c-4546-6d0e-08dd0561a917 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|376014|1800799024; X-Microsoft-Antispam-Message-Info: 90IlWOk+6wnhVZE/2cmiiYpmZzVezxdJP30nJmeYheEHtnEkWI7M7kGCrYiR0762GJRvrIUKLKhLhroKN3Qa32XPfivVR4ejQz+Szh2RzlE/ZeYyqrPdjicnKRJHOCJ+OacJyvgO3kR2bGgKHqKlBEWHuyAl1XoDiebeykqmX91eV6/gDk+e+3IVbERCfOc2XBrFgRW965qr/S3WyGupp0X280JqKcfjASLL9qHQP7p8Zwc9XYBRDMOa53zUC9UwRXY25TE8BElHhaqUfvZsZisTD6OQNUwomYPwwezfyWLDhnMuUDJvO88kWWtT6HvnxewFchbX8tVIyKO76Jh8W3nTDn+4GGWDehYepZZoIh+d/kjMGUCACbEVzB3J/2fld7aC9/CxQU1lmAjYwI2tscc+mvETM/Ht1+r5WU7lzYcfJCfPwUN6Pz/fVN/76tF6nLBWKNDPi1OgHoXGkbKA7GdmgvbfUMKR3LEG3NeUXqyzGfq4g1A/JYJhhG0wLRcWLtQXMuWECDWWrXBZTHKCEVZi6LKhSBPXh9c7YbnQhb3pOWkgpTZ7bZStxY+UQ+D8xSX297xQc/z5O+8m9LhVZyr3sjPswVaCWeHEEV0uVlXN9S+vz4j5THWOaR5N018qTUROCmfhV7BkjPbxNaOcLPRdA2NBgpGKdwP/FHS3zV/P2hPl52T29XVe6PwyPsih/QxajRzF94iIluIOzB8ybRlx3IO2CgC6u+nGaPDtUtlvplfkT1/8R7zGix1Wt64YnZGVMwi6Kf3ByI31ogpgefeUkPLwAWjQnBXfwhtjSPutDTWdQeCGFxuyIcRNgsSWRV8fQ42577Uwlue6Z9l7imJ0LAUMeJnUnwYKIBRNSrktyEc02c5bmPMKCgA8eIC+tBqQYNzZJVD+LE/HNFCJBi2sFEbGqgZyEqM6hrvtxyackVvVmenl0/3GL4xoACxhUmDqaDuHyU6FwFlpodne7HksdGHPSioeRZpKYnbHIynOZaF5p2oCXtA2ZpmHzt/MrjGXGsRI7yTjy1lJ19whwoBHxNHVGjCNzDBmbH0iAteCeot+d7NJkmROPJzX5TEpZ1kLDiQmOvnFtWpHCSRPlcUhutje/jMyrZmLnsV1PYfRg021+IvpCmcHTh7HeBdE282mgWt2ZvlJh2Ti5tIt7NPLtBh47gM6acdZn452ANoVTvqRJZd7X1wdLDxKJjvYsTza5pTHn9jjh6NJ3pLvSOUAcAzd+IactrJ2OvhQayaO2ZQ6ZY2sdq+j/J+vOIuOCa/FqmLevZbpybKFdidF+amHL4upJ8FAFFsA4wbfgBr+owc2wMJJdx3UjN6sq2td X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR04MB8898.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(366016)(376014)(1800799024);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam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xoR7YwSxCOuW8l+N2yw7ylDVephzNd9b6hQ1RFVDDxPIvKRQSLS/5HfIoVgytvCfpT/OX0thAocZ18lxx7H/J+QxWWlj2YzzZf/aySv3l743vzy//5ewHIRbwz+YtB15kiawNfEQ5ZIVauiiOuSwrgRqoigttZNxIGlpLEAfTir3X6qVmoYYQxTYdhkvnc/0kS2Ipnhyt/lSfKi4RosNuNXMQ74MXvjHAx1tQGuncXfOkeq2bx9rEqm2UehPLNmPqfyxbZF8NvY4LV+yAOyTZeS8dbiZ657c1/NvZnFB5toOoxmwXxusDY6rBfHBHP7NL90lk+ssnISXAVoIkoexFjSRYv7CINOWZEhpb05i7xBTwfs7ySo44Kr1bGkQCAGg/e3NSHys2f3s+JEYfyzYTGjNB44RrcNbbfBUt8jmzdFAWhmhGGPIRTMbC8+LOcMHIKWoSKobMba5Kb6xQT5uEnrTvGrGKmcO59sV9qlgzkTGOQzJ3Gp4iDHdX7lxmKMXQDylUNEj+dbfw8AxWi/Sgfw2W+ERhSQ3f1CTJl5KS/kQa6nw3iigTDlfJhE/DYOiuKgg9H/nQ5iRQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b4f013da-519c-4546-6d0e-08dd0561a917 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 15 Nov 2024 10:38:36.5333 (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: scBuPT8umGHTS39Uahb/yGi91M2Up6V8PGRewNsOvWe276v4waNADpqC29qLF7i9LFCSzf3qHIA6pUpIEwmtwA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB8776 This makes BAP parse_base public, so other plugins can reuse the logic (BASS should also parse BASE internally for the Scan Delegator implementation). Since different plugins need to handle BISes differently, this commit also reworks parse_base to receive a BIS handler callback which will be called for each parsed BIS. --- profiles/audio/bap.c | 78 +++++++++++++++++++++++--------------------- profiles/audio/bap.h | 8 +++++ 2 files changed, 48 insertions(+), 38 deletions(-) diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index df685c6d3..98b28f15a 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -1086,8 +1086,42 @@ static void create_stream_for_bis(struct bap_data *bap_data, NULL, NULL); } -static bool parse_base(struct bap_data *bap_data, struct bt_iso_base *base, - struct bt_iso_qos *qos, util_debug_func_t func) +static void bis_handler(uint8_t bis, uint8_t sgrp, struct iovec *caps, + struct iovec *meta, struct bt_iso_qos *qos, void *user_data) +{ + struct bap_data *data = user_data; + struct bt_bap_pac *lpac; + char *path; + + bass_add_stream(data->device, meta, caps, qos, sgrp, bis); + + if (!bass_check_bis(data->device, bis)) + /* If this Broadcast Sink is acting as a Scan + * Delegator, only attempt to create streams + * for the BISes required by the peer Broadcast + * Assistant. + */ + return; + + /* Check if this BIS matches any local PAC */ + bt_bap_verify_bis(data->bap, bis, + caps, &lpac); + + if (!lpac) + return; + + if (asprintf(&path, "%s/bis%d", + device_get_path(data->device), + bis) < 0) + return; + + create_stream_for_bis(data, lpac, qos, + caps, meta, path); +} + +bool parse_base(struct bt_iso_base *base, struct bt_iso_qos *qos, + util_debug_func_t func, bap_stream_cb_t handler, + void *user_data) { struct iovec iov = { .iov_base = base->base, @@ -1167,9 +1201,6 @@ static bool parse_base(struct bap_data *bap_data, struct bt_iso_base *base, uint8_t bis_index; struct iovec *l3_caps; struct iovec *merged_caps; - struct bt_bap_pac *matched_lpac; - char *path; - int err; if (!util_iov_pull_u8(&iov, &bis_index)) { ret = false; @@ -1177,18 +1208,12 @@ static bool parse_base(struct bap_data *bap_data, struct bt_iso_base *base, } util_debug(func, NULL, "BIS #%d", bis_index); - err = asprintf(&path, "%s/bis%d", - device_get_path(bap_data->device), - bis_index); - if (err < 0) - continue; /* Read Codec Specific Configuration */ l3_caps = new0(struct iovec, 1); if (!util_iov_pull_u8(&iov, (void *)&l3_caps->iov_len)) { free(l3_caps); - free(path); ret = false; goto group_fail; } @@ -1206,34 +1231,11 @@ static bool parse_base(struct bap_data *bap_data, struct bt_iso_base *base, func); merged_caps = bt_bap_merge_caps(l2_caps, l3_caps); - if (!merged_caps) { - free(path); + if (!merged_caps) continue; - } - - bass_add_stream(bap_data->device, meta, merged_caps, - qos, idx, bis_index); - - if (!bass_check_bis(bap_data->device, bis_index)) { - /* If this Broadcast Sink is acting as a Scan - * Delegator, only attempt to create streams - * for the BISes required by the peer Broadcast - * Assistant. - */ - continue; - } - - /* Check if this BIS matches any local PAC */ - bt_bap_verify_bis(bap_data->bap, bis_index, - merged_caps, &matched_lpac); - - if (matched_lpac == NULL) { - free(path); - continue; - } - create_stream_for_bis(bap_data, matched_lpac, qos, - merged_caps, meta, path); + handler(bis_index, idx, merged_caps, meta, + qos, user_data); } group_fail: @@ -1299,7 +1301,7 @@ static gboolean big_info_report_cb(GIOChannel *io, GIOCondition cond, /* Analyze received BASE data and create remote media endpoints for each * BIS matching our capabilities */ - parse_base(data, &base, &qos, bap_debug); + parse_base(&base, &qos, bap_debug, bis_handler, data); service_set_connecting(req->data.service); diff --git a/profiles/audio/bap.h b/profiles/audio/bap.h index cfe633311..cf2593db8 100644 --- a/profiles/audio/bap.h +++ b/profiles/audio/bap.h @@ -7,5 +7,13 @@ * */ +typedef void (*bap_stream_cb_t)(uint8_t bis, uint8_t sgrp, + struct iovec *caps, struct iovec *meta, + struct bt_iso_qos *qos, void *user_data); + struct bt_bap *bap_get_session(struct btd_device *device); void bap_scan_delegator_probe(struct btd_device *device); + +bool parse_base(struct bt_iso_base *base, struct bt_iso_qos *qos, + util_debug_func_t func, bap_stream_cb_t handler, + void *user_data);