From patchwork Tue May 30 14:13:36 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Silviu Florian Barbulescu X-Patchwork-Id: 13260179 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id ECB37C7EE31 for ; Tue, 30 May 2023 14:15:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233062AbjE3OPj (ORCPT ); Tue, 30 May 2023 10:15:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232518AbjE3OPh (ORCPT ); Tue, 30 May 2023 10:15:37 -0400 Received: from EUR01-HE1-obe.outbound.protection.outlook.com (mail-he1eur01on2045.outbound.protection.outlook.com [40.107.13.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6C56102 for ; Tue, 30 May 2023 07:15:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=JjYroOB8vhDyR0rZ0eyN9Ctu5uD9t6WBKi6BF9bd2e17ELvqg3ARZqib6NG76+6WcSXUcG8mxg5GPtJaSiEy2Gu9Htc29eHmzlSnBfo+KWunT4kXKfYnj5AypH+MS4YJt9nOIWz99c6tF48n4qQDCJic7LL0aB+cLUOcI7WlYbCA/Lx0CLhWV+jVzNmLVimzhTlsWIr6w8e7lCOadzJvxNDzpguAFLH/nKB17bG40ElKYVveOR94zDUB+o+/ImPcjUe4UqUIAAx/I5ly0lXGiIPZopAaUAbi/vU7L7M7F62HLlnckkHSxhGCEnqQFX2Dk4MyNZKshUo4M2yuw6w5Aw== 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=+jHE0/7x1oj43W1g6+zf2Y/KKbUhBn5veuy6zbmt6fM=; b=VWbtUBUff7CghWp3UbErCRyjdVCC5GQ6hMW4J5gKcYkbbx0kRorHhsVwsZh3iU7G/CdsZ/MFzqgC+YLYzeHowQb60bSzec74mg5gThTD25Qs1cmYXpwxAaQ4apJ7G2gi9VCLYRYSphXGTSmXpIqd7XCPy7xJrGcLXdT55BRKEsJqXYWhf8i3xzvWAAoqqOOPYKjFksVFXlx81aPRYLCsNYSKxiFhYxDRmOD5Is00dTNIue2djjPv3nVu6I8w6KMlTZl5cu068ecZyvUgVDuew4BwU4KOSmst1lF6JYPyPz0uwaPTKiEW+nnKCWwDvO+TNm147fAlCjvFhgVsPMpVuQ== 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=+jHE0/7x1oj43W1g6+zf2Y/KKbUhBn5veuy6zbmt6fM=; b=og8+La70TB1FQYX+9fdHGHERrArELm7fqZ+UzN/2m0Ew/SSx7SJnV5tJ2lgGnQXMjJMr+OZvqSFGG0k9qi1BtQlV3V9tlw7jMNmpHPqtS7Ds04JsskPjyQpUhKG52yF7/lS08IPDB2f/y/YAxE7JGF4ew+d/LZ9418DX0Iwnvo4= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5344.eurprd04.prod.outlook.com (2603:10a6:803:4b::31) by DBBPR04MB7913.eurprd04.prod.outlook.com (2603:10a6:10:1ee::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Tue, 30 May 2023 14:14:02 +0000 Received: from VI1PR04MB5344.eurprd04.prod.outlook.com ([fe80::cedb:51d6:a774:f81a]) by VI1PR04MB5344.eurprd04.prod.outlook.com ([fe80::cedb:51d6:a774:f81a%7]) with mapi id 15.20.6433.022; Tue, 30 May 2023 14:14:02 +0000 From: Silviu Florian Barbulescu To: linux-bluetooth@vger.kernel.org Cc: Silviu Florian Barbulescu Subject: [PATCH BlueZ v3 1/4] Split bt_bap_qos structure into unicast and broadcast structures Date: Tue, 30 May 2023 17:13:36 +0300 Message-Id: <20230530141339.100733-2-silviu.barbulescu@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230530141339.100733-1-silviu.barbulescu@nxp.com> References: <20230530141339.100733-1-silviu.barbulescu@nxp.com> X-ClientProxiedBy: AM0PR07CA0021.eurprd07.prod.outlook.com (2603:10a6:208:ac::34) To VI1PR04MB5344.eurprd04.prod.outlook.com (2603:10a6:803:4b::31) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5344:EE_|DBBPR04MB7913:EE_ X-MS-Office365-Filtering-Correlation-Id: 884a1bc8-36b7-40f8-957f-08db61181ea8 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: sHLYKnJCRhoe70wrvNNy0ymta8QyCiqSH3jKv7a1VG00u0olsNgXu9L+STQvGTR7vZ9oDeVP6hQpd1F+lZisxmes9E28r1JbZDe9piNoJ0+yeJNTnojTelpeYYCaeSrcVjDYMO40TY9NjshtoOtPV7ITcwpgqyKheKZinqZQKJrpX7vjqFHktswbp+9ptN55W2X+Vplot7BAog8Q7zOIKxRYpHlc+zHcfevOVmHuolwy5Ii7P6JtiL0HwmMFzM8X3JABmkFFD2v68W5DU3htcG5Im4Ch2X3XvD5FfATKT4i8Ttu0iRBzJWtc2IgDlgiP9tQowFGERtiJCYV5G/14WzNGhkADIowF9J7qGi5iJYnkq7aRyS3hUHp0PHIVGmjtxrw/rpplotYfBSmQ8BN7c2W7jKtevCgi2StQ3grxu9hYtGY0WW3M6z9EvwwT9OTNg1pcWwAgc781bHeZJehAe4DE+gm65OpPJyaVaL7Q/Yp/UBlsDIpLaS+4mHGG7ZKxia31rQuXBOoVlEpkUiaOclklNm2oZRlcBg6aW1U57HPqnHzMRgpRfEwRdDBpScIfdv44y0wHl3ls7RrJedkmjurpePKIzsQZ/tZqxofsZSJIxzY8qDAyLGWDyeSTQ/ZU X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5344.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(366004)(376002)(396003)(346002)(136003)(451199021)(478600001)(38100700002)(38350700002)(66556008)(66476007)(66946007)(41300700001)(52116002)(6486002)(8676002)(5660300002)(86362001)(8936002)(26005)(2906002)(30864003)(1076003)(186003)(6512007)(6506007)(83380400001)(4326008)(6916009)(316002)(6666004)(2616005)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dN801EirF4W0uKsXlZyY8JB1SUqRhls7SStoGIkBmfbDnUFFGecMv7TK7URPGAPPExmLqMN1WFS9E74OYIu/Gr9kwvFDXGlKk0uv2D4BoivKjbSVb9AqVQlczvAhlU1xX24S5RE0ZWVz8emrj3nO171JlcoyflyDgNVF0ZRcH7Shk2jo+0i0NTjKThXzqymnIlFazpz3h4q4kq9fHaOI9qDhmuDdu2rltUiXZExDbvqpnZHt3Rb+ZoOAvQl3B+qaPomCATLex80oXklQABhP3hBFinmh50R4RuOCAXdvvsB/OBVWpLlAJB6tdUVFWLiKCCAM3qEuKeboGz1mqX8VeDbseHYmWqYsfX2kr68bpaLwqyXSk4xuT9XaWyFMhy4azqC9dd8OzpkTLcM3gYxwy/HseBT5mV9R/GlSg9bJXNOF19pTA1GaSBCifSaZZVYY6U3zEdkR4N47SZlzYteqzuPF9CJJ+9IrVsm62SJ3MBp6bVLlXvfvP8RtjKigpNUg3gT30EjcVIEn+wEbo3godNGvU1yqgWmeJMgaEcPNKzKFEfTlU4R0NYbbjO343KQH3o9OjWRMOxnJuoMNjeZpKAFl+l8KgfDk+7C6QkvKAa0aaZCqPMoFNm9gRlGtheQ1OIGUZq4dV7UOBVhDykgfWKlpEQQzTUd/Txls6IECnPJeBMKvRFPPqmBCwCO1O915DoKVkBzApFiM1vqVQ0cyO3PHihtpsX3Y01EUJM+KlhS27+cPdIRiH187unTG3u8HgZ7uD4Sfz5nk0i1cfSl9NHvGT1zE+3KZXaFfYZT84Km360ybQiqhbrW3FJ2ij904OiADMCUVU0/moBXXPbycckz2t1ZC+Lp4VldryYbiWKU2zn0SwImv72nG9x33ps6+X987jJR01IvCJodgDdCKZBLRCL1gIKJjw26Q4+REN7SKzF2kVxk+KJOBGUqHGNdSyuG1peYZo5ISAcvSGM+o6Pvitb6FIb7fMMZ9Nm7mRrEiTxlQyNFuyKO57NZuV9LpAqt/1cCp84CGnIvymLApJSJMF17Vau7NQCWyohSb6YuwONIOL++yJQlYAYhJdAnAxOm297MMy6NTL2LAb9sVsavg9ZHyUmjvtKKRYAbH/V2gjKSVOX8Vd90888uzil7pqRHO89YzDr7Gz8/uAHrI4RkmVbCKNv0ZOTl6HE50jUe6jwFJ2uSeAUaVFTowZteqduySF/7ZZCugxmjhIxCFs/kaOgybs/pJb7Hq4t+RXPfuNryPx9xtUr3fVqc6+lEGyiULdBb6/upeNFcVoYQo/eQaacyHXg/g0Z2dzwL4KdMVAvD9eOd6xhQp/JoTQeuJJm4yIK3Uzfsj/+t7D/yCoFKsb432vgITUWGm6wSf+5L5UKkkdWEfEOMsYPUMt3Pqtf5vm0LPP3sU+5q2vNurBHM/DSYye9s+VHplnzHIMvX8YKnTvOQPdDtVnyrD9vyI/f7qlK+n35mJ5t5OI5D30kj5T4FOJ7HCRLGxaMThEkAYqZ0gSS1jBYhrEb643Y20/Wj3x4xe7zJ/2nVEzO7ibM9hH+WHNxAXnbvNZzDCK/pB7QFwkCbzNc3ttkzXOb+zNKcGh7iz0ZfLgPnyKe8LPg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 884a1bc8-36b7-40f8-957f-08db61181ea8 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5344.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2023 14:14:02.6952 (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: y/PXWq7LBV5cXGaaEZ2BWcZWemxL1+ztdYrIXl8N/oXcyzD2ltkPrLGtITypDwGGqNms9A46peJz3Qwmyrp1ayCbdWHPvLjWhcJ5WsixaDM= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7913 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This splits bt_bap_qos structure into unicast and broadcast structures --- profiles/audio/bap.c | 58 +++++++++++++----------- profiles/audio/media.c | 33 ++++++++------ profiles/audio/transport.c | 25 ++++++----- src/shared/bap.c | 92 ++++++++++++++++++++------------------ src/shared/bap.h | 42 ++++++++++++++--- unit/test-bap.c | 75 ++++++++++++++++--------------- 6 files changed, 188 insertions(+), 137 deletions(-) diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index 1a543a9ce..cbaf705c0 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -253,6 +253,7 @@ static int parse_properties(DBusMessageIter *props, struct iovec **caps, struct iovec **metadata, struct bt_bap_qos *qos) { const char *key; + struct bt_bap_io_qos io_qos; while (dbus_message_iter_get_arg_type(props) == DBUS_TYPE_DICT_ENTRY) { DBusMessageIter value, entry; @@ -282,17 +283,17 @@ static int parse_properties(DBusMessageIter *props, struct iovec **caps, if (var != DBUS_TYPE_BYTE) goto fail; - dbus_message_iter_get_basic(&value, &qos->cig_id); + dbus_message_iter_get_basic(&value, &qos->ucast.cig_id); } else if (!strcasecmp(key, "CIS")) { if (var != DBUS_TYPE_BYTE) goto fail; - dbus_message_iter_get_basic(&value, &qos->cis_id); + dbus_message_iter_get_basic(&value, &qos->ucast.cis_id); } else if (!strcasecmp(key, "Interval")) { if (var != DBUS_TYPE_UINT32) goto fail; - dbus_message_iter_get_basic(&value, &qos->interval); + dbus_message_iter_get_basic(&value, &io_qos.interval); } else if (!strcasecmp(key, "Framing")) { dbus_bool_t val; @@ -301,7 +302,7 @@ static int parse_properties(DBusMessageIter *props, struct iovec **caps, dbus_message_iter_get_basic(&value, &val); - qos->framing = val; + qos->ucast.framing = val; } else if (!strcasecmp(key, "PHY")) { const char *str; @@ -311,42 +312,43 @@ static int parse_properties(DBusMessageIter *props, struct iovec **caps, dbus_message_iter_get_basic(&value, &str); if (!strcasecmp(str, "1M")) - qos->phy = 0x01; + io_qos.phy = 0x01; else if (!strcasecmp(str, "2M")) - qos->phy = 0x02; + io_qos.phy = 0x02; else goto fail; } else if (!strcasecmp(key, "SDU")) { if (var != DBUS_TYPE_UINT16) goto fail; - dbus_message_iter_get_basic(&value, &qos->sdu); + dbus_message_iter_get_basic(&value, &io_qos.sdu); } else if (!strcasecmp(key, "Retransmissions")) { if (var != DBUS_TYPE_BYTE) goto fail; - dbus_message_iter_get_basic(&value, &qos->rtn); + dbus_message_iter_get_basic(&value, &io_qos.rtn); } else if (!strcasecmp(key, "Latency")) { if (var != DBUS_TYPE_UINT16) goto fail; - dbus_message_iter_get_basic(&value, &qos->latency); + dbus_message_iter_get_basic(&value, &io_qos.latency); } else if (!strcasecmp(key, "Delay")) { if (var != DBUS_TYPE_UINT32) goto fail; - dbus_message_iter_get_basic(&value, &qos->delay); + dbus_message_iter_get_basic(&value, &qos->ucast.delay); } else if (!strcasecmp(key, "TargetLatency")) { if (var != DBUS_TYPE_BYTE) goto fail; dbus_message_iter_get_basic(&value, - &qos->target_latency); + &qos->ucast.target_latency); } dbus_message_iter_next(props); } + memcpy(&qos->ucast.io_qos, &io_qos, sizeof(io_qos)); return 0; fail: @@ -456,8 +458,8 @@ static DBusMessage *set_configuration(DBusConnection *conn, DBusMessage *msg, } /* Mark CIG and CIS to be auto assigned */ - ep->qos.cig_id = BT_ISO_QOS_CIG_UNSET; - ep->qos.cis_id = BT_ISO_QOS_CIS_UNSET; + ep->qos.ucast.cig_id = BT_ISO_QOS_CIG_UNSET; + ep->qos.ucast.cis_id = BT_ISO_QOS_CIS_UNSET; if (parse_properties(&props, &ep->caps, &ep->metadata, &ep->qos) < 0) { DBG("Unable to parse properties"); @@ -734,11 +736,11 @@ static void bap_iso_qos(struct bt_bap_qos *qos, struct bt_iso_io_qos *io) if (!qos) return; - io->interval = qos->interval; - io->latency = qos->latency; - io->sdu = qos->sdu; - io->phy = qos->phy; - io->rtn = qos->rtn; + io->interval = qos->ucast.io_qos.interval; + io->latency = qos->ucast.io_qos.latency; + io->sdu = qos->ucast.io_qos.sdu; + io->phy = qos->ucast.io_qos.phy; + io->rtn = qos->ucast.io_qos.rtn; } static bool match_stream_qos(const void *data, const void *user_data) @@ -749,10 +751,10 @@ static bool match_stream_qos(const void *data, const void *user_data) qos = bt_bap_stream_get_qos((void *)stream); - if (iso_qos->ucast.cig != qos->cig_id) + if (iso_qos->ucast.cig != qos->ucast.cig_id) return false; - return iso_qos->ucast.cis == qos->cis_id; + return iso_qos->ucast.cis == qos->ucast.cis_id; } static void iso_confirm_cb(GIOChannel *io, void *user_data) @@ -993,8 +995,10 @@ static void bap_create_io(struct bap_data *data, struct bap_ep *ep, } memset(&iso_qos, 0, sizeof(iso_qos)); - iso_qos.ucast.cig = qos[0] ? qos[0]->cig_id : qos[1]->cig_id; - iso_qos.ucast.cis = qos[0] ? qos[0]->cis_id : qos[1]->cis_id; + iso_qos.ucast.cig = qos[0] ? qos[0]->ucast.cig_id : + qos[1]->ucast.cig_id; + iso_qos.ucast.cis = qos[0] ? qos[0]->ucast.cis_id : + qos[1]->ucast.cis_id; bap_iso_qos(qos[0], &iso_qos.ucast.in); bap_iso_qos(qos[1], &iso_qos.ucast.out); @@ -1179,8 +1183,8 @@ static void bap_connecting(struct bt_bap_stream *stream, bool state, int fd, g_io_channel_set_close_on_unref(io, FALSE); /* Attempt to get CIG/CIS if they have not been set */ - if (ep->qos.cig_id == BT_ISO_QOS_CIG_UNSET || - ep->qos.cis_id == BT_ISO_QOS_CIS_UNSET) { + if (ep->qos.ucast.cig_id == BT_ISO_QOS_CIG_UNSET || + ep->qos.ucast.cis_id == BT_ISO_QOS_CIS_UNSET) { struct bt_iso_qos qos; GError *err = NULL; @@ -1192,12 +1196,12 @@ static void bap_connecting(struct bt_bap_stream *stream, bool state, int fd, return; } - ep->qos.cig_id = qos.ucast.cig; - ep->qos.cis_id = qos.ucast.cis; + ep->qos.ucast.cig_id = qos.ucast.cig; + ep->qos.ucast.cis_id = qos.ucast.cis; } DBG("stream %p fd %d: CIG 0x%02x CIS 0x%02x", stream, fd, - ep->qos.cig_id, ep->qos.cis_id); + ep->qos.ucast.cig_id, ep->qos.ucast.cis_id); } static void bap_attached(struct bt_bap *bap, void *user_data) diff --git a/profiles/audio/media.c b/profiles/audio/media.c index 6ce668e31..515263af3 100644 --- a/profiles/audio/media.c +++ b/profiles/audio/media.c @@ -6,7 +6,7 @@ * Copyright (C) 2006-2007 Nokia Corporation * Copyright (C) 2004-2009 Marcel Holtmann * Copyright (C) 2011 BMW Car IT GmbH. All rights reserved. - * + * Copyright 2023 NXP * */ @@ -748,7 +748,10 @@ static int parse_select_properties(DBusMessageIter *props, struct iovec *caps, struct bt_bap_qos *qos) { const char *key; + struct bt_bap_io_qos io_qos; + uint8_t framing = 0; + memset(&io_qos, 0, sizeof(io_qos)); while (dbus_message_iter_get_arg_type(props) == DBUS_TYPE_DICT_ENTRY) { DBusMessageIter value, entry; int var; @@ -777,17 +780,17 @@ static int parse_select_properties(DBusMessageIter *props, struct iovec *caps, if (var != DBUS_TYPE_BYTE) goto fail; - dbus_message_iter_get_basic(&value, &qos->cig_id); + dbus_message_iter_get_basic(&value, &qos->ucast.cig_id); } else if (!strcasecmp(key, "CIS")) { if (var != DBUS_TYPE_BYTE) goto fail; - dbus_message_iter_get_basic(&value, &qos->cis_id); + dbus_message_iter_get_basic(&value, &qos->ucast.cis_id); } else if (!strcasecmp(key, "Interval")) { if (var != DBUS_TYPE_UINT32) goto fail; - dbus_message_iter_get_basic(&value, &qos->interval); + dbus_message_iter_get_basic(&value, &io_qos.interval); } else if (!strcasecmp(key, "Framing")) { dbus_bool_t val; @@ -796,7 +799,7 @@ static int parse_select_properties(DBusMessageIter *props, struct iovec *caps, dbus_message_iter_get_basic(&value, &val); - qos->framing = val; + framing = val; } else if (!strcasecmp(key, "PHY")) { const char *str; @@ -806,42 +809,44 @@ static int parse_select_properties(DBusMessageIter *props, struct iovec *caps, dbus_message_iter_get_basic(&value, &str); if (!strcasecmp(str, "1M")) - qos->phy = 0x01; + io_qos.phy = 0x01; else if (!strcasecmp(str, "2M")) - qos->phy = 0x02; + io_qos.phy = 0x02; else goto fail; } else if (!strcasecmp(key, "SDU")) { if (var != DBUS_TYPE_UINT16) goto fail; - dbus_message_iter_get_basic(&value, &qos->sdu); + dbus_message_iter_get_basic(&value, &io_qos.sdu); } else if (!strcasecmp(key, "Retransmissions")) { if (var != DBUS_TYPE_BYTE) goto fail; - dbus_message_iter_get_basic(&value, &qos->rtn); + dbus_message_iter_get_basic(&value, &io_qos.rtn); } else if (!strcasecmp(key, "Latency")) { if (var != DBUS_TYPE_UINT16) goto fail; - dbus_message_iter_get_basic(&value, &qos->latency); + dbus_message_iter_get_basic(&value, &io_qos.latency); } else if (!strcasecmp(key, "Delay")) { if (var != DBUS_TYPE_UINT32) goto fail; - dbus_message_iter_get_basic(&value, &qos->delay); + dbus_message_iter_get_basic(&value, &qos->ucast.delay); } else if (!strcasecmp(key, "TargetLatency")) { if (var != DBUS_TYPE_BYTE) goto fail; dbus_message_iter_get_basic(&value, - &qos->target_latency); + &qos->ucast.target_latency); } dbus_message_iter_next(props); } + memcpy(&qos->ucast.io_qos, &io_qos, sizeof(io_qos)); + qos->ucast.framing = framing; return 0; fail: @@ -875,8 +880,8 @@ static void pac_select_cb(struct media_endpoint *endpoint, void *ret, int size, memset(&qos, 0, sizeof(qos)); /* Mark CIG and CIS to be auto assigned */ - qos.cig_id = BT_ISO_QOS_CIG_UNSET; - qos.cis_id = BT_ISO_QOS_CIS_UNSET; + qos.ucast.cig_id = BT_ISO_QOS_CIG_UNSET; + qos.ucast.cis_id = BT_ISO_QOS_CIS_UNSET; memset(&caps, 0, sizeof(caps)); memset(&meta, 0, sizeof(meta)); diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c index 9172d167e..82f5fa6fe 100644 --- a/profiles/audio/transport.c +++ b/profiles/audio/transport.c @@ -5,6 +5,7 @@ * * Copyright (C) 2006-2007 Nokia Corporation * Copyright (C) 2004-2009 Marcel Holtmann + * Copyright 2023 NXP * * */ @@ -828,7 +829,7 @@ static gboolean qos_exists(const GDBusPropertyTable *property, void *data) struct media_transport *transport = data; struct bap_transport *bap = transport->data; - return bap->qos.phy != 0x00; + return bap->qos.ucast.io_qos.phy != 0x00; } static gboolean get_cig(const GDBusPropertyTable *property, @@ -838,7 +839,7 @@ static gboolean get_cig(const GDBusPropertyTable *property, struct bap_transport *bap = transport->data; dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE, - &bap->qos.cig_id); + &bap->qos.ucast.cig_id); return TRUE; } @@ -850,7 +851,7 @@ static gboolean get_cis(const GDBusPropertyTable *property, struct bap_transport *bap = transport->data; dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE, - &bap->qos.cis_id); + &bap->qos.ucast.cis_id); return TRUE; } @@ -862,7 +863,7 @@ static gboolean get_interval(const GDBusPropertyTable *property, struct bap_transport *bap = transport->data; dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, - &bap->qos.interval); + &bap->qos.ucast.io_qos.interval); return TRUE; } @@ -872,7 +873,7 @@ static gboolean get_framing(const GDBusPropertyTable *property, { struct media_transport *transport = data; struct bap_transport *bap = transport->data; - dbus_bool_t val = bap->qos.framing; + dbus_bool_t val = bap->qos.ucast.framing; dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &val); @@ -885,7 +886,8 @@ static gboolean get_phy(const GDBusPropertyTable *property, struct media_transport *transport = data; struct bap_transport *bap = transport->data; - dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE, &bap->qos.phy); + dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE, + &bap->qos.ucast.io_qos.phy); return TRUE; } @@ -896,7 +898,8 @@ static gboolean get_sdu(const GDBusPropertyTable *property, struct media_transport *transport = data; struct bap_transport *bap = transport->data; - dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, &bap->qos.sdu); + dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, + &bap->qos.ucast.io_qos.sdu); return TRUE; } @@ -907,7 +910,8 @@ static gboolean get_retransmissions(const GDBusPropertyTable *property, struct media_transport *transport = data; struct bap_transport *bap = transport->data; - dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE, &bap->qos.rtn); + dbus_message_iter_append_basic(iter, DBUS_TYPE_BYTE, + &bap->qos.ucast.io_qos.rtn); return TRUE; } @@ -919,7 +923,7 @@ static gboolean get_latency(const GDBusPropertyTable *property, struct bap_transport *bap = transport->data; dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT16, - &bap->qos.latency); + &bap->qos.ucast.io_qos.latency); return TRUE; } @@ -930,7 +934,8 @@ static gboolean get_delay(const GDBusPropertyTable *property, struct media_transport *transport = data; struct bap_transport *bap = transport->data; - dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, &bap->qos.delay); + dbus_message_iter_append_basic(iter, DBUS_TYPE_UINT32, + &bap->qos.ucast.delay); return TRUE; } diff --git a/src/shared/bap.c b/src/shared/bap.c index f194f466f..dd9eb797a 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -4,6 +4,7 @@ * BlueZ - Bluetooth protocol stack for Linux * * Copyright (C) 2022 Intel Corporation. All rights reserved. + * Copyright 2023 NXP * */ @@ -861,15 +862,15 @@ static void stream_notify_qos(struct bt_bap_stream *stream) status->state = ep->state; qos = (void *)status->params; - qos->cis_id = stream->qos.cis_id; - qos->cig_id = stream->qos.cig_id; - put_le24(stream->qos.interval, qos->interval); - qos->framing = stream->qos.framing; - qos->phy = stream->qos.phy; - qos->sdu = cpu_to_le16(stream->qos.sdu); - qos->rtn = stream->qos.rtn; - qos->latency = cpu_to_le16(stream->qos.latency); - put_le24(stream->qos.delay, qos->pd); + qos->cis_id = stream->qos.ucast.cis_id; + qos->cig_id = stream->qos.ucast.cig_id; + put_le24(stream->qos.ucast.io_qos.interval, qos->interval); + qos->framing = stream->qos.ucast.framing; + qos->phy = stream->qos.ucast.io_qos.phy; + qos->sdu = cpu_to_le16(stream->qos.ucast.io_qos.sdu); + qos->rtn = stream->qos.ucast.io_qos.rtn; + qos->latency = cpu_to_le16(stream->qos.ucast.io_qos.latency); + put_le24(stream->qos.ucast.delay, qos->pd); gatt_db_attribute_notify(ep->attr, (void *) status, len, bt_bap_get_att(stream->bap)); @@ -898,8 +899,8 @@ static void stream_notify_metadata(struct bt_bap_stream *stream) status->state = ep->state; meta = (void *)status->params; - meta->cis_id = stream->qos.cis_id; - meta->cig_id = stream->qos.cig_id; + meta->cis_id = stream->qos.ucast.cis_id; + meta->cig_id = stream->qos.ucast.cig_id; if (stream->meta) { meta->len = stream->meta->iov_len; @@ -1575,20 +1576,22 @@ static uint8_t ascs_qos(struct bt_ascs *ascs, struct bt_bap *bap, memset(&qos, 0, sizeof(qos)); - qos.cig_id = req->cig; - qos.cis_id = req->cis; - qos.interval = get_le24(req->interval); - qos.framing = req->framing; - qos.phy = req->phy; - qos.sdu = le16_to_cpu(req->sdu); - qos.rtn = req->rtn; - qos.latency = le16_to_cpu(req->latency); - qos.delay = get_le24(req->pd); + qos.ucast.cig_id = req->cig; + qos.ucast.cis_id = req->cis; + qos.ucast.io_qos.interval = get_le24(req->interval); + qos.ucast.framing = req->framing; + qos.ucast.io_qos.phy = req->phy; + qos.ucast.io_qos.sdu = le16_to_cpu(req->sdu); + qos.ucast.io_qos.rtn = req->rtn; + qos.ucast.io_qos.latency = le16_to_cpu(req->latency); + qos.ucast.delay = get_le24(req->pd); DBG(bap, "CIG 0x%02x CIS 0x%02x interval %u framing 0x%02x " "phy 0x%02x SDU %u rtn %u latency %u pd %u", - req->cig, req->cis, qos.interval, qos.framing, qos.phy, - qos.sdu, qos.rtn, qos.latency, qos.delay); + req->cig, req->cis, qos.ucast.io_qos.interval, + qos.ucast.framing, qos.ucast.io_qos.phy, + qos.ucast.io_qos.sdu, qos.ucast.io_qos.rtn, + qos.ucast.io_qos.latency, qos.ucast.delay); ep = bap_get_local_endpoint_id(bap, req->ase); if (!ep) { @@ -3295,13 +3298,13 @@ static void ep_status_qos(struct bt_bap *bap, struct bt_bap_endpoint *ep, if (!ep->stream) return; - ep->stream->qos.interval = interval; - ep->stream->qos.framing = qos->framing; - ep->stream->qos.phy = qos->phy; - ep->stream->qos.sdu = sdu; - ep->stream->qos.rtn = qos->rtn; - ep->stream->qos.latency = latency; - ep->stream->qos.delay = pd; + ep->stream->qos.ucast.io_qos.interval = interval; + ep->stream->qos.ucast.framing = qos->framing; + ep->stream->qos.ucast.io_qos.phy = qos->phy; + ep->stream->qos.ucast.io_qos.sdu = sdu; + ep->stream->qos.ucast.io_qos.rtn = qos->rtn; + ep->stream->qos.ucast.io_qos.latency = latency; + ep->stream->qos.ucast.delay = pd; if (ep->old_state == BT_ASCS_ASE_STATE_CONFIG) bap_stream_config_cfm(ep->stream); @@ -4201,8 +4204,8 @@ unsigned int bt_bap_stream_config(struct bt_bap_stream *stream, memset(&config, 0, sizeof(config)); config.ase = stream->ep->id; - config.latency = qos->target_latency; - config.phy = qos->phy; + config.latency = qos->ucast.target_latency; + config.phy = qos->ucast.io_qos.phy; config.codec = stream->rpac->codec; iov[0].iov_base = &config; @@ -4384,15 +4387,15 @@ unsigned int bt_bap_stream_qos(struct bt_bap_stream *stream, /* TODO: Figure out how to pass these values around */ qos.ase = stream->ep->id; - qos.cig = data->cig_id; - qos.cis = data->cis_id; - put_le24(data->interval, qos.interval); - qos.framing = data->framing; - qos.phy = data->phy; - qos.sdu = cpu_to_le16(data->sdu); - qos.rtn = data->rtn; - qos.latency = cpu_to_le16(data->latency); - put_le24(data->delay, qos.pd); + qos.cig = data->ucast.cig_id; + qos.cis = data->ucast.cis_id; + put_le24(data->ucast.io_qos.interval, qos.interval); + qos.framing = data->ucast.framing; + qos.phy = data->ucast.io_qos.phy; + qos.sdu = cpu_to_le16(data->ucast.io_qos.sdu); + qos.rtn = data->ucast.io_qos.rtn; + qos.latency = cpu_to_le16(data->ucast.io_qos.latency); + put_le24(data->ucast.delay, qos.pd); iov.iov_base = &qos; iov.iov_len = sizeof(qos); @@ -4796,8 +4799,8 @@ int bt_bap_stream_io_link(struct bt_bap_stream *stream, return -EALREADY; if (stream->client != link->client || - stream->qos.cig_id != link->qos.cig_id || - stream->qos.cis_id != link->qos.cis_id) + stream->qos.ucast.cig_id != link->qos.ucast.cig_id || + stream->qos.ucast.cis_id != link->qos.ucast.cis_id) return -EINVAL; if (!stream->links) @@ -4834,7 +4837,7 @@ static void bap_stream_get_in_qos(void *data, void *user_data) struct bt_bap_qos **qos = user_data; if (!qos || *qos || stream->ep->dir != BT_BAP_SOURCE || - !stream->qos.sdu) + !stream->qos.ucast.io_qos.sdu) return; *qos = &stream->qos; @@ -4845,7 +4848,8 @@ static void bap_stream_get_out_qos(void *data, void *user_data) struct bt_bap_stream *stream = data; struct bt_bap_qos **qos = user_data; - if (!qos || *qos || stream->ep->dir != BT_BAP_SINK || !stream->qos.sdu) + if (!qos || *qos || stream->ep->dir != BT_BAP_SINK || + !stream->qos.ucast.io_qos.sdu) return; *qos = &stream->qos; diff --git a/src/shared/bap.h b/src/shared/bap.h index e9f769d0e..0c42e730f 100644 --- a/src/shared/bap.h +++ b/src/shared/bap.h @@ -4,6 +4,7 @@ * BlueZ - Bluetooth protocol stack for Linux * * Copyright (C) 2022 Intel Corporation. All rights reserved. + * Copyright 2023 NXP * */ @@ -49,17 +50,46 @@ struct bt_ltv { uint8_t value[0]; } __packed; -struct bt_bap_qos { +struct bt_bap_io_qos { + uint32_t interval; /* Frame interval */ + uint16_t latency; /* Transport Latency */ + uint16_t sdu; /* Maximum SDU Size */ + uint8_t phy; /* PHY */ + uint8_t rtn; /* Retransmission Effort */ +}; + +struct bt_bap_ucast_qos { uint8_t cig_id; uint8_t cis_id; - uint32_t interval; /* Frame interval */ uint8_t framing; /* Frame framing */ - uint8_t phy; /* PHY */ - uint16_t sdu; /* Maximum SDU Size */ - uint8_t rtn; /* Retransmission Effort */ - uint16_t latency; /* Transport Latency */ uint32_t delay; /* Presentation Delay */ uint8_t target_latency; /* Target Latency */ + struct bt_bap_io_qos io_qos; +}; + +struct bt_bap_bcast_qos { + uint8_t big; + uint8_t bis; + uint8_t sync_interval; + uint8_t packing; + uint8_t framing; + uint8_t encryption; + struct iovec bcode; + uint8_t options; + uint16_t skip; + uint16_t sync_timeout; + uint8_t sync_cte_type; + uint8_t mse; + uint16_t timeout; + uint8_t pa_sync; + struct bt_bap_io_qos io_qos; +}; + +struct bt_bap_qos { + union { + struct bt_bap_ucast_qos ucast; + struct bt_bap_bcast_qos bcast; + }; }; typedef void (*bt_bap_ready_func_t)(struct bt_bap *bap, void *user_data); diff --git a/unit/test-bap.c b/unit/test-bap.c index bf525742d..adade07db 100644 --- a/unit/test-bap.c +++ b/unit/test-bap.c @@ -712,12 +712,15 @@ static void test_disc(void) #define QOS_BALANCED_2M \ { \ .target_latency = BT_BAP_CONFIG_LATENCY_BALANCED, \ - .phy = BT_BAP_CONFIG_PHY_2M, \ + .io_qos.phy = BT_BAP_CONFIG_PHY_2M, \ } - +#define QOS_UCAST \ +{\ + .ucast = QOS_BALANCED_2M, \ +} static struct test_config cfg_snk_8_1 = { .cc = LC3_CONFIG_8_1, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .snk = true, }; @@ -727,7 +730,7 @@ static struct test_config cfg_snk_8_1 = { static struct test_config cfg_snk_8_2 = { .cc = LC3_CONFIG_8_2, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .snk = true, }; @@ -737,7 +740,7 @@ static struct test_config cfg_snk_8_2 = { static struct test_config cfg_snk_16_1 = { .cc = LC3_CONFIG_16_1, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .snk = true, }; @@ -747,7 +750,7 @@ static struct test_config cfg_snk_16_1 = { static struct test_config cfg_snk_16_2 = { .cc = LC3_CONFIG_16_2, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .snk = true, }; @@ -757,7 +760,7 @@ static struct test_config cfg_snk_16_2 = { static struct test_config cfg_snk_24_1 = { .cc = LC3_CONFIG_24_1, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .snk = true, }; @@ -767,7 +770,7 @@ static struct test_config cfg_snk_24_1 = { static struct test_config cfg_snk_24_2 = { .cc = LC3_CONFIG_24_2, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .snk = true, }; @@ -777,7 +780,7 @@ static struct test_config cfg_snk_24_2 = { static struct test_config cfg_snk_32_1 = { .cc = LC3_CONFIG_32_1, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .snk = true, }; @@ -787,7 +790,7 @@ static struct test_config cfg_snk_32_1 = { static struct test_config cfg_snk_32_2 = { .cc = LC3_CONFIG_32_2, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .snk = true, }; @@ -797,7 +800,7 @@ static struct test_config cfg_snk_32_2 = { static struct test_config cfg_snk_44_1 = { .cc = LC3_CONFIG_44_1, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .snk = true, }; @@ -807,7 +810,7 @@ static struct test_config cfg_snk_44_1 = { static struct test_config cfg_snk_44_2 = { .cc = LC3_CONFIG_44_2, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .snk = true, }; @@ -817,7 +820,7 @@ static struct test_config cfg_snk_44_2 = { static struct test_config cfg_snk_48_1 = { .cc = LC3_CONFIG_48_1, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .snk = true, }; @@ -827,7 +830,7 @@ static struct test_config cfg_snk_48_1 = { static struct test_config cfg_snk_48_2 = { .cc = LC3_CONFIG_48_2, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .snk = true, }; @@ -837,7 +840,7 @@ static struct test_config cfg_snk_48_2 = { static struct test_config cfg_snk_48_3 = { .cc = LC3_CONFIG_48_3, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .snk = true, }; @@ -847,7 +850,7 @@ static struct test_config cfg_snk_48_3 = { static struct test_config cfg_snk_48_4 = { .cc = LC3_CONFIG_48_4, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .snk = true, }; @@ -857,7 +860,7 @@ static struct test_config cfg_snk_48_4 = { static struct test_config cfg_snk_48_5 = { .cc = LC3_CONFIG_48_5, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .snk = true, }; @@ -867,7 +870,7 @@ static struct test_config cfg_snk_48_5 = { static struct test_config cfg_snk_48_6 = { .cc = LC3_CONFIG_48_6, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .snk = true, }; @@ -899,7 +902,7 @@ static struct test_config cfg_snk_48_6 = { static struct test_config cfg_src_8_1 = { .cc = LC3_CONFIG_8_1, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .src = true, }; @@ -909,7 +912,7 @@ static struct test_config cfg_src_8_1 = { static struct test_config cfg_src_8_2 = { .cc = LC3_CONFIG_8_2, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .src = true, }; @@ -919,7 +922,7 @@ static struct test_config cfg_src_8_2 = { static struct test_config cfg_src_16_1 = { .cc = LC3_CONFIG_16_1, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .src = true, }; @@ -929,7 +932,7 @@ static struct test_config cfg_src_16_1 = { static struct test_config cfg_src_16_2 = { .cc = LC3_CONFIG_16_2, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .src = true, }; @@ -939,7 +942,7 @@ static struct test_config cfg_src_16_2 = { static struct test_config cfg_src_24_1 = { .cc = LC3_CONFIG_24_1, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .src = true, }; @@ -949,7 +952,7 @@ static struct test_config cfg_src_24_1 = { static struct test_config cfg_src_24_2 = { .cc = LC3_CONFIG_24_2, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .src = true, }; @@ -959,7 +962,7 @@ static struct test_config cfg_src_24_2 = { static struct test_config cfg_src_32_1 = { .cc = LC3_CONFIG_32_1, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .src = true, }; @@ -969,7 +972,7 @@ static struct test_config cfg_src_32_1 = { static struct test_config cfg_src_32_2 = { .cc = LC3_CONFIG_32_2, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .src = true, }; @@ -979,7 +982,7 @@ static struct test_config cfg_src_32_2 = { static struct test_config cfg_src_44_1 = { .cc = LC3_CONFIG_44_1, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .src = true, }; @@ -989,7 +992,7 @@ static struct test_config cfg_src_44_1 = { static struct test_config cfg_src_44_2 = { .cc = LC3_CONFIG_44_2, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .src = true, }; @@ -999,7 +1002,7 @@ static struct test_config cfg_src_44_2 = { static struct test_config cfg_src_48_1 = { .cc = LC3_CONFIG_48_1, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .src = true, }; @@ -1009,7 +1012,7 @@ static struct test_config cfg_src_48_1 = { static struct test_config cfg_src_48_2 = { .cc = LC3_CONFIG_48_2, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .src = true, }; @@ -1019,7 +1022,7 @@ static struct test_config cfg_src_48_2 = { static struct test_config cfg_src_48_3 = { .cc = LC3_CONFIG_48_3, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .src = true, }; @@ -1029,7 +1032,7 @@ static struct test_config cfg_src_48_3 = { static struct test_config cfg_src_48_4 = { .cc = LC3_CONFIG_48_4, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .src = true, }; @@ -1039,7 +1042,7 @@ static struct test_config cfg_src_48_4 = { static struct test_config cfg_src_48_5 = { .cc = LC3_CONFIG_48_5, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .src = true, }; @@ -1049,7 +1052,7 @@ static struct test_config cfg_src_48_5 = { static struct test_config cfg_src_48_6 = { .cc = LC3_CONFIG_48_6, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .src = true, }; @@ -1141,7 +1144,7 @@ static void test_scc_cc_lc3(void) static struct test_config cfg_snk_vs = { .cc = IOV_NULL, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .snk = true, .vs = true, }; @@ -1155,7 +1158,7 @@ static struct test_config cfg_snk_vs = { static struct test_config cfg_src_vs = { .cc = IOV_NULL, - .qos = QOS_BALANCED_2M, + .qos = QOS_UCAST, .src = true, .vs = true, }; From patchwork Tue May 30 14:13:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Silviu Florian Barbulescu X-Patchwork-Id: 13260177 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DAF51C77B73 for ; Tue, 30 May 2023 14:15:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233067AbjE3OPJ (ORCPT ); Tue, 30 May 2023 10:15:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233029AbjE3OPG (ORCPT ); Tue, 30 May 2023 10:15:06 -0400 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2074.outbound.protection.outlook.com [40.107.6.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB58F10D for ; Tue, 30 May 2023 07:14:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=X7NWLLv8/27hOGlPZbXyrFV7gQGY5anGG5FmLTjkGuujTPPcD+wXSJ+mOY4D4jqYlUMq5R3Nls8/J/0o3pzNOpP4OQ5I/96uqcc+t+rhTppMGTXkjZyUNqnq16O5AAW7z7VjHG8I9gDcrjff9XOfPJcNzC7U8SsaL8Lo2VjkyhUFaN1vlWl/yf7rb+9awDeGgydKTMN6QbRtwN/UaVWBU5x9IoCSxYYcgE7575s+rFEJkvd0fahSI+Gya8bHQPujd2vgsDyaIxzIkOxmvIC3YVjy2cOaGiTwb6Vq9oHbclQROa2HfTu5pMaGpP50zla/wTMLEgtrrKWVXJ1LxoYtrQ== 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=vZFozbnhpsbNMdYLuYWAInF30dkevK+2QMzveSTo5Bs=; b=gbAcZbFWa+Cfi2/wm6kQ1GDha5gqeJ5nW91hGqjiJMVC5Z758HLNClaFQTC57bx7VCHPGrXc2l7786PXb93y49hPMYPYIbmHHcRNmUZf1mNYwb8reRMypvrsGKrCKjysGtjgdZN7KljhfcJy1RTS2rXiBCH7UaONXGlGPXh96DmaMTB4+rLBP80t7+uECSwUh+gipF0jFgkF4xMKS/4MJI7yMDu8MFlit3ZuVZ5Jii9t8ktuw7oDVp1vxEWlnd3uWqmayyb/kFgh+KitMKUP8t5mNhU7T5HTUpzHomV8flaXBlSFafEZRsxciAzr8FgDtq7SPbAsN4mqkKK0NqSMLA== 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=vZFozbnhpsbNMdYLuYWAInF30dkevK+2QMzveSTo5Bs=; b=iw+CaZMMfs944uf2ezOajUmqREp6IC/93mbrI1hzdH83EEFUyN/cvlAOC+GU/e7XmED0oQdSYCUrUHTzpy58GH7p/Z/zf20FlmfGOtXmlpELpWZ07sWGqrnnVnzKfb56HGHyuWo+etmMtmQY6e9R7ZNcSh4yqpUiN7ovv+FIbyg= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5344.eurprd04.prod.outlook.com (2603:10a6:803:4b::31) by DBBPR04MB7913.eurprd04.prod.outlook.com (2603:10a6:10:1ee::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Tue, 30 May 2023 14:14:05 +0000 Received: from VI1PR04MB5344.eurprd04.prod.outlook.com ([fe80::cedb:51d6:a774:f81a]) by VI1PR04MB5344.eurprd04.prod.outlook.com ([fe80::cedb:51d6:a774:f81a%7]) with mapi id 15.20.6433.022; Tue, 30 May 2023 14:14:05 +0000 From: Silviu Florian Barbulescu To: linux-bluetooth@vger.kernel.org Cc: Silviu Florian Barbulescu Subject: [PATCH BlueZ v3 2/4] Update bluetoothctl with support for broadcast source Date: Tue, 30 May 2023 17:13:37 +0300 Message-Id: <20230530141339.100733-3-silviu.barbulescu@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230530141339.100733-1-silviu.barbulescu@nxp.com> References: <20230530141339.100733-1-silviu.barbulescu@nxp.com> X-ClientProxiedBy: AM0PR07CA0021.eurprd07.prod.outlook.com (2603:10a6:208:ac::34) To VI1PR04MB5344.eurprd04.prod.outlook.com (2603:10a6:803:4b::31) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5344:EE_|DBBPR04MB7913:EE_ X-MS-Office365-Filtering-Correlation-Id: fd4e0179-ae7d-4406-b788-08db61182036 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: qr4rpfzyOo62fOMGPUD/TydFs9w9CO/iJATDqPpMhHOZ5NYVR3utfcuyGT5EM4t2apgLqPe0shzi+kiOvyeoTq9E585KWSNsvP4+M2PbST0mVrQ23Sbxqz53BSCj4H1/oVbM6+L43cYLN2PcRRCIGgxaEEi0SZYaDs1evZ9eOQotSncrC2xpTu6DFCzUBQQqOVKfoGaN54h5Rip91Q+c1QgOvD6ElOzYq/8SkG+0ucnjJyh5khzQN+dfjg4f7suCt+cHWMthc151QOPqpxo8mFwaH9gavnIJEz31Z11DomIGRsTjyaMVViSgF8hPJarbgwudk5TrgTJ2G84lR2j8KjlOrXCTbImurtyFBu2Lfhh1yVKAOWC39lxhEEOkwG/faEAbIDfQlvfGS2/cyKQHr9bCxmCaylRlt6FvCDRWf1rxuiNsqzihneKeuv6nsp1+v6PFkkrHRClVifa2kvrbWV1WWqJAyKgRC8Ylbv3y2Pizbgn8no7/1ewtP8I49iHI2ikXK8eV50nc8V2l2bOW8wKOlfJdjS7MTnq4I9gBAHUgjCS45I9tswamcMvgVBix5+JTh+CI/orFHYbhcKNZw7SmzrG4g6vlOINSmHLAru9LLW/CIdxkPEi72TL2Wf6q X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5344.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(366004)(376002)(396003)(346002)(136003)(451199021)(478600001)(38100700002)(38350700002)(66556008)(66476007)(66946007)(41300700001)(52116002)(6486002)(8676002)(5660300002)(86362001)(8936002)(26005)(2906002)(30864003)(1076003)(186003)(6512007)(6506007)(83380400001)(4326008)(6916009)(316002)(6666004)(2616005)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DGKnCMAfp0cV/8NthgOQE+u5pmGRAQ3L01RHtswJ+i31rr3G1GNNI1uwBPPpZCJyNFcwYuNTd2SYoXQP1yDsEpxkrC2/30U9qbg3FNAD4jTh4bJoJxQc3UCCKgy+FSKWgwkcJqeNx/SxyZDm3OTKtU32kLPxmY3WbhBVV/4cxfJtY3rJz9YMcybkOmQXlawH3pADBRp1xEHBfGvOOoZxcUjzTNB08jYtmhl/9DeWzWstV2+SUL1vC0WZwTSs0IzAc/ZfDHDjLVIrLBzBPYtmUCNHEKVHmdBepg/H6abj/ifAWAY1cIKrPPbiN9YTyJlakE0qLvqeolEcM82Tnczh7vDE2ALwJ5YSe+v3Sd3mPzNGjIoiKXD3+p6xbavr0fibaecaxlkA2Z3DGHgQJPHp7gyUDeBK9/DWYgXE+vp7UKLJmemavwVt5VY4l4ILiKTgD6STIafJSuC2QvaZkuyCx6vUHtknQixGFF93RftuBzwqPYNBDeCEshb8go0ylcp31Io/Q1yZCDYkPdaflgGZwRdjMZpeyrmEm9GbJy7ZqU48msrRjlq5/tAbhascmkaAfsKf+oGor3EmKGn02tHExbyC4XhzJqi8rTOe0DefnbTsnJ1PpRFAwys7/ZIqxN+L4aacqZh70ALHYktZ61SasyZPgWWBZgeWL0f4ZWhj9t6aEiVZGVEaZY9DCVqKc6PHCH2rLSC1U2Ha5ppBFtsNn27rEmLhQpImtCUi3H9ZRIN9SrH/24nzFM1IuEo/hAgg2Rne4uMJY+w2gcyRqGEK0ZeZBWfTLB2BVdQheQYSeyfUGWYJwL4iS0udxhja9bK324p48pmpGTlH5CriKaJoXBxYdg+SzqydSICC4/tHv8z/JkJgWUQkDyA7cEpbZV9khdr5Q0Hpg7ln/EO73LNyt572IkhDZlUrdW+dXBP+pj95KrxO0EoYC/sj3mfuo4gwhCJDzwS+1wE7WQDfHevjbPIod0EY64ZEl+xVJMFwFBASggt1Duw3FV3lpeTEyAzl6I8AdkdTBDfB1QDsTC14HvLo0w8sCHERtac0LbCW5pUIEcKubf3RLkGVvv1FdjtSo5+0y3Zil9GFKPjR6cLnO6HM7spx7kMlKIxSHGDtq/s7/6tAogwBPJeXMgnt5aIxbjZ/hREXmOQeiKGqgCx/zNLos1B9jQVM+BxX+xwx112Pb6vJT2HxUGX3G3MmGkVIeb02c7EK8RJAnEznhSO846qzb07ov+0/Su2uEAVN60+qWZ1oTM09UKJ6ZYCaIIywPLUGCRbl7U7O7Tv16cMohxTFoNpzvUSgorazMneJFMj4JEKPQkvKqsIsCCgdKi7PXf4C4aKy324XcU6IHIYE/cMqzw09MCDaFamN207/5KVEnSwOtuVgrVNScV0Dxbj3zWSCg2Kx+EF0TpxcxOGugt9Vq/0RqT46BxT+w660CbR0TQpwPAIDfWQpTFZWz5zBlu60RQGT0d4HNqN6VoLOegFrqcC1vIQ9QLiDCL6xbTqFl6XasSY1dGiwO28kPQwLkTjGTSWUDyIYnkMJfopfwty3/toUyMuTlEDDGpKV1cgFrVh5/jQk8TdN0+3iqLQVixv8BSZVERna7bhA1/W+rQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fd4e0179-ae7d-4406-b788-08db61182036 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5344.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2023 14:14:05.2294 (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: NweQUhnMtH75bY+YA6S2qvyUht39prrZY3tviO87W3x0BsnifbzTWz6d5HUgToEursH8OAb1FR/Pxtsa4Y17JmlFLT43j/DquOL6ZIDoN1w= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7913 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds bluetoothctl support for broadcast source. To test the current implementation use bluetoothctl with the following commands: endpoint.register 00001852-0000-1000-8000-00805f9b34fb 0x06 transport.acquire /org/bluez/hci0/dev_00_00_00_00_00_00/pac_broadcast0/fd0 transport.send /org/bluez/hci0/dev_00_00_00_00_00_00/pac_broadcast0/fd0 --- client/player.c | 223 ++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 199 insertions(+), 24 deletions(-) diff --git a/client/player.c b/client/player.c index a9f56fb94..be22e8ab9 100644 --- a/client/player.c +++ b/client/player.c @@ -74,11 +74,13 @@ struct endpoint { bool auto_accept; bool acquiring; uint8_t max_transports; - uint8_t cig; - uint8_t cis; + uint8_t iso_group; + uint8_t iso_stream; char *transport; DBusMessage *msg; struct preset *preset; + bool broadcast; + struct iovec *bcode; }; static DBusConnection *dbus_conn; @@ -104,6 +106,22 @@ struct transport { struct io *timer_io; }; +static const uint8_t base_lc3_16_2_1[] = { + 0x28, 0x00, 0x00, /* Presentation Delay */ + 0x01, /* Number of Subgroups */ + 0x01, /* Number of BIS */ + 0x06, 0x00, 0x00, 0x00, 0x00, /* Code ID = LC3 (0x06) */ + 0x11, /* Codec Specific Configuration */ + 0x02, 0x01, 0x03, /* 16 KHZ */ + 0x02, 0x02, 0x01, /* 10 ms */ + 0x05, 0x03, 0x01, 0x00, 0x00, 0x00, /* Front Left */ + 0x03, 0x04, 0x28, 0x00, /* Frame Length 40 bytes */ + 0x04, /* Metadata */ + 0x03, 0x02, 0x02, 0x00, /* Audio Context: Convertional */ + 0x01, /* BIS */ + 0x00, /* Codec Specific Configuration */ +}; + static void endpoint_unregister(void *data) { struct endpoint *ep = data; @@ -1154,6 +1172,16 @@ static const struct capabilities { CODEC_CAPABILITIES(PAC_SOURCE_UUID, LC3_ID, LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY, 3u, 30, 240)), + /* Broadcast LC3 Source: + * + * Frequencies: 8Khz 11Khz 16Khz 22Khz 24Khz 32Khz 44.1Khz 48Khz + * Duration: 7.5 ms 10 ms + * Channel count: 3 + * Frame length: 30-240 + */ + CODEC_CAPABILITIES(BAA_SERVICE_UUID, LC3_ID, + LC3_DATA(LC3_FREQ_ANY, LC3_DURATION_ANY, + 3u, 30, 240)), }; struct codec_qos { @@ -1435,6 +1463,7 @@ static struct preset { PRESET(A2DP_SINK_UUID, A2DP_CODEC_SBC, sbc_presets, 6), PRESET(PAC_SINK_UUID, LC3_ID, lc3_presets, 3), PRESET(PAC_SOURCE_UUID, LC3_ID, lc3_presets, 3), + PRESET(BAA_SERVICE_UUID, LC3_ID, lc3_presets, 3), }; static void parse_vendor_codec(const char *codec, uint16_t *vid, uint16_t *cid) @@ -1707,6 +1736,27 @@ struct endpoint_config { const struct codec_qos *qos; }; +#define BCODE {0x01, 0x02, 0x68, 0x05, 0x53, 0xf1, 0x41, 0x5a, \ + 0xa2, 0x65, 0xbb, 0xaf, 0xc6, 0xea, 0x03, 0xb8} + +static struct bt_iso_qos bcast_qos = { + .bcast = { + .big = BT_ISO_QOS_BIG_UNSET, + .bis = BT_ISO_QOS_BIS_UNSET, + .sync_interval = 0x07, + .packing = 0x00, + .framing = 0x00, + .encryption = 0x00, + .bcode = BCODE, + .options = 0x00, + .skip = 0x0000, + .sync_timeout = 0x4000, + .sync_cte_type = 0x00, + .mse = 0x00, + .timeout = 0x4000, + } + }; + static void append_properties(DBusMessageIter *iter, struct endpoint_config *cfg) { @@ -1714,6 +1764,7 @@ static void append_properties(DBusMessageIter *iter, struct codec_qos *qos = (void *)cfg->qos; const char *key = "Capabilities"; const char *meta = "Metadata"; + const char *keyBCode = "BroadcastCode"; dbus_message_iter_open_container(iter, DBUS_TYPE_ARRAY, "{sv}", &dict); @@ -1742,16 +1793,27 @@ static void append_properties(DBusMessageIter *iter, DBUS_TYPE_BYTE, &cfg->target_latency); } - if (cfg->ep->cig != BT_ISO_QOS_CIG_UNSET) { - bt_shell_printf("CIG 0x%2.2x\n", cfg->ep->cig); + if ((!cfg->ep->broadcast) && + (cfg->ep->iso_group != BT_ISO_QOS_GROUP_UNSET)) { + bt_shell_printf("CIG 0x%2.2x\n", cfg->ep->iso_group); g_dbus_dict_append_entry(&dict, "CIG", DBUS_TYPE_BYTE, - &cfg->ep->cig); + &cfg->ep->iso_group); + } else { + bt_shell_printf("BIG 0x%2.2x\n", bcast_qos.bcast.big); + g_dbus_dict_append_entry(&dict, "BIG", DBUS_TYPE_BYTE, + &bcast_qos.bcast.big); } - if (cfg->ep->cis != BT_ISO_QOS_CIS_UNSET) { - bt_shell_printf("CIS 0x%2.2x\n", cfg->ep->cis); + if ((!cfg->ep->broadcast) && + (cfg->ep->iso_stream != BT_ISO_QOS_STREAM_UNSET)) { + bt_shell_printf("CIS 0x%2.2x\n", cfg->ep->iso_stream); g_dbus_dict_append_entry(&dict, "CIS", DBUS_TYPE_BYTE, - &cfg->ep->cis); + &cfg->ep->iso_stream); + + } else { + bt_shell_printf("BIS 0x%2.2x\n", bcast_qos.bcast.bis); + g_dbus_dict_append_entry(&dict, "BIS", DBUS_TYPE_BYTE, + &bcast_qos.bcast.bis); } bt_shell_printf("Interval %u\n", qos->interval); @@ -1759,10 +1821,19 @@ static void append_properties(DBusMessageIter *iter, g_dbus_dict_append_entry(&dict, "Interval", DBUS_TYPE_UINT32, &qos->interval); - bt_shell_printf("Framing %s\n", qos->framing ? "true" : "false"); + if (!cfg->ep->broadcast) { + bt_shell_printf("Framing %s\n", + qos->framing ? "true" : "false"); - g_dbus_dict_append_entry(&dict, "Framing", DBUS_TYPE_BOOLEAN, - &qos->framing); + g_dbus_dict_append_entry(&dict, "Framing", DBUS_TYPE_BOOLEAN, + &qos->framing); + } else { + bt_shell_printf("Framing %s\n", + bcast_qos.bcast.framing ? "true" : "false"); + + g_dbus_dict_append_entry(&dict, "Framing", DBUS_TYPE_BOOLEAN, + &bcast_qos.bcast.framing); + } bt_shell_printf("PHY %s\n", qos->phy); @@ -1787,6 +1858,57 @@ static void append_properties(DBusMessageIter *iter, g_dbus_dict_append_entry(&dict, "Delay", DBUS_TYPE_UINT32, &qos->delay); + if (!cfg->ep->broadcast) + goto done; + + bt_shell_printf("SyncInterval %u\n", bcast_qos.bcast.sync_interval); + + g_dbus_dict_append_entry(&dict, "SyncInterval", DBUS_TYPE_BYTE, + &bcast_qos.bcast.sync_interval); + + bt_shell_printf("Encryption %u\n", bcast_qos.bcast.encryption); + + g_dbus_dict_append_entry(&dict, "Encryption", DBUS_TYPE_BYTE, + &bcast_qos.bcast.encryption); + + bt_shell_printf("Options %u\n", bcast_qos.bcast.options); + + g_dbus_dict_append_entry(&dict, "Options", DBUS_TYPE_BYTE, + &bcast_qos.bcast.options); + + bt_shell_printf("Skip %u\n", bcast_qos.bcast.skip); + + g_dbus_dict_append_entry(&dict, "Skip", DBUS_TYPE_UINT16, + &bcast_qos.bcast.skip); + + bt_shell_printf("SyncTimeout %u\n", bcast_qos.bcast.sync_timeout); + + g_dbus_dict_append_entry(&dict, "SyncTimeout", DBUS_TYPE_UINT16, + &bcast_qos.bcast.sync_timeout); + + bt_shell_printf("SyncCteType %u\n", bcast_qos.bcast.sync_cte_type); + + g_dbus_dict_append_entry(&dict, "SyncCteType", DBUS_TYPE_BYTE, + &bcast_qos.bcast.sync_cte_type); + + bt_shell_printf("MSE %u\n", bcast_qos.bcast.mse); + + g_dbus_dict_append_entry(&dict, "MSE", DBUS_TYPE_BYTE, + &bcast_qos.bcast.mse); + + bt_shell_printf("Timeout %u\n", bcast_qos.bcast.timeout); + + g_dbus_dict_append_entry(&dict, "Timeout", DBUS_TYPE_UINT16, + &bcast_qos.bcast.timeout); + + bt_shell_printf("BroadcastCode:\n"); + bt_shell_hexdump(cfg->ep->bcode->iov_base, cfg->ep->bcode->iov_len); + + g_dbus_dict_append_basic_array(&dict, DBUS_TYPE_STRING, &keyBCode, + DBUS_TYPE_BYTE, + &cfg->ep->bcode->iov_base, + cfg->ep->bcode->iov_len); + done: dbus_message_iter_close_container(iter, &dict); } @@ -1826,8 +1948,18 @@ static DBusMessage *endpoint_select_properties_reply(struct endpoint *ep, cfg = new0(struct endpoint_config, 1); cfg->ep = ep; - /* Copy capabilities */ - iov_append(&cfg->caps, preset->data.iov_base, preset->data.iov_len); + if (ep->broadcast) { + iov_append(&cfg->ep->bcode, bcast_qos.bcast.bcode, + sizeof(bcast_qos.bcast.bcode)); + /* Copy capabilities for broadcast*/ + iov_append(&cfg->caps, base_lc3_16_2_1, + sizeof(base_lc3_16_2_1)); + } else { + /* Copy capabilities */ + iov_append(&cfg->caps, preset->data.iov_base, + preset->data.iov_len); + } + cfg->target_latency = preset->target_latency; /* Copy metadata */ @@ -2239,14 +2371,14 @@ fail: } -static void endpoint_cis(const char *input, void *user_data) +static void endpoint_iso_stream(const char *input, void *user_data) { struct endpoint *ep = user_data; char *endptr = NULL; int value; if (!strcasecmp(input, "a") || !strcasecmp(input, "auto")) { - ep->cis = BT_ISO_QOS_CIS_UNSET; + ep->iso_stream = BT_ISO_QOS_STREAM_UNSET; } else { value = strtol(input, &endptr, 0); @@ -2255,20 +2387,20 @@ static void endpoint_cis(const char *input, void *user_data) return bt_shell_noninteractive_quit(EXIT_FAILURE); } - ep->cis = value; + ep->iso_stream = value; } endpoint_register(ep); } -static void endpoint_cig(const char *input, void *user_data) +static void endpoint_iso_group(const char *input, void *user_data) { struct endpoint *ep = user_data; char *endptr = NULL; int value; if (!strcasecmp(input, "a") || !strcasecmp(input, "auto")) { - ep->cig = BT_ISO_QOS_CIG_UNSET; + ep->iso_group = BT_ISO_QOS_GROUP_UNSET; } else { value = strtol(input, &endptr, 0); @@ -2277,10 +2409,15 @@ static void endpoint_cig(const char *input, void *user_data) return bt_shell_noninteractive_quit(EXIT_FAILURE); } - ep->cig = value; + ep->iso_group = value; } - bt_shell_prompt_input(ep->path, "CIS (auto/value):", endpoint_cis, ep); + if (!ep->broadcast) + bt_shell_prompt_input(ep->path, "CIS (auto/value):", + endpoint_iso_stream, ep); + else + bt_shell_prompt_input(ep->path, "BIS (auto/value):", + endpoint_iso_stream, ep); } static void endpoint_max_transports(const char *input, void *user_data) @@ -2302,13 +2439,24 @@ static void endpoint_max_transports(const char *input, void *user_data) ep->max_transports = value; } - bt_shell_prompt_input(ep->path, "CIG (auto/value):", endpoint_cig, ep); + if (ep->broadcast) + bt_shell_prompt_input(ep->path, "BIG (auto/value):", + endpoint_iso_group, ep); + else + bt_shell_prompt_input(ep->path, "CIG (auto/value):", + endpoint_iso_group, ep); } static void endpoint_auto_accept(const char *input, void *user_data) { struct endpoint *ep = user_data; + if (!strcmp(ep->uuid, BAA_SERVICE_UUID)) { + ep->broadcast = true; + } else { + ep->broadcast = false; + } + if (!strcasecmp(input, "y") || !strcasecmp(input, "yes")) { ep->auto_accept = true; bt_shell_prompt_input(ep->path, "Max Transports (auto/value):", @@ -2321,7 +2469,12 @@ static void endpoint_auto_accept(const char *input, void *user_data) return bt_shell_noninteractive_quit(EXIT_FAILURE); } - bt_shell_prompt_input(ep->path, "CIG (auto/value):", endpoint_cig, ep); + if (ep->broadcast) + bt_shell_prompt_input(ep->path, "BIG (auto/value):", + endpoint_iso_group, ep); + else + bt_shell_prompt_input(ep->path, "CIG (auto/value):", + endpoint_iso_group, ep); } static void endpoint_set_metadata(const char *input, void *user_data) @@ -3050,8 +3203,8 @@ static void register_endpoints(GDBusProxy *proxy) ep->cid); ep->max_transports = UINT8_MAX; ep->auto_accept = true; - ep->cig = BT_ISO_QOS_CIG_UNSET; - ep->cis = BT_ISO_QOS_CIS_UNSET; + ep->iso_group = BT_ISO_QOS_GROUP_UNSET; + ep->iso_stream = BT_ISO_QOS_STREAM_UNSET; endpoint_register(ep); } } @@ -3595,6 +3748,7 @@ static void cmd_acquire_transport(int argc, char *argv[]) { GDBusProxy *proxy; int i; + struct endpoint *ep, *link; for (i = 1; i < argc; i++) { proxy = g_dbus_proxy_lookup(transports, NULL, argv[i], @@ -3610,6 +3764,27 @@ static void cmd_acquire_transport(int argc, char *argv[]) return bt_shell_noninteractive_quit(EXIT_FAILURE); } + ep = find_ep_by_transport(g_dbus_proxy_get_path(proxy)); + if (!ep || ep->acquiring) { + bt_shell_printf("Transport %s already in acquiring process\n", + argv[i]); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + + ep->acquiring = true; + + link = find_link_by_proxy(proxy); + if (link) { + bt_shell_printf("Link %s found\n", link->transport); + /* If link already acquiring wait it to be complete */ + if (link->acquiring) { + bt_shell_printf("Link %s already in acquiring process\n", + argv[i]); + return bt_shell_noninteractive_quit(EXIT_FAILURE); + } + link->acquiring = true; + } + if (!g_dbus_proxy_method_call(proxy, "Acquire", NULL, acquire_reply, proxy, NULL)) { bt_shell_printf("Failed acquire transport\n"); From patchwork Tue May 30 14:13:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Silviu Florian Barbulescu X-Patchwork-Id: 13260178 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 35DB8C7EE2C for ; Tue, 30 May 2023 14:15:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233058AbjE3OPh (ORCPT ); Tue, 30 May 2023 10:15:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233046AbjE3OPf (ORCPT ); Tue, 30 May 2023 10:15:35 -0400 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2074.outbound.protection.outlook.com [40.107.6.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F14E1BE for ; Tue, 30 May 2023 07:15:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WXiMnpWleayWRDQaZLf+SdoA8/GYPlx7V4wa/8U5mNpkzeCVhw4zO6kIiDBMuiDYxGIuHC1HxWvsraHRlkQ1MLLhZr7yr5HXq5iqMrlu682XL/tP+VzT2HcM5ftoV2xAXdAAJF+Lsi1nXgm4vRjBfrF6j/WOIg0WG3tHXbhUXV5cXcmfosTi8A+eEizj6LUvXtiPtUpFJf3pwlzS1ygGQ92bbjeeD+k5P6LsLn83C0hlGevNCSdJCVkyH/drlzPUhFIwhJlrHBSV9KjuJ+Cz6VSimirUh1RkZGejiKngJiZNlvThjtQrPjQGFlPm2GhW0pKpq/k/gzzG0p82uOjqRg== 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=H9PURCvLfRlWzmxstRD0oNpReiKJ28IbNP1wbLOeJgw=; b=NAZdHkogirtquSJZcnPl4jO+QnOt2G34zYEp46FhSEBA8orLiJuXiM0PEgTQH3qwK5yv/BQSqN13LWnaU9vIA9ts1nBkC11uGG/uPJMy2AnFpP+qCZiVrvL+Awnu9PDIvK91Fufn67i2mp6VNW7M3Ft8RVoAUsjOIffGKKxHMaQeerwIvB1/RXdXKayg8b9a9/V/JYqtxDG2grPmerzGVy4Eh1kRnRDBrC/RSCB1tUirkvXA8/42BwcGiP0UNRoBthGv6+KfvAW+Utuhwqfbp8SlM78/Zh1LQ0dLwTRw0CsYQaxnQri1/vl/KfbCEepSAtDI+J96F08svodwHOl7zw== 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=H9PURCvLfRlWzmxstRD0oNpReiKJ28IbNP1wbLOeJgw=; b=WiGvZQnLp00PrbEf9qmKklEQCFCoND91iRsySptuTR9Bj+86tgQBEZYniOGrcT37OYMYrvCT3Xj2ayQXmDAgj0AIbC/kWEAPfxcyiBho+c1//DXeSPghns/h/e2PhkykwmsQ9dLzUT6u38JugNT546SaA6F1Eh+VcI6kRnaKtFo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5344.eurprd04.prod.outlook.com (2603:10a6:803:4b::31) by DBBPR04MB7913.eurprd04.prod.outlook.com (2603:10a6:10:1ee::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Tue, 30 May 2023 14:14:06 +0000 Received: from VI1PR04MB5344.eurprd04.prod.outlook.com ([fe80::cedb:51d6:a774:f81a]) by VI1PR04MB5344.eurprd04.prod.outlook.com ([fe80::cedb:51d6:a774:f81a%7]) with mapi id 15.20.6433.022; Tue, 30 May 2023 14:14:06 +0000 From: Silviu Florian Barbulescu To: linux-bluetooth@vger.kernel.org Cc: Silviu Florian Barbulescu Subject: [PATCH BlueZ v3 3/4] This adds the initial code for BAP broadcast source Date: Tue, 30 May 2023 17:13:38 +0300 Message-Id: <20230530141339.100733-4-silviu.barbulescu@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230530141339.100733-1-silviu.barbulescu@nxp.com> References: <20230530141339.100733-1-silviu.barbulescu@nxp.com> X-ClientProxiedBy: AM0PR07CA0021.eurprd07.prod.outlook.com (2603:10a6:208:ac::34) To VI1PR04MB5344.eurprd04.prod.outlook.com (2603:10a6:803:4b::31) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5344:EE_|DBBPR04MB7913:EE_ X-MS-Office365-Filtering-Correlation-Id: f5382157-072c-4099-5a0c-08db61182120 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: mkQhAwVOjarEfLeVlYWdGOaMNxcMlL0iXjGkeswdpd/Bb6/6KOkbZuQPwXycfV88PRF/GJUr1vqjEZ3XXc8se+vjvyfO1Wupw9NWtxEC8OfLf833C2Vs89GAg6udYzdYnNq9Cjy8s6JvYQ0kg0XWh4Qv4OZulJcc40nnk4Q1IfKR6OaYtRbT4oExMwploycRenvecYxG+17jS7KnpF52kygtPEi4NbTEge79zNOzl+mkuB+hAy5EE/yBU+Jx1i2jB4sUho1tzoYO9Yg/L3jz0TgslXlTUumwl8/6uY43+7N1lFTXbrboc7pUFKkJMUPfC9wYouxmvG2BofGv29ZwZmHCCn0rR7sLkXQsaHb+tjkyttxbxLaFT7PD00JwXiLwGwUfsz2eF/0MA9sNyvUwsPQWdpSjIvmBr0tg/rXW46Q+UXwaiivh3yGhqW9lwJBzBbu7513UUdiwhBhJq8eyk7VVXgyGsQ7ODp+w00IRzDB9UYF0Apad8JhgrsmgvP2CZWqLB7X9FMLFIrGiPzmJ3WI3U2K/lzO8dAB9m1XP+Kn6Dxi5rnG2sbA4UE3LQQZzo9mYUd3z5uxK42gHfcVM7c6ppdFOw8WzBlTAhx04qTv5MEJgadOISExNZ+L8dRi2 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5344.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(366004)(376002)(396003)(346002)(136003)(451199021)(478600001)(38100700002)(38350700002)(66556008)(66476007)(66946007)(41300700001)(52116002)(6486002)(8676002)(5660300002)(86362001)(8936002)(26005)(2906002)(30864003)(1076003)(186003)(6512007)(6506007)(83380400001)(4326008)(6916009)(316002)(6666004)(2616005)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: t+b8j0n9Xjy3hebNZS1FNJRVnIkEUybQTTkxubj0c5dKoMlaBcGDp9R1mfvLvyBTrymoXv0mAAdmQmQ0ByFnZ0JZUuT+FmSFF6zjwEjxYzqQgmG6R0BHtOv9B2p9zQCVOgCYA1PwwFTzO5p3U3XugCswCT5+TolfWMhIZzJsZ0DXpH0hHTm0fDsWS7qlR3tn0GyNRveXWQrgg2T5OeWMYPxJikulE42NqrsuYlJJXEQwyAkh+96klSgfHvttAF3QjGnykMt4V8KEuj88zsF0X45stgMbDRkt1EGDsF2Y5quODymJ0o/e/HU2Lb4B8HCNdKQItjpViiJl20hHcWHIuQIWBgN0N279rm/bXOB2FktuxhSuwUx53WwmcuOWK7VHjiPjSQo5uelXzFY1ExMtm9v+f3n7RsOfNiweW7C+malRBnDSHxGisJNB46DELbGnUSBxWgHGoii7cBpzHianlM2ktTGBlYst7csYOdx1dhEIlKsXn/s3SCu6IxaRFZwyda1yq3D899hdNFfT6DBw/cGABHjzZi0dlcoAegkcmkYgfpqcL9aJR6QIJhNaN9lByy7+Q0/X35dAm7UHLqM47n99boX9Cd7EaqxZdYyRsrLm/07sKsKjvAxbyx1RiHjFa8wDk9SpbEkJdxkR+ilN2wSWU/Q/iYLiXUTZrT7AiQbViS0sCOk/DZfrMlm6Z9Vsy0hiqvrIC7wzHoqNXNIOvoEF1UETLWJ/ECyHPXhR6cLGmaKnzNncc00dtF1rFe3qbt2OXayzpT04zUBZJaBY04FL694bSrG3oT+FOrtM4CtOqqTLPqAOiw3jcMxM1gwkb8VKdAG4r5KuLHvnqwHhm/zkSXZqqXXOOvEh9sPgSYzU8siD9Sv+kiUbeMg05/L3DK5ZpPpQrSTnoIgUyyN6jILfJVSTdZCEg1m7KVzw/YcJvRQCJwOnnCqkjinqvI1bMaBdytdrfzq6eMGA1Ab1JKw3gNnhn7Ue8v8/qSBTE+FZL8rHQ4hEWMDzr/8IV/gYiw5cloYZ2BqLuSNifbMl8r8HwrHGF7QjhANSNmIPeOUIYhC9Q4VWGi2HJUA9T/xBkLAGgAyWmmSWXqUYwqkKO5w7KjCsmzMlhnnlcZa3LuLqQFmPa0p7iND3dTpckpzEOSGMGKxkeS61jh5x48wUYHviBHwSNAYDpugbcxEIBIqFZXKQZ6DI6Bmvcmbl2THZQ/uvG9qRTuPX7VPOMQMiTX1epDuT18NNikpKPidI/LbHQX+RswX5MW/Fum3GUjIUlwJyEQbtbwMBZNwDk1tyq+Ps2IRV7sw60+7L0/uxvpq42Z2ZmnepbiMcK6SHURInj+k3KMDawzkMZxOc8sRBT5gCKI1UyIvEv6RR68190IL9FtML4wBRw/gj13uKphmx/FKscGCd6DKUTlySuhdezyCYdO8Venz3tK9wfCJJaqQQASV2BsioJ4uuUx1sdfaKKSLXE13GvFpHeVw3YfVzKGswNSoygrDOrCB/RCsjRQG2qtsdGG0gMW0yuY6RxVW5I3uXU9jnX4rP2MwZKGqDdgUTJ3FeG2vAay9m6ndBcbEIs9yhibXG1znjeHDEaG/6A+NVPN+QsNxioDH8JXNhdw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: f5382157-072c-4099-5a0c-08db61182120 X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5344.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2023 14:14:06.7500 (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: cqgk708XD3OH7g+2+IPl+mNDBDTr0M7GXZ6bp2CSM0da+oveJyARi21Hcx0tDWuJPpiZ7v7pCxl4+7tRwbCyU4xjtaesXhG85Xb/aAiyyrw= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7913 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds initial support for BAP broadcast source. --- src/shared/bap.c | 282 +++++++++++++++++++++++++++++++++++++++++------ src/shared/bap.h | 38 +++++-- 2 files changed, 274 insertions(+), 46 deletions(-) diff --git a/src/shared/bap.c b/src/shared/bap.c index dd9eb797a..26f41be76 100644 --- a/src/shared/bap.c +++ b/src/shared/bap.c @@ -121,6 +121,8 @@ struct bt_bap_db { struct bt_ascs *ascs; struct queue *sinks; struct queue *sources; + struct queue *broadcast_sources; + struct queue *broadcast_sinks; }; struct bt_bap_req { @@ -623,6 +625,18 @@ static struct bt_bap_endpoint *bap_endpoint_new(struct bt_bap_db *bdb, return ep; } +static struct bt_bap_endpoint *bap_endpoint_new_broacast(struct bt_bap_db *bdb) +{ + struct bt_bap_endpoint *ep; + + ep = new0(struct bt_bap_endpoint, 1); + ep->bdb = bdb; + ep->attr = NULL; + ep->dir = BT_BAP_BCAST_SOURCE; + + return ep; +} + static struct bt_bap_endpoint *bap_get_endpoint(struct queue *endpoints, struct bt_bap_db *db, struct gatt_db_attribute *attr) @@ -645,6 +659,30 @@ static struct bt_bap_endpoint *bap_get_endpoint(struct queue *endpoints, return ep; } +static struct bt_bap_endpoint *bap_get_endpoint_bcast(struct queue *endpoints, + struct bt_bap_db *db) +{ + struct bt_bap_endpoint *ep; + + if (!db) + return NULL; + /* + * We have support for only one stream so we will have + * only one endpoint. + * TO DO add support for more then one stream + */ + if (queue_length(endpoints) > 0) + return queue_peek_head(endpoints); + + ep = bap_endpoint_new_broacast(db); + if (!ep) + return NULL; + + queue_push_tail(endpoints, ep); + + return ep; +} + static bool bap_endpoint_match_id(const void *data, const void *match_data) { const struct bt_bap_endpoint *ep = data; @@ -1261,6 +1299,37 @@ static void bap_stream_state_changed(struct bt_bap_stream *stream) bt_bap_unref(bap); } +static void stream_set_state_broadcast(struct bt_bap_stream *stream, + uint8_t state) +{ + struct bt_bap_endpoint *ep = stream->ep; + struct bt_bap *bap = stream->bap; + const struct queue_entry *entry; + + ep->old_state = ep->state; + ep->state = state; + + bt_bap_ref(bap); + + for (entry = queue_get_entries(bap->state_cbs); entry; + entry = entry->next) { + struct bt_bap_state *state = entry->data; + + if (state->func) + state->func(stream, stream->ep->old_state, + stream->ep->state, state->data); + } + + /* Post notification updates */ + switch (stream->ep->state) { + case BT_ASCS_ASE_STATE_IDLE: + bap_stream_detach(stream); + break; + } + + bt_bap_unref(bap); +} + static void stream_set_state(struct bt_bap_stream *stream, uint8_t state) { struct bt_bap_endpoint *ep = stream->ep; @@ -1397,6 +1466,11 @@ static void ep_config_cb(struct bt_bap_stream *stream, int err) if (err) return; + if (bt_bap_stream_get_type(stream) == BT_BAP_STREAM_TYPE_BROADCAST) { + stream_set_state_broadcast(stream, BT_BAP_STREAM_STATE_CONFIG); + return; + } + stream_set_state(stream, BT_BAP_STREAM_STATE_CONFIG); } @@ -2222,6 +2296,8 @@ static struct bt_bap_db *bap_db_new(struct gatt_db *db) bdb->db = gatt_db_ref(db); bdb->sinks = queue_new(); bdb->sources = queue_new(); + bdb->broadcast_sources = queue_new(); + bdb->broadcast_sinks = queue_new(); if (!bap_db) bap_db = queue_new(); @@ -2397,6 +2473,16 @@ static void bap_add_source(struct bt_bap_pac *pac) iov.iov_len, NULL); } +static void bap_add_broadcast_source(struct bt_bap_pac *pac) +{ + queue_push_tail(pac->bdb->broadcast_sources, pac); +} + +static void bap_add_broadcast_sink(struct bt_bap_pac *pac) +{ + queue_push_tail(pac->bdb->broadcast_sinks, pac); +} + static void notify_pac_added(void *data, void *user_data) { struct bt_bap_pac_changed *changed = data; @@ -2413,6 +2499,54 @@ static void notify_session_pac_added(void *data, void *user_data) queue_foreach(bap->pac_cbs, notify_pac_added, user_data); } +struct bt_bap_pac *bt_bap_add_vendor_pac_bcast(struct gatt_db *db, + const char *name, uint8_t type, + uint8_t id, uint16_t cid, uint16_t vid, + struct bt_bap_pac_qos *qos, + struct iovec *data, + struct iovec *metadata, + struct bt_bap_pac_ops *pac_ops, + void *user_data) +{ + struct bt_bap_db *bdb; + struct bt_bap_pac *pac, *pac_brodcast_sink; + struct bt_bap_codec codec; + + if (!db) + return NULL; + + bdb = bap_get_db(db); + if (!bdb) + return NULL; + + if ((id != 0xff) && ((cid != 0U) || (vid != 0U))) + return NULL; + + codec.id = id; + codec.cid = cid; + codec.vid = vid; + + pac = bap_pac_new(bdb, name, type, &codec, qos, data, metadata); + + switch (type) { + case BT_BAP_BCAST_SOURCE: + // For broadcast, add local pac and remote pac. + bap_add_broadcast_source(pac); + pac_brodcast_sink = bap_pac_new(bdb, name, type, &codec, qos, + data, metadata); + bap_add_broadcast_sink(pac_brodcast_sink); + break; + default: + bap_pac_free(pac); + return NULL; + } + + bt_bap_pac_set_ops(pac, pac_ops, user_data); + queue_foreach(sessions, notify_session_pac_added, pac); + + return pac; +} + struct bt_bap_pac *bt_bap_add_vendor_pac(struct gatt_db *db, const char *name, uint8_t type, uint8_t id, uint16_t cid, uint16_t vid, @@ -2489,6 +2623,21 @@ uint32_t bt_bap_pac_get_locations(struct bt_bap_pac *pac) } } +uint8_t bt_bap_stream_get_type(struct bt_bap_stream *stream) +{ + if (!stream) + return BT_BAP_STREAM_TYPE_UNKNOWN; + + if ((bt_bap_pac_get_type(stream->lpac) == BT_BAP_SINK) || + (bt_bap_pac_get_type(stream->lpac) == BT_BAP_SOURCE)) + return BT_BAP_STREAM_TYPE_UNICAST; + else if ((bt_bap_pac_get_type(stream->lpac) == BT_BAP_BCAST_SOURCE) || + (bt_bap_pac_get_type(stream->lpac) == BT_BAP_BCAST_SINK)) + return BT_BAP_STREAM_TYPE_BROADCAST; + else + return BT_BAP_STREAM_TYPE_UNKNOWN; +} + static void notify_pac_removed(void *data, void *user_data) { struct bt_bap_pac_changed *changed = data; @@ -2547,6 +2696,9 @@ bool bt_bap_remove_pac(struct bt_bap_pac *pac) if (queue_remove_if(pac->bdb->sources, NULL, pac)) goto found; + if (queue_remove_if(pac->bdb->broadcast_sources, NULL, pac)) + goto found; + return false; found: @@ -3879,6 +4031,25 @@ clone: return true; } +bool bt_bap_attach_broadcast(struct bt_bap *bap) +{ + struct bt_bap_endpoint *ep; + + if (queue_find(sessions, NULL, bap)) + return true; + + if (!sessions) + sessions = queue_new(); + + queue_push_tail(sessions, bap); + + ep = bap_get_endpoint_bcast(bap->remote_eps, bap->ldb); + if (ep) + ep->bap = bap; + + return true; +} + static void stream_foreach_detach(void *data, void *user_data) { struct bt_bap_stream *stream = data; @@ -4083,7 +4254,11 @@ void bt_bap_foreach_pac(struct bt_bap *bap, uint8_t type, func, user_data); case BT_BAP_SOURCE: return bap_foreach_pac(bap->ldb->sinks, bap->rdb->sources, - func, user_data); + func, user_data); + case BT_BAP_BCAST_SOURCE: + return bap_foreach_pac(bap->ldb->broadcast_sources, + bap->ldb->broadcast_sinks, + func, user_data); } } @@ -4196,42 +4371,51 @@ unsigned int bt_bap_stream_config(struct bt_bap_stream *stream, if (!bap_stream_valid(stream)) return 0; - if (!stream->client) { - stream_config(stream, data, NULL); - return 0; - } + if (bt_bap_stream_get_type(stream) == BT_BAP_STREAM_TYPE_UNICAST) { + if (!stream->client) { + stream_config(stream, data, NULL); + return 0; + } - memset(&config, 0, sizeof(config)); + memset(&config, 0, sizeof(config)); - config.ase = stream->ep->id; - config.latency = qos->ucast.target_latency; - config.phy = qos->ucast.io_qos.phy; - config.codec = stream->rpac->codec; + config.ase = stream->ep->id; + config.latency = qos->ucast.target_latency; + config.phy = qos->ucast.io_qos.phy; + config.codec = stream->rpac->codec; - iov[0].iov_base = &config; - iov[0].iov_len = sizeof(config); + iov[0].iov_base = &config; + iov[0].iov_len = sizeof(config); - if (data) { - if (!bap_print_cc(data->iov_base, data->iov_len, - stream->bap->debug_func, - stream->bap->debug_data)) - return 0; + if (data) { + if (!bap_print_cc(data->iov_base, data->iov_len, + stream->bap->debug_func, + stream->bap->debug_data)) + return 0; - config.cc_len = data->iov_len; - iov[1] = *data; - iovlen++; - } + config.cc_len = data->iov_len; + iov[1] = *data; + iovlen++; + } - req = bap_req_new(stream, BT_ASCS_CONFIG, iov, iovlen, func, user_data); + req = bap_req_new(stream, BT_ASCS_CONFIG, iov, iovlen, + func, user_data); - if (!bap_queue_req(stream->bap, req)) { - bap_req_free(req); - return 0; - } + if (!bap_queue_req(stream->bap, req)) { + bap_req_free(req); + return 0; + } - stream->qos = *qos; + stream->qos = *qos; - return req->id; + return req->id; + } else if (bt_bap_stream_get_type(stream) == + BT_BAP_STREAM_TYPE_BROADCAST) { + stream->qos = *qos; + return 0; + } else { + return 0; + } } static bool match_pac(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, @@ -4292,7 +4476,7 @@ struct bt_bap_stream *bt_bap_stream_new(struct bt_bap *bap, if (rpac) type = rpac->type; else if (lpac) { - switch(lpac->type) { + switch (lpac->type) { case BT_BAP_SINK: type = BT_BAP_SOURCE; break; @@ -4357,6 +4541,10 @@ bool bt_bap_stream_set_user_data(struct bt_bap_stream *stream, void *user_data) stream->user_data = user_data; + if (bt_bap_stream_get_type(stream) == BT_BAP_STREAM_TYPE_BROADCAST) + stream->lpac->ops->config(stream, stream->cc, &stream->qos, + ep_config_cb, stream->lpac->user_data); + return true; } @@ -4466,7 +4654,7 @@ unsigned int bt_bap_stream_enable(struct bt_bap_stream *stream, bt_bap_stream_func_t func, void *user_data) { - int ret; + int ret = 0; /* Table 3.2: ASE state machine transition * Initiating device - client Only @@ -4474,12 +4662,19 @@ unsigned int bt_bap_stream_enable(struct bt_bap_stream *stream, if (!bap_stream_valid(stream) || !stream->client) return 0; - ret = bap_stream_metadata(stream, BT_ASCS_ENABLE, metadata, func, - user_data); - if (!ret || !enable_links) - return ret; + if (bt_bap_stream_get_type(stream) == BT_BAP_STREAM_TYPE_UNICAST) { + ret = bap_stream_metadata(stream, BT_ASCS_ENABLE, metadata, + func, user_data); + if (!ret || !enable_links) + return ret; - queue_foreach(stream->links, bap_stream_enable_link, metadata); + queue_foreach(stream->links, bap_stream_enable_link, metadata); + } else if (bt_bap_stream_get_type(stream) == + BT_BAP_STREAM_TYPE_BROADCAST) { + stream_set_state_broadcast(stream, + BT_BAP_STREAM_STATE_STREAMING); + return 1; + } return ret; } @@ -4658,6 +4853,16 @@ unsigned int bt_bap_stream_release(struct bt_bap_stream *stream, bap = stream->bap; + /* If stream is broadcast, no BT_ASCS_RELEASE is required */ + if (bt_bap_stream_get_type(stream) == BT_BAP_STREAM_TYPE_BROADCAST) { + if (!bap_stream_valid(stream)) { + stream_set_state_broadcast(stream, + BT_BAP_STREAM_STATE_IDLE); + stream = NULL; + } + return 0; + } + /* If stream does not belong to a client session, clean it up now */ if (!bap_stream_valid(stream)) { stream_set_state(stream, BT_BAP_STREAM_STATE_IDLE); @@ -4693,8 +4898,13 @@ uint32_t bt_bap_stream_get_location(struct bt_bap_stream *stream) if (stream->ep->dir == BT_BAP_SOURCE) return pacs->source_loc_value; - else + else if (stream->ep->dir == BT_BAP_SINK) return pacs->sink_loc_value; + else + /* TO DO get the location values from metadata + * for brodcast source and sink + */ + return stream->bap->ldb->pacs->source_loc_value; } struct iovec *bt_bap_stream_get_config(struct bt_bap_stream *stream) diff --git a/src/shared/bap.h b/src/shared/bap.h index 0c42e730f..f1dab5f39 100644 --- a/src/shared/bap.h +++ b/src/shared/bap.h @@ -17,6 +17,12 @@ #define BT_BAP_SINK 0x01 #define BT_BAP_SOURCE 0x02 +#define BT_BAP_BCAST_SOURCE 0x03 +#define BT_BAP_BCAST_SINK 0x04 + +#define BT_BAP_STREAM_TYPE_UNICAST 0x01 +#define BT_BAP_STREAM_TYPE_BROADCAST 0x02 +#define BT_BAP_STREAM_TYPE_UNKNOWN 0x03 #define BT_BAP_STREAM_STATE_IDLE 0x00 #define BT_BAP_STREAM_STATE_CONFIG 0x01 @@ -128,6 +134,25 @@ struct bt_bap_pac_qos { uint32_t ppd_max; }; +struct bt_bap_pac_ops { + int (*select)(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, + struct bt_bap_pac_qos *qos, + bt_bap_pac_select_t cb, void *cb_data, void *user_data); + int (*config)(struct bt_bap_stream *stream, struct iovec *cfg, + struct bt_bap_qos *qos, bt_bap_pac_config_t cb, + void *user_data); + void (*clear)(struct bt_bap_stream *stream, void *user_data); +}; + +struct bt_bap_pac *bt_bap_add_vendor_pac_bcast(struct gatt_db *db, + const char *name, uint8_t type, + uint8_t id, uint16_t cid, uint16_t vid, + struct bt_bap_pac_qos *qos, + struct iovec *data, + struct iovec *metadata, + struct bt_bap_pac_ops *pac_ops, + void *user_data); + struct bt_bap_pac *bt_bap_add_vendor_pac(struct gatt_db *db, const char *name, uint8_t type, uint8_t id, uint16_t cid, uint16_t vid, @@ -141,16 +166,6 @@ struct bt_bap_pac *bt_bap_add_pac(struct gatt_db *db, const char *name, struct iovec *data, struct iovec *metadata); -struct bt_bap_pac_ops { - int (*select)(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, - struct bt_bap_pac_qos *qos, - bt_bap_pac_select_t cb, void *cb_data, void *user_data); - int (*config)(struct bt_bap_stream *stream, struct iovec *cfg, - struct bt_bap_qos *qos, bt_bap_pac_config_t cb, - void *user_data); - void (*clear)(struct bt_bap_stream *stream, void *user_data); -}; - bool bt_bap_pac_set_ops(struct bt_bap_pac *pac, struct bt_bap_pac_ops *ops, void *user_data); @@ -160,6 +175,8 @@ uint8_t bt_bap_pac_get_type(struct bt_bap_pac *pac); uint32_t bt_bap_pac_get_locations(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); /* Session related function */ @@ -179,6 +196,7 @@ struct bt_bap *bt_bap_ref(struct bt_bap *bap); void bt_bap_unref(struct bt_bap *bap); bool bt_bap_attach(struct bt_bap *bap, struct bt_gatt_client *client); +bool bt_bap_attach_broadcast(struct bt_bap *bap); void bt_bap_detach(struct bt_bap *bap); bool bt_bap_set_debug(struct bt_bap *bap, bt_bap_debug_func_t cb, From patchwork Tue May 30 14:13:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Silviu Florian Barbulescu X-Patchwork-Id: 13260180 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 633F8C77B73 for ; Tue, 30 May 2023 14:16:05 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233064AbjE3OQE (ORCPT ); Tue, 30 May 2023 10:16:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58144 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233000AbjE3OQC (ORCPT ); Tue, 30 May 2023 10:16:02 -0400 Received: from EUR04-DB3-obe.outbound.protection.outlook.com (mail-db3eur04on2074.outbound.protection.outlook.com [40.107.6.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D1F971B4 for ; Tue, 30 May 2023 07:15:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Z9nGiTrYdnRMpjkmO6oP5QegVSvEdNuPFoH/2jHtzFEHKiKkVyhoJje8w7LG5SWAJz0+LHsBqGZGZ0v6PQTSEpJ9y4N6Roi8XcLh88Ouj2P6g8Mc/vZKq9+eJYZ3V+LypEqntVot4k0VW4Kq41qf+B/1akgBBoiEaB40xy2SFcojhY8fLJOwjTHBPO6vtNSyECehQ9GcZc5Ywd6xoyJVTKOvbdHJLgV7pcMp192UU6KWuG/wwdMSkzhzPgzIsg/lKGm1at7x6p0jABKuTbBojZv+gGgyyp6v+ozRQjCAYm+YGcosWW+hs6Zmahr51RT/jaOvNU6eT/l7R6trrgO5VA== 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=Wvl2zaw/G+bK3BhUSz82aMy8L2svBG0TUswBrJ+dxoo=; b=BbAkpo9FFZgBfecxT8dUuHIfF5m2vGgDGShS/YUm6kK9QDFiepZBJDZkUBjHRE4JH0y+yRw3uxTv4Bjrr53OEhjavft+CdRNFzX9ODUrhG5nAcc4yejAHaQH8uw5bmrlOOjbya3G0kwiRYKOmXzJ4RhpHHnFS2cIiWCiHEhUxBta+vMhm4p+xxCtknPTx6K18TOqocTawZABoYTx5OFFSY5T8EgyzmnX33ObaThHPXdhOn8E29Ne1W+vo5d0wyP8UaRo6Rnvxvs7qBTvkMvBX9RJIW6QWvOB6r/lJsOFKHUOg9lMhWrrm4phWM8Ikq3xmgsNF50n++by/fOpTDNr2A== 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=Wvl2zaw/G+bK3BhUSz82aMy8L2svBG0TUswBrJ+dxoo=; b=bLadE7IJ/Eb0Si+/+n55Fiqo+cY+g5Jc1E5NuoBpNMAjZ9/OaxffRRNYEYSdiEI5W7j3emqKzMmYUPrInDyReylogsAjCTz3FRqdUNjj/lutWgEslgaQVVoScuLjUMT0a1a42WUnLODjkWoi46a9O4iDFwfz5+4nxTPNurHIxvo= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from VI1PR04MB5344.eurprd04.prod.outlook.com (2603:10a6:803:4b::31) by DBBPR04MB7913.eurprd04.prod.outlook.com (2603:10a6:10:1ee::7) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6433.23; Tue, 30 May 2023 14:14:08 +0000 Received: from VI1PR04MB5344.eurprd04.prod.outlook.com ([fe80::cedb:51d6:a774:f81a]) by VI1PR04MB5344.eurprd04.prod.outlook.com ([fe80::cedb:51d6:a774:f81a%7]) with mapi id 15.20.6433.022; Tue, 30 May 2023 14:14:08 +0000 From: Silviu Florian Barbulescu To: linux-bluetooth@vger.kernel.org Cc: Silviu Florian Barbulescu Subject: [PATCH BlueZ v3 4/4] Update BAP plugin with broadcast source support Date: Tue, 30 May 2023 17:13:39 +0300 Message-Id: <20230530141339.100733-5-silviu.barbulescu@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230530141339.100733-1-silviu.barbulescu@nxp.com> References: <20230530141339.100733-1-silviu.barbulescu@nxp.com> X-ClientProxiedBy: AM0PR07CA0021.eurprd07.prod.outlook.com (2603:10a6:208:ac::34) To VI1PR04MB5344.eurprd04.prod.outlook.com (2603:10a6:803:4b::31) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: VI1PR04MB5344:EE_|DBBPR04MB7913:EE_ X-MS-Office365-Filtering-Correlation-Id: 23af4f87-8bc9-483d-110e-08db611821fe X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: DeeDYFhdcolnLPYAmedGjqjAic3HLywyoQK1VslYAUZwPX2x/auIHM3aaPgEfaooJiYLZqDnes0BLMqV17GI2Sc4W3ie5vmQmnBsqnyyDL+tlm8BOtqwLYRupRCe/eYTTehRAe1oL2nQnP9QPYT8MnZmq0Aw56rDiOeD2Cd8F7sJ4ffWAbSS1H2LPgxmZob8G08O0uxyvd513UjWGfILuFfwXmwm/iUIG15fvPpRr2VbnkmchKStoeiufmJIuGwXREXHqBZKhUMiDbTjJGk+JY1wNzS3guLRLbRYIi+w8Ce78nokuzkDMzm9veyR6rttQDwwk5PUOll6dakyhzPIRQPdc9CW9O31IMYCJ/qgXBdS6K7nSBhEVERnDeCjmwfKtPP/8UAeu2WirxN528bb2rzmVyo0DRyXj0W55czwNVKuM/R3xysaZcRykX4GZoFE5T0mcQDWH7rThZ4Qzzpm6hvBoEnqom7nlpQFO5nv+Zz1dMcZEtnf9g6lgApQ0TnwAKe+LCXqMtawnn67j79NIP+UGaM/Avo1RTpBZQzVTopqN0j86bXmHGmyDTM9pirjKT7jWDksGorVXXFHQGaEzJgEYA5XjolkwSXtTSusxb2wIR3FHwmsN3uUfVRU+re9 X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:VI1PR04MB5344.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(39860400002)(366004)(376002)(396003)(346002)(136003)(451199021)(478600001)(38100700002)(38350700002)(66556008)(66476007)(66946007)(41300700001)(52116002)(6486002)(8676002)(5660300002)(86362001)(8936002)(26005)(2906002)(30864003)(1076003)(186003)(6512007)(6506007)(15650500001)(83380400001)(4326008)(6916009)(316002)(6666004)(2616005)(36756003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 01Mfu4vzPJ1JeVGy0MonUdI8QKBr+j+es1qWqc0oV2Ma1pA0sLeWdVliUxQDdj6aKAcBXQuAn6Sz247MlLZbVagW1GkDt00jEabb78kM5I3dsLmoK9jAKEUtDY1P3Y1h9Zx5gDxvlAYeAWXUIgcvbCxq8UTlE9K5bLvBIUfop1s2s9//mfisuNF8BsukpOTGOo4iOsTD0xLUbq74IwaxDugqzVyxPjGw4JGnm3GWYprvds2G7Wia0z712PtlxoyPVarTVtbaHkvCq0MqxacFCbfUG2UhWRGhNXlppfqJofA7IN9GHdiCT60cFrf9dDzTX6dovL0JuRcprLI2aNCb3Y0UAVvfMTpDupAXSuuOhe1z22jnHEy7haw0GxdaDq+qJopB579PIbxaIBxl34r/HBKKyDAYsLol77TIU3ButxuD2ojFkriwN8VUQD4stCu1F25y//uC5gljKNwvQISNeKm2a4kPFjhPRMY0WzXgphEqxJCFI/ZeGibgPKfJCEI3wrj2hVKkhqvmYo3CEXUriF2jeFya59ziPj9gdMxgtpln7nsVt41FcVvATDXEdI7kuCauupIsJVaAe3T1Uvfi9j1JjVk9qXHq65qqbrWBVdPWmCuSaIeIHTwpUURYrs0z+I9zh1Zzc+k0CWFuhiL3+KcYQLEy0591Js8XhWXDhv7DT6SkY3jHL857RwqTFQXvbbAmi55f7/6L9YhXHnGFtuCwuJvfdU5PFwCZgjbxSnoAiM/Jaup2agy6oYtKbXlRUllfbbRNBKbxdVisAAsAp3TzfXWIyYwGtTJmwp5K+iysfna2f5wrttsAuo2V1iZTXqnAF+yQm29hkqcfkbHjBZaQgP6+RhuaCzyeLn2UAlV0zk7d31XhVPUVZEOcfEWQoZy4NUpKDYT0QUfAhgKuXsIZ/ZNnc86zYTT0j2Vk994xwmHc6zx0poQMFF9Imv+iKXoTOM400CSZ9YMCEigLv8zfH/xoSVoPEUrTsS0CNXzGJOIm71zt74S8rHJSZ/Bsgxg0ZfHjir+vN/yGLJ094FviZFV/OwqcWPPHb62dK5zCtR8mmxiAqsw6wWUwqCLXseqV5yvXZagT4hDnIzJhm0GVF7C66DOcodrvoGKsJZz7MrdxKkQRp/xLjiyYWcIO2CJ6ogGpeh5CQb3yn7pDCNBWCMFMnlypVDtDk13DtoYVIPoyKR3JKKzo/x38b3MzvGZwNSEz6C6kIzmnNQk6wH/1dbGRyxowwg0hnaBK2pd8t2+4GTMG3MiSQDvx0LYGcrr2NDfhX8UVHcARTVTe2rWGeY7Thp6XKV90nfACgBRPRYwm0iVGJA5rnhCktWbY2gPkOtNMxxikQ5atYr9WOgikQ7sXAkylC29j6az+1afFb+vzxS/dFoc6wfxagXGXgTwWOibal0jW/yniBE4Wm805yJ99Uv420FRCnJ953aC0d1npChbiqaLwHcsIVktbNCYPJwRKzlw5OsYe66Xk7nwoUnZ8+fzxfkXOYFVuPdUaZu9wZhyFLrGgxJuvmfjCqk3JGvpJh7e4MN1qNlkniJfgawoArZZaPau5mfdcy5BqB2Cec8QMb+51dG3pN3F71nBmpg7SQhcOlRejjsCcag== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 23af4f87-8bc9-483d-110e-08db611821fe X-MS-Exchange-CrossTenant-AuthSource: VI1PR04MB5344.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 May 2023 14:14:08.2313 (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: uyx1zmfjsdEfSXXMLryWVmz4rFFX2pLYjqlTvUqC8PBerhYrPn/0ZYFPQKs46wr5gdPh5CW0mXEdSyW8Kd/YZDCqUiwSFoSHfqpDTm1iwLY= X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB7913 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This updates BAP plugin with broadcast source support. --- profiles/audio/bap.c | 436 +++++++++++++++++++++++++++++++++---- profiles/audio/media.c | 113 +++++++++- profiles/audio/transport.c | 32 ++- 3 files changed, 519 insertions(+), 62 deletions(-) diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index cbaf705c0..fb8188819 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -82,13 +82,25 @@ struct bap_data { unsigned int pac_id; struct queue *srcs; struct queue *snks; + struct queue *bcast; struct queue *streams; GIOChannel *listen_io; int selecting; + void *user_data; }; static struct queue *sessions; +static bool bap_data_set_user_data(struct bap_data *data, void *user_data) +{ + if (!data) + return false; + + data->user_data = user_data; + + return true; +} + static void bap_debug(const char *str, void *user_data) { DBG_IDX(0xffff, "%s", str); @@ -167,8 +179,10 @@ static gboolean get_uuid(const GDBusPropertyTable *property, if (queue_find(ep->data->snks, NULL, ep)) uuid = PAC_SINK_UUID; - else + if (queue_find(ep->data->srcs, NULL, ep)) uuid = PAC_SOURCE_UUID; + else + uuid = BAA_SERVICE_UUID; dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &uuid); @@ -254,6 +268,7 @@ static int parse_properties(DBusMessageIter *props, struct iovec **caps, { const char *key; struct bt_bap_io_qos io_qos; + bool broadcast = false; while (dbus_message_iter_get_arg_type(props) == DBUS_TYPE_DICT_ENTRY) { DBusMessageIter value, entry; @@ -284,11 +299,21 @@ static int parse_properties(DBusMessageIter *props, struct iovec **caps, goto fail; dbus_message_iter_get_basic(&value, &qos->ucast.cig_id); + } else if (!strcasecmp(key, "BIG")) { + if (var != DBUS_TYPE_BYTE) + goto fail; + + dbus_message_iter_get_basic(&value, &qos->bcast.big); } else if (!strcasecmp(key, "CIS")) { if (var != DBUS_TYPE_BYTE) goto fail; dbus_message_iter_get_basic(&value, &qos->ucast.cis_id); + } else if (!strcasecmp(key, "BIS")) { + if (var != DBUS_TYPE_BYTE) + goto fail; + + dbus_message_iter_get_basic(&value, &qos->bcast.bis); } else if (!strcasecmp(key, "Interval")) { if (var != DBUS_TYPE_UINT32) goto fail; @@ -342,13 +367,61 @@ static int parse_properties(DBusMessageIter *props, struct iovec **caps, goto fail; dbus_message_iter_get_basic(&value, - &qos->ucast.target_latency); + &qos->ucast.target_latency); + } else if (!strcasecmp(key, "Encryption")) { + if (var != DBUS_TYPE_BYTE) + goto fail; + + dbus_message_iter_get_basic(&value, + &qos->bcast.encryption); + DBG("Got Encryption for bcast"); + broadcast = true; + } else if (!strcasecmp(key, "Options")) { + if (var != DBUS_TYPE_BYTE) + goto fail; + + dbus_message_iter_get_basic(&value, + &qos->bcast.options); + } else if (!strcasecmp(key, "Skip")) { + if (var != DBUS_TYPE_UINT16) + goto fail; + + dbus_message_iter_get_basic(&value, + &qos->bcast.skip); + } else if (!strcasecmp(key, "SyncTimeout")) { + if (var != DBUS_TYPE_UINT16) + goto fail; + + dbus_message_iter_get_basic(&value, + &qos->bcast.sync_timeout); + } else if (!strcasecmp(key, "SyncCteType")) { + if (var != DBUS_TYPE_BYTE) + goto fail; + + dbus_message_iter_get_basic(&value, + &qos->bcast.sync_cte_type); + } else if (!strcasecmp(key, "MSE")) { + if (var != DBUS_TYPE_BYTE) + goto fail; + + dbus_message_iter_get_basic(&value, + &qos->bcast.mse); + } else if (!strcasecmp(key, "Timeout")) { + if (var != DBUS_TYPE_UINT16) + goto fail; + + dbus_message_iter_get_basic(&value, + &qos->bcast.timeout); } dbus_message_iter_next(props); } - memcpy(&qos->ucast.io_qos, &io_qos, sizeof(io_qos)); + if (broadcast) + memcpy(&qos->bcast.io_qos, &io_qos, sizeof(io_qos)); + else + memcpy(&qos->ucast.io_qos, &io_qos, sizeof(io_qos)); + return 0; fail: @@ -510,6 +583,8 @@ static void ep_free(void *data) util_iov_free(ep->caps, 1); util_iov_free(ep->metadata, 1); + if (bt_bap_stream_get_type(ep->stream) == BT_BAP_STREAM_TYPE_BROADCAST) + util_iov_free(&ep->qos.bcast.bcode, 1); free(ep->path); free(ep); } @@ -553,6 +628,11 @@ static struct bap_ep *ep_register(struct btd_service *service, i = queue_length(data->srcs); suffix = "source"; break; + case BT_BAP_BCAST_SOURCE: + queue = data->bcast; + i = queue_length(data->bcast); + suffix = "broadcast"; + break; default: return NULL; } @@ -611,12 +691,14 @@ static void bap_config(void *data, void *user_data) ep->id = bt_bap_stream_config(ep->stream, &ep->qos, ep->caps, config_cb, ep); - if (!ep->id) { - DBG("Unable to config stream"); - util_iov_free(ep->caps, 1); - ep->caps = NULL; - util_iov_free(ep->metadata, 1); - ep->metadata = NULL; + if (bt_bap_stream_get_type(ep->stream) == BT_BAP_STREAM_TYPE_UNICAST) { + if (!ep->id) { + DBG("Unable to config stream"); + util_iov_free(ep->caps, 1); + ep->caps = NULL; + util_iov_free(ep->metadata, 1); + ep->metadata = NULL; + } } bt_bap_stream_set_user_data(ep->stream, ep->path); @@ -652,6 +734,7 @@ done: queue_foreach(ep->data->srcs, bap_config, NULL); queue_foreach(ep->data->snks, bap_config, NULL); + queue_foreach(ep->data->bcast, bap_config, NULL); } static bool pac_found(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, @@ -668,8 +751,13 @@ static bool pac_found(struct bt_bap_pac *lpac, struct bt_bap_pac *rpac, return true; } - /* TODO: Cache LRU? */ - if (btd_service_is_initiator(service)) { + if (bt_bap_pac_get_type(lpac) != BT_BAP_BCAST_SOURCE) { + /* TODO: Cache LRU? */ + if (btd_service_is_initiator(service)) { + if (!bt_bap_select(lpac, rpac, select_cb, ep)) + ep->data->selecting++; + } + } else { if (!bt_bap_select(lpac, rpac, select_cb, ep)) ep->data->selecting++; } @@ -700,11 +788,18 @@ static struct bap_ep *bap_find_ep_by_stream(struct bap_data *data, { struct bap_ep *ep; - ep = queue_find(data->snks, match_ep_by_stream, stream); - if (ep) - return ep; + if (bt_bap_stream_get_type(stream) == BT_BAP_STREAM_TYPE_UNICAST) { + ep = queue_find(data->snks, match_ep_by_stream, stream); + if (ep) + return ep; - return queue_find(data->srcs, match_ep_by_stream, stream); + return queue_find(data->srcs, match_ep_by_stream, stream); + } else if (bt_bap_stream_get_type(stream) == + BT_BAP_STREAM_TYPE_BROADCAST) { + + return queue_find(data->bcast, match_ep_by_stream, stream); + } else + return NULL; } static void iso_connect_cb(GIOChannel *chan, GError *err, gpointer user_data) @@ -943,6 +1038,69 @@ static void bap_connect_io(struct bap_data *data, struct bap_ep *ep, bt_bap_stream_io_connecting(stream, g_io_channel_unix_get_fd(io)); } +static void bap_connect_io_broadcast(struct bap_data *data, struct bap_ep *ep, + struct bt_bap_stream *stream, + struct bt_iso_qos *qos, int defer) +{ + struct btd_adapter *adapter = device_get_adapter(data->device); + GIOChannel *io = NULL; + GError *err = NULL; + bdaddr_t dst_addr = {0}; + char addr[18]; + struct bt_iso_base base; + + /* If IO already set and we are in the creation step, + * skip creating it again + */ + if (bt_bap_stream_get_io(stream) && (defer == true)) + return; + + if (ep->io_id) { + g_source_remove(ep->io_id); + ep->io_id = 0; + } + base.base_len = ep->caps->iov_len; + + memset(base.base, 0, 248); + memcpy(base.base, ep->caps->iov_base, base.base_len); + DBG("ep %p stream %p defer %s", ep, stream, defer ? "true" : "false"); + ba2str(btd_adapter_get_address(adapter), addr); + + /* Just create socket and advance to the configured state + * (when defer = true) + */ + if (defer == true) { + io = bt_io_connect(bap_connect_io_cb, ep, NULL, &err, + BT_IO_OPT_SOURCE_BDADDR, + btd_adapter_get_address(adapter), + BT_IO_OPT_DEST_BDADDR, + &dst_addr, + BT_IO_OPT_DEST_TYPE, + BDADDR_LE_PUBLIC, + BT_IO_OPT_MODE, BT_IO_MODE_ISO, + BT_IO_OPT_QOS, qos, + BT_IO_OPT_BASE, &base, + BT_IO_OPT_DEFER_TIMEOUT, defer, + BT_IO_OPT_INVALID); + + if (!io) { + error("%s", err->message); + g_error_free(err); + return; + } + + ep->io_id = g_io_add_watch(io, G_IO_HUP | G_IO_ERR | G_IO_NVAL, + bap_io_disconnected, ep); + + ep->io = io; + + bt_bap_stream_io_connecting(stream, + g_io_channel_unix_get_fd(io)); + } else { + /* TODO: Advance stream state to Streaming */ + } +} + static void bap_listen_io(struct bap_data *data, struct bt_bap_stream *stream, struct bt_iso_qos *qos) { @@ -989,22 +1147,51 @@ static void bap_create_io(struct bap_data *data, struct bap_ep *ep, if (!queue_find(data->streams, NULL, stream)) queue_push_tail(data->streams, stream); - if (!bt_bap_stream_io_get_qos(stream, &qos[0], &qos[1])) { - error("bt_bap_stream_get_qos_links: failed"); - return; - } - memset(&iso_qos, 0, sizeof(iso_qos)); - iso_qos.ucast.cig = qos[0] ? qos[0]->ucast.cig_id : + + if (bt_bap_stream_get_type(stream) == BT_BAP_STREAM_TYPE_UNICAST) { + if (!bt_bap_stream_io_get_qos(stream, &qos[0], &qos[1])) { + error("bt_bap_stream_get_qos_links: failed"); + return; + } + + iso_qos.ucast.cig = qos[0] ? qos[0]->ucast.cig_id : qos[1]->ucast.cig_id; - iso_qos.ucast.cis = qos[0] ? qos[0]->ucast.cis_id : + iso_qos.ucast.cis = qos[0] ? qos[0]->ucast.cis_id : qos[1]->ucast.cis_id; - bap_iso_qos(qos[0], &iso_qos.ucast.in); - bap_iso_qos(qos[1], &iso_qos.ucast.out); + bap_iso_qos(qos[0], &iso_qos.ucast.in); + bap_iso_qos(qos[1], &iso_qos.ucast.out); + } else if (bt_bap_stream_get_type(stream) == + BT_BAP_STREAM_TYPE_BROADCAST) { + if (defer == true) { + iso_qos.bcast.big = ep->qos.bcast.big; + iso_qos.bcast.bis = ep->qos.bcast.bis; + iso_qos.bcast.sync_interval = ep->qos.bcast.sync_interval; + iso_qos.bcast.packing = ep->qos.bcast.packing; + iso_qos.bcast.framing = ep->qos.bcast.framing; + iso_qos.bcast.encryption = ep->qos.bcast.encryption; + memcpy(iso_qos.bcast.bcode, + ep->qos.bcast.bcode.iov_base, 16); + iso_qos.bcast.options = ep->qos.bcast.options; + iso_qos.bcast.skip = ep->qos.bcast.skip; + iso_qos.bcast.sync_timeout = ep->qos.bcast.sync_timeout; + iso_qos.bcast.sync_cte_type = ep->qos.bcast.sync_cte_type; + iso_qos.bcast.mse = ep->qos.bcast.mse; + iso_qos.bcast.timeout = ep->qos.bcast.timeout; + memcpy(&iso_qos.bcast.out, &ep->qos.bcast.io_qos, + sizeof(struct bt_iso_io_qos)); + } + } else + return; if (ep) - bap_connect_io(data, ep, stream, &iso_qos, defer); + if (bt_bap_stream_get_type(stream) == + BT_BAP_STREAM_TYPE_BROADCAST) + bap_connect_io_broadcast(data, ep, stream, + &iso_qos, defer); + else + bap_connect_io(data, ep, stream, &iso_qos, defer); else bap_listen_io(data, stream, &iso_qos); } @@ -1043,12 +1230,16 @@ static void bap_state(struct bt_bap_stream *stream, uint8_t old_state, } - /* Wait QoS response to respond */ - ep->id = bt_bap_stream_qos(stream, &ep->qos, qos_cb, - ep); - if (!ep->id) { - error("Failed to Configure QoS"); - bt_bap_stream_release(stream, NULL, NULL); + if (bt_bap_stream_get_type(stream) == + BT_BAP_STREAM_TYPE_UNICAST) { + /* Wait QoS response to respond */ + ep->id = bt_bap_stream_qos(stream, &ep->qos, + qos_cb, ep); + if (!ep->id) { + error("Failed to Configure QoS"); + bt_bap_stream_release(stream, + NULL, NULL); + } } } break; @@ -1059,6 +1250,13 @@ static void bap_state(struct bt_bap_stream *stream, uint8_t old_state, if (ep) bap_create_io(data, ep, stream, false); break; + case BT_BAP_STREAM_STATE_STREAMING: + if (bt_bap_stream_get_type(stream) == + BT_BAP_STREAM_TYPE_BROADCAST) { + if (ep) + bap_create_io(data, ep, stream, false); + } + break; } } @@ -1078,6 +1276,21 @@ static void pac_added(struct bt_bap_pac *pac, void *user_data) bt_bap_foreach_pac(data->bap, BT_BAP_SINK, pac_found, service); } +static void pac_added_broadcast(struct bt_bap_pac *pac, void *user_data) +{ + struct btd_service *service = user_data; + struct bap_data *data; + + if (bt_bap_pac_get_type(pac) == BT_BAP_BCAST_SOURCE) { + DBG("pac %p", pac); + + data = btd_service_get_user_data(service); + + bt_bap_foreach_pac(data->bap, BT_BAP_BCAST_SOURCE, + pac_found, service); + } +} + static bool ep_match_pac(const void *data, const void *match_data) { const struct bap_ep *ep = data; @@ -1118,6 +1331,38 @@ static void pac_removed(struct bt_bap_pac *pac, void *user_data) ep_unregister(ep); } +static void pac_removed_broadcast(struct bt_bap_pac *pac, void *user_data) +{ + struct btd_service *service = user_data; + struct bap_data *data; + struct queue *queue; + struct bap_ep *ep; + + DBG("pac %p", pac); + + data = btd_service_get_user_data(service); + + switch (bt_bap_pac_get_type(pac)) { + case BT_BAP_SINK: + queue = data->srcs; + break; + case BT_BAP_SOURCE: + queue = data->snks; + break; + case BT_BAP_BCAST_SOURCE: + queue = data->bcast; + break; + default: + return; + } + + ep = queue_remove_if(queue, ep_match_pac, pac); + if (!ep) + return; + + ep_unregister(ep); +} + static struct bap_data *bap_data_new(struct btd_device *device) { struct bap_data *data; @@ -1126,6 +1371,7 @@ static struct bap_data *bap_data_new(struct btd_device *device) data->device = device; data->srcs = queue_new(); data->snks = queue_new(); + data->bcast = queue_new(); return data; } @@ -1158,6 +1404,14 @@ static bool match_data(const void *data, const void *match_data) return bdata->bap == bap; } +static bool match_data_bap_data(const void *data, const void *match_data) +{ + const struct bap_data *bdata = data; + const struct btd_adapter *adapter = match_data; + + return bdata->user_data == adapter; +} + static void bap_connecting(struct bt_bap_stream *stream, bool state, int fd, void *user_data) { @@ -1182,26 +1436,50 @@ static void bap_connecting(struct bt_bap_stream *stream, bool state, int fd, g_io_channel_set_close_on_unref(io, FALSE); - /* Attempt to get CIG/CIS if they have not been set */ - if (ep->qos.ucast.cig_id == BT_ISO_QOS_CIG_UNSET || + if (bt_bap_stream_get_type(ep->stream) == BT_BAP_STREAM_TYPE_UNICAST) { + /* Attempt to get CIG/CIS if they have not been set */ + if (ep->qos.ucast.cig_id == BT_ISO_QOS_CIG_UNSET || ep->qos.ucast.cis_id == BT_ISO_QOS_CIS_UNSET) { - struct bt_iso_qos qos; - GError *err = NULL; + struct bt_iso_qos qos; + GError *err = NULL; + + if (!bt_io_get(io, &err, BT_IO_OPT_QOS, &qos, + BT_IO_OPT_INVALID)) { + error("%s", err->message); + g_error_free(err); + g_io_channel_unref(io); + return; + } - if (!bt_io_get(io, &err, BT_IO_OPT_QOS, &qos, - BT_IO_OPT_INVALID)) { - error("%s", err->message); - g_error_free(err); - g_io_channel_unref(io); - return; + ep->qos.ucast.cig_id = qos.ucast.cig; + ep->qos.ucast.cis_id = qos.ucast.cis; } - ep->qos.ucast.cig_id = qos.ucast.cig; - ep->qos.ucast.cis_id = qos.ucast.cis; - } - - DBG("stream %p fd %d: CIG 0x%02x CIS 0x%02x", stream, fd, + DBG("stream %p fd %d: CIG 0x%02x CIS 0x%02x", stream, fd, ep->qos.ucast.cig_id, ep->qos.ucast.cis_id); + } else if (bt_bap_stream_get_type(ep->stream) == + BT_BAP_STREAM_TYPE_BROADCAST) { + /* Attempt to get BIG/BIS if they have not been set */ + if (ep->qos.bcast.big == BT_ISO_QOS_BIG_UNSET || + ep->qos.bcast.bis == BT_ISO_QOS_BIS_UNSET) { + struct bt_iso_qos qos; + GError *err = NULL; + + if (!bt_io_get(io, &err, BT_IO_OPT_QOS, &qos, + BT_IO_OPT_INVALID)) { + error("%s", err->message); + g_error_free(err); + g_io_channel_unref(io); + return; + } + + ep->qos.bcast.big = qos.bcast.big; + ep->qos.bcast.bis = qos.bcast.bis; + } + + DBG("stream %p fd %d: BIG 0x%02x BIS 0x%02x", stream, fd, + ep->qos.bcast.big, ep->qos.bcast.bis); + } } static void bap_attached(struct bt_bap *bap, void *user_data) @@ -1349,6 +1627,70 @@ static int bap_disconnect(struct btd_service *service) return 0; } +static int bap_adapter_probe(struct btd_profile *p, + struct btd_adapter *adapter) +{ + struct btd_device *device = btd_adapter_get_device(adapter, + BDADDR_ANY, BDADDR_LE_PUBLIC); + struct btd_gatt_database *database = btd_adapter_get_database(adapter); + struct btd_service *service = service_create(device, p); + struct bap_data *data; + char addr[18]; + + ba2str(device_get_address(device), addr); + DBG("%s", addr); + + if (!btd_adapter_has_exp_feature(adapter, EXP_FEAT_ISO_SOCKET)) { + error("BAP requires ISO Socket which is not enabled"); + return -ENOTSUP; + } + + data = bap_data_new(device); + data->service = service; + + data->bap = bt_bap_new(btd_gatt_database_get_db(database), + btd_device_get_gatt_db(device)); + if (!data->bap) { + error("Unable to create BAP instance"); + free(data); + return -EINVAL; + } + + bap_data_add(data); + + if (!bt_bap_attach_broadcast(data->bap)) { + error("BAP unable to attach"); + return -EINVAL; + } + + data->state_id = bt_bap_state_register(data->bap, bap_state, + bap_connecting, data, NULL); + data->pac_id = bt_bap_pac_register(data->bap, pac_added_broadcast, + pac_removed_broadcast, service, NULL); + + bt_bap_set_user_data(data->bap, service); + bap_data_set_user_data(data, adapter); + return 0; +} + +static void bap_adapter_remove(struct btd_profile *p, + struct btd_adapter *adapter) +{ + struct bap_data *data = queue_find(sessions, match_data_bap_data, + adapter); + char addr[18]; + + ba2str(btd_adapter_get_address(adapter), addr); + DBG("%s", addr); + + if (!data) { + error("BAP service not handled by profile"); + return; + } + + bap_data_remove(data); +} + static struct btd_profile bap_profile = { .name = "bap", .priority = BTD_PROFILE_PRIORITY_MEDIUM, @@ -1357,6 +1699,8 @@ static struct btd_profile bap_profile = { .device_remove = bap_remove, .accept = bap_accept, .disconnect = bap_disconnect, + .adapter_probe = bap_adapter_probe, + .adapter_remove = bap_adapter_remove, .auto_connect = true, .experimental = true, }; diff --git a/profiles/audio/media.c b/profiles/audio/media.c index 515263af3..185478efa 100644 --- a/profiles/audio/media.c +++ b/profiles/audio/media.c @@ -750,6 +750,7 @@ static int parse_select_properties(DBusMessageIter *props, struct iovec *caps, const char *key; struct bt_bap_io_qos io_qos; uint8_t framing = 0; + bool broadcast = false; memset(&io_qos, 0, sizeof(io_qos)); while (dbus_message_iter_get_arg_type(props) == DBUS_TYPE_DICT_ENTRY) { @@ -781,11 +782,21 @@ static int parse_select_properties(DBusMessageIter *props, struct iovec *caps, goto fail; dbus_message_iter_get_basic(&value, &qos->ucast.cig_id); + } else if (!strcasecmp(key, "BIG")) { + if (var != DBUS_TYPE_BYTE) + goto fail; + + dbus_message_iter_get_basic(&value, &qos->bcast.big); } else if (!strcasecmp(key, "CIS")) { if (var != DBUS_TYPE_BYTE) goto fail; dbus_message_iter_get_basic(&value, &qos->ucast.cis_id); + } else if (!strcasecmp(key, "BIS")) { + if (var != DBUS_TYPE_BYTE) + goto fail; + + dbus_message_iter_get_basic(&value, &qos->bcast.bis); } else if (!strcasecmp(key, "Interval")) { if (var != DBUS_TYPE_UINT32) goto fail; @@ -840,13 +851,75 @@ static int parse_select_properties(DBusMessageIter *props, struct iovec *caps, dbus_message_iter_get_basic(&value, &qos->ucast.target_latency); + } else if (!strcasecmp(key, "Encryption")) { + if (var != DBUS_TYPE_BYTE) + goto fail; + + dbus_message_iter_get_basic(&value, + &qos->bcast.encryption); + broadcast = true; + } else if (!strcasecmp(key, "Options")) { + if (var != DBUS_TYPE_BYTE) + goto fail; + + dbus_message_iter_get_basic(&value, + &qos->bcast.options); + } else if (!strcasecmp(key, "Skip")) { + if (var != DBUS_TYPE_UINT16) + goto fail; + + dbus_message_iter_get_basic(&value, + &qos->bcast.skip); + } else if (!strcasecmp(key, "SyncTimeout")) { + if (var != DBUS_TYPE_UINT16) + goto fail; + + dbus_message_iter_get_basic(&value, + &qos->bcast.sync_timeout); + } else if (!strcasecmp(key, "SyncCteType")) { + if (var != DBUS_TYPE_BYTE) + goto fail; + + dbus_message_iter_get_basic(&value, + &qos->bcast.sync_cte_type); + + } else if (!strcasecmp(key, "SyncInterval")) { + if (var != DBUS_TYPE_BYTE) + goto fail; + + dbus_message_iter_get_basic(&value, + &qos->bcast.sync_interval); + } else if (!strcasecmp(key, "MSE")) { + if (var != DBUS_TYPE_BYTE) + goto fail; + + dbus_message_iter_get_basic(&value, + &qos->bcast.mse); + } else if (!strcasecmp(key, "Timeout")) { + if (var != DBUS_TYPE_UINT16) + goto fail; + + dbus_message_iter_get_basic(&value, + &qos->bcast.timeout); + } else if (!strcasecmp(key, "BroadcastCode")) { + if (var != DBUS_TYPE_ARRAY) + goto fail; + + parse_array(&value, &qos->bcast.bcode); } dbus_message_iter_next(props); } - memcpy(&qos->ucast.io_qos, &io_qos, sizeof(io_qos)); - qos->ucast.framing = framing; + if (broadcast) { + memcpy(&qos->bcast.io_qos, &io_qos, sizeof(io_qos)); + qos->bcast.framing = framing; + + } else { + memcpy(&qos->ucast.io_qos, &io_qos, sizeof(io_qos)); + qos->ucast.framing = framing; + } + return 0; fail: @@ -1169,16 +1242,26 @@ static bool endpoint_init_pac(struct media_endpoint *endpoint, uint8_t type, metadata->iov_len = endpoint->metadata_size; } - endpoint->pac = bt_bap_add_vendor_pac(db, name, type, endpoint->codec, - endpoint->cid, endpoint->vid, &endpoint->qos, + if (type == BT_BAP_SINK || type == BT_BAP_SOURCE) { + endpoint->pac = bt_bap_add_vendor_pac(db, name, type, + endpoint->codec, endpoint->cid, + endpoint->vid, &endpoint->qos, &data, metadata); + } else { + endpoint->pac = bt_bap_add_vendor_pac_bcast(db, name, + type, endpoint->codec, endpoint->cid, + endpoint->vid, &endpoint->qos, + &data, metadata, &pac_ops, endpoint); + } + if (!endpoint->pac) { error("Unable to create PAC"); free(metadata); return false; } - bt_bap_pac_set_ops(endpoint->pac, &pac_ops, endpoint); + if (type == BT_BAP_SINK || type == BT_BAP_SOURCE) + bt_bap_pac_set_ops(endpoint->pac, &pac_ops, endpoint); DBG("PAC %s registered", name); @@ -1198,6 +1281,12 @@ static bool endpoint_init_pac_source(struct media_endpoint *endpoint, int *err) return endpoint_init_pac(endpoint, BT_BAP_SOURCE, err); } +static bool endpoint_init_broadcast_source(struct media_endpoint *endpoint, + int *err) +{ + return endpoint_init_pac(endpoint, BT_BAP_BCAST_SOURCE, err); +} + static bool endpoint_properties_exists(const char *uuid, struct btd_device *dev, void *user_data) @@ -1300,6 +1389,18 @@ static bool experimental_endpoint_supported(struct btd_adapter *adapter) return g_dbus_get_flags() & G_DBUS_FLAG_ENABLE_EXPERIMENTAL; } +static bool experimental_broadcaster_ep_supported(struct btd_adapter *adapter) +{ + + if (!btd_adapter_has_exp_feature(adapter, EXP_FEAT_ISO_SOCKET)) + return false; + + if (!btd_adapter_has_settings(adapter, MGMT_SETTING_ISO_BROADCASTER)) + return false; + + return g_dbus_get_flags() & G_DBUS_FLAG_ENABLE_EXPERIMENTAL; +} + static struct media_endpoint_init { const char *uuid; bool (*func)(struct media_endpoint *endpoint, int *err); @@ -1313,6 +1414,8 @@ static struct media_endpoint_init { experimental_endpoint_supported }, { PAC_SOURCE_UUID, endpoint_init_pac_source, experimental_endpoint_supported }, + { BAA_SERVICE_UUID, endpoint_init_broadcast_source, + experimental_broadcaster_ep_supported }, }; static struct media_endpoint * diff --git a/profiles/audio/transport.c b/profiles/audio/transport.c index 82f5fa6fe..fac8261bf 100644 --- a/profiles/audio/transport.c +++ b/profiles/audio/transport.c @@ -526,6 +526,13 @@ static void media_owner_add(struct media_owner *owner, owner->pending = req; } +static void *get_stream_bap(struct media_transport *transport) +{ + struct bap_transport *bap = transport->data; + + return bap->stream; +} + static DBusMessage *acquire(DBusConnection *conn, DBusMessage *msg, void *data) { @@ -541,15 +548,24 @@ static DBusMessage *acquire(DBusConnection *conn, DBusMessage *msg, return btd_error_not_authorized(msg); owner = media_owner_create(msg); + if (bt_bap_stream_get_type(get_stream_bap(transport)) == + BT_BAP_STREAM_TYPE_BROADCAST) { + req = media_request_create(msg, 0x00); + media_owner_add(owner, req); + media_transport_set_owner(transport, owner); + } id = transport->resume(transport, owner); if (id == 0) { media_owner_free(owner); return btd_error_not_authorized(msg); } - req = media_request_create(msg, id); - media_owner_add(owner, req); - media_transport_set_owner(transport, owner); + if (bt_bap_stream_get_type(get_stream_bap(transport)) == + BT_BAP_STREAM_TYPE_UNICAST) { + req = media_request_create(msg, id); + media_owner_add(owner, req); + media_transport_set_owner(transport, owner); + } return NULL; } @@ -1483,13 +1499,6 @@ static void bap_connecting(struct bt_bap_stream *stream, bool state, int fd, bap_update_links(transport); } -static void *get_stream_bap(struct media_transport *transport) -{ - struct bap_transport *bap = transport->data; - - return bap->stream; -} - static void free_bap(void *data) { struct bap_transport *bap = data; @@ -1560,7 +1569,8 @@ struct media_transport *media_transport_create(struct btd_device *device, goto fail; properties = a2dp_properties; } else if (!strcasecmp(uuid, PAC_SINK_UUID) || - !strcasecmp(uuid, PAC_SOURCE_UUID)) { + !strcasecmp(uuid, PAC_SOURCE_UUID) || + !strcasecmp(uuid, BAA_SERVICE_UUID)) { if (media_transport_init_bap(transport, stream) < 0) goto fail; properties = bap_properties;