From patchwork Fri May 5 08:29:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 679416 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 965B3C77B7C for ; Fri, 5 May 2023 08:31:57 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231147AbjEEIb4 (ORCPT ); Fri, 5 May 2023 04:31:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33112 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231390AbjEEIbr (ORCPT ); Fri, 5 May 2023 04:31:47 -0400 Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2068.outbound.protection.outlook.com [40.107.249.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA52918FD7 for ; Fri, 5 May 2023 01:31:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=hcfXkp1IdS7aBjcARwrpjNHOT+mCGMxZ8DWAcap+hdBnsuU5QifSTKOk+Utufk9iTZmlo98Aj1mJL7Y+QvSKpKAq3iryYWMYgBIcajY1RP7SnUsWfVMy2MjZzyz9ABB27nGIWrJa2uUe13q/Ww01ga+raLTMZTTE87UuGhAcQplspszFxJ/+yN1yJj6Fv1Kv/syjhYPpsJguB+3c7FcPBR5KA9jvIucDc6Y3Zhoo9rczjbea5bSjYfthad65810pTm2S1k7IasvJEGMDAjW0ZdlgQ6A9FlQEyliUSC77udbx21w3Pdghy3uk9qL0su0rBQBlIXBdRdUfxTjYPTf8ow== 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=3c6M4NGcB0HRHi2DXB/m5rSiCFRP3Ggu00Wn6INDAro=; b=FKqkRx9uOmUKXUJxvLlQQxXES1cZliJEZ53fwo7mgQra4tEqKBQhPJPeIwSVIHAIktEnd6TVg8Mu3Rs+UU9O8j6JZ//P9qdCgJzuTSo91ge1zoYQaK1fwBsAit/4LiXET/ExyMSBePb316lsSOqnJFCQx/99k3pXEL+PWsHE+6HW7mAXkHOa67czitSha8swLDs0n9GCAHCK+5JNwLUoPN+jDHTnxtsIH6Ps8ARfMRmXLwPKzZYVXgSl1zIDRKHPMswlih1goqvkgCGjeQ/xGQ7tm8BN3eq/RCPeQ9tgSO12fjwycoC26QIqSiGUOXV1KrdV9hu3A412AxPsB9SWPg== 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=3c6M4NGcB0HRHi2DXB/m5rSiCFRP3Ggu00Wn6INDAro=; b=lEXXkH58mYbYRAkANG7yxlsv/ymHg1wZMHz+Ojfo9A+UELELxSG9c/O2/TUSZOrqh+dBTxlzdv4UHhnzW/BJISMSyB7DOkQ+HjVVqYtm4M1mCedxZdmAWi9Zh2DHZeafl5LrEumEdh1paIKCabnOuGqYso6o1KwtIeGEyazeekc= 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 AS8PR04MB8101.eurprd04.prod.outlook.com (2603:10a6:20b:3f6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.27; Fri, 5 May 2023 08:30:23 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::afb8:bb33:948f:d1e1]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::afb8:bb33:948f:d1e1%9]) with mapi id 15.20.6363.027; Fri, 5 May 2023 08:30:23 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: Iulia Tanasescu Subject: [PATCH BlueZ 1/5] lib/uuid: Add BASS UUIDs Date: Fri, 5 May 2023 11:29:39 +0300 Message-Id: <20230505082943.92033-2-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230505082943.92033-1-iulia.tanasescu@nxp.com> References: <20230505082943.92033-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AM4PR07CA0036.eurprd07.prod.outlook.com (2603:10a6:205:1::49) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|AS8PR04MB8101:EE_ X-MS-Office365-Filtering-Correlation-Id: c99f4636-204c-49d5-c259-08db4d42f8a4 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dKJXyj3x8R50bhnyjszOiQ0jb/tXDxsB+6iCaIA1XhWJ9d6YDqul/eA61sWiOO/xh44k5FsHdY4J1Vz7qTEElkXt6akZ5emCXRdDmCwxN0oP5EMIx4sA90xq6uo9Q+5wrgjHY170MvWLMAdAmxnVM01mQAqTAtVstpX8di29UfmYtWlSmNV2+GRwerGIRjvxFZt1M+RqmJDCg+je4uXEL/uC7cNw0H7QsmALWj+OkVc30SVoVe/e3LDh3a/HY1cnGNCn9sQwLkfSoP7AHRTU0h0X9fj7LMDxUK6p/6pFGyO9oNFgQ70sx8Oz9ym2VmSu6OjRzaZ9O+Ocf90rhZ/MXxy3BmnkgIrq/r4jfdr0o+kXqMR5h2E/toG1Zz7a9L9mCDOFrjR/CXpQOvqdXkB3+xzME5CSILAeCXGTEAV1keU0f9mRsDSi+H49y4hawI2BZDoXQb+6206+htz6xxcliIgHi7M3n0jvrzjgxz7wrJv14CIGPxEJhuXIFXbERq0SWazcLO/pkqHBT2aKptj6pj2O05CMcCxZvSVXTweNSKaXBKssX2Bd+YUrWLleOAP23BW1lVX0RUtybTMbALh3ZzHkCuKhICSMIZdy41awixIg2G202DkYBBoiPgXMWDX8 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:(13230028)(4636009)(396003)(39860400002)(376002)(136003)(366004)(346002)(451199021)(52116002)(6916009)(4326008)(66946007)(66556008)(66476007)(6666004)(478600001)(316002)(36756003)(86362001)(6486002)(2616005)(55236004)(6506007)(6512007)(1076003)(26005)(8676002)(5660300002)(8936002)(4744005)(44832011)(2906002)(41300700001)(38100700002)(186003)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: oKQZUGEw0p8eL+iCSIP7Ig9tX3CN1asewVIKlv38Awfjjfj/K5K1UbVjjiqGbs4XutpztoV2EzpDSy2rRgQs1WY3QJMNAL6Aq3ShPhK0eZpjNCwuAKR3yGkBPZwNkNWUWt9L3QhvnQklssxVbLFYSLVDzF4H6r1B8Pz//Q2YPTr4yuFOps6qm3dF2UbOLn75zNXnXxamJe1HT9Mz7D5x1tLR1MJCwI0+JAoaL7qq/5IN55XBL7fK0JTWamcJlZvutXPWxB9FVmdweKWdxxMgcPldjBC0NdG6Snw6w81WM/NrSDiWvDmHAXdv9i0jUIbYBYVirZutqfUJ0Xf0KHht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jY/6nYvL4evDIWDtBjnkfxLZ/f9ngOlGWxgaXqE5LuEc2YQv4j4bOKH0+4loUrrxY0I9bjhMus2/SebLZlN21mo/Eo/bzphTOdD7Ls4W2RC7Ha1BZnHHySJ0fVBTlqJcY1qSH4vl4Sdhs6mV7FO5VMywY2wOG+h/R9JnsbsyESOP3k2j77OwTatJweREIw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c99f4636-204c-49d5-c259-08db4d42f8a4 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2023 08:30:23.8594 (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: JcJ2ym6b/6Zl+ERoysprQgETI1QDUnSM38fejNaeRgqKiCjcp0zSLtSo1iZIaDdZg6aDS0uj+Q6wvYTW3C6K5Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8101 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds BASS UUIDs which will be used by Basic Audio Profile. --- lib/uuid.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/uuid.h b/lib/uuid.h index 84ff46cd8..ddde4bfa3 100644 --- a/lib/uuid.h +++ b/lib/uuid.h @@ -5,6 +5,7 @@ * * Copyright (C) 2011 Nokia Corporation * Copyright (C) 2011 Marcel Holtmann + * Copyright 2023 NXP * * */ @@ -164,6 +165,10 @@ extern "C" { #define ASE_SOURCE_UUID 0x2bc5 #define ASE_CP_UUID 0x2bc6 +#define BASS_UUID 0x184f +#define BCAST_AUDIO_SCAN_CP_UUID 0x2bc7 +#define BCAST_RECV_STATE_UUID 0x2bc8 + #define VCS_UUID 0x1844 #define VOL_OFFSET_CS_UUID 0x1845 #define AUDIO_INPUT_CS_UUID 0x1843 From patchwork Fri May 5 08:29:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 680276 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 05F99C77B7C for ; Fri, 5 May 2023 08:32:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230484AbjEEIcH (ORCPT ); Fri, 5 May 2023 04:32:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33154 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230448AbjEEIcF (ORCPT ); Fri, 5 May 2023 04:32:05 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2087.outbound.protection.outlook.com [40.107.22.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 424F0191FC for ; Fri, 5 May 2023 01:31:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ng0bynqTquRVw0d/VVNcYD7ogzAH9/ISsZ2DhT23bARCu8w1wjnCVwfDDPR159ywos6Zloa5RdZ169TR4ZLnNvv95ZCB9OVajgRWvZack26zSJwSP5YtO3Xt3d1Qr6PsbR7QGHMpIoKwwNfsmDD87gadTLmb0PPyYYy0U56ZtFJgJzgexdtDAm3YarH5E7hYRPrsaGJJ0rIo8HBhO9ZgwwaDewuz7Te5SJY5iglux8+7G8reztIH6EUIrODbiq67myTHEftLDX/2/Nj81xkA2Rd7pDr9U+qtFw6txFN9lpmQRqGvtM+Yd+j8km51NyLVHE5/AjEOUu07b0cUo5gWKg== 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=+pdkTX87giOIrwDhjQXeDQhDRzR4Q1mOAgAOmbhDLNA=; b=fme39QSue9ABekJ/oqKZ2zWWxOutJNOsFwrEE1NrhahbaKlgPd62MlaYGwjVHUgOrCTxd6W4BLHGl6FJ3fYhiGGYMWW3w5xqhaD8aFoqmN0pZROOgGj+7pUb7cmPw76ASfEf9+5qukdyXfO+2fdFWU+pgyX6b0S5Xp9+SJJea7lla56zRBODipBFZ9eDKfpImrTD26oY/mF4/mBf5W5h44KHuq9OjTaUvO/6jh5c35iE2HhLa+Er4q/aX2acMzCgscY9QxB0oXx/2BVQNiE0BO0XoATIg2XmJ8Tw6qAR4NpZITvYnO81uvjjD8nZTzWfSaNLjIa2VW8BNMGeI82plw== 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=+pdkTX87giOIrwDhjQXeDQhDRzR4Q1mOAgAOmbhDLNA=; b=CaS9B8d1HFvgx6E/6ot5CMlrD7yaQdvi6zbpJSvTBJqFvGFoZMiPUxjFvDpOwX5KkCCfv/9T6if/yc19+NyXrxODtTz5DWKmrcVXCHOqeyGjpRKUXJlf2pP8OyTCvJgrqoxdLVWjyRritDqQc4O2PXHtS9CRR8a5esclLv/t92s= 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 AS8PR04MB8101.eurprd04.prod.outlook.com (2603:10a6:20b:3f6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.27; Fri, 5 May 2023 08:30:29 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::afb8:bb33:948f:d1e1]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::afb8:bb33:948f:d1e1%9]) with mapi id 15.20.6363.027; Fri, 5 May 2023 08:30:28 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: Iulia Tanasescu Subject: [PATCH BlueZ 2/5] shared/att-types: Add BT_ERROR_WRITE_REQUEST_REJECTED error code Date: Fri, 5 May 2023 11:29:40 +0300 Message-Id: <20230505082943.92033-3-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230505082943.92033-1-iulia.tanasescu@nxp.com> References: <20230505082943.92033-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AM4PR07CA0036.eurprd07.prod.outlook.com (2603:10a6:205:1::49) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|AS8PR04MB8101:EE_ X-MS-Office365-Filtering-Correlation-Id: 69bcd736-5fac-4f47-339e-08db4d42fba9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: F5ychZcSvqQu/dg0THTjTxy7UKiZ6FGNqUqfCQucDJLnesSTlLA09VH7J51QYvuvqOW5q/QVgBhit//8pLDUZurWaYfrXX7/lDx790OdPG62gkhvyx9DCzcRM44EVBtNydyU8gsh3zWLcKVyQKQmFotWcfD5aADme5GQYcQUXNnlFC6aHetBRZsESzpmJU5/sVDbFmCx+AdnS3BlJ+Za7dQvgWjqa8YmO5y/+PyRaXg/sS0tuuEu7sM+3/NePQvHumpHBvQ8OQKPJetCnqEpGQ6ghr+Sg5S8MnZcJBlN4t2OFsFcR4j9A8supu6eZ+eSPIRpDd2n919B2JQ2HtoOTS1xn76eJ4M5VBitHYbQiL2MR85zUHkD6rQPnDt0ta9G3D9ZrwuLLgp9mmsjucLCL4yDk3s05S72vnitzL2U7QoGHPTqzSvFinv5iPrU9GU4KtbapTAObpQyjLw5eJaZNuccEUIPVm2Z8pD1WJhJDHSLz3giPO3JTiPxY+fO3i3WrglaDbRD0hw0k7Bskh+FM0s6kXhEHFUVcxrvFKWaNLtQbViri3yXcisXz63/LfLwCS/bdmOTyOYeU9O7zVSgClOZ1UQYz2wmV7sCyGHqWv+kXgZRoMTzGqyMXnxy8ufi 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:(13230028)(4636009)(396003)(39860400002)(376002)(136003)(366004)(346002)(451199021)(52116002)(6916009)(4326008)(66946007)(66556008)(66476007)(6666004)(478600001)(316002)(36756003)(86362001)(6486002)(83380400001)(2616005)(55236004)(6506007)(6512007)(1076003)(26005)(8676002)(5660300002)(8936002)(4744005)(44832011)(2906002)(41300700001)(38100700002)(186003)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: YWIP6Gn9GBU9++6z4emVDrR9bTzjb3uZevLrrvU1/pawk/mBjoGBtXQYIMqhI2Fb6fOBChkikk863DscH5GZHpTi6FTttkLesCgxgJi9oQ/mGjR211khgI1BDGSh7UGFN7OpLem75NOAXtsd+rOoiqMt2YgdZ3xjqBp1jgWSD4P5ytg+LoXmfgB6VdnbZj/3co7taxjSB/CICPbBGG2WTCyV18WPwy0wlWxmvj6FXUAK9aH2xQkmVK45CWRCbV7/Nc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DSrRqNUjzuRmtp4k3fWSYpzjL2acKV8AZ89Lo+/e1msDLDEFhsU9VUTN+Dzlfw1uvmN1YJlotKa3Tml+s5ca5DE6jIrZtEpTUXf1V9hFWvNI0g/GxC6GwbJBWDYtrm16+L+ijq5TT0FfY+4rwdtfvcLFtIpzNk+l9530BihtscdFUA7+fj+AppPq0ZRI7U/PUHhQO+ev993aJsj6KpdpfRrdLJwzB4bms72VnZH6bBmkhM2mKVFTqL4BUSP9ILO+sM7LQoNvU8PpG4KHRahEO9RTyxxK+DFfK/iNevfWA2XC7YxcwzYRhQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 69bcd736-5fac-4f47-339e-08db4d42fba9 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2023 08:30:28.9209 (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: aLwWAjSTng9Dnaf+RyI4HBvbF6GXApexCD7H9JZ9fY+kTPYUJa091M1pGI+RokGttq3DD7t0rQDv7criB3Hbiw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8101 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds Write Request Rejected Common Profile and Service Error Code. --- src/shared/att-types.h | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/shared/att-types.h b/src/shared/att-types.h index a08b24155..69f45b6aa 100644 --- a/src/shared/att-types.h +++ b/src/shared/att-types.h @@ -4,6 +4,7 @@ * BlueZ - Bluetooth protocol stack for Linux * * Copyright (C) 2014 Google Inc. + * Copyright 2023 NXP * * */ @@ -101,9 +102,10 @@ struct bt_att_pdu_error_rsp { /* * Common Profile and Service Error Code descriptions (see Supplement to the * Bluetooth Core Specification, sections 1.2 and 2). The error codes within - * 0xE0-0xFC are reserved for future use. The remaining 3 are defined as the + * 0xE0-0xFB are reserved for future use. The remaining 4 are defined as the * following: */ +#define BT_ERROR_WRITE_REQUEST_REJECTED 0xfc #define BT_ERROR_CCC_IMPROPERLY_CONFIGURED 0xfd #define BT_ERROR_ALREADY_IN_PROGRESS 0xfe #define BT_ERROR_OUT_OF_RANGE 0xff From patchwork Fri May 5 08:29:41 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 680275 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 46653C77B75 for ; Fri, 5 May 2023 08:32:19 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230448AbjEEIcQ (ORCPT ); Fri, 5 May 2023 04:32:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57884 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229789AbjEEIcP (ORCPT ); Fri, 5 May 2023 04:32:15 -0400 Received: from EUR04-VI1-obe.outbound.protection.outlook.com (mail-vi1eur04on0628.outbound.protection.outlook.com [IPv6:2a01:111:f400:fe0e::628]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 883A518DC3 for ; Fri, 5 May 2023 01:32:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=k5vNMLWne2dnz/szezrWRspGYKqBOMbAsmxxOw01bcCJRBW2Ov4VOpz8M0E7hCExoizGuUYDPlvbAF4qyIRZugsCZdhdGfcFayZ+H8OpBBVNSuP6oezHl/HMwMh6jN5wdX0Wl5z0BhHqqzQrV9OmrSjQhPU7Ddj1H6BLrSFUQReZWnBNKig+Rye87T2XfXCK43giLtIxYwdIUiyaov4KZX92XyjJuIdpyRDxT8XcBeonHI3Y4sWyqMxn2eGXXl/RAOOALUFbyyTJgZmGqcdc5/MAP8zjXLDK5wSdibbwiqArhbU+OXO9ICqu8N2Vam2+sZ7IMnLbPkGi2g1Qocp1AA== 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=xUxK6Xl5KFDUyCR9bSXzDY1SgDCIv08OlXJE/3mET7c=; b=NXOLqliMgI7QCnWLpof0RMyhzPXTdGXVfzLPeG4MQ1PVcPZS2sM4mBKvw0fN0BHQnqjlBPvbR41W2iOnelFuxIhSMGZskGpDm/4KHtHKNsynLMKyBEJqjXQpZHk1ItgZ1TTXeYzLSAOGAAEdI2Atwnt85S9VUxrBFHTmejg2MlbIUO9OLHQLntU9k05wIzECtZJBZF9ogg8pu9ZbYxZgp6tTI4mlmAcBQzwQMtUxyqgaLsgAQiUtEvjStjGcuXUYcNuZr565hbaAzFkZOR3qV0m3z/ag6o2AfPvY8aqDQsvJcqpi+N1vrET1gx/5O8vxjKyaQBsOoL24+rS/tD6ekA== 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=xUxK6Xl5KFDUyCR9bSXzDY1SgDCIv08OlXJE/3mET7c=; b=JX4GEIbjL6khNkH0VKPVHMvNShA+w9HLLrMWj38DLJQ0Dlz3FkdwNnKz0/DfMBPNFPEdcOplR59ehveTGP/cHo1Rp/qVITOPrA/E+Nlicr54S4zGChADhSNooTXlk9Yga97q5ngR53riJeCF2e0Ih2sCn8DtCTG2HOKwa1CBi5k= 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 AS8PR04MB8101.eurprd04.prod.outlook.com (2603:10a6:20b:3f6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.27; Fri, 5 May 2023 08:30:32 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::afb8:bb33:948f:d1e1]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::afb8:bb33:948f:d1e1%9]) with mapi id 15.20.6363.027; Fri, 5 May 2023 08:30:32 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: Iulia Tanasescu Subject: [PATCH BlueZ 3/5] shared/util: Add iovec helpers for pulling/pushing le32 and le24 values Date: Fri, 5 May 2023 11:29:41 +0300 Message-Id: <20230505082943.92033-4-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230505082943.92033-1-iulia.tanasescu@nxp.com> References: <20230505082943.92033-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AM4PR07CA0036.eurprd07.prod.outlook.com (2603:10a6:205:1::49) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|AS8PR04MB8101:EE_ X-MS-Office365-Filtering-Correlation-Id: 7ba2263e-5044-4382-5e3c-08db4d42fd48 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: wyIix3IpEjkx4QkdPTOxS4IycklQfB7VXM2OALhXiawDBkPFUNKbBDjswvewRue/vMVCuMFB/quAf54U95kpm7NW4Bc3Z3IWW0IzpnptGX0+Y4UxbTJ94yYo+X4DG0r6UqPoZky+uJ5N+RZPg5/26zdh1tOT64LwFCTCRwkcy+uICeAHX/HagBDUIfCP1/oseq53kHfQHco7zhY0N7gwVlTN+aXz5/S+w2YgHGRUXINwdxr9o6zo5EwWXBjQAxp06FOps2ilvskfSucZGZZLeJy+4IcYKDcq8nHAM78QJxI3YV1zgdtDUmJ3npCmLR7P1Kurld13OuhEtQNkPzCqgD4/bwzRGYT+L1j02Ck20oW3dzJ+oTfKLa7KFmL9AnGO9mjz9ljDaTr6lCfn+mhbW4MZT0/+vDnb1i2XhcN24sGpKQ4csiLET0vMQ7UObMc26O0CwGSdSmHTpjs8xWqkhr8Rgj3yEYk7jkagSY3XKS4JX6MwEZc8rBXmH4mgh6f63SqKZbAUiY6aWmknPuw5Xmx/DMuuZ0Qkky/aeQqbt+zlpNI2dkwbThwkmj1CpoSYMSnkXUIl5SOEdJ175vhpKo+LIjsCTZSwm5UOvP0BpyaKCm7Z+2Cvlp3x89Wq6B9t 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:(13230028)(4636009)(396003)(39860400002)(376002)(136003)(366004)(346002)(451199021)(52116002)(6916009)(4326008)(66946007)(66556008)(66476007)(6666004)(478600001)(316002)(36756003)(86362001)(6486002)(2616005)(55236004)(6506007)(6512007)(1076003)(26005)(8676002)(5660300002)(8936002)(44832011)(2906002)(41300700001)(38100700002)(186003)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ge13dI7c73lYaQofkhutVWKoz1mcmtLu8J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ZXfOHSrLKWTSEB1/shzsG4dpsjH56KBQXESjbknzW+oc1pKUhlcHqnz9G1Enz1ndWwB2M18VDONn7y7bOQy+KvUonCHWVcjbzKWMB2+QUG2/74wECEhFziIiaCBFlEysKtAeeZyzC0YmB0I/0bSig58T8rSAdZFgM5ISvRyVNeU5oymxeiAnvRA7APjK9kHxmDGs7pDbwfS0rgGtPDy7mL5xyf3JE99iEnMRrV8g0jNorHcRoVK9eDDDGs+uAY7l0ZAlmwKaVmjF3cm5DcsLXBqPVSukkpaiu5MIhbXlPmwRw5t0efiDwNzyayx8oC/tr+2PX9I51rnJbdg494aF5x8NfcPVDA4oZQSAgDdZxprnbkz9CZBo5f5C2Z3esHpKm0q9HLYBVLNzEZY9VUWFkts/JWgXeJAqcdYtAMVVoR1S1hj2jczGLQLr6ADYeNyTo4r9YtR9ri5COyAZ//DYGfoVE2ybxsEcVDNwHMSMf1/LGj+XzKw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7ba2263e-5044-4382-5e3c-08db4d42fd48 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2023 08:30:32.6367 (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: 77UAGm7EIQo6tjZ4RFItWNg5FlK2PXuDXEDanjoGHeGxruQprxuAa3WpZHYrcJQuT4y0xI9P/CqQEC428joHbg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8101 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds iovec helper functions for handling le32 and le24 values. --- src/shared/util.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++ src/shared/util.h | 5 +++++ 2 files changed, 58 insertions(+) diff --git a/src/shared/util.c b/src/shared/util.c index 9a4a8d77a..f9d8ecbaa 100644 --- a/src/shared/util.c +++ b/src/shared/util.c @@ -4,6 +4,7 @@ * BlueZ - Bluetooth protocol stack for Linux * * Copyright (C) 2012-2014 Intel Corporation. All rights reserved. + * Copyright 2023 NXP * * */ @@ -28,6 +29,8 @@ #include #endif +#include + /* define MAX_INPUT for musl */ #ifndef MAX_INPUT #define MAX_INPUT _POSIX_MAX_INPUT @@ -274,6 +277,32 @@ void *util_iov_push_mem(struct iovec *iov, size_t len, const void *data) return p; } +void *util_iov_push_le32(struct iovec *iov, uint32_t val) +{ + void *p; + + p = util_iov_push(iov, sizeof(uint32_t)); + if (!p) + return NULL; + + put_le32(val, p); + + return p; +} + +void *util_iov_push_le24(struct iovec *iov, uint32_t val) +{ + void *p; + + p = util_iov_push(iov, sizeof(uint24_t)); + if (!p) + return NULL; + + put_le24(val, p); + + return p; +} + void *util_iov_pull(struct iovec *iov, size_t len) { if (!iov) @@ -298,6 +327,30 @@ void *util_iov_pull_mem(struct iovec *iov, size_t len) return NULL; } +void *util_iov_pull_le32(struct iovec *iov, uint32_t *val) +{ + void *data = iov->iov_base; + + if (util_iov_pull(iov, sizeof(uint32_t))) { + *val = get_le32(data); + return data; + } + + return NULL; +} + +void *util_iov_pull_le24(struct iovec *iov, uint32_t *val) +{ + void *data = iov->iov_base; + + if (util_iov_pull(iov, sizeof(uint24_t))) { + *val = get_le24(data); + return data; + } + + return NULL; +} + static const struct { uint16_t uuid; const char *str; diff --git a/src/shared/util.h b/src/shared/util.h index dc84f9635..b99a959b8 100644 --- a/src/shared/util.h +++ b/src/shared/util.h @@ -4,6 +4,7 @@ * BlueZ - Bluetooth protocol stack for Linux * * Copyright (C) 2012-2014 Intel Corporation. All rights reserved. + * Copyright 2023 NXP * * */ @@ -115,8 +116,12 @@ int util_iov_memcmp(const struct iovec *iov1, const struct iovec *iov2); void util_iov_memcpy(struct iovec *iov, void *src, size_t len); void *util_iov_push(struct iovec *iov, size_t len); void *util_iov_push_mem(struct iovec *iov, size_t len, const void *data); +void *util_iov_push_le32(struct iovec *iov, uint32_t val); +void *util_iov_push_le24(struct iovec *iov, uint32_t val); void *util_iov_pull(struct iovec *iov, size_t len); void *util_iov_pull_mem(struct iovec *iov, size_t len); +void *util_iov_pull_le32(struct iovec *iov, uint32_t *val); +void *util_iov_pull_le24(struct iovec *iov, uint32_t *val); void util_iov_free(struct iovec *iov, size_t cnt); const char *bt_uuid16_to_str(uint16_t uuid); From patchwork Fri May 5 08:29:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 679415 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 444F0C77B7C for ; Fri, 5 May 2023 08:32:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231156AbjEEIcL (ORCPT ); Fri, 5 May 2023 04:32:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58822 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230448AbjEEIcI (ORCPT ); Fri, 5 May 2023 04:32:08 -0400 Received: from EUR02-DB5-obe.outbound.protection.outlook.com (mail-db5eur02on2068.outbound.protection.outlook.com [40.107.249.68]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AA76917DD1 for ; Fri, 5 May 2023 01:31:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=WrJ3h9tya9Ts/bHTIWC1rzgg8Vj1UsNo+T4QIJP2XSJV/amaWp+atHiuaoZAHC8BDhvvtLIPEU5352XEWKI7Z/QSd/BadlsS1uSjqQErcWSpFhSeGzJ5iYTXIG2b01jq212MRePfwDe+4QG4umuFFYYZ7/0jY9fYaNUTD3jhefXLd85vOK3kQ1qnsTiJTonj6jIPUhybaD9tpHvqTvx2poVfo7+mu1q/EyBQRdwMUTHpqMp0ePAGtKSgocAdnvuC/qTMMpiDbYt8YdYnyhKLWI1eUPTaaGiOcc6Se0hoHVCWM9msfLIW4+zOEZKUK9WNEZHnLTHn8jtThKpQsLShjQ== 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=QQqT7e2djAxAFfALLsy66t3E024TB7y4jIkIGbOVdls=; b=K7uDIlOrZNmaUiiyPb3y6Nqe3UvRteXo5bQ0D1UAhre84G1iSV2vJl3egreqay3y+CZwTMLyfXg1h1bx3aucXwpDhc5hC+DpiNu0EcteVAp8QyJ6aEZP5v5kn5S59qz6fGaBwMhSoCjabQ2yegBjEK24KhQt7lvLQ+vUhHI4k7MZw6Lgbk3GZwjnv77wJqyCcfcXNJ2p7FCSbpLcDZEycFTiRaTFPDqohHSv06asVRVuYTIRedGHzszxo2uWmNuGZOlagQqsN5DRC3FYy58149sxEEfRc2ZNHe6zWmVDq8bsROduXBJc0Okp8nNLPmBJXry3gZanb3aJwl18wRebjA== 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=QQqT7e2djAxAFfALLsy66t3E024TB7y4jIkIGbOVdls=; b=NAPg8k3rAqP1J29TwsxAsicQYlaDhRIhrUiZK6nZ3pUYtmK3W5sropjS2+eSxmCYL2NOLhD+D4C8j1zl677qmgKYs2FZHA7KuG095hJiDhOZBLXGL3dHJ3i3b3Jw/Gxe4dntdTCVaD8pLvSnWLhO3g+Fx+tt/7cMjWDbJ38oFa8= 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 AS8PR04MB8101.eurprd04.prod.outlook.com (2603:10a6:20b:3f6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.27; Fri, 5 May 2023 08:30:37 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::afb8:bb33:948f:d1e1]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::afb8:bb33:948f:d1e1%9]) with mapi id 15.20.6363.027; Fri, 5 May 2023 08:30:37 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: Iulia Tanasescu Subject: [PATCH BlueZ 4/5] shared/bass: Add initial code for handling BASS Date: Fri, 5 May 2023 11:29:42 +0300 Message-Id: <20230505082943.92033-5-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230505082943.92033-1-iulia.tanasescu@nxp.com> References: <20230505082943.92033-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AM4PR07CA0036.eurprd07.prod.outlook.com (2603:10a6:205:1::49) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|AS8PR04MB8101:EE_ X-MS-Office365-Filtering-Correlation-Id: c22572f1-e1dc-42b6-181a-08db4d42ff47 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: Xi7IrWaraZv1uNffcoH7eKRDxkpt1k2L+OXN3krdxDELqpSZQHrirmhKnDd2Y8edKpymBMLuJjJr6i9TRfCwFH2AwmGEU9mAJdV7f4ThMloldUGtWZ1xWPtiLQZ6YFgS6gAlGShl1oKZyFYmyD1u2AvDaIyj9JGCeCBe5Mc7EksLlihoFW0pRgiuDvtyUwkRQoDNmQcDPJWSEQ6hghC8AB7kjpG8QVCp28B6YZNV2ur8kUIFKYd5CofBlk0i1ldV6KzuJIeYTjhgZxNr1H/aJajYouxOZOLEnV3mFcaO+SvWU34C2MTY2y9IFDN7CL6DGYQ8XGRu9QcNdV+3bEBC7rfzmCp6HUkY/vxUAm6nc7Z0Y80rXmc3dyY1xLQ2wULaUD3iKlWaq/MRNlB4GIfdaY96h5egTGv4sbNaOaKb7VsJ5vM3r+MzlVq6nQ3ToDlgFRFq2/+x3VfoojqfNK/DNHK6ZWhF6cvKB8cVgcf/NWYsotoH0cFZbShBQFH/2HsvacMP7O+vHE39nj5lOX+kgeBb1Biy7n1LvxNFxtTUpPLCLN/9NBCyzOv2S4xMMUO8Hs2BpWq3nI8xNrWPxTJrg1DHrLvzCvXmS4BKrsDyW5PBVjlOjubkjsLjlvtl+EJl 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:(13230028)(4636009)(396003)(39860400002)(376002)(136003)(366004)(346002)(451199021)(52116002)(6916009)(4326008)(66946007)(66556008)(66476007)(6666004)(478600001)(316002)(36756003)(86362001)(6486002)(83380400001)(2616005)(55236004)(6506007)(6512007)(1076003)(26005)(8676002)(5660300002)(8936002)(44832011)(2906002)(30864003)(41300700001)(38100700002)(186003)(38350700002); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gWw06W2o5E9astvH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uB8Z5DQ+EnzBNUn7W5IBUMcsRxGNRHi4VSvbKiTGFSmyNuEGvGvbbWtiakk7MfBI+Az7pONkutv7ILGcVw7riJjnBvTt2oHz8833ae3DVWgU/dJtJVkwftj2997y+U/O9q3PooFjKprMJLDHVP1bRC8lRVGpcUOPT2FF6vP8NMU109RhLTJNvLADXpRww3mcnq32aimv2wleIvZMIvYHfS4dbedmm0+C1+6CKbhGjaJzGKFybFYWDvd7JeToFxs5gIEuCR8qiZT8sR402jbQvnO9N6mS6jHwO93NGxy8j1XIhSl3zD90z9w6NQMVQhYJ2TTXC5EpZG2XdE83/B9gerahmHizOuKbuxGYDN335x9Zwz7WiCgbPdLsBof2DH3Lzr1guG/5YhRGtZRY8g6EOdzmnIHx4fGM7v3dups2WO/cmONTGDGOEklnFrgLWLxDfivbgiP9imqgrSbcSrblAJhqaIfXe7yyot3nF0jYZTwXgKXYgIxOYOOydxjaXYGWoLu80x1qRbN+nlxNsO1UmSXcfVLA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c22572f1-e1dc-42b6-181a-08db4d42ff47 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2023 08:30:37.5027 (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: 9fMarnYhIkdl4ev9I9vZcGv+sN/6uOi1qzZkZQUq75c/cO4K38Cq+oBitBtpuYsj+P5/L6/cklMK9JqN7YDSvA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8101 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds initial code for Broadcast Audio Scan Service. --- Makefile.am | 1 + src/shared/bass.c | 1012 +++++++++++++++++++++++++++++++++++++++++++++ src/shared/bass.h | 122 ++++++ 3 files changed, 1135 insertions(+) create mode 100644 src/shared/bass.c create mode 100644 src/shared/bass.h diff --git a/Makefile.am b/Makefile.am index 7ded3ba75..48f0cefa7 100644 --- a/Makefile.am +++ b/Makefile.am @@ -234,6 +234,7 @@ shared_sources = src/shared/io.h src/shared/timeout.h \ src/shared/mcs.h src/shared/mcp.h src/shared/mcp.c \ src/shared/vcp.c src/shared/vcp.h \ src/shared/csip.c src/shared/csip.h \ + src/shared/bass.h src/shared/bass.c \ src/shared/lc3.h src/shared/tty.h if READLINE diff --git a/src/shared/bass.c b/src/shared/bass.c new file mode 100644 index 000000000..fd4f28ac5 --- /dev/null +++ b/src/shared/bass.c @@ -0,0 +1,1012 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright 2023 NXP + * + */ + +#define _GNU_SOURCE +#include +#include +#include +#include +#include +#include + +#include "lib/bluetooth.h" +#include "lib/uuid.h" + +#include "src/shared/queue.h" +#include "src/shared/util.h" +#include "src/shared/att.h" +#include "src/shared/gatt-db.h" +#include "src/shared/gatt-client.h" +#include "src/shared/bass.h" + +#define DBG(_bass, fmt, arg...) \ + bass_debug(_bass, "%s:%s() " fmt, __FILE__, __func__, ## arg) + +struct bt_bass_db; + +struct bt_bass_cb { + unsigned int id; + bt_bass_func_t attached; + bt_bass_func_t detached; + void *user_data; +}; + +struct bt_bcast_recv_state { + struct bt_bass_db *bdb; + struct gatt_db_attribute *attr; + struct gatt_db_attribute *ccc; +}; + +struct bt_bass_db { + struct gatt_db *db; + struct queue *bcast_srcs; + struct gatt_db_attribute *service; + struct gatt_db_attribute *bcast_audio_scan_cp; + struct bt_bcast_recv_state *bcast_recv_states[NUM_BCAST_RECV_STATES]; +}; + +struct bt_bass { + int ref_count; + struct bt_bass_db *ldb; + struct bt_bass_db *rdb; + struct bt_gatt_client *client; + struct bt_att *att; + + struct queue *notify; + + bt_bass_debug_func_t debug_func; + bt_bass_destroy_func_t debug_destroy; + void *debug_data; + + void *user_data; +}; + +typedef void (*bass_notify_t)(struct bt_bass *bass, uint16_t value_handle, + const uint8_t *value, uint16_t length, + void *user_data); + +struct bt_bass_notify { + unsigned int id; + struct bt_bass *bass; + bass_notify_t func; + void *user_data; +}; + +static struct queue *bass_db; +static struct queue *bass_cbs; +static struct queue *sessions; + +static void bass_debug(struct bt_bass *bass, const char *format, ...) +{ + va_list ap; + + if (!bass || !format || !bass->debug_func) + return; + + va_start(ap, format); + util_debug_va(bass->debug_func, bass->debug_data, format, ap); + va_end(ap); +} + +static int +bass_build_bcast_src_from_notif(struct bt_bcast_src *bcast_src, + const uint8_t *value, uint16_t length) +{ + struct bt_bass_subgroup_data *subgroup_data = NULL; + uint8_t *id; + uint8_t *addr_type; + uint8_t *addr; + uint8_t *sid; + uint32_t bid; + uint8_t *pa_sync_state; + uint8_t *enc; + uint8_t *bad_code = NULL; + uint8_t *num_subgroups; + uint32_t bis_sync_state; + uint8_t *meta_len; + uint8_t *meta; + + struct iovec iov = { + .iov_base = (void *) value, + .iov_len = length, + }; + + /* Extract all fields from notification */ + id = util_iov_pull_mem(&iov, sizeof(*id)); + if (!id) { + DBG(bcast_src->bass, "Unable to parse Broadcast Receive State"); + return -1; + } + + addr_type = util_iov_pull_mem(&iov, sizeof(*addr_type)); + if (!addr_type) { + DBG(bcast_src->bass, "Unable to parse Broadcast Receive State"); + return -1; + } + + addr = util_iov_pull_mem(&iov, sizeof(bdaddr_t)); + if (!addr) { + DBG(bcast_src->bass, "Unable to parse Broadcast Receive State"); + return -1; + } + + sid = util_iov_pull_mem(&iov, sizeof(*sid)); + if (!sid) { + DBG(bcast_src->bass, "Unable to parse Broadcast Receive State"); + return -1; + } + + if (!util_iov_pull_le24(&iov, &bid)) { + DBG(bcast_src->bass, "Unable to parse Broadcast Receive State"); + return -1; + } + + pa_sync_state = util_iov_pull_mem(&iov, sizeof(*pa_sync_state)); + if (!pa_sync_state) { + DBG(bcast_src->bass, "Unable to parse Broadcast Receive State"); + return -1; + } + + enc = util_iov_pull_mem(&iov, sizeof(*enc)); + if (!enc) { + DBG(bcast_src->bass, "Unable to parse Broadcast Receive State"); + return -1; + } + + if (*enc == BT_BASS_BIG_ENC_STATE_BAD_CODE) { + bad_code = util_iov_pull_mem(&iov, BT_BASS_BCAST_CODE_SIZE); + if (!bad_code) { + DBG(bcast_src->bass, "Unable to parse " + "Broadcast Receive State"); + return -1; + } + } + + num_subgroups = util_iov_pull_mem(&iov, sizeof(*num_subgroups)); + if (!num_subgroups) { + DBG(bcast_src->bass, "Unable to parse Broadcast Receive State"); + return -1; + } + + if (*num_subgroups == 0) + goto done; + + subgroup_data = malloc((*num_subgroups) * sizeof(*subgroup_data)); + if (!subgroup_data) { + DBG(bcast_src->bass, "Unable to allocate memory"); + return -1; + } + + memset(subgroup_data, 0, (*num_subgroups) * sizeof(*subgroup_data)); + + for (int i = 0; i < *num_subgroups; i++) { + if (!util_iov_pull_le32(&iov, &bis_sync_state)) { + DBG(bcast_src->bass, "Unable to parse " + "Broadcast Receive State"); + + for (int j = 0; j < i; j++) + free(subgroup_data[j].meta); + + free(subgroup_data); + return -1; + } + + subgroup_data[i].bis_sync = bis_sync_state; + + meta_len = util_iov_pull_mem(&iov, sizeof(*meta_len)); + if (!meta_len) { + DBG(bcast_src->bass, "Unable to parse " + "Broadcast Receive State"); + + for (int j = 0; j < i; j++) + free(subgroup_data[j].meta); + + free(subgroup_data); + return -1; + } + + subgroup_data[i].meta_len = *meta_len; + + if (*meta_len == 0) + continue; + + subgroup_data[i].meta = malloc(*meta_len); + if (!subgroup_data[i].meta) { + DBG(bcast_src->bass, "Unable to allocate memory"); + + for (int j = 0; j < i; j++) + free(subgroup_data[j].meta); + + free(subgroup_data); + return -1; + } + + meta = util_iov_pull_mem(&iov, *meta_len); + if (!meta) { + DBG(bcast_src->bass, "Unable to parse " + "Broadcast Receive State"); + + for (int j = 0; j < i; j++) + free(subgroup_data[j].meta); + + free(subgroup_data); + return -1; + } + + memcpy(subgroup_data[i].meta, meta, *meta_len); + } + +done: + /* + * If no errors occurred, copy extracted fields into + * the broadcast source structure + */ + if (bcast_src->subgroup_data) { + for (int i = 0; i < bcast_src->num_subgroups; i++) + free(bcast_src->subgroup_data[i].meta); + + free(bcast_src->subgroup_data); + } + + bcast_src->id = *id; + bcast_src->addr_type = *addr_type; + memcpy(&bcast_src->addr, addr, sizeof(bdaddr_t)); + bcast_src->sid = *sid; + bcast_src->bid = bid; + bcast_src->sync_state = *pa_sync_state; + bcast_src->enc = *enc; + + if (*enc == BT_BASS_BIG_ENC_STATE_BAD_CODE) + memcpy(bcast_src->bad_code, bad_code, BT_BASS_BCAST_CODE_SIZE); + else + memset(bcast_src->bad_code, 0, BT_BASS_BCAST_CODE_SIZE); + + bcast_src->num_subgroups = *num_subgroups; + + bcast_src->subgroup_data = subgroup_data; + + return 0; +} + +static int +bass_build_bcast_src_from_read_rsp(struct bt_bcast_src *bcast_src, + const uint8_t *value, uint16_t length) +{ + return bass_build_bcast_src_from_notif(bcast_src, value, length); +} + +static uint8_t *bass_build_notif_from_bcast_src(struct bt_bcast_src *bcast_src, + size_t *notif_len) +{ + size_t len = 0; + uint8_t *notif = NULL; + struct iovec iov; + + *notif_len = 0; + + if (!bcast_src) + return NULL; + + len = BT_BASS_BCAST_SRC_LEN + bcast_src->num_subgroups * + BT_BASS_BCAST_SRC_SUBGROUP_LEN; + + if (bcast_src->enc == BT_BASS_BIG_ENC_STATE_BAD_CODE) + len += BT_BASS_BCAST_CODE_SIZE; + + for (size_t i = 0; i < bcast_src->num_subgroups; i++) { + /* Add length for subgroup metadata */ + len += bcast_src->subgroup_data[i].meta_len; + } + + notif = malloc(len); + if (!notif) + return NULL; + + memset(notif, 0, len); + + iov.iov_base = notif; + iov.iov_len = 0; + + util_iov_push_mem(&iov, sizeof(bcast_src->id), + &bcast_src->id); + util_iov_push_mem(&iov, sizeof(bcast_src->addr_type), + &bcast_src->addr_type); + util_iov_push_mem(&iov, sizeof(bcast_src->addr), + &bcast_src->addr); + util_iov_push_mem(&iov, sizeof(bcast_src->sid), + &bcast_src->sid); + util_iov_push_le24(&iov, bcast_src->bid); + util_iov_push_mem(&iov, sizeof(bcast_src->sync_state), + &bcast_src->sync_state); + util_iov_push_mem(&iov, sizeof(bcast_src->enc), + &bcast_src->enc); + + if (bcast_src->enc == BT_BASS_BIG_ENC_STATE_BAD_CODE) + util_iov_push_mem(&iov, sizeof(bcast_src->bad_code), + bcast_src->bad_code); + + util_iov_push_mem(&iov, sizeof(bcast_src->num_subgroups), + &bcast_src->num_subgroups); + + for (size_t i = 0; i < bcast_src->num_subgroups; i++) { + /* Add subgroup bis_sync */ + util_iov_push_le32(&iov, bcast_src->subgroup_data[i].bis_sync); + + /* Add subgroup meta_len */ + util_iov_push_mem(&iov, + sizeof(bcast_src->subgroup_data[i].meta_len), + &bcast_src->subgroup_data[i].meta_len); + + /* Add subgroup metadata */ + if (bcast_src->subgroup_data[i].meta_len > 0) + util_iov_push_mem(&iov, + bcast_src->subgroup_data[i].meta_len, + bcast_src->subgroup_data[i].meta); + } + + *notif_len = len; + return notif; +} + +static uint8_t * +bass_build_read_rsp_from_bcast_src(struct bt_bcast_src *bcast_src, + size_t *rsp_len) +{ + return bass_build_notif_from_bcast_src(bcast_src, rsp_len); +} + +static bool bass_check_cp_command_subgroup_data_len(uint8_t num_subgroups, + struct iovec *iov) +{ + uint32_t bis_sync_state; + uint8_t *meta_len; + uint8_t *meta; + + for (int i = 0; i < num_subgroups; i++) { + if (!util_iov_pull_le32(iov, &bis_sync_state)) + return false; + + meta_len = util_iov_pull_mem(iov, + sizeof(*meta_len)); + if (!meta_len) + return false; + + meta = util_iov_pull_mem(iov, *meta_len); + if (!meta) + return false; + } + + return true; +} + +static bool bass_check_cp_command_len(struct iovec *iov) +{ + struct bt_bass_bcast_audio_scan_cp_hdr *hdr; + union { + struct bt_bass_add_src_params *add_src_params; + struct bt_bass_mod_src_params *mod_src_params; + struct bt_bass_set_bcast_code_params *set_bcast_code_params; + struct bt_bass_remove_src_params *remove_src_params; + } params; + + /* Get command header */ + hdr = util_iov_pull_mem(iov, sizeof(*hdr)); + + if (!hdr) + return false; + + /* Check command parameters */ + switch (hdr->op) { + case BT_BASS_ADD_SRC: + params.add_src_params = util_iov_pull_mem(iov, + sizeof(*params.add_src_params)); + if (!params.add_src_params) + return false; + + if (!bass_check_cp_command_subgroup_data_len( + params.add_src_params->num_subgroups, + iov)) + return false; + + break; + case BT_BASS_MOD_SRC: + params.mod_src_params = util_iov_pull_mem(iov, + sizeof(*params.mod_src_params)); + if (!params.mod_src_params) + return false; + + if (!bass_check_cp_command_subgroup_data_len( + params.mod_src_params->num_subgroups, + iov)) + return false; + + break; + case BT_BASS_SET_BCAST_CODE: + params.set_bcast_code_params = util_iov_pull_mem(iov, + sizeof(*params.set_bcast_code_params)); + if (!params.set_bcast_code_params) + return false; + + break; + case BT_BASS_REMOVE_SRC: + params.remove_src_params = util_iov_pull_mem(iov, + sizeof(*params.remove_src_params)); + if (!params.remove_src_params) + return false; + + break; + case BT_BASS_REMOTE_SCAN_STOPPED: + case BT_BASS_REMOTE_SCAN_STARTED: + break; + default: + return true; + } + + if (iov->iov_len > 0) + return false; + + return true; +} + +static void bass_bcast_audio_scan_cp_write(struct gatt_db_attribute *attrib, + unsigned int id, uint16_t offset, + const uint8_t *value, size_t len, + uint8_t opcode, struct bt_att *att, + void *user_data) +{ + struct iovec iov = { + .iov_base = (void *)value, + .iov_len = len, + }; + + /* Validate written command length */ + if (!bass_check_cp_command_len(&iov)) { + if (opcode == BT_ATT_OP_WRITE_REQ) { + gatt_db_attribute_write_result(attrib, id, + BT_ERROR_WRITE_REQUEST_REJECTED); + } + return; + } + + /* TODO: Implement handlers for the written opcodes */ + gatt_db_attribute_write_result(attrib, id, + BT_BASS_ERROR_OPCODE_NOT_SUPPORTED); +} + +static bool bass_src_match_attrib(const void *data, const void *match_data) +{ + const struct bt_bcast_src *bcast_src = data; + const struct gatt_db_attribute *attr = match_data; + + return (bcast_src->attr == attr); +} + +static void bass_bcast_recv_state_read(struct gatt_db_attribute *attrib, + unsigned int id, uint16_t offset, + uint8_t opcode, struct bt_att *att, + void *user_data) +{ + struct bt_bass_db *bdb = user_data; + uint8_t *rsp; + size_t rsp_len; + struct bt_bcast_src *bcast_src; + + bcast_src = queue_find(bdb->bcast_srcs, + bass_src_match_attrib, + attrib); + + if (!bcast_src) { + gatt_db_attribute_read_result(attrib, id, 0, NULL, + 0); + return; + } + + /* Build read response */ + rsp = bass_build_read_rsp_from_bcast_src(bcast_src, &rsp_len); + + if (!rsp) { + gatt_db_attribute_read_result(attrib, id, + BT_ATT_ERROR_UNLIKELY, + NULL, 0); + return; + } + + gatt_db_attribute_read_result(attrib, id, 0, (void *)rsp, + rsp_len); + + free(rsp); +} + +static void bcast_recv_new(struct bt_bass_db *bdb, int i) +{ + struct bt_bcast_recv_state *bcast_recv_state; + bt_uuid_t uuid; + + if (!bdb) + return; + + bcast_recv_state = new0(struct bt_bcast_recv_state, 1); + bcast_recv_state->bdb = bdb; + + bt_uuid16_create(&uuid, BCAST_RECV_STATE_UUID); + bcast_recv_state->attr = + gatt_db_service_add_characteristic(bdb->service, &uuid, + BT_ATT_PERM_READ, + BT_GATT_CHRC_PROP_READ | + BT_GATT_CHRC_PROP_NOTIFY, + bass_bcast_recv_state_read, NULL, + bdb); + + bcast_recv_state->ccc = gatt_db_service_add_ccc(bdb->service, + BT_ATT_PERM_READ | BT_ATT_PERM_WRITE); + + bdb->bcast_recv_states[i] = bcast_recv_state; +} + +static void bass_new(struct bt_bass_db *bdb) +{ + bt_uuid_t uuid; + int i; + + /* Populate DB with BASS attributes */ + bt_uuid16_create(&uuid, BASS_UUID); + bdb->service = gatt_db_add_service(bdb->db, &uuid, true, + 3 + (NUM_BCAST_RECV_STATES * 3)); + + for (i = 0; i < NUM_BCAST_RECV_STATES; i++) + bcast_recv_new(bdb, i); + + bt_uuid16_create(&uuid, BCAST_AUDIO_SCAN_CP_UUID); + bdb->bcast_audio_scan_cp = + gatt_db_service_add_characteristic(bdb->service, + &uuid, + BT_ATT_PERM_WRITE, + BT_GATT_CHRC_PROP_WRITE, + NULL, bass_bcast_audio_scan_cp_write, + bdb); + + gatt_db_service_set_active(bdb->service, true); +} + +static void bass_bcast_src_free(void *data) +{ + struct bt_bcast_src *bcast_src = data; + + for (int i = 0; i < bcast_src->num_subgroups; i++) + free(bcast_src->subgroup_data[i].meta); + + free(bcast_src->subgroup_data); + free(bcast_src); +} + +static void read_bcast_recv_state(bool success, uint8_t att_ecode, + const uint8_t *value, uint16_t length, + void *user_data) +{ + struct bt_bcast_src *bcast_src = user_data; + + if (!success) { + DBG(bcast_src->bass, "Unable to read " + "Broadcast Receive State: error 0x%02x", + att_ecode); + return; + } + + if (length == 0) { + queue_remove(bcast_src->bass->rdb->bcast_srcs, bcast_src); + bass_bcast_src_free(bcast_src); + return; + } + + if (bass_build_bcast_src_from_read_rsp(bcast_src, value, length)) { + queue_remove(bcast_src->bass->rdb->bcast_srcs, bcast_src); + bass_bcast_src_free(bcast_src); + return; + } +} + +static void bcast_recv_state_notify(struct bt_bass *bass, uint16_t value_handle, + const uint8_t *value, uint16_t length, + void *user_data) +{ + struct gatt_db_attribute *attr = user_data; + struct bt_bcast_src *bcast_src; + bool new_src = false; + + bcast_src = queue_find(bass->rdb->bcast_srcs, + bass_src_match_attrib, attr); + if (!bcast_src) { + new_src = true; + bcast_src = malloc(sizeof(*bcast_src)); + + if (!bcast_src) { + DBG(bass, "Failed to allocate " + "memory for broadcast source"); + return; + } + + memset(bcast_src, 0, sizeof(struct bt_bcast_src)); + bcast_src->bass = bass; + bcast_src->attr = attr; + } + + if (bass_build_bcast_src_from_notif(bcast_src, value, length) + && new_src) { + bass_bcast_src_free(bcast_src); + return; + } + + if (new_src) + queue_push_tail(bass->rdb->bcast_srcs, bcast_src); +} + +static void bass_register(uint16_t att_ecode, void *user_data) +{ + struct bt_bass_notify *notify = user_data; + + if (att_ecode) + DBG(notify->bass, "BASS register notify failed: 0x%04x", + att_ecode); +} + +static void bass_notify(uint16_t value_handle, const uint8_t *value, + uint16_t length, void *user_data) +{ + struct bt_bass_notify *notify = user_data; + + if (notify->func) + notify->func(notify->bass, value_handle, value, length, + notify->user_data); +} + +static void bass_notify_destroy(void *data) +{ + struct bt_bass_notify *notify = data; + struct bt_bass *bass = notify->bass; + + if (queue_remove_if(bass->notify, NULL, notify)) + free(notify); +} + +static unsigned int bass_register_notify(struct bt_bass *bass, + uint16_t value_handle, + bass_notify_t func, + void *user_data) +{ + struct bt_bass_notify *notify; + + notify = new0(struct bt_bass_notify, 1); + notify->bass = bass; + notify->func = func; + notify->user_data = user_data; + + notify->id = bt_gatt_client_register_notify(bass->client, + value_handle, bass_register, + bass_notify, notify, + bass_notify_destroy); + if (!notify->id) { + DBG(bass, "Unable to register for notifications"); + free(notify); + return 0; + } + + queue_push_tail(bass->notify, notify); + + return notify->id; +} + +static void foreach_bass_char(struct gatt_db_attribute *attr, void *user_data) +{ + struct bt_bass *bass = user_data; + uint16_t value_handle; + bt_uuid_t uuid, uuid_bcast_audio_scan_cp, uuid_bcast_recv_state; + + /* Get attribute value handle and uuid */ + if (!gatt_db_attribute_get_char_data(attr, NULL, &value_handle, + NULL, NULL, &uuid)) + return; + + bt_uuid16_create(&uuid_bcast_audio_scan_cp, BCAST_AUDIO_SCAN_CP_UUID); + bt_uuid16_create(&uuid_bcast_recv_state, BCAST_RECV_STATE_UUID); + + if (!bt_uuid_cmp(&uuid, &uuid_bcast_audio_scan_cp)) { + /* Found Broadcast Audio Scan Control Point characteristic */ + bass->rdb->bcast_audio_scan_cp = attr; + + DBG(bass, "Broadcast Audio Scan Control Point " + "found: handle 0x%04x", value_handle); + } + + if (!bt_uuid_cmp(&uuid, &uuid_bcast_recv_state)) { + /* Found Broadcast Receive State characteristic */ + struct bt_bcast_src *bcast_src = + queue_find(bass->rdb->bcast_srcs, + bass_src_match_attrib, attr); + + if (!bcast_src) { + bcast_src = malloc(sizeof(struct bt_bcast_src)); + + if (bcast_src == NULL) { + DBG(bass, "Failed to allocate " + "memory for broadcast source"); + return; + } + + memset(bcast_src, 0, sizeof(struct bt_bcast_src)); + bcast_src->bass = bass; + bcast_src->attr = attr; + + queue_push_tail(bass->rdb->bcast_srcs, bcast_src); + } + + bt_gatt_client_read_value(bass->client, value_handle, + read_bcast_recv_state, + bcast_src, NULL); + + (void)bass_register_notify(bass, value_handle, + bcast_recv_state_notify, + attr); + + DBG(bass, "Broadcast Receive State found: handle 0x%04x", + value_handle); + } +} + +static void foreach_bass_service(struct gatt_db_attribute *attr, + void *user_data) +{ + struct bt_bass *bass = user_data; + + /* Store BASS service reference */ + bass->rdb->service = attr; + + /* Handle BASS characteristics */ + gatt_db_service_foreach_char(attr, foreach_bass_char, bass); +} + +bool bt_bass_attach(struct bt_bass *bass, struct bt_gatt_client *client) +{ + bt_uuid_t uuid; + + if (!sessions) + sessions = queue_new(); + + queue_push_tail(sessions, bass); + + if (!client) + return true; + + if (bass->client) + return false; + + bass->client = bt_gatt_client_clone(client); + if (!bass->client) + return false; + + bt_uuid16_create(&uuid, BASS_UUID); + gatt_db_foreach_service(bass->rdb->db, &uuid, foreach_bass_service, + bass); + + return true; +} + +static void bass_detached(void *data, void *user_data) +{ + struct bt_bass_cb *cb = data; + struct bt_bass *bass = user_data; + + cb->detached(bass, cb->user_data); +} + +void bt_bass_detach(struct bt_bass *bass) +{ + if (!queue_remove(sessions, bass)) + return; + + bt_gatt_client_unref(bass->client); + bass->client = NULL; + + queue_foreach(bass_cbs, bass_detached, bass); +} + +static void bass_db_free(void *data) +{ + struct bt_bass_db *bdb = data; + + if (!bdb) + return; + + gatt_db_unref(bdb->db); + queue_destroy(bdb->bcast_srcs, bass_bcast_src_free); + + free(bdb); +} + +static void bass_free(void *data) +{ + struct bt_bass *bass = data; + + bt_bass_detach(bass); + bass_db_free(bass->rdb); + queue_destroy(bass->notify, NULL); + + free(bass); +} + +void bt_bass_unref(struct bt_bass *bass) +{ + if (!bass) + return; + + if (__sync_sub_and_fetch(&bass->ref_count, 1)) + return; + + bass_free(bass); +} + +bool bt_bass_set_user_data(struct bt_bass *bass, void *user_data) +{ + if (!bass) + return false; + + bass->user_data = user_data; + + return true; +} + +static struct bt_bass_db *bass_db_new(struct gatt_db *db) +{ + struct bt_bass_db *bdb; + + if (!db) + return NULL; + + bdb = new0(struct bt_bass_db, 1); + bdb->db = gatt_db_ref(db); + bdb->bcast_srcs = queue_new(); + + if (!bass_db) + bass_db = queue_new(); + + bass_new(bdb); + + queue_push_tail(bass_db, bdb); + + return bdb; +} + +static bool bass_db_match(const void *data, const void *match_data) +{ + const struct bt_bass_db *bdb = data; + const struct gatt_db *db = match_data; + + return (bdb->db == db); +} + +static struct bt_bass_db *bass_get_db(struct gatt_db *db) +{ + struct bt_bass_db *bdb; + + bdb = queue_find(bass_db, bass_db_match, db); + if (bdb) + return bdb; + + return bass_db_new(db); +} + +static struct bt_bass *bt_bass_ref(struct bt_bass *bass) +{ + if (!bass) + return NULL; + + __sync_fetch_and_add(&bass->ref_count, 1); + + return bass; +} + +struct bt_bass *bt_bass_new(struct gatt_db *ldb, struct gatt_db *rdb) +{ + struct bt_bass *bass; + struct bt_bass_db *db; + + if (!ldb) + return NULL; + + db = bass_get_db(ldb); + if (!db) + return NULL; + + bass = new0(struct bt_bass, 1); + bass->ldb = db; + bass->notify = queue_new(); + + if (!rdb) + goto done; + + db = new0(struct bt_bass_db, 1); + db->db = gatt_db_ref(rdb); + db->bcast_srcs = queue_new(); + + bass->rdb = db; + +done: + bt_bass_ref(bass); + + return bass; +} + +struct bt_att *bt_bass_get_att(struct bt_bass *bass) +{ + if (!bass) + return NULL; + + if (bass->att) + return bass->att; + + return bt_gatt_client_get_att(bass->client); +} + +bool bt_bass_set_debug(struct bt_bass *bass, bt_bass_debug_func_t func, + void *user_data, bt_bass_destroy_func_t destroy) +{ + if (!bass) + return false; + + if (bass->debug_destroy) + bass->debug_destroy(bass->debug_data); + + bass->debug_func = func; + bass->debug_destroy = destroy; + bass->debug_data = user_data; + + return true; +} + +unsigned int bt_bass_register(bt_bass_func_t attached, bt_bass_func_t detached, + void *user_data) +{ + struct bt_bass_cb *cb; + static unsigned int id; + + if (!attached && !detached) + return 0; + + if (!bass_cbs) + bass_cbs = queue_new(); + + cb = new0(struct bt_bass_cb, 1); + cb->id = ++id ? id : ++id; + cb->attached = attached; + cb->detached = detached; + cb->user_data = user_data; + + queue_push_tail(bass_cbs, cb); + + return cb->id; +} +static bool match_id(const void *data, const void *match_data) +{ + const struct bt_bass_cb *cb = data; + unsigned int id = PTR_TO_UINT(match_data); + + return (cb->id == id); +} + +bool bt_bass_unregister(unsigned int id) +{ + struct bt_bass_cb *cb; + + cb = queue_remove_if(bass_cbs, match_id, UINT_TO_PTR(id)); + if (!cb) + return false; + + free(cb); + + return true; +} diff --git a/src/shared/bass.h b/src/shared/bass.h new file mode 100644 index 000000000..d3474f7cf --- /dev/null +++ b/src/shared/bass.h @@ -0,0 +1,122 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright 2023 NXP + * + */ + +struct bt_bass; + +#define NUM_BCAST_RECV_STATES 2 +#define BT_BASS_BCAST_CODE_SIZE 16 +#define BT_BASS_BIG_SYNC_FAILED_BITMASK 0xFFFFFFFF +#define BT_BASS_BCAST_SRC_LEN 15 +#define BT_BASS_BCAST_SRC_SUBGROUP_LEN 5 + +/* Application error codes */ +#define BT_BASS_ERROR_OPCODE_NOT_SUPPORTED 0x80 +#define BT_BASS_ERROR_INVALID_SOURCE_ID 0x81 + +/* PA_Sync_State values */ +#define BT_BASS_NOT_SYNCHRONIZED_TO_PA 0x00 +#define BT_BASS_SYNC_INFO_RE 0x01 +#define BT_BASS_SYNCHRONIZED_TO_PA 0x02 +#define BT_BASS_FAILED_TO_SYNCHRONIZE_TO_PA 0x03 +#define BT_BASS_NO_PAST 0x04 + +/* BIG_Encryption values */ +#define BT_BASS_BIG_ENC_STATE_NO_ENC 0x00 +#define BT_BASS_BIG_ENC_STATE_BCODE_REQ 0x01 +#define BT_BASS_BIG_ENC_STATE_DEC 0x02 +#define BT_BASS_BIG_ENC_STATE_BAD_CODE 0x03 + +/* BASS subgroup field of the Broadcast + * Receive State characteristic + */ +struct bt_bass_subgroup_data { + uint32_t bis_sync; + uint32_t pending_bis_sync; + uint8_t meta_len; + uint8_t *meta; +}; + +/* BASS Broadcast Source structure */ +struct bt_bcast_src { + struct bt_bass *bass; + struct gatt_db_attribute *attr; + uint8_t id; + uint8_t addr_type; + bdaddr_t addr; + uint8_t sid; + uint32_t bid; + uint8_t sync_state; + uint8_t enc; + uint8_t bad_code[BT_BASS_BCAST_CODE_SIZE]; + uint8_t num_subgroups; + struct bt_bass_subgroup_data *subgroup_data; +}; + +/* Broadcast Audio Scan Control Point + * header structure + */ +struct bt_bass_bcast_audio_scan_cp_hdr { + uint8_t op; +} __packed; + +#define BT_BASS_REMOTE_SCAN_STOPPED 0x00 + +#define BT_BASS_REMOTE_SCAN_STARTED 0x01 + +#define BT_BASS_ADD_SRC 0x02 + +struct bt_bass_add_src_params { + uint8_t addr_type; + bdaddr_t addr; + uint8_t sid; + uint8_t bid[3]; + uint8_t pa_sync; + uint16_t pa_interval; + uint8_t num_subgroups; + uint8_t subgroup_data[]; +} __packed; + +#define BT_BASS_MOD_SRC 0x03 + +struct bt_bass_mod_src_params { + uint8_t id; + uint8_t pa_sync; + uint16_t pa_interval; + uint8_t num_subgroups; + uint8_t subgroup_data[]; +} __packed; + +#define BT_BASS_SET_BCAST_CODE 0x04 + +struct bt_bass_set_bcast_code_params { + uint8_t id; + uint8_t bcast_code[BT_BASS_BCAST_CODE_SIZE]; +} __packed; + +#define BT_BASS_REMOVE_SRC 0x05 + +struct bt_bass_remove_src_params { + uint8_t id; +} __packed; + +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); + +struct bt_att *bt_bass_get_att(struct bt_bass *bass); +unsigned int bt_bass_register(bt_bass_func_t attached, bt_bass_func_t detached, + void *user_data); +bool bt_bass_unregister(unsigned int id); +bool bt_bass_set_debug(struct bt_bass *bass, bt_bass_debug_func_t func, + void *user_data, bt_bass_destroy_func_t destroy); +struct bt_bass *bt_bass_new(struct gatt_db *ldb, struct gatt_db *rdb); +bool bt_bass_set_user_data(struct bt_bass *bass, void *user_data); +void bt_bass_unref(struct bt_bass *bass); +bool bt_bass_attach(struct bt_bass *bass, struct bt_gatt_client *client); +void bt_bass_detach(struct bt_bass *bass); From patchwork Fri May 5 08:29:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 679414 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 99C7BC77B7C for ; Fri, 5 May 2023 08:32:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231357AbjEEIc3 (ORCPT ); Fri, 5 May 2023 04:32:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33208 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231271AbjEEIcU (ORCPT ); Fri, 5 May 2023 04:32:20 -0400 Received: from EUR05-AM6-obe.outbound.protection.outlook.com (mail-am6eur05on2087.outbound.protection.outlook.com [40.107.22.87]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 62F08A27D for ; Fri, 5 May 2023 01:32:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XzTbS4vWtSVYZouqxw5V34foFymQLbTM9egamauY/6ugvdlb+QO4jUPFjf9U0qXqOsac+e14uyCS9mhG1RnP3BPtgAcbiAve+y8ZL3gWJSZyaUWlaaVGUU2dcgyefBQA9H1eGH/dgN2R0xRH2/ywyEgXOHc0SuBvGGprzzaW6Q2e+YvAOkr5j1tbXOo0S5dIQv9VORC9805ZrHRFBxpFQXO+KDA03xJX8JRWrLtvfsL+Ermea4DIuCrTlGya9HmnERJRZqB2H5glrau/G8K3N2/1rztsWDSaWoCs6OUkIxTiay4aQ/Q45kRGhAZF/QOTuHemulAHYcwG7iR7ODakMA== 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=zRel/F0NwVENSkPF2fzn69Gcc+rRSXASsPZ2W2Iaaik=; b=D+IqzRiXNbtqOhl3YhSqL98zpTkJCQ7sFcRYu1RviyFyfuDamcCvFhJz/DYWeoJOsetb2L4L7NB7Gcz1DOinauQwgpWnSxfkyNw3dL9CAmAgHhqxPpoMjLLoM/zKfQ9HxC7zGa9nyg8h7OtnIJj0T8lFNuh9BYOdYfJZYNxGhwHwOdD3TrWfuw6r/2TAALRUiQ4pnONyecFqplC+8EZxjCpjaX5FbapLzS8jLAlGMZzRoeh9h/uWu3GEoTkB/c8uvAj3dJ57ELaxCeHZ6KNTAkQGKWBwlQuqZBsFzYgavTYk7k+ipaAuKFUVWd72zaxmOMCEMlpIN4mAvoWOeIIclw== 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=zRel/F0NwVENSkPF2fzn69Gcc+rRSXASsPZ2W2Iaaik=; b=mc+k/nceCRw2ctnQKwHEp4EDHEShUHvcGmzZA+pm6609DiOS/SizOCagE/i2ZmoHPi8DuBpHuwnHD9M4BRtc6JTLKyUCuJuTnvMsXkclsmBoJM1UWnLxJu87oDP5llsFjGvYtfhYYtEvp5t8H/WIzzIJZhaAEKTNBIcEGRpqTX4= 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 AS8PR04MB8101.eurprd04.prod.outlook.com (2603:10a6:20b:3f6::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6363.27; Fri, 5 May 2023 08:30:41 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::afb8:bb33:948f:d1e1]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::afb8:bb33:948f:d1e1%9]) with mapi id 15.20.6363.027; Fri, 5 May 2023 08:30:41 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: Iulia Tanasescu Subject: [PATCH BlueZ 5/5] profiles: Add initial code for BASS plugin Date: Fri, 5 May 2023 11:29:43 +0300 Message-Id: <20230505082943.92033-6-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230505082943.92033-1-iulia.tanasescu@nxp.com> References: <20230505082943.92033-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AM4PR07CA0036.eurprd07.prod.outlook.com (2603:10a6:205:1::49) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|AS8PR04MB8101:EE_ X-MS-Office365-Filtering-Correlation-Id: 3cd00f49-a368-4926-1995-08db4d43026d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 5MgqWcDbgRWgim9aQ6CB65hNxZM6PSA23UNWI14/HoMoFGysFl5dpv5l5/4FUWXBWq7LI4S1+kiDdmec3S4NtBWcjqtZHl39Iw8sybJOmCGJO+kjNG8c6bnu8hUUMgVvhUYxMLtB1MnpASxiZWMR9v+JGbGAZpq0ywoUDJ8+wr21Ym4wKfxQYQqisUs6RC4Y+5TQdmqtKTvkiDgWgTvrR7Ny+AoIK63+1JRwj7C7x0TMk59SYHIjZLmlIkvF0ptwIXsgkMIzCPLu+BJrQg4bm7zUEAqj836xntb+WykppVS5sOwTTM/SBDFnE3NgNGhZb+JeAM9wPRxzLveK3H+X9oxsj4zOw4QRq3EpMUEDdxntkI51JlSKBHd6Mzym5g4Zv/oEfRFMzQX5ujFcHQg832tUO1i0ePeXnS/LvnQTMQNIhk9lTZtJsFm69F4RQNIP+tAdD8qFtY4XoiA0Got9H89SP8ifYHCSkB2on3L6ZR4E5ocVSkF1UvgZokycKCIW5sHe4xfCIXKSKMZ3v3/RfCc4TlLiQtyi34BP4h8j2ZcrduZP8tSDN2SM3KnlxstJ3gnqSUVOeumF6ukQZiTph9ItjT7jbdqtgi60We2sp1HmL0YRt6Mw/nxyGCybJULH 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:(13230028)(4636009)(396003)(39860400002)(376002)(136003)(366004)(346002)(451199021)(52116002)(6916009)(4326008)(66946007)(66556008)(66476007)(478600001)(316002)(36756003)(86362001)(6486002)(2616005)(55236004)(6506007)(6512007)(1076003)(26005)(8676002)(5660300002)(8936002)(44832011)(2906002)(41300700001)(38100700002)(186003)(38350700002); DIR:OUT; SFP:1101; X-MS-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bxp658dQfxr2308FfcKD6hLLVUIo5M0TWVbwhXKJyVBNz0KvRa7vL6+Hg6oEaz4soMAPejmX6QoXrsPgT88QbOkoSeO/i+VyoHTljzUizRLa9MNWVTX6c0hlLMilo+f9+OX2MLSl+fwFs0LD9oTmyiT0ti37SRl2btKYu/RYzH64r5TVuCNyj59QlHx4krkKcNjpKIuv/jgm+E8tA21NbNeb4oCwlnVoUQe1QCRvqmCDV+zm3xocKuAwO3CmYdHlDIlPMIugTRClD6+muMakJd3ekqxeZKaiYZRR0ifP24TJRXHZ7FOqCEklMIN4DcFrWW6uhhtTmrmdgyHCrWGwdW2F2OXOYsa0a2fowUfg7sf/+BsQVHtpqcqtKAYptMQnCNSBf3CQEJ/v9FXoakrn8QGPrn+MnhouLH2FKEbhxq5v7ZNKB0K0eUDpmvKXcmuq7nzdRKTll56GTEiEg3wMb8JgzudE3MDWOL0koLIl57T2rqhBQK6BrRI8cDv8FNoXKIR7NDH3JLaEpsMy9XWbQZT7MxoQwmqiYntB9zCkDnOQMFFWb91WvP5AgPXXG/5Gfltad0RWL9Q0jn9MyK7O5K54zekRw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3cd00f49-a368-4926-1995-08db4d43026d X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 May 2023 08:30:41.6248 (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: TyZTdVOdZtBHHYCV+TadzsfQ8v0x+/FIUC4mvPIBpY/ar/M4CzgLfef5P4b5Mkx9elKB9/B/G837VU+KLMgcUw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: AS8PR04MB8101 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds initial code for BASS plugin. --- Makefile.plugins | 5 + configure.ac | 4 + profiles/audio/bass.c | 305 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 314 insertions(+) create mode 100644 profiles/audio/bass.c diff --git a/Makefile.plugins b/Makefile.plugins index 0f119e871..fc19522e4 100644 --- a/Makefile.plugins +++ b/Makefile.plugins @@ -122,6 +122,11 @@ builtin_modules += bap builtin_sources += profiles/audio/bap.c endif +if BASS +builtin_modules += bass +builtin_sources += profiles/audio/bass.c +endif + if MCP builtin_modules += mcp builtin_sources += profiles/audio/mcp.c diff --git a/configure.ac b/configure.ac index 6f890110f..c5c5d7f00 100644 --- a/configure.ac +++ b/configure.ac @@ -199,6 +199,10 @@ AC_ARG_ENABLE(bap, AS_HELP_STRING([--disable-bap], [disable BAP profile]), [enable_bap=${enableval}]) AM_CONDITIONAL(BAP, test "${enable_bap}" != "no") +AC_ARG_ENABLE(bass, AS_HELP_STRING([--disable-bass], + [disable BASS service]), [enable_bass=${enableval}]) +AM_CONDITIONAL(BASS, test "${enable_bass}" != "no") + AC_ARG_ENABLE(mcp, AS_HELP_STRING([--disable-mcp], [disable MCP profile]), [enable_mcp=${enableval}]) AM_CONDITIONAL(MCP, test "${enable_mcp}" != "no") diff --git a/profiles/audio/bass.c b/profiles/audio/bass.c new file mode 100644 index 000000000..a7fcc9718 --- /dev/null +++ b/profiles/audio/bass.c @@ -0,0 +1,305 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright 2023 NXP + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "gdbus/gdbus.h" + +#include "lib/bluetooth.h" +#include "lib/uuid.h" + +#include "src/dbus-common.h" +#include "src/shared/util.h" +#include "src/shared/att.h" +#include "src/shared/queue.h" +#include "src/shared/gatt-db.h" +#include "src/shared/gatt-client.h" +#include "src/shared/gatt-server.h" +#include "src/shared/bass.h" + +#include "src/plugin.h" +#include "src/adapter.h" +#include "src/gatt-database.h" +#include "src/device.h" +#include "src/profile.h" +#include "src/service.h" +#include "src/log.h" +#include "src/error.h" + +#define BASS_UUID_STR "0000184f-0000-1000-8000-00805f9b34fb" + +struct bass_data { + struct btd_device *device; + struct btd_service *service; + struct bt_bass *bass; +}; + +static struct queue *sessions; + +static void bass_debug(const char *str, void *user_data) +{ + DBG_IDX(0xffff, "%s", str); +} + +static struct bass_data *bass_data_new(struct btd_device *device) +{ + struct bass_data *data; + + data = new0(struct bass_data, 1); + data->device = device; + + return data; +} + +static void bass_data_add(struct bass_data *data) +{ + DBG("data %p", data); + + if (queue_find(sessions, NULL, data)) { + error("data %p already added", data); + return; + } + + bt_bass_set_debug(data->bass, bass_debug, NULL, NULL); + + if (!sessions) + sessions = queue_new(); + + queue_push_tail(sessions, data); + + if (data->service) + btd_service_set_user_data(data->service, data); +} + +static bool match_data(const void *data, const void *match_data) +{ + const struct bass_data *bdata = data; + const struct bt_bass *bass = match_data; + + return bdata->bass == bass; +} + +static void bass_data_free(struct bass_data *data) +{ + if (data->service) { + btd_service_set_user_data(data->service, NULL); + bt_bass_set_user_data(data->bass, NULL); + } + + bt_bass_unref(data->bass); + free(data); +} + +static void bass_data_remove(struct bass_data *data) +{ + DBG("data %p", data); + + if (!queue_remove(sessions, data)) + return; + + bass_data_free(data); + + if (queue_isempty(sessions)) { + queue_destroy(sessions, NULL); + sessions = NULL; + } +} + +static void bass_detached(struct bt_bass *bass, void *user_data) +{ + struct bass_data *data; + + DBG("%p", bass); + + data = queue_find(sessions, match_data, bass); + if (!data) { + error("Unable to find bass session"); + return; + } + + /* If there is a service it means there is BASS thus we can keep + * instance allocated. + */ + if (data->service) + return; + + bass_data_remove(data); +} + +static void bass_attached(struct bt_bass *bass, void *user_data) +{ + struct bass_data *data; + struct bt_att *att; + struct btd_device *device; + + DBG("%p", bass); + + data = queue_find(sessions, match_data, bass); + if (data) + return; + + att = bt_bass_get_att(bass); + if (!att) + return; + + device = btd_adapter_find_device_by_fd(bt_att_get_fd(att)); + if (!device) { + error("Unable to find device"); + return; + } + + data = bass_data_new(device); + data->bass = bass; + + bass_data_add(data); +} + +static int bass_probe(struct btd_service *service) +{ + struct btd_device *device = btd_service_get_device(service); + struct btd_adapter *adapter = device_get_adapter(device); + struct btd_gatt_database *database = btd_adapter_get_database(adapter); + struct bass_data *data = btd_service_get_user_data(service); + char addr[18]; + + ba2str(device_get_address(device), addr); + DBG("%s", addr); + + /* Ignore, if we were probed for this device already */ + if (data) { + error("Profile probed twice for the same device!"); + return -EINVAL; + } + + data = bass_data_new(device); + data->service = service; + + data->bass = bt_bass_new(btd_gatt_database_get_db(database), + btd_device_get_gatt_db(device)); + if (!data->bass) { + error("Unable to create BASS instance"); + free(data); + return -EINVAL; + } + + bass_data_add(data); + bt_bass_set_user_data(data->bass, service); + + return 0; +} + +static void bass_remove(struct btd_service *service) +{ + struct btd_device *device = btd_service_get_device(service); + struct bass_data *data; + char addr[18]; + + ba2str(device_get_address(device), addr); + DBG("%s", addr); + + data = btd_service_get_user_data(service); + if (!data) { + error("BASS service not handled by profile"); + return; + } + + bass_data_remove(data); +} +static int bass_accept(struct btd_service *service) +{ + struct btd_device *device = btd_service_get_device(service); + struct bt_gatt_client *client = btd_device_get_gatt_client(device); + struct bass_data *data = btd_service_get_user_data(service); + char addr[18]; + + ba2str(device_get_address(device), addr); + DBG("%s", addr); + + if (!data) { + error("BASS service not handled by profile"); + return -EINVAL; + } + + if (!bt_bass_attach(data->bass, client)) { + error("BASS unable to attach"); + return -EINVAL; + } + + btd_service_connecting_complete(service, 0); + + return 0; +} + +static int bass_disconnect(struct btd_service *service) +{ + struct bass_data *data = btd_service_get_user_data(service); + struct btd_device *device = btd_service_get_device(service); + char addr[18]; + + ba2str(device_get_address(device), addr); + DBG("%s", addr); + + bt_bass_detach(data->bass); + + btd_service_disconnecting_complete(service, 0); + + return 0; +} + +static struct btd_profile bass_service = { + .name = "bass", + .priority = BTD_PROFILE_PRIORITY_MEDIUM, + .remote_uuid = BASS_UUID_STR, + .device_probe = bass_probe, + .device_remove = bass_remove, + .accept = bass_accept, + .disconnect = bass_disconnect, +}; + +static unsigned int bass_id; + +static int bass_init(void) +{ + if (!(g_dbus_get_flags() & G_DBUS_FLAG_ENABLE_EXPERIMENTAL)) { + warn("D-Bus experimental not enabled"); + return -ENOTSUP; + } + + btd_profile_register(&bass_service); + bass_id = bt_bass_register(bass_attached, bass_detached, NULL); + + return 0; +} + +static void bass_exit(void) +{ + if (g_dbus_get_flags() & G_DBUS_FLAG_ENABLE_EXPERIMENTAL) { + btd_profile_unregister(&bass_service); + bt_bass_unregister(bass_id); + } +} + +BLUETOOTH_PLUGIN_DEFINE(bass, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, + bass_init, bass_exit)