From patchwork Mon Aug 5 12:04:24 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 816842 Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazon11011011.outbound.protection.outlook.com [52.101.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 690AA156F37 for ; Mon, 5 Aug 2024 12:04:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.65.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722859486; cv=fail; b=jVL+llIwInbC9mNdcB4vX4hxLbKvIcFCUGKpZBQOgeks+SO97DExaghgBd7r+Y0nWgJUOnXgnBqwqLxf8N1VM95VehBAjppfug24KqAvdauQrLgJeuShdp5HNsPNwX7bO1JyGi/o6SetZe+zElSm21HilQj57vabablwyXXVATY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722859486; c=relaxed/simple; bh=TnAeWgDBmNzggLQvmiET41tVW25Dfronvkn2/sdGRog=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=lPX3W6pugrtdJyvjYctcURagVAbUbweuTsHZLPlEZQzQvZD4+gxhOlwI+LKrTd/zHNCICII8Zmh78TRtEaODluUb45nWwfumZprLZEbLexszhjW5c0HZZ7vuIdQ1M25N1rnjAcC8JQBLdqdi1F8REwSrPb8HtQNp/zfuUTqPmsw= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=WBwWBaHp; arc=fail smtp.client-ip=52.101.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="WBwWBaHp" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=DIyW43NIfJSKrtQNNo3y1jGzpt27IqXYWmykS6EHca3NM9qBg+MWO7b9lvAoh3HSSA0Ud33TAdE1vGhmDCA3eeTZH8uOGXLJUIzLeRTkGF1P3HtKddzrlamVR+OcybXxhZPwS854uV8QqsoOSNqvlZGqq9vhsCkNXIHJMTRws0oqROoLyjwOHJ6U/71nh2W0voWm4Zge9I44etApqvhSS84HIyfCG+68BJe63Jc0E05Gbngq0O9Anaenxo9hC2u7dmPu6cQqLAMoeyCAX2AzXnch0wtTeamPd4FTeMxm+qhr0DEzStL++4njnmZwmlPHhArtyGf14vS/w6eFNlCXhw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=CPxi3BWbCSoTNTrb5HY2wFmx/1sJ2a1EVXyQS2VPzoE=; b=KOMYPC1FP3oKN7RrrMmPBE2S7lS7wISKRyrDxuD0/SJMS0TTnFEoeXBhEbSzB7WvzkqapQ91vUfv1MtCVyXj2/mlOFx7qelaSgW0GRNTZk7yyEP4Nw7b+no2ZoGgAMbtWtTgj2SETwzFK0Z1PO2C5UrB9ypKufvvJKnmR5JgYw22Y1xP4CSYRt+IVyyCqFvZtdSKZjI6q/JGlI6EWOvp1f4ml2xTg8RcAOs1P+1F6TZjwjIMmARIk4DSj4kyjlVrz0fTlr5EC4jvAWv48hnotMxZv53mPB4+oM6sNh49u3aCuK3DPx4dHFgPJuOh0taS+KjdfPmU1nh1VclqgCe9OQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=CPxi3BWbCSoTNTrb5HY2wFmx/1sJ2a1EVXyQS2VPzoE=; b=WBwWBaHpypUOdHjpR3fySdE/Jr7AclO6jhIjYww16eiMMjVte6TStQ+y0YABhTKfBtSFckFIlPnIhzUl+gHjEFLk4UPdtY7zyGqhAKYzimKj3QJrHYCGO2ndWa2brQOcuCwRNpjHSexlgpKIPnDik8asc2jKr/4LCOKNyulriGpgZ9+LUYY3UF5CNyoR8GwMqsKHGLtCsRleVIgqQyrB6+87r6UYQ1tMxxGqj9b5hwLp9JJ8kNYIsQ0TbLMgrou2VqhYaZqeS/ccFGhfKcA40MagoWn1pUQBKcp8BErltOk2uFegMpIYFjqj+OyauYTYEX9u46GpMl3OR6SzCVOnow== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) by DU4PR04MB10499.eurprd04.prod.outlook.com (2603:10a6:10:568::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Mon, 5 Aug 2024 12:04:41 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::5e22:869c:33c:9654]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::5e22:869c:33c:9654%5]) with mapi id 15.20.7828.023; Mon, 5 Aug 2024 12:04:40 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, vlad.pruteanu@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Iulia Tanasescu Subject: [PATCH BlueZ 2/7] device: Add support to iterate through service data Date: Mon, 5 Aug 2024 15:04:24 +0300 Message-Id: <20240805120429.67606-3-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240805120429.67606-1-iulia.tanasescu@nxp.com> References: <20240805120429.67606-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AS4P195CA0023.EURP195.PROD.OUTLOOK.COM (2603:10a6:20b:5d6::14) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|DU4PR04MB10499:EE_ X-MS-Office365-Filtering-Correlation-Id: 45c18427-a4d7-45a4-9447-08dcb546c936 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014; X-Microsoft-Antispam-Message-Info: MKF1y5bx3WayHwdhdpKseHO9CvNonge7Nl0i6y7ryhmbtPpqtJboxc7R/jXgqSXQNOdY9/XeQ49xxtFXxjtpIOJbo/bnCphsjKg8rDiShY+Dr9K09wFnliFctU2vtPMsdo61XCGQbU2Pa2Pd6NpAnWE0MjRBFR1Hwxk+LjKK5VGTIe9ySdG9ZGgwZOd8eq+2wRaoBiZamwYXzs8B9AzrrvQ0i+c/9mWhIo1LyQXl8zAi73sgxBMXnWvlY8qTyD8bt1O2nohWAqw6AZwg9Hq5/cFBP9iBF8js2syU5KQjBhGbwnOM3qUR57C/JmTPSx1LDc5ylTa77fFkRJHk+3a84e/o1pYiFDKqhH5oRns9+Em+E/SorKMhzwiFAN/FkXPLPRWpIxjH7RMsEbqD+W5J80m8aII8VpHKhxoWrWhJOUbsJYhbMWeAd2gadP5bzEhIGA4y1BxjOH89RZJNIgTlw5Uwv61EE6XdGrb7c+EGQ9rn/5jPEojoJM1ys7LADP7DQ/aOmtehrMGa7wPBBeBJyh3dnZ/gVHXL1O53NR2cxe1vL0/54JUYNq953gNG/HpWsXZEyVuHZrrv9vozixay5ryUvIKJdswh/GjBxLGoq7yKoFZcTsVnbYsUW+lmFpFWLCI8lsjDQ04PWR11M/pyfB1fy5zBMxIS5+HpSS8FsUvhtdDxUFXV28+2t4TyiBbyV3bqcmSLQ3zY4pQSDCkSpyO8LJfcS/9+NbR9pAjsFQrG1XRUlRgjkGkoLsHj/5mtWuLXX4UG2wiMwdlT/n5MtUofvsS5P1hi0qI/OBMTx2GByz8SSAWqtp3FLbecYpybyLjcZreryGUGZwIsUQLi0bglWBbkXJ8SBBiBxaayizm42BR8YIaW5x5oaapticbkKb1n8AEedv30C+ILTgg0TutGy7gOW1uLX2oX+LHSvvxWLvY+qzqXH6Daw8lNfr/UKfaj+fcmr1GmGqtd+GnUk3TL1eZ/kzz9sDPZ+0u7LOz3ENYFYfHA13UTFmyZ+L7m/hHV74bOgEbKphzAbhjYeJ9kcwua08gX7zCODbxCypHS3oR3+JILioh0NS/JKTUw9C9a3lkPKuzMRIJAfLt75OiGlRmp8UEh5NDKhoxrJAzf6IC+Ff0ViT5REmI6f1pNW2IM2O/IbW+aQYjf9OIAQe5nlCpjPqBnesFQkFW8EsbcQQAdfC5uGvWJ8PURdpZSIHN/HX0OurYHhiOmn/K0eBFTpLEL+abeaGA4qdwzpFwIf/0z6mqKsbPtGaZaWaIvaOcQm6hyec1pZB9ZikhSsBMgeUjdu/xT1HvziiGUKeek7AZuCeSlBIAUM7aE8R5EKBW9x4URRI9+laV/13e4Ew== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR04MB8898.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(1800799024)(376014); DIR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YSiN+boeemjaar6bTD9Pw1KRgr1V1HZIvE8S+MWZiLlnpQ1RSUPA5FQTOzaQOPNZN9Di25zubyl8O/6FxXlhC1TUeVudmYKji6nz7PNtgtZ8WkrzR2pNvHS5xKpFgQpNS555fRUioANslilt8DG36D/BjtKcofGfRJ4j9z48JOuac5a8QTQ6r+zN/OYnWH+q0LxV75eBOq0z0C2sNUyBI+A31/FDHf96FWmp6LUrAGOwWXbcyXyIlKvaxreBO7pBmlsueTraYOIkji/c7UcKTQch5R/za/SdRr1RzXg1JwXi9An3Pwy2KtA4bvml4m7GCztPKcYDcieMOVx3GdcC1ASOC5cBxlRpAXvPf4oBUdnqS4p1eF8h28UQy7wnXw00H9xp0lBQPwRI6THxfTl+krI2xLUrg6W3FYi2Yr1hr27WrbpVJ3nbCizABQICNTjGHJwsLPhXfJpW6gxZsp8o2l89oVMvECQppzMrUhUtm5C+aFUWGJgwmDzS060BMIY6T2nHdc25Z6M/vKfvhaCLCU1vQ85q/NcSpO44DYtpgB7VKd1jGHUWWsKTogMKQFSamOaulMYvykUMGBpWMsfAjY3pWZsvvDdhQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 45c18427-a4d7-45a4-9447-08dcb546c936 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 12:04:40.8775 (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: cWXKjJjB2oM/+DNkltYphVhaICkLDtCyEJw92cCQ7QwT3611ptB15Bc9S6oSzPPBTAbqiPXaLYT2O2ZZgXbOhQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU4PR04MB10499 Some usecases require iterating through the service data structures advertised by a scanned device - for example, a Broadcast Source advertises the Broadcast Audio Announcement Service UUID, with the Broadcast ID as service data. The Broadcast ID is used by audio profiles to uniquely identify the Broadcast Source. This adds an API to iterate through the service data advertised by a device. --- src/device.c | 8 +++++++- src/device.h | 5 ++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/device.c b/src/device.c index a1dc0750c..cf7264051 100644 --- a/src/device.c +++ b/src/device.c @@ -5,7 +5,7 @@ * * Copyright (C) 2006-2010 Nokia Corporation * Copyright (C) 2004-2010 Marcel Holtmann - * + * Copyright 2024 NXP * */ @@ -7374,3 +7374,9 @@ void btd_device_set_conn_param(struct btd_device *device, uint16_t min_interval, max_interval, latency, timeout); } + +void btd_device_foreach_service_data(struct btd_device *dev, bt_ad_func_t func, + void *data) +{ + bt_ad_foreach_service_data(dev->ad, func, data); +} diff --git a/src/device.h b/src/device.h index 3742f6028..97536774e 100644 --- a/src/device.h +++ b/src/device.h @@ -5,7 +5,7 @@ * * Copyright (C) 2006-2010 Nokia Corporation * Copyright (C) 2004-2010 Marcel Holtmann - * + * Copyright 2024 NXP * */ @@ -211,3 +211,6 @@ void btd_device_foreach_ad(struct btd_device *dev, bt_device_ad_func_t func, void btd_device_set_conn_param(struct btd_device *device, uint16_t min_interval, uint16_t max_interval, uint16_t latency, uint16_t timeout); +void btd_device_foreach_service_data(struct btd_device *dev, + bt_device_ad_func_t func, + void *data); From patchwork Mon Aug 5 12:04:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 816841 Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazon11011011.outbound.protection.outlook.com [52.101.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C885A156F41 for ; Mon, 5 Aug 2024 12:04:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.65.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722859490; cv=fail; b=WSbBDeTgg7wCNqWS47VNYa++QERTw8jjayDsxOUKhu0PWrVyfCD7wELr77yLgBW07IfGLQqZjPvVEkNtLIfL8wXbeXZk44j4fuyaGhXzlWgzRMalrhh2VPaFjPFl9aX0reTfXHGd/5ibkduPyex10iHmBkJE0dZ5e0g0xdSligE= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722859490; c=relaxed/simple; bh=xfcJrAwt+06PNZqjD3RQnimQ9UwdR7Z5qJLwUEcUGyI=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=elIg552xCvJp3cBO2/OlppjK/I6gQCiiEhSr1RfjEcRVlY4+LLcNW2U+NNlAi/SypVcc8oyvo8bS6oyXof5Fwi1HQlv8MDN7otP46NP9OowxUk17kvO/D1Vh61PHjHK7UQVOvVm080YbWKacNLkSve0+YsFboU3QI4cndH0M454= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=ic7YCTXy; arc=fail smtp.client-ip=52.101.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="ic7YCTXy" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mRxVhlczBa2Wrgl+t7nvzeUCSIOC30JXd3L7rs+6jHLQsQHeB/3P+zGbT3m8vFQf+7kJx45JcuQFGFVjOdY0IPfJa7rulne573j6CKkrS9GHn/Xg+QkV0iF/lqCXomOPzXvHURAtgrwcj1ATBlgUphtYQspaHlKAX2FcIvd+AuS24coRVxW606FPXJaj6yxaGDA0D4/i5WewpE5DuKfkkvLs7S/vBWIpQGGUoHfgdeTWvBqan1N7aPdrrQXwuWwMX29LOE4IJ1zXdIOIjnNxPCPxOL7Jd7NoepBP70KnjsS9O1I/sb/ce1506sHxGBK2a5U6pjMKxCQeM3EfAwcUNg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=n7hvhC227PZ8nEM98BLq7s6OpzOOErPdsk2RTW1HKWs=; b=g2E5eppjOmFPEwYcPnq0zxVEX/xtwfSaqFmnlYj3TZY58mvPZlpwd2Fi/N0/YIVfqU5/49Vh1BAg7P6I+PfrHZtr9zIXDDMF2+8d98yIajxqSUABaViDlAwUmmNtJtZDxyV3DCiQkRh7FVJX0i1uRa6cyLRnxzl+/+zXWEleK4zWjvtx9TsKTYCBtc37n2iQGtiYZNTI7ah/qUYNemFUQz8PDWYwBwPVpVnZH9h4IK26yliiKzGJYObGdIZ20NbkUuNrnIWEsjMZgkh0NuYDdztQqay5h7H8kHbzxBhgj77bSSb0SarTBimlBZJFvUjA3EWJrTiccGvOvTtqFMSHHQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=n7hvhC227PZ8nEM98BLq7s6OpzOOErPdsk2RTW1HKWs=; b=ic7YCTXyPXSJoRFP0WzZsaH6SGOWWurGSHjfMpNhasx8LOCUZxhtnkjQ+aEWF5UuiCFcp5egmR7yyMUcwIV1XK72Q+QKv5N4ADqMIhHsV46Pfb3/p7YC3Jd2R+fF8A+JJIWsQafkE10S+Nmue+/xwsA1v3IqZC6m+ob5Gk6t6rUxA2Up3GkW09TWj9o4gaWms0qcNNr8BBdzex3c3Ih9zqXdwnoWAiZLxmCORdzqkUlFDJJe+AJKXbSF0rveTisjGJvVQ5OBpQ1T0s1nc/3JGN4qOl89qeh/APMHbCdKOn28dF+JuUVxOh5Kr2Ht3+xfxVBlXnkZvOfFIOKzVJNnRg== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) by DU4PR04MB10499.eurprd04.prod.outlook.com (2603:10a6:10:568::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Mon, 5 Aug 2024 12:04:46 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::5e22:869c:33c:9654]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::5e22:869c:33c:9654%5]) with mapi id 15.20.7828.023; Mon, 5 Aug 2024 12:04:46 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, vlad.pruteanu@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Iulia Tanasescu Subject: [PATCH BlueZ 4/7] shared/bass: Add APIs to register bcast src changed cb Date: Mon, 5 Aug 2024 15:04:26 +0300 Message-Id: <20240805120429.67606-5-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240805120429.67606-1-iulia.tanasescu@nxp.com> References: <20240805120429.67606-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AS4P195CA0030.EURP195.PROD.OUTLOOK.COM (2603:10a6:20b:5d6::17) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|DU4PR04MB10499:EE_ X-MS-Office365-Filtering-Correlation-Id: 41663558-256a-4097-89f1-08dcb546cc3b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014; X-Microsoft-Antispam-Message-Info: +y2bsoExxWc65/GGJEJR/ePFifIcLMhvnED6fnzzxZ4qROZCMv6J1FomvbJnotQvzSj/RHZm9HGBivEjPD3Lq32scI+z3eIrVRq2bU9XDU133SdC3uqhOrZx806O/ICJK2enPxbkvPysI32oUQeDyETc1stdMFNxNpNyuxs9fi62YlqvUAfqn4CQ5XIn9baVA3E6OIfz8iTGHKLJ1DS2aqy8cNK6wuxjph9xzGsklQW8bfLd30u+CfgscWw3Eq7gn7xunb8DHpd1tD1SCJVtjWvd4whF+d7WMVi2z3yLTJT5FcH0Iju3UCM10i9i3xo11AstekhF0gW3U/hB1jK0W4Hxkfuhk0SjrpotimAg2NqZmd4OtDzttq4pc75J4VELiacinnuyzw28OsWRadHa0gKU5o5Ned8gQpB4WiYteG7wb3FcmElR89U0JXCGVE8T2hrqfqvi+CYk0Uk9YKK1ekrRx6qykkmpZ7dBKwOTivWF3Jug4fT1FWfNstttmn4fmxd3Nwe3OlgTuP4mfgFXigqm0PJIviWZJzfrhCHKwd9HazaSQ1QHtemTluRBVhT9N6egFpWBLSIuk1aw10J1tlEEHGzDCTli2AfP2sOb1vuXicuuZZBHKAqDcVapgR3SU79Cx6grWKWggA4oETvEN8vOf5Gy4fCh0YcjD3w/w2JbaVaytWUaYUT2RM9vUequb/uf9clWHcFk5SS2bTEXJnhl+KwQaVuY9Tj+A/IsXvL2c51A6M85S1WiI+NqvzqpMxvoUlxgKqDvcNpNbz9XhQ6oSPpn9RfFxrPjUlm25iWD7tpxQqd+bwAuI9kqx3Y9qCEl4G+d0Taavev1myHFP1eAJYTN/YK+tnZcz0WrIB4P7j+qs0qVzH+XFDu5eoBB5N9yzqd3uuA1oNsAHle6t8Q9D6TSpbp0hFw0FE/T2KCYrSG2pBStkNXqZrA7rBvIUx6AEv7OTXNel4OfpKZEzqrI1ffCZ7HIMnfiU0HJv4EAYyYQVhyE8uvoyZiMmyJLJHjS8Ibgc7KazEZk6wDMZyPx65R1CobGwqdHViQrhXOV1UHnsqoCTU/Ja1sR26ALY0jutI19jQ77m3XgZNsTO33kYHKtBhiCOIL87MqpWutOFo8nvUK5G9KYk5flpadPCbn5hu8sAYKpEMVmF++57ofd+Sa+E6fHm75Vnkkdpu4ID0T2GIukG1VeBZ8Due4GJSZ7plckhN+bYvHSf4QgK01+MOWzCS1BTRShmuoZVlED5URkG20Lps6ZB4rKuxFBEGO0zBP/qqiQLNEb+Ev0n+xjT1VU69w4aEwR3FyF3seebdpfPdbAoFDEM8RzFc5T4VqFVzkEuql48CfLnbEtXA== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR04MB8898.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(1800799024)(376014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: JTKpy0J/fTJZk6nKqApDbQ207XLivQeVsSL8/UXBJrmbt39h1L9l7S8xbo/yBKmGuSTF9DHzxSCsE00u5ODly1ZCqI3LxuI4m4gwoc/tXfo6I5VT9jhE2EHWYy2vIaVdl1oud69Wx0bmJ+dYqsDNJGTvp0cjMEDo5iUmfyiQV0tYLPJSC96YkZ/z91KqFExIInCWpOppQ+gIileMve8mkZgt8ZlTvkKbTyAa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fEDYBYO2xDMsab9FGTNXOe6siyY9NZNvqLBSF/63A4eV4aQI6U0Wz9DfioHz9I3iFipg+elS0GjzlWbRgyA4M5gZadyF6ovn2jNLx+DfS7Bdg6v937RrmiCN1OyiKgKeQ8MxGuOlzwvdyRN4eoEsLrurqzFkb84IRlke3nkAyaExmObsi6FVV/e6qSxo7y62i8VyWs0JI6OQQdUA08SKbafo8mqNb0Xavr3OKnJ+jhNZeMIpErNn/DE8hS18wG36P/otGdv9F+118ACrzSDt4I6yyZCi7kOrC5ti5ie3GtW419t5g== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 41663558-256a-4097-89f1-08dcb546cc3b X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 12:04:45.9824 (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: TcWdGHiw0scz+LaxKSqpNMX/inygAmR3gaqR9LrCTR8T4WfbKTxc20dp2YW2/HCt+R1AsdGv9Xb7BkGzCBnrTQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU4PR04MB10499 A BAP Broadcast Assistant (BASS Client) needs to listen for GATT notifications for Broadcast Receive State characteristics from peer Scan Delegators (BASS Servers), in order to learn about updates in Broadcasters known by the peer - for example, the Assistant can be informed if the peer requires a Broadcast Code to decrypt an encrypted stream. This adds APIs that the BASS plugin can use to register/unregister callbacks to be called on each received notification. --- src/shared/bass.c | 95 +++++++++++++++++++++++++++++++++++++++++++++++ src/shared/bass.h | 5 +++ 2 files changed, 100 insertions(+) diff --git a/src/shared/bass.c b/src/shared/bass.c index d9ab210b7..b54bf3094 100644 --- a/src/shared/bass.c +++ b/src/shared/bass.c @@ -71,6 +71,8 @@ struct bt_bass { bt_bass_destroy_func_t debug_destroy; void *debug_data; + struct queue *src_cbs; + void *user_data; }; @@ -118,6 +120,13 @@ static struct bt_iso_qos default_qos = { } }; +struct bt_bass_src_changed { + unsigned int id; + bt_bass_src_func_t cb; + bt_bass_destroy_func_t destroy; + void *data; +}; + static void bass_bcast_src_free(void *data); static void bass_debug(struct bt_bass *bass, const char *format, ...) @@ -132,6 +141,64 @@ static void bass_debug(struct bt_bass *bass, const char *format, ...) va_end(ap); } +unsigned int bt_bass_src_register(struct bt_bass *bass, bt_bass_src_func_t cb, + void *user_data, bt_bass_destroy_func_t destroy) +{ + struct bt_bass_src_changed *changed; + static unsigned int id; + + if (!bass) + return 0; + + changed = new0(struct bt_bass_src_changed, 1); + if (!changed) + return 0; + + changed->id = ++id ? id : ++id; + changed->cb = cb; + changed->destroy = destroy; + changed->data = user_data; + + queue_push_tail(bass->src_cbs, changed); + + return changed->id; +} + +static void bass_src_changed_free(void *data) +{ + struct bt_bass_src_changed *changed = data; + + if (changed->destroy) + changed->destroy(changed->data); + + free(changed); +} + +static bool match_src_changed_id(const void *data, const void *match_data) +{ + const struct bt_bass_src_changed *changed = data; + unsigned int id = PTR_TO_UINT(match_data); + + return (changed->id == id); +} + +bool bt_bass_src_unregister(struct bt_bass *bass, unsigned int id) +{ + struct bt_bass_src_changed *changed; + + if (!bass) + return false; + + changed = queue_remove_if(bass->src_cbs, match_src_changed_id, + UINT_TO_PTR(id)); + if (!changed) + return false; + + bass_src_changed_free(changed); + + return true; +} + static int bass_build_bcast_src(struct bt_bcast_src *bcast_src, const uint8_t *value, uint16_t length) { @@ -1321,6 +1388,27 @@ static void read_bcast_recv_state(bool success, uint8_t att_ecode, } } +static void notify_src_changed(void *data, void *user_data) +{ + struct bt_bass_src_changed *changed = data; + struct bt_bcast_src *bcast_src = user_data; + uint32_t bis_sync = 0; + + for (uint8_t i = 0; i < bcast_src->num_subgroups; i++) { + struct bt_bass_subgroup_data *sgrp = + &bcast_src->subgroup_data[i]; + + /* Create a bitmask of all BIS indices that the peer has + * synchronized with. + */ + bis_sync |= sgrp->bis_sync; + } + + if (changed->cb) + changed->cb(bcast_src->id, bcast_src->bid, bcast_src->enc, + bis_sync, changed->data); +} + static void bcast_recv_state_notify(struct bt_bass *bass, uint16_t value_handle, const uint8_t *value, uint16_t length, void *user_data) @@ -1353,6 +1441,11 @@ static void bcast_recv_state_notify(struct bt_bass *bass, uint16_t value_handle, if (new_src) queue_push_tail(bass->rdb->bcast_srcs, bcast_src); + + /* Notify the update in the Broadcast Receive State characteristic + * to all drivers that registered a callback. + */ + queue_foreach(bass->src_cbs, notify_src_changed, bcast_src); } static void bass_register(uint16_t att_ecode, void *user_data) @@ -1562,6 +1655,7 @@ static void bass_free(void *data) bt_bass_detach(bass); bass_db_free(bass->rdb); queue_destroy(bass->notify, NULL); + queue_destroy(bass->src_cbs, bass_src_changed_free); free(bass); } @@ -1656,6 +1750,7 @@ struct bt_bass *bt_bass_new(struct gatt_db *ldb, struct gatt_db *rdb, bass = new0(struct bt_bass, 1); bass->ldb = db; bass->notify = queue_new(); + bass->src_cbs = queue_new(); if (!rdb) goto done; diff --git a/src/shared/bass.h b/src/shared/bass.h index 864b01637..01c1279bb 100644 --- a/src/shared/bass.h +++ b/src/shared/bass.h @@ -119,6 +119,8 @@ struct bt_bass_remove_src_params { typedef void (*bt_bass_func_t)(struct bt_bass *bass, void *user_data); typedef void (*bt_bass_destroy_func_t)(void *user_data); typedef void (*bt_bass_debug_func_t)(const char *str, void *user_data); +typedef void (*bt_bass_src_func_t)(uint8_t id, uint32_t bid, uint8_t enc, + uint32_t bis_sync, void *user_data); struct bt_att *bt_bass_get_att(struct bt_bass *bass); struct bt_gatt_client *bt_bass_get_client(struct bt_bass *bass); @@ -138,3 +140,6 @@ void bt_bass_add_db(struct gatt_db *db, const bdaddr_t *adapter_bdaddr); int bt_bass_send(struct bt_bass *bass, struct bt_bass_bcast_audio_scan_cp_hdr *hdr, struct iovec *params); +unsigned int bt_bass_src_register(struct bt_bass *bass, bt_bass_src_func_t cb, + void *user_data, bt_bass_destroy_func_t destroy); +bool bt_bass_src_unregister(struct bt_bass *bass, unsigned int id); From patchwork Mon Aug 5 12:04:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 816840 Received: from DB3PR0202CU003.outbound.protection.outlook.com (mail-northeuropeazon11011011.outbound.protection.outlook.com [52.101.65.11]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 31DA1156F48 for ; Mon, 5 Aug 2024 12:04:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=52.101.65.11 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722859495; cv=fail; b=FP8LnfVHw8IiQOpt8h/3Goax3h5JTXEZH8t5nQOc1/Y2irQJTVDkujIV1cayYiiBBODkH6abnTds4nad4bsASAQ5sgWZOIWaBkM8r1hn8q6YqSO/JmEe0p/wl6TjCWpcHP5QdjL2f3nLYh4f9Zud6/fqiinQ02sVOcpCTUW3+bY= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1722859495; c=relaxed/simple; bh=j6gvTI+bJ7k28rh2d+w6H3NeCpw1RdhIy3vtUIiMYgk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: Content-Type:MIME-Version; b=XZMdrN7FfS2jR+D5JWUSwbdsQlFhZY/Zf90G0eng4PdEZLNjLziOrIpVr4Wwo11HsYk2PIgQS+MG8rFTgRL1xVlVqAwgWNoAJwuG5hEl5fMVLDNSlo6oTZl59T9U8424eXlZ3aGk5XBE3SNI+ssvJ7fY+r4H9L3Acez1IGdwgYM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=TdyHKZfs; arc=fail smtp.client-ip=52.101.65.11 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="TdyHKZfs" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=hVDrLpRKZhWyPOCt/6+vv4E/MOI86WCl9iQZkF1RY49tyQPPY8byzF9q0HhnRpIE7xMvNhYQuBb8UbIl5BZPptOSOAFqGiQOeQoDsmxFXMWcMXCCtL/t4PtUbKoNIs/TCm3/lg9uSK+h40opLcmfBcW59wAyAxwBWRzgp44T7L3K2nMZ8S2Z3li5RtzGTDPTL+QUuVzeWgcylG9o61+St2jks1GNAVN0lD+T2Qmjh/u0jlQzZMFlz4EWjlK0eXb8fbpFV8PLnBEzmeCbfWbo9BRJqOyE2B1xt3zJ1wIHaTnHTpzbpjXmBrLDrF9jF2volJhJBGaFqwQJwOUkpOQqXA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Zrpot0YDEBBZnfYFkguLklbCwu1oOwLX8hRdLNVMRKk=; b=MYEztRpdyR+KRMcZUWKLa2/rax+mBlCWmZhn93DDW6/Ql9tz1eh2Xa6H+AiX+irLwv36xKidGaSUR5LDh9jDXMEPyHwqsvkGWtc3OvzHmtO5uLIpPUuXOYGSwVPGtuoZcXw10H9V6WIV0ijV/yeNAjh7gJ1D3vXI21egdNVPADjNPLxyiDkcbJe5+LXY2IfJFPw5FC3E+6flno8iUGinc/sderIh0JFs8xZGNAYvz6qBwN62h+kB3PalIVhLCMfjtRUu+/1T98sx91nlsG65hXATt+a7OMBp+aef9+0VI+EABm/fFXUF3SxPguSjbIbcsEmcSw3kxlM1rrdLdIDFvw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=nxp.com; dmarc=pass action=none header.from=nxp.com; dkim=pass header.d=nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nxp.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Zrpot0YDEBBZnfYFkguLklbCwu1oOwLX8hRdLNVMRKk=; b=TdyHKZfsltFWNh5nbl+6ZtxUlhYqRCZ71a5fq2cR2aQWovbNfAcWMEqHFa3nkijPZwNgtEHkxX+EIrHF9qSogLu07dTrjtqbQGlpD7UCHpanBRdUIKOqxhBVuPbnlEBiqnsYaQzxwOBBQw0OrJJEhikb2u7IVdzaXVkC8Q9TPlX5mn0NZBNRxghT70d97myaqwHCloYfeYnuic/PDokyBoAGOe2mGn6/y9llHFORcyOVvLKZLlW7DRP5VtABLEcdjq/As55CRcq7jbNpigeth9f4L1iRQxgMWlp0PKgk0SyCFtldBfaKQRmQY6wAHav4ECJkasGWkb9Xjdd3QWDb5w== Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) by DU4PR04MB10499.eurprd04.prod.outlook.com (2603:10a6:10:568::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7828.26; Mon, 5 Aug 2024 12:04:51 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::5e22:869c:33c:9654]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::5e22:869c:33c:9654%5]) with mapi id 15.20.7828.023; Mon, 5 Aug 2024 12:04:51 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, vlad.pruteanu@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Iulia Tanasescu Subject: [PATCH BlueZ 6/7] bass: Implement MediaAssistant Push method Date: Mon, 5 Aug 2024 15:04:28 +0300 Message-Id: <20240805120429.67606-7-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20240805120429.67606-1-iulia.tanasescu@nxp.com> References: <20240805120429.67606-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AS4P250CA0006.EURP250.PROD.OUTLOOK.COM (2603:10a6:20b:5df::8) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|DU4PR04MB10499:EE_ X-MS-Office365-Filtering-Correlation-Id: ff44e418-7bdc-48e6-29dc-08dcb546cfa1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|366016|1800799024|376014; X-Microsoft-Antispam-Message-Info: RmaCiGLDhvFzZ4YzBpSa/+jFHNF1JmnJszYlxK+KfVUlKxheMhEXYNVs+QkpCoNalOohvg60v9c8LPaFnaKupdZUYtyOVGWeGVzkeEHxs+Vq5TskjE6ddyOQdbXKmhLnKhUFSKwCGotRVVoEUAxTIBk8EuRqzggkJtVPGRhCUe2CYnmUEHTCo2IniSVhHn3oVACrRnBzZS8VG3mEcze4AVenHTSiyS53KpRvH16bRiL1ytM6/+UdbGfDMk2Fm0+BL0rBOSfjFBYYCrlmZPPrux4namlQ/O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DfRlsg== X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR04MB8898.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(1800799024)(376014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 2eAINssomf6409Wpc9cufOVdGe+XgoO2DeH4ODAS6UPRTygKmg0hdoKbcWejqQtiEt7ZVRbmKvX6lFrNnb1KSCHrddbbv6T3cziNstbTMT3FuejvZj1hdTfeJgqV84Y1iNsQ8SLCOWzt0fMTAKad0fAPTdWxK5iJ+8S4tAg0mvAp+h8kS1DqiiKrnDKYeth0fJw1t/0eVL9ur03Nje/mrey+YhSXU83pqxmZAJ/AC09p1PlQ7dhXIACO/RyAK8TyTdvHp2mniK7Y3hqcilC9lAf5hz24sv8Hqi0n2WpWONiK4jT4kpTJL2G8J8YGCdHCY32h29xtUKV9TVs1sABep0asOWsK/mpGyw9guJMjnMgYgaZw6Ee+9fW+bOtUuxifs/94EQAxH+LBfe6/afXTX/6sNIp6KunfPBgP7SW6Y+uUFrFk++NxVxNKT7zc1ABiThgiCeK0hBYyUCFOIsbZdTcjGV378xFQk9DQmVzzhOiJdx+/wOpxPL+HDSyDkF41ADJUnIXkF7vPiAQUY1iXlXLAKzhjKHu7VP8c2acL5ZwyvoL86PQInALG1YnK4HWRfEX/EUuZilMYHSN0vvBu2PqWh8XJ+0ft3FkGesCfrMahKWiGHT04uXYji5tN42++FDVgXhjZHW7GHUCVsU+U9Npvrx+FdX1G2gtn32PWPD5wPwONWRIm5gB22Akt7wuRsMcFUMC+EdSxFunL/6baPNRJMVH3Cs30OPprxzimL9F2l/lH6sI5XnWpdLd9b68yb1l5cKgW4eucRR4vlPEjCFmRlCSDhDtXU6FjVrSed8KQ5t+lOpaq4yXbohkmYNe5SrmnuICrspqEmrhq+0m4Yz9kXZlZaSQTQuu9SXlJmC5srV2e2uX4PFL0z8FbqZwH+gQRhFM409F5b7goQ8Ch/csnb9YL5+c2DHswUuPEagGEgj+PlkNrL5uDMmgoIpqXZ3IYP62Ssnfc9UYzFWplpy01NRroDLiMdCQdjds8CLFtWxhcc0i1cam/UOXpS/G9RXNkEHLOUUNG1rwyhC4ZfxGT+MlWtKWcPwMuKK2e1exPmCeMq61eLoj2DMLloS/M21lTTiMhVXyNzd3jQy2IbrIAuN0RnHVd6PQGt93s/dFYbebLsCfb9BB4hxpdmYSZFuwgOIaItYLtiPZpN0LL/OPPYXtr2jtCdi/GoOfIUZa6KVVftKGKqjtU5zYLgu4CD8OhGvIU50F1wMYKs+FJIx94TY/ikNGrpMnRkroWLujxYE6ZFb0xxpex9rCI/XeORTHzta+VjAFzNuczcpf73S9RdVffdRI5z6OE/lsZ4TDa/pBAj06B0YdBtEUME+SE6jXWzaPlNuLYnXXVcB6IAAl93e7tnY4ZRJh1yr76TmRopiOaABwaK1VNQ8cEtgRIgHzOKae6bJxx96r385zkjvq6eyV7qY7PXQG8VUhWZOa6EGSxjRaQ4xbM7tm9UFira/nSPGD//KU9yfOpW/ws7mylcHLGsM3R0qDB81GGhakBcLHfABH3ZZICZaAXVrnmV5tryr449UcSjmSukpBMDnnQ8R7TkhfkfhbQV4MsUrDPFK0KTTTNV0iO7di94uvSuLOdXPsbb8iyKigpCghNPA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: ff44e418-7bdc-48e6-29dc-08dcb546cfa1 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Aug 2024 12:04:51.7022 (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: 8gJ9qN6/V5iqsHkMk2MKBJzsvYRyZyhRLS+EbY0QPamBenIn2R9DDOVejbI73mMXuZx488g9WeqxDwsSYJtb0A== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU4PR04MB10499 This implements the MediaAssistant "Push" method, which sends a GATT write command for the Broadcast Audio Scan Control Point characteristic with the "Add Source" opcode. This also registers a callback with shared/bass, to handle GATT notifications from the peer. A MediaAssistant object transitions to different states, depending on information received in the callback. The callback is also useful to check if the peer requires a Broadcast Code to decrypt the stream - in this case, the Assistant uses the "Set Broadcast_Code" operation to provide the code. --- profiles/audio/bass.c | 295 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 295 insertions(+) diff --git a/profiles/audio/bass.c b/profiles/audio/bass.c index 795b4b80a..b3740f64e 100644 --- a/profiles/audio/bass.c +++ b/profiles/audio/bass.c @@ -70,10 +70,18 @@ enum assistant_state { */ }; +static const char *const str_state[] = { + "ASSISTANT_STATE_IDLE", + "ASSISTANT_STATE_PENDING", + "ASSISTANT_STATE_REQUESTING", + "ASSISTANT_STATE_ACTIVE", +}; + struct bass_data { struct btd_device *device; struct btd_service *service; struct bt_bass *bass; + unsigned int src_id; }; struct bass_assistant { @@ -92,14 +100,206 @@ struct bass_assistant { static struct queue *sessions; static struct queue *assistants; +static const char *state2str(enum assistant_state state); + static void bass_debug(const char *str, void *user_data) { DBG_IDX(0xffff, "%s", str); } +static void assistant_set_state(struct bass_assistant *assistant, + enum assistant_state state) +{ + enum assistant_state old_state = assistant->state; + const char *str; + + if (old_state == state) + return; + + assistant->state = state; + + DBG("State changed %s: %s -> %s", assistant->path, str_state[old_state], + str_state[state]); + + str = state2str(state); + + if (g_strcmp0(str, state2str(old_state)) != 0) + g_dbus_emit_property_changed(btd_get_dbus_connection(), + assistant->path, + MEDIA_ASSISTANT_INTERFACE, + "State"); +} + +static int assistant_parse_qos(struct bass_assistant *assistant, + DBusMessageIter *iter) +{ + DBusMessageIter dict; + const char *key; + + dbus_message_iter_recurse(iter, &dict); + + while (dbus_message_iter_get_arg_type(&dict) == DBUS_TYPE_DICT_ENTRY) { + DBusMessageIter value, entry; + int var; + + dbus_message_iter_recurse(&dict, &entry); + dbus_message_iter_get_basic(&entry, &key); + + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &value); + + var = dbus_message_iter_get_arg_type(&value); + + if (!strcasecmp(key, "BCode")) { + DBusMessageIter array; + struct iovec iov = {0}; + + if (var != DBUS_TYPE_ARRAY) + return -EINVAL; + + dbus_message_iter_recurse(&value, &array); + dbus_message_iter_get_fixed_array(&array, + &iov.iov_base, + (int *)&iov.iov_len); + + if (iov.iov_len != BT_BASS_BCAST_CODE_SIZE) { + error("Invalid size for BCode: %zu != 16", + iov.iov_len); + return -EINVAL; + } + + memcpy(assistant->qos.bcast.bcode, iov.iov_base, + iov.iov_len); + + return 0; + } + + dbus_message_iter_next(&dict); + } + + return 0; +} + +static int assistant_parse_props(struct bass_assistant *assistant, + DBusMessageIter *props) +{ + DBusMessageIter value, entry, array; + const char *key; + + while (dbus_message_iter_get_arg_type(props) == DBUS_TYPE_DICT_ENTRY) { + dbus_message_iter_recurse(props, &entry); + dbus_message_iter_get_basic(&entry, &key); + + dbus_message_iter_next(&entry); + dbus_message_iter_recurse(&entry, &value); + + if (!strcasecmp(key, "Metadata")) { + struct iovec iov; + + if (dbus_message_iter_get_arg_type(&value) != + DBUS_TYPE_ARRAY) + goto fail; + + dbus_message_iter_recurse(&value, &array); + dbus_message_iter_get_fixed_array(&array, + &iov.iov_base, + (int *)&iov.iov_len); + + util_iov_free(assistant->meta, 1); + assistant->meta = util_iov_dup(&iov, 1); + DBG("Parsed Metadata"); + } else if (!strcasecmp(key, "QoS")) { + if (dbus_message_iter_get_arg_type(&value) != + DBUS_TYPE_ARRAY) + goto fail; + + if (assistant_parse_qos(assistant, &value)) + goto fail; + + DBG("Parsed QoS"); + } + + dbus_message_iter_next(props); + } + + return 0; + +fail: + DBG("Failed parsing %s", key); + + return -EINVAL; +} + static DBusMessage *push(DBusConnection *conn, DBusMessage *msg, void *user_data) { + struct bass_assistant *assistant = user_data; + struct bt_bass_bcast_audio_scan_cp_hdr hdr; + struct bt_bass_add_src_params params; + struct iovec iov = {0}; + uint32_t bis_sync = 0; + uint8_t meta_len = 0; + int err; + DBusMessageIter props, dict; + + DBG(""); + + dbus_message_iter_init(msg, &props); + + if (dbus_message_iter_get_arg_type(&props) != DBUS_TYPE_ARRAY) { + DBG("Unable to parse properties"); + return btd_error_invalid_args(msg); + } + + dbus_message_iter_recurse(&props, &dict); + + if (assistant_parse_props(assistant, &dict)) { + DBG("Unable to parse properties"); + return btd_error_invalid_args(msg); + } + + hdr.op = BT_BASS_ADD_SRC; + + if (device_get_le_address_type(assistant->device) == BDADDR_LE_PUBLIC) + params.addr_type = BT_BASS_ADDR_PUBLIC; + else + params.addr_type = BT_BASS_ADDR_RANDOM; + + bacpy(¶ms.addr, device_get_address(assistant->device)); + put_le24(assistant->bid, params.bid); + params.pa_sync = PA_SYNC_NO_PAST; + params.pa_interval = PA_INTERVAL_UNKNOWN; + params.num_subgroups = assistant->sgrp + 1; + + util_iov_append(&iov, ¶ms, sizeof(params)); + + /* Metadata and the BIS index associated with the MediaAssistant + * object will be set in the subgroup they belong to. For the other + * subgroups, no metadata and no BIS index will be provided. + */ + for (uint8_t sgrp = 0; sgrp < assistant->sgrp; sgrp++) { + util_iov_append(&iov, &bis_sync, sizeof(bis_sync)); + util_iov_append(&iov, &meta_len, sizeof(meta_len)); + } + + bis_sync = (1 << (assistant->bis - 1)); + meta_len = assistant->meta->iov_len; + + util_iov_append(&iov, &bis_sync, sizeof(bis_sync)); + util_iov_append(&iov, &meta_len, sizeof(meta_len)); + util_iov_append(&iov, assistant->meta->iov_base, + assistant->meta->iov_len); + + err = bt_bass_send(assistant->data->bass, &hdr, &iov); + if (err) { + DBG("Unable to send BASS Write Command"); + return btd_error_failed(msg, strerror(-err)); + } + + free(iov.iov_base); + + assistant_set_state(assistant, ASSISTANT_STATE_PENDING); + return g_dbus_create_reply(msg, DBUS_TYPE_INVALID); } @@ -381,6 +581,8 @@ static void bass_data_free(struct bass_data *data) bt_bass_set_user_data(data->bass, NULL); } + bt_bass_src_unregister(data->bass, data->src_id); + bt_bass_unref(data->bass); queue_remove_all(assistants, assistant_match_data, @@ -453,6 +655,93 @@ static void bass_attached(struct bt_bass *bass, void *user_data) bass_data_add(data); } +static void bass_handle_bcode_req(struct bass_assistant *assistant, int id) +{ + struct bt_bass_bcast_audio_scan_cp_hdr hdr; + struct bt_bass_set_bcast_code_params params; + struct iovec iov = {0}; + int err; + + assistant_set_state(assistant, ASSISTANT_STATE_REQUESTING); + + hdr.op = BT_BASS_SET_BCAST_CODE; + + params.id = id; + memcpy(params.bcast_code, assistant->qos.bcast.bcode, + BT_BASS_BCAST_CODE_SIZE); + + iov.iov_base = malloc0(sizeof(params)); + if (!iov.iov_base) + return; + + util_iov_push_mem(&iov, sizeof(params), ¶ms); + + err = bt_bass_send(assistant->data->bass, &hdr, &iov); + if (err) { + DBG("Unable to send BASS Write Command"); + return; + } + + free(iov.iov_base); +} + +static void bass_src_changed(uint8_t id, uint32_t bid, uint8_t enc, + uint32_t bis_sync, void *user_data) +{ + const struct queue_entry *entry; + + for (entry = queue_get_entries(assistants); entry; + entry = entry->next) { + struct bass_assistant *assistant = entry->data; + uint32_t bis = 1 << (assistant->bis - 1); + + if (assistant->bid != bid) + /* Only handle assistant objects + * that match the source + */ + continue; + + switch (enc) { + case BT_BASS_BIG_ENC_STATE_BCODE_REQ: + if (assistant->state != ASSISTANT_STATE_PENDING) + /* Only handle assistant objects that + * have been pushed by the user + */ + break; + + /* Provide Broadcast Code to peer */ + bass_handle_bcode_req(assistant, id); + break; + case BT_BASS_BIG_ENC_STATE_NO_ENC: + if (assistant->state != ASSISTANT_STATE_PENDING) + /* Only handle assistant objects that + * have been pushed by the user + */ + break; + + /* Match BIS index */ + if (bis & bis_sync) + assistant_set_state(assistant, + ASSISTANT_STATE_ACTIVE); + break; + case BT_BASS_BIG_ENC_STATE_DEC: + /* Only handle assistant objects that + * have requested a Broadcast Code + */ + if (assistant->state != ASSISTANT_STATE_REQUESTING) + break; + + /* Match BIS index */ + if (bis & bis_sync) + assistant_set_state(assistant, + ASSISTANT_STATE_ACTIVE); + break; + default: + continue; + } + } +} + static int bass_probe(struct btd_service *service) { struct btd_device *device = btd_service_get_device(service); @@ -485,6 +774,12 @@ static int bass_probe(struct btd_service *service) bass_data_add(data); bt_bass_set_user_data(data->bass, service); + /* Register callback to be called when notifications for + * Broadcast Receive State characteristics are received. + */ + data->src_id = bt_bass_src_register(data->bass, bass_src_changed, + data, NULL); + return 0; }