From patchwork Tue Sep 5 07:09:09 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitin Jadhav X-Patchwork-Id: 720472 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 D9950CA0FF8 for ; Tue, 5 Sep 2023 16:27:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244002AbjIEQXD (ORCPT ); Tue, 5 Sep 2023 12:23:03 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35918 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353666AbjIEHJq (ORCPT ); Tue, 5 Sep 2023 03:09:46 -0400 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2089.outbound.protection.outlook.com [40.107.7.89]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BEFD1B4 for ; Tue, 5 Sep 2023 00:09:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QJPk6mSCYxOdY1Aue9Bro3m8/2QsuOm3bSNvn2imIsvUzbBloDHUk6p3c+XOJDgZwo0FGxT72N1yoSDF9euBzWiJBobwUPn/yuawI42bRLa5iR7VA5aIesvJrOwt5KSUlRIJUBZmspD6v38Uf0uC2zJf89aNY6rh8EigndufMS5UoPE/AVPEbndxNBtXS7tS/amMPugPqCHBtIZihOvJ3LY/GmslbFvxas9kx+AE3OOB7n7Tq15TXAJxsMLs4hd2X0u2G6XOZWLcSksk9xeuZgSA5m/+aXeeP+9OXT3VUNNvXwQYH7YBYWfLWeDUVWERaJRbJNETKXEIY8GgpR5tZQ== 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=kHjpEsTxiKVXO3w7TxwvpHsCBA0riV72SOVE0BjXJaI=; b=M81sTjnCzNXIfprt97riGBTwGVfw3FuUM7uqi7lCXfB92XVNDqCyhMIho/PwvLCjebBk1wJXiXW+z7eaixYA6aEoWKDjeFNW9BeTAAG3yvqX0lpGAznCZYy7i1wRHax6LwUxzBee+JZovzmq4LV6Gi13KmZjjqYMKpjdYdkYaCUHZu54q0k4k/IO5ryWk4NNJVKjegPA2eIkJNx735mqQ93Dsm83jUcIHwrlnq2hVDS5FCVUc8j2ekFedEKe7RAm5xZpogO86yB1SJJkkAblqKKauVDrLDvhsIQa0poGpYacSVLSLuLMDR/vKovPcc4PNQIIuexc//j7mhoOG+c9RQ== 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=kHjpEsTxiKVXO3w7TxwvpHsCBA0riV72SOVE0BjXJaI=; b=OD/oQKcq/NdatNWzP2nCsbMXJUA9VI0kO/xI+0q1QUgiXwik8f0AwKwy5pkGkFbcX3ScJA786MPXrnnvdMsQKkFaT2dMfz2zUk5Iqg2n2jOa80TjrQppkG5byyvgdzOx1aMx4wbYaA94UK/DizpwEUSfOLbSvsiHgjAJ3Tfuu1k= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB9126.eurprd04.prod.outlook.com (2603:10a6:20b:449::16) by DBBPR04MB8058.eurprd04.prod.outlook.com (2603:10a6:10:1e7::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Tue, 5 Sep 2023 07:09:40 +0000 Received: from AS8PR04MB9126.eurprd04.prod.outlook.com ([fe80::2320:fa57:8f7c:bb64]) by AS8PR04MB9126.eurprd04.prod.outlook.com ([fe80::2320:fa57:8f7c:bb64%6]) with mapi id 15.20.6745.030; Tue, 5 Sep 2023 07:09:40 +0000 From: Nitin Jadhav To: linux-bluetooth@vger.kernel.org Cc: devyani.godbole@nxp.com, mahesh.talewad@nxp.com, luiz.dentz@gmail.com, nitin.jadhav@nxp.com Subject: [PATCH BlueZ v2 1/4] lib/uuid.h: Add UUID(s) Date: Tue, 5 Sep 2023 10:09:09 +0300 Message-Id: <20230905070912.82340-2-nitin.jadhav@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230905070912.82340-1-nitin.jadhav@nxp.com> References: <20230905070912.82340-1-nitin.jadhav@nxp.com> X-ClientProxiedBy: SI2PR02CA0031.apcprd02.prod.outlook.com (2603:1096:4:195::16) To AS8PR04MB9126.eurprd04.prod.outlook.com (2603:10a6:20b:449::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB9126:EE_|DBBPR04MB8058:EE_ X-MS-Office365-Filtering-Correlation-Id: 8578028b-17be-482e-9a94-08dbaddf127c X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: X4XjEsMZuWcAt6v/r5BzCWqPLajVNStm952iPaXfc8Q2Gz4u2WesJra++L7MQW/zKzuTyQJpWnJ3lO+sl26BiWQHbebX23C/B8nRBf09zPym+bxrNjqO58KtmXHlZyJtMECuWvPKFLd5RX91xMQctd4TN1ICJ8o0411rjYPxIzxt7MLKHJ96oRM4AYcrKn+6/Kec7u+McClJdpaJyxqYlgbccEmVyEiFEomXT6QH9XFVaIPKc5+4dHlavYDjnhx8VecYOTR6qo2zOQBgzh9gevaG/u6OyPaHKeMpQSPjRRe51Q2i01pm07LpQ0TDghXU24566Cc7kwfdWLERIxTJZm7ZfqKdSfV33BFL3GlhA302E9mVQHxAoLP/LCeb3WMjQ9ZglcB/rI/N+3pFO5fYi9wi0yEEzFsalK3O8XamzpkP8jXP2nunKhTVdYqRP7B+sF4HldQkJqDrR0EzOwXNqcs8OB7oNLDB/BZVg83LT5Wu3gVDrKvJW0bgu0ugIo9QRn9TM2D4vlC2dKgxzM0cC2YqPWwrHmtxHiDSpTZrszwuj/CSrldFGe0MoiYbVheaBBIo+r7BDAvEyzg2tYPoufuEPubmuuYu3Aw2pcTMcK4/YURjgmQlmvTOsRQun5o5 X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR04MB9126.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(396003)(346002)(376002)(136003)(39860400002)(366004)(451199024)(1800799009)(186009)(66946007)(66556008)(66476007)(6916009)(478600001)(38100700002)(38350700002)(316002)(4744005)(2906002)(41300700001)(86362001)(8936002)(8676002)(4326008)(5660300002)(44832011)(6506007)(83380400001)(6512007)(6666004)(6486002)(52116002)(55236004)(2616005)(26005)(1076003)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: lRjEzR97RyvED3sTaf0L2gtrIe9UqVL73gZosDR2sWyZ0sDd5AM9xBL7OjUTQqBRiog5aYlzj+KWUIvlQcQFbGQ15ekrWAlQhDPhrkCftRCsk4RLaNPLgCzwjJbiKGVOqZRyX8CIVnyTlO8KvgPF8Pn7Dxopu0JkqN/Mc3Ij9aiKT1P4JSOs4ok2MmARnZlpuSx7OBiI2z8WQNpFQNh0zI/9BDC52GrEoekgP7hW3Bor8c0q6y5vDwnvWUyuUgZmuI7bBgnUoOJ/vY7nbuFtfsxJiHHfhwyL9cwq+OZa9vlBsKWwcIqODPBlyF5SJTQweKw0bjLEDD07T/XKIDeab4PoksUKgmfpqB7RQKMOCBHxjkmdc9iSjaltLa+3Oz8mDZHKhLhS+fmJrnd+GxJJ6s/wuitc2iMgTFldsXyK21drpXtDSTExs5GDiVLHoOSvlQWdQro78rF3BsQNOulqs7lm1l4vlHt/0pXCVGvBmcE9QgsJu4RvVkGmA75PUF3lAuSm9NpNgZSKaFSwKM727GObEsHG9EtvA6myDAy/VDZ7b07NnylZLl4BAgN/VKudhG8Yh+PblMZL5Q4yDyIaalbHsX29o3I/Uui9TV65I52YBXItzhfCdBwz08cQQf9jtJlL7w+mptPWpxwSAsFjUJqOE4Jw1LMn6MAm+02zCGORtkeniRPB41ud2KKF0mypPXgztaraQhgUpRv4BRc3TMgR8V/fTq8tc6/JxeKdWBRE/vcJXL0cizArz+MDCMCmhygtm4qgY3/JYGRp5SXQOLFrN2gbRYz/znKZwpv3OqqwfEJOeTeqH+9x7A21tohIIPG7dGYrm2PpEX8d/2ofLL5MYzy8YE9YXzkVuSUkctzM/2vm61088fr1JEb5jBWUgncUB+ytMWvKbjVtvwW3Blg/3kwvv478A5EW1Ns2YnmhkH/43i3U4PZBvRYpQALy5iaerEqfH5MYOO/Ql6Vl3HzrbslYqUMawqwqU8L6GqC2g69++bsgNUT8qSTioID4oZbUY+oFlJ8VYJK4Hv7Z7LLdQir8OU4v+GbJ8Xk3g3iTESCuFT13zdVf09zvfCnruMax+IT7nV0vTiazOXusPdYhMQ6pVKXh7D4D2owpRgwtFM+378m6dKtZWkbgckRTU2+LU1vq0Mfvhux/v2Zxe4ts8GZHJp+ccQ/878Or/xeriNqsbSSMpXdZ4M+NoIzjrzi5RsMCr3tcG4VvZzZmeMS4vRvm31rgL8kGhAS/7cy7kdpjOxxzU0kgPhDBoFRiwBPTpHcxeG0LPbSgMndYtekmUcIYpaA6tf+nNAeeANZWl4wDHVqDH3iS6fia3kFQXhAilfe85Z5tAAmELkKg2MuGSinTOCrOQt//kIgaakdO9L7Jn9Tj/ngOpFb63yfdg5+OeknHdpt9yAYbZM74Y4NcugV1200hdPCC1XjKDVY6WC44n1eOC4aoFR0CtIue9/4/xVIBSg+4djadn1NwCcC3gONeZRW4TMiil7bKtuYoOyeUHY3M31uoSKtv2Tj5iDUV4zGVcozAStF8DiRXliMcHdEDrNw3p7cOdpYw5PPsvi65VxBu74+AmoYWBG8y X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8578028b-17be-482e-9a94-08dbaddf127c X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB9126.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2023 07:09:40.5865 (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: gOWqFNR3/V4n++UhP3fhs7ZdtwZ5Qfnu7p+HUE6FbXPaUMZqWJq7EcAiKi9CtBJTSvD55xgfTPYM4BvqebjSOw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB8058 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Add MICS characteristic uuid(s) Co-developed-by: Mahesh Talewad Signed-off-by: Mahesh Talewad Signed-off-by: Nitin Jadhav --- lib/uuid.h | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lib/uuid.h b/lib/uuid.h index cd3b3655f..a79eeee18 100644 --- a/lib/uuid.h +++ b/lib/uuid.h @@ -206,6 +206,11 @@ extern "C" { #define CS_LOCK 0x2B86 #define CS_RANK 0x2B87 + +/* Microphone Control Service(MICS) */ +#define MICS_UUID 0x184D +#define MUTE_CHRC_UUID 0x2BC3 + typedef struct { enum { BT_UUID_UNSPEC = 0, From patchwork Tue Sep 5 07:09:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitin Jadhav X-Patchwork-Id: 720475 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 37A73CA0FF8 for ; Tue, 5 Sep 2023 16:22:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349857AbjIEQWP (ORCPT ); Tue, 5 Sep 2023 12:22:15 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353669AbjIEHJ4 (ORCPT ); Tue, 5 Sep 2023 03:09:56 -0400 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2074.outbound.protection.outlook.com [40.107.7.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 10533CC7 for ; Tue, 5 Sep 2023 00:09:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=P7PMQceJG3zCE/2bTzmUAbn0AV8L73ovchJYONzH3OrZUpWPDQzV5IgSp2keZ0W7ikViwND1JL16n8uxbN0jJIzl6GxmcCdhoJzr2aPnnnRBXGNOzAfy1243M9WgH4UDosMDnv0mjIOvFW3jtSx0A3SkSM87TSY7qSRveWKNUqTBGVUQ5uG7Vr4559yMLHfQV/FbC7v8X1ta32jSgbYoZRdtYnH9PaPBTYsYYnvXA7v5rO2CmjRtmNZxvMYj42DcN5E11ZiaZX892r20imYv19MMtrmqrUKEIP3Km8bGipLWZjcUX52qDpebdwInM1XRqQj66OF6E2pk7m+4/zpuSQ== 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=FSMT7anxis4XnZT55IqrZ80Uet4MUDgC9xAuttBq4tE=; b=Cr79zNJc2BtqkABms0vXk9QZLjAlPtBGyvm4A6iSZVV5TICbNngaZIERwWubdK4Y2X5SqVHNHIVn5lwFQ7/ZBQyWpclu98z+DEnge5PsMIdHESUfyHJH1DnVILCb1aJLZ3UtBfsVGCDYz50S5luPqkx+025MQ1e/TLBMWenApTjUvnvvQ5ENJyvBwcA6Og8Tw4j02s0GwXCxD10GFMPllacl0NM5lLqh3GkrrVGXi6K4cRXP/hapskGV3PMETQVfr+b8o+8OcglO8zO22oUoRgmQIgrR1MUp6dV+7L3rrP8SMV6ESmBkWrvrlYabjK295W7UsEnJyL2/2li3fmhyhQ== 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=FSMT7anxis4XnZT55IqrZ80Uet4MUDgC9xAuttBq4tE=; b=bzb60P/lmWwep6i/98r8dSK7Pr5VskIHL/suycXh9iGdaAgNTYDP6MSpRYdltX+yI0fc/pKpj5EBsk4fGdX6mQJ4TDK7R+9nGZ0tpZ5iIIQT7yi6jQem6ACO5Ducc8+0OdMtaAgHGUrx5Sj4bQoDfMonEpPHBFhmPDFMSkLAMwI= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB9126.eurprd04.prod.outlook.com (2603:10a6:20b:449::16) by DBBPR04MB8058.eurprd04.prod.outlook.com (2603:10a6:10:1e7::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Tue, 5 Sep 2023 07:09:47 +0000 Received: from AS8PR04MB9126.eurprd04.prod.outlook.com ([fe80::2320:fa57:8f7c:bb64]) by AS8PR04MB9126.eurprd04.prod.outlook.com ([fe80::2320:fa57:8f7c:bb64%6]) with mapi id 15.20.6745.030; Tue, 5 Sep 2023 07:09:47 +0000 From: Nitin Jadhav To: linux-bluetooth@vger.kernel.org Cc: devyani.godbole@nxp.com, mahesh.talewad@nxp.com, luiz.dentz@gmail.com, nitin.jadhav@nxp.com Subject: [PATCH BlueZ v2 2/4] src/shared/micp.c: To implement MICP profile MICS service Date: Tue, 5 Sep 2023 10:09:10 +0300 Message-Id: <20230905070912.82340-3-nitin.jadhav@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230905070912.82340-1-nitin.jadhav@nxp.com> References: <20230905070912.82340-1-nitin.jadhav@nxp.com> X-ClientProxiedBy: SI2PR02CA0031.apcprd02.prod.outlook.com (2603:1096:4:195::16) To AS8PR04MB9126.eurprd04.prod.outlook.com (2603:10a6:20b:449::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB9126:EE_|DBBPR04MB8058:EE_ X-MS-Office365-Filtering-Correlation-Id: 31c770bf-38d9-4eeb-cffa-08dbaddf16d5 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2YRutk02JJmZXKbxFh+Id1i+76OqfYH3goLCkXVM8/ews+GsG/JBaf3F7PxnYaZvzQIIEP0DgK5732RCYEmkKExKYiC8vdVw03AulK8X2VOiSP+r9YPQF41gXyxlEcy0jw4RUG8+8Y6XebZnVQWSzw/rrDNp9fgHgHtyH5vWZiUthDKpQKb+R1Co7BItk9IWSJKUgmE7GDF43J/HNNhDTsQJ89PKPMR1S3kkCMoYqHDPwOGIy7Islu5J+L1cjV0E0/SOYa/hAI28abKKOOpXA8l5UCS/mG56bN04P+qhYEKlyVJjUie9EoN2L76R0WRYuhSVlVfQuR1sux4hcgpbI8xAqA7FKq+zOMFsceWw75JDuHwtQCSERkFQy9a7L8K2Tb3Hk70IWfTVy4QMAOZty/JKE8ygoPbqTWwWq2Xs231vV/S6n/cGSUPWAKM8eKc9VT6Oz/OJ/fF9BpYLMK81323hc/Cnki4xqfVF8YTBhDrlfD9Js26QHRLa06L2SHsSYYYRguA6sEhg216qswfqZgEfWQzcQTXOQ1tbFpDNvzZnb72xvaMNx9UpNs4uv2wYkt9gItihN5d3z0TmmdkgwIS07frOdTEoHrcs82gYEW8= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR04MB9126.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(396003)(346002)(376002)(136003)(39860400002)(366004)(451199024)(1800799009)(186009)(66946007)(66556008)(66476007)(6916009)(478600001)(38100700002)(38350700002)(316002)(30864003)(2906002)(41300700001)(86362001)(8936002)(8676002)(4326008)(5660300002)(44832011)(6506007)(83380400001)(6512007)(6666004)(6486002)(52116002)(55236004)(2616005)(26005)(1076003)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: uhDoSQpYsHwhNtfUvueTPyPU/KRHSf+VCzCiqfnfvO+QW/4VaGSJK/saSoMG4Iowlmlx3hSMWa4h4JW4l8vJ4iUHWpoIFx6cQaUxbZfk9VX/yxE5WuXQChgvSCxSSMVkc4K12/s9y3ipq/dmwJPPDEeG/sWcQSTau8QQEww/U7lGVvT/rU+ElDDciAHQ2Wqzeiif2EPcMzw6CSwdhtl0fBp86hGRIWKM3igmcN3OJDfXUJ1tLUudKVDfS12PSEulUbZEAoyqmwTB7L8zYAE1ajJeE8Fbb/JBS6EAlSbuj7hdE89rv/rTgWdumiQwYuKxfqWopZqfnsUpKzroZQ6c8ra8XxLtc5P/nwIaqXAPCr7BePD8Fdw4RoEOPOdv1loycjWVFNw9LD4ASx06mZNYkndQOpgEAsug1TKqerfNtBZsbW8guEfZjKZUBieTg+4Z/hyybYurP/WV2g7qgvYJurjgNZpVZjuTgoACUylvvllOMOqn0GL+nwqnpETaoK/ty93NdXgVhX1ACoZ170KgnGqH5i315RdzHVrILfZQgn06Mb02JonUvLdy/e7aZsa7ocND8wFa74tq0RIb7/16ILnwut2D8PLL4IIz+ADXfs8C8OMQ6X0GgBeGahTaRce/ajj6Wtt7HA1FZdvMer9ECFy7uuPePLmqIP/AuEQIZzpYn8GpQjFfpUNF5guRkzpa303tu/qhiuJrD0k2dt72vkYEUpBV+znZcbGMG11gNhz4dCsJaiF6bl0E0cp9pDj7intOp1pjhkU3dB/yN+FoeZktME6MRN4bIwdckSi09yW1OHOHVcln+6q9Dh2sxMLYJ3FiiB4RyXOE4GhUClw60gpm+1oH7d5UaNBrxZ/e/Bi6/gPpAEL509IAp29QEKZE0QcSMK1282BqqaT5jO9oXoTq0/Gy/pr1X/B8ZH1r27BNyRlMFGFtbpDSvu32PraR9v6JsVgpJ0APt2dOOM/fiaQqDBu46xKNSR2Pt9R5CBC2zIk75VCt/sFPhVIODv+bf1bfQuN81P6B7nvmX1bCDf++iQlQgepBR3ZmMrzI+ZdRQXxJJINpDMk4mf+SyE9sD+M645y83uohNrAgLG4UeghEeny7UiNIVTH85yfWclzKUQ7vXr+ZlDcpUx+QoCJf+K80jfAckBp5BcseNze2DRZmCTIqULhMBLkasfGpcfGn7Pxv+nTVHWsYcBwLJtbgirhMxPgO4+trNOCbli1vjRAMCpyLXSs1J39wWygEC2ahua0xT6q4IlnIHN2wZ/Itqfvr5Ck7nuJTiU0kNJ5NH1NFdZ4CE2OY0CgeG4E7ze0r6o3cRG9UegnS6B0y6JlKBEtZK/cL96ET0ZyqKD3DWyJE9OFx0xQoeFC/lkZssuEw7yWrN+Qn1AgtRr4q+NFPG7wm9WEfxQ6JxKyxz1+2YMqIuy2kNqGrDVMZUq0NVnvhhbSbxwgsjt10cFsBrrZZ7veNiv/eSSFMdUd8xWXMh5GN1fYklbGUiypgYMip3hQhRwYOrwb/YgjvTVbK30CwFo/b/jx8KD/RefwHtGmR2HmbkUNV2+5s4x0uJ4aDtZV6eLv6bMkgRnmtlpFWaf/f X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 31c770bf-38d9-4eeb-cffa-08dbaddf16d5 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB9126.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2023 07:09:47.8158 (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: qEluy2boBsJl7By30iahJdsiUtSw/HYCQMTwl7//Y/3hwuoFIxbML1TK3C9sKHdIs5eoF5xKwR4QXgfh0YOZBw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB8058 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org - Implementation of functions related profile and service for MICS and MICP - Specifications referred for implementation: MICS - MICS_v1.0.pdf MICP - MICP_v1.0.pdf Co-developed-by: Mahesh Talewad Signed-off-by: Mahesh Talewad Signed-off-by: Nitin Jadhav --- Makefile.am | 1 + src/shared/micp.c | 887 ++++++++++++++++++++++++++++++++++++++++++++++ src/shared/micp.h | 83 +++++ 3 files changed, 971 insertions(+) create mode 100644 src/shared/micp.c create mode 100644 src/shared/micp.h diff --git a/Makefile.am b/Makefile.am index 4b9b7e5cd..6f40f2a74 100644 --- a/Makefile.am +++ b/Makefile.am @@ -233,6 +233,7 @@ shared_sources = src/shared/io.h src/shared/timeout.h \ src/shared/bap.h src/shared/bap.c src/shared/ascs.h \ src/shared/mcs.h src/shared/mcp.h src/shared/mcp.c \ src/shared/vcp.c src/shared/vcp.h \ + src/shared/micp.c src/shared/micp.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 diff --git a/src/shared/micp.c b/src/shared/micp.c new file mode 100644 index 000000000..90d05b301 --- /dev/null +++ b/src/shared/micp.c @@ -0,0 +1,887 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2023 NXP Semiconductors. All rights reserved. + * + */ +#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/timeout.h" +#include "src/shared/att.h" +#include "src/shared/gatt-db.h" +#include "src/shared/gatt-server.h" +#include "src/shared/gatt-helpers.h" +#include "src/shared/micp.h" + +#define DBG(_micp, fmt, arg...) \ + micp_debug(_micp, "%s:%s() " fmt, __FILE__, __func__, ##arg) + +/* Application error codes */ +#define MICP_ERROR_MUTE_DISABLED 0x80 +#define MICP_ERROR_VALUE_NOT_ALLOWED 0x13 +#define BT_ATT_ERROR_OPCODE_NOT_SUPPORTED 0x81 + +/* Mute char values */ +#define MICS_NOT_MUTED 0x00 +#define MICS_MUTED 0x01 +#define MICS_DISABLED 0x02 + +static struct queue *micp_db; +static struct queue *micp_cbs; +static struct queue *sessions; + +struct bt_micp_cb { + unsigned int id; + bt_micp_func_t attached; + bt_micp_func_t detached; + void *user_data; +}; + +typedef void (*micp_func_t)(struct bt_micp *micp, bool success, + uint8_t att_ecode, const uint8_t *value, + uint16_t length, void *user_data); + +struct bt_micp_pending { + unsigned int id; + struct bt_micp *micp; + micp_func_t func; + void *userdata; +}; + +struct bt_micp_ready { + unsigned int id; + bt_micp_ready_func_t func; + bt_micp_destroy_func_t destroy; + void *data; +}; + +typedef void (*micp_notify_t)(struct bt_micp *micp, uint16_t value_handle, + const uint8_t *value, uint16_t length, + void *user_data); + +struct bt_micp_notify { + unsigned int id; + struct bt_micp *micp; + micp_notify_t func; + void *user_data; +}; + +static void *iov_pull_mem(struct iovec *iov, size_t len) +{ + void *data = iov->iov_base; + + if (iov->iov_len < len) + return NULL; + + iov->iov_base += len; + iov->iov_len -= len; + + return data; +} + +static struct bt_micp_db *micp_get_mdb(struct bt_micp *micp) +{ + if (!micp) + return NULL; + + if (micp->ldb) + return micp->ldb; + + return NULL; +} + +static uint8_t *mdb_get_mute_state(struct bt_micp_db *vdb) +{ + if (!vdb->mics) + return NULL; + + return &(vdb->mics->mute_stat); +} + +struct bt_mics *micp_get_mics(struct bt_micp *micp) +{ + if (!micp) + return NULL; + + if (micp->rdb->mics) + return micp->rdb->mics; + + micp->rdb->mics = new0(struct bt_mics, 1); + micp->rdb->mics->mdb = micp->rdb; + + return micp->rdb->mics; +} + +static void micp_detached(void *data, void *user_data) +{ + struct bt_micp_cb *cb = data; + struct bt_micp *micp = user_data; + + cb->detached(micp, cb->user_data); +} + +void bt_micp_detach(struct bt_micp *micp) +{ + if (!queue_remove(sessions, micp)) + return; + + bt_gatt_client_unref(micp->client); + micp->client = NULL; + + queue_foreach(micp_cbs, micp_detached, micp); +} + +static void micp_db_free(void *data) +{ + struct bt_micp_db *mdb = data; + + if (!mdb) + return; + + gatt_db_unref(mdb->db); + + free(mdb->mics); + free(mdb); +} + +static void micp_ready_free(void *data) +{ + struct bt_micp_ready *ready = data; + + if (ready->destroy) + ready->destroy(ready->data); + + free(ready); +} + +static void micp_free(void *data) +{ + struct bt_micp *micp = data; + + bt_micp_detach(micp); + + micp_db_free(micp->rdb); + + queue_destroy(micp->pending, NULL); + queue_destroy(micp->ready_cbs, micp_ready_free); + + free(micp); +} + +bool bt_micp_set_user_data(struct bt_micp *micp, void *user_data) +{ + + if (!micp) + return false; + + micp->user_data = user_data; + + return true; +} + +static bool micp_db_match(const void *data, const void *match_data) +{ + const struct bt_micp_db *mdb = data; + const struct gatt_db *db = match_data; + + return (mdb->db == db); +} + +struct bt_att *bt_micp_get_att(struct bt_micp *micp) +{ + if (!micp) + return NULL; + + if (micp->att) + return micp->att; + + return bt_gatt_client_get_att(micp->client); +} + +struct bt_micp *bt_micp_ref(struct bt_micp *micp) +{ + if (!micp) + return NULL; + + __sync_fetch_and_add(&micp->ref_count, 1); + + return micp; +} + +void bt_micp_unref(struct bt_micp *micp) +{ + if (!micp) + return; + + if (__sync_sub_and_fetch(&micp->ref_count, 1)) + return; + + micp_free(micp); +} + +static void micp_debug(struct bt_micp *micp, const char *format, ...) +{ + va_list ap; + + if (!micp || !format || !micp->debug_func) + return; + + va_start(ap, format); + util_debug_va(micp->debug_func, micp->debug_data, format, ap); + va_end(ap); +} + +static void micp_disconnected(int err, void *user_data) +{ + struct bt_micp *micp = user_data; + + DBG(micp, "micp %p disconnected err %d", micp, err); + + bt_micp_detach(micp); +} + +static struct bt_micp *micp_get_session(struct bt_att *att, struct gatt_db *db) +{ + const struct queue_entry *entry; + struct bt_micp *micp; + + for (entry = queue_get_entries(sessions); entry; entry = entry->next) { + struct bt_micp *micp = entry->data; + + if (att == bt_micp_get_att(micp)) + return micp; + } + + micp = bt_micp_new(db, NULL); + micp->att = att; + + bt_att_register_disconnect(att, micp_disconnected, micp, NULL); + + bt_micp_attach(micp, NULL); + + return micp; +} + +static void mics_mute_read(struct gatt_db_attribute *attrib, + unsigned int id, uint16_t offset, + uint8_t opcode, struct bt_att *att, + void *user_data) +{ + struct bt_mics *mics = user_data; + struct iovec iov; + + iov.iov_base = &mics->mute_stat; + iov.iov_len = sizeof(mics->mute_stat); + + gatt_db_attribute_read_result(attrib, id, 0, iov.iov_base, + iov.iov_len); +} + +static uint8_t mics_not_muted(struct bt_mics *mics, struct bt_micp *micp, + struct iovec *iov) +{ + struct bt_micp_db *mdb; + uint8_t *mute_state; + + DBG(micp, "Mute state OP: Not Muted"); + + mdb = micp_get_mdb(micp); + if (!mdb) { + DBG(micp, "error: MDB not available"); + return 0; + } + + mute_state = mdb_get_mute_state(mdb); + if (!mute_state) { + DBG(micp, "Error : Mute State not available"); + return 0; + } + + *mute_state = MICS_NOT_MUTED; + + gatt_db_attribute_notify(mdb->mics->ms, (void *)mute_state, + sizeof(uint8_t), bt_micp_get_att(micp)); + + return 0; +} + +static uint8_t mics_muted(struct bt_mics *mics, struct bt_micp *micp, + struct iovec *iov) +{ + struct bt_micp_db *mdb; + uint8_t *mute_state; + + DBG(micp, "Mute state OP: Muted"); + + mdb = micp_get_mdb(micp); + if (!mdb) { + DBG(micp, "error: MDB not available"); + return 0; + } + + mute_state = mdb_get_mute_state(mdb); + + *mute_state = MICS_MUTED; + + gatt_db_attribute_notify(mdb->mics->ms, (void *)mute_state, + sizeof(uint8_t), bt_micp_get_att(micp)); + + return 0; +} + +#define MICS_OP(_str, _op, _size, _func) \ + { \ + .str = _str, \ + .op = _op, \ + .size = _size, \ + .func = _func, \ + } + +struct mics_op_handler { + const char *str; + uint8_t op; + size_t size; + uint8_t (*func)(struct bt_mics *mics, struct bt_micp *micp, + struct iovec *iov); +} micp_handlers[] = { + MICS_OP("Not Muted", MICS_NOT_MUTED, + sizeof(uint8_t), mics_not_muted), + MICS_OP("Muted", MICS_MUTED, + sizeof(uint8_t), mics_muted), + {}}; + +static void mics_mute_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 bt_mics *mics = user_data; + struct bt_micp *micp = micp_get_session(att, mics->mdb->db); + struct iovec iov = { + .iov_base = (void *)value, + .iov_len = len, + }; + uint8_t *micp_op, *mute_state; + struct mics_op_handler *handler; + uint8_t ret = BT_ATT_ERROR_REQUEST_NOT_SUPPORTED; + struct bt_micp_db *mdb; + + DBG(micp, "MICS Mute Char write: len: %ld: %ld", len, iov.iov_len); + + if (offset) { + DBG(micp, "invalid offset: %d", offset); + ret = BT_ATT_ERROR_INVALID_OFFSET; + goto respond; + } + + if (len < sizeof(*micp_op)) { + DBG(micp, "invalid length: %ld < %ld sizeof(param)", len, + sizeof(*micp_op)); + ret = BT_ATT_ERROR_INVALID_ATTRIBUTE_VALUE_LEN; + goto respond; + } + + micp_op = iov_pull_mem(&iov, sizeof(*micp_op)); + + if ((*micp_op == MICS_DISABLED) || (*micp_op != MICS_NOT_MUTED + && *micp_op != MICS_MUTED)) { + DBG(micp, "Invalid operation - MICS DISABLED/RFU mics op:%d", + micp_op); + ret = MICP_ERROR_VALUE_NOT_ALLOWED; + goto respond; + } + + mdb = micp_get_mdb(micp); + if (!mdb) { + DBG(micp, "error: MDB not available"); + goto respond; + } + + mute_state = mdb_get_mute_state(mdb); + if (*mute_state == MICS_DISABLED) { + DBG(micp, "state: MICS DISABLED , can not write value: %d", + *micp_op); + ret = MICP_ERROR_MUTE_DISABLED; + goto respond; + } + + for (handler = micp_handlers; handler && handler->str; handler++) { + DBG(micp, "handler->op: %d micp_op: %d iov.iov_len: %ld", + handler->op, *micp_op, iov.iov_len); + if (handler->op != *micp_op) + continue; + + if (len < handler->size) { + DBG(micp, "invalid len %ld : %ld < %ld handler->size", + len, iov.iov_len, handler->size); + ret = BT_ATT_ERROR_OPCODE_NOT_SUPPORTED; + goto respond; + } + + break; + } + + if (handler && handler->str) { + DBG(micp, "%s", handler->str); + + ret = handler->func(mics, micp, &iov); + } else { + DBG(micp, "unknown opcode 0x%02x", *micp_op); + ret = BT_ATT_ERROR_OPCODE_NOT_SUPPORTED; + } + +respond: + gatt_db_attribute_write_result(attrib, id, ret); +} + +static struct bt_mics *mics_new(struct gatt_db *db) +{ + struct bt_mics *mics; + bt_uuid_t uuid; + + if (!db) + return NULL; + + mics = new0(struct bt_mics, 1); + + mics->mute_stat = MICS_MUTED; + + /* Populate DB with MICS attributes */ + bt_uuid16_create(&uuid, MICS_UUID); + mics->service = gatt_db_add_service(db, &uuid, true, 4); + + bt_uuid16_create(&uuid, MUTE_CHRC_UUID); + mics->ms = gatt_db_service_add_characteristic(mics->service, + &uuid, + BT_ATT_PERM_READ | BT_ATT_PERM_WRITE, + BT_GATT_CHRC_PROP_READ | BT_GATT_CHRC_PROP_WRITE + | BT_GATT_CHRC_PROP_NOTIFY, + mics_mute_read, mics_mute_write, + mics); + + mics->ms_ccc = gatt_db_service_add_ccc(mics->service, + BT_ATT_PERM_READ | BT_ATT_PERM_WRITE); + + gatt_db_service_set_active(mics->service, true); + + return mics; +} + +static struct bt_micp_db *micp_db_new(struct gatt_db *db) +{ + struct bt_micp_db *mdb; + + if (!db) + return NULL; + + mdb = new0(struct bt_micp_db, 1); + mdb->db = gatt_db_ref(db); + + if (!micp_db) + micp_db = queue_new(); + + mdb->mics = mics_new(db); + mdb->mics->mdb = mdb; + + queue_push_tail(micp_db, mdb); + + return mdb; +} + +static struct bt_micp_db *micp_get_db(struct gatt_db *db) +{ + struct bt_micp_db *mdb; + + mdb = queue_find(micp_db, micp_db_match, db); + if (mdb) + return mdb; + + return micp_db_new(db); +} + +void bt_micp_add_db(struct gatt_db *db) +{ + micp_db_new(db); +} + +bool bt_micp_set_debug(struct bt_micp *micp, bt_micp_debug_func_t func, + void *user_data, bt_micp_destroy_func_t destroy) +{ + if (!micp) + return false; + + if (micp->debug_destroy) + micp->debug_destroy(micp->debug_data); + + micp->debug_func = func; + micp->debug_destroy = destroy; + micp->debug_data = user_data; + + return true; +} + +unsigned int bt_micp_register(bt_micp_func_t attached, bt_micp_func_t detached, + void *user_data) +{ + struct bt_micp_cb *cb; + static unsigned int id; + + if (!attached && !detached) + return 0; + + if (!micp_cbs) + micp_cbs = queue_new(); + + cb = new0(struct bt_micp_cb, 1); + cb->id = ++id ? id : ++id; + cb->attached = attached; + cb->detached = detached; + cb->user_data = user_data; + + queue_push_tail(micp_cbs, cb); + + return cb->id; +} + +static bool match_id(const void *data, const void *match_data) +{ + const struct bt_micp_cb *cb = data; + unsigned int id = PTR_TO_UINT(match_data); + + return (cb->id == id); +} + +bool bt_micp_unregister(unsigned int id) +{ + struct bt_micp_cb *cb; + + cb = queue_remove_if(micp_cbs, match_id, UINT_TO_PTR(id)); + if (!cb) + return false; + + free(cb); + + return true; +} + +struct bt_micp *bt_micp_new(struct gatt_db *ldb, struct gatt_db *rdb) +{ + struct bt_micp *micp; + struct bt_micp_db *mdb; + + if (!ldb) + return NULL; + + mdb = micp_get_db(ldb); + if (!mdb) + return NULL; + + micp = new0(struct bt_micp, 1); + micp->ldb = mdb; + micp->pending = queue_new(); + micp->ready_cbs = queue_new(); + + if (!rdb) + goto done; + + mdb = new0(struct bt_micp_db, 1); + mdb->db = gatt_db_ref(rdb); + + micp->rdb = mdb; + +done: + bt_micp_ref(micp); + + return micp; +} + +static void micp_pending_destroy(void *data) +{ + struct bt_micp_pending *pending = data; + struct bt_micp *micp = pending->micp; + + if (queue_remove_if(micp->pending, NULL, pending)) + free(pending); +} + +static void micp_pending_complete(bool success, uint8_t att_ecode, + const uint8_t *value, uint16_t length, + void *user_data) +{ + struct bt_micp_pending *pending = user_data; + + if (pending->func) + pending->func(pending->micp, success, att_ecode, value, length, + pending->userdata); +} + +static void micp_read_value(struct bt_micp *micp, uint16_t value_handle, + micp_func_t func, void *user_data) +{ + struct bt_micp_pending *pending; + + pending = new0(struct bt_micp_pending, 1); + pending->micp = micp; + pending->func = func; + pending->userdata = user_data; + + pending->id = bt_gatt_client_read_value(micp->client, value_handle, + micp_pending_complete, pending, + micp_pending_destroy); + + if (!pending->id) { + DBG(micp, "unable to send read request"); + free(pending); + return; + } + + queue_push_tail(micp->pending, pending); +} + +static void micp_register(uint16_t att_ecode, void *user_data) +{ + struct bt_micp_notify *notify = user_data; + + if (att_ecode) + DBG(notify->micp, "MICP register failed 0x%04x", att_ecode); +} + +static void micp_notify(uint16_t value_handle, const uint8_t *value, + uint16_t length, void *user_data) +{ + struct bt_micp_notify *notify = user_data; + + if (notify->func) + notify->func(notify->micp, value_handle, value, length, + notify->user_data); +} + +static void micp_notify_destroy(void *data) +{ + struct bt_micp_notify *notify = data; + struct bt_micp *micp = notify->micp; + + if (queue_remove_if(micp->notify, NULL, notify)) + free(notify); +} + +static unsigned int micp_register_notify(struct bt_micp *micp, + uint16_t value_handle, + micp_notify_t func, + void *user_data) +{ + struct bt_micp_notify *notify; + + notify = new0(struct bt_micp_notify, 1); + notify->micp = micp; + notify->func = func; + notify->user_data = user_data; + + notify->id = bt_gatt_client_register_notify(micp->client, + value_handle, micp_register, + micp_notify, notify, + micp_notify_destroy); + if (!notify->id) { + DBG(micp, "Unable to register for notifications"); + free(notify); + return 0; + } + + queue_push_tail(micp->notify, notify); + + return notify->id; +} + +static void micp_mute_state_notify(struct bt_micp *micp, uint16_t value_handle, + const uint8_t *value, uint16_t length, + void *user_data) +{ + uint8_t mute_state; + + memcpy(&mute_state, value, sizeof(mute_state)); + + DBG(micp, "Mute state: 0x%x", mute_state); +} + +static void read_mute_state(struct bt_micp *micp, bool success, + uint8_t att_ecode, const uint8_t *value, + uint16_t length, void *user_data) +{ + uint8_t *mute_state; + struct iovec iov = { + .iov_base = (void *)value, + .iov_len = length, + }; + + if (!success) { + DBG(micp, "Unable to read Mute state: error 0x%02x", att_ecode); + return; + } + + mute_state = iov_pull_mem(&iov, sizeof(uint8_t)); + if (mute_state == NULL) { + DBG(micp, "Unable to get Mute state"); + return; + } + + DBG(micp, "Mute state: %x", *mute_state); +} + +static void foreach_mics_char(struct gatt_db_attribute *attr, void *user_data) +{ + struct bt_micp *micp = user_data; + uint16_t value_handle; + bt_uuid_t uuid, uuid_mute; + struct bt_mics *mics; + + if (!gatt_db_attribute_get_char_data(attr, NULL, &value_handle, + NULL, NULL, &uuid)) + return; + + bt_uuid16_create(&uuid_mute, MUTE_CHRC_UUID); + if (!bt_uuid_cmp(&uuid, &uuid_mute)) { + DBG(micp, "MICS Mute characteristic found: handle 0x%04x", + value_handle); + + mics = micp_get_mics(micp); + if (!mics || mics->ms) + return; + + mics->ms = attr; + + micp_read_value(micp, value_handle, read_mute_state, micp); + + micp->mute_id = micp_register_notify(micp, value_handle, + micp_mute_state_notify, NULL); + } +} + +static void foreach_mics_service(struct gatt_db_attribute *attr, + void *user_data) +{ + struct bt_micp *micp = user_data; + struct bt_mics *mics = micp_get_mics(micp); + + mics->service = attr; + + gatt_db_service_set_claimed(attr, true); + gatt_db_service_foreach_char(attr, foreach_mics_char, micp); +} + +unsigned int bt_micp_ready_register(struct bt_micp *micp, + bt_micp_ready_func_t func, void *user_data, + bt_micp_destroy_func_t destroy) +{ + struct bt_micp_ready *ready; + static unsigned int id; + + DBG(micp, "bt_micp_ready_register_Entry\n"); + if (!micp) + return 0; + + ready = new0(struct bt_micp_ready, 1); + ready->id = ++id ? id : ++id; + ready->func = func; + ready->destroy = destroy; + ready->data = user_data; + + queue_push_tail(micp->ready_cbs, ready); + + return ready->id; +} + +static bool match_ready_id(const void *data, const void *match_data) +{ + const struct bt_micp_ready *ready = data; + unsigned int id = PTR_TO_UINT(match_data); + + return (ready->id == id); +} + +bool bt_micp_ready_unregister(struct bt_micp *micp, unsigned int id) +{ + struct bt_micp_ready *ready; + + ready = queue_remove_if(micp->ready_cbs, match_ready_id, + UINT_TO_PTR(id)); + if (!ready) + return false; + + micp_ready_free(ready); + + return true; +} + +static struct bt_micp *bt_micp_ref_safe(struct bt_micp *micp) +{ + if (!micp || !micp->ref_count) + return NULL; + + return bt_micp_ref(micp); +} + +static void micp_notify_ready(struct bt_micp *micp) +{ + const struct queue_entry *entry; + + if (!bt_micp_ref_safe(micp)) + return; + + for (entry = queue_get_entries(micp->ready_cbs); entry; + entry = entry->next) { + struct bt_micp_ready *ready = entry->data; + + ready->func(micp, ready->data); + } + + bt_micp_unref(micp); +} + +static void micp_idle(void *data) +{ + struct bt_micp *micp = data; + + micp->idle_id = 0; + micp_notify_ready(micp); +} + +bool bt_micp_attach(struct bt_micp *micp, struct bt_gatt_client *client) +{ + bt_uuid_t uuid; + + if (!sessions) + sessions = queue_new(); + + queue_push_tail(sessions, micp); + + if (!client) + return true; + + if (micp->client) + return false; + + micp->client = bt_gatt_client_clone(client); + if (!micp->client) + return false; + + bt_gatt_client_idle_register(micp->client, micp_idle, micp, NULL); + + bt_uuid16_create(&uuid, MICS_UUID); + gatt_db_foreach_service(micp->ldb->db, &uuid, foreach_mics_service, + micp); + return true; +} diff --git a/src/shared/micp.h b/src/shared/micp.h new file mode 100644 index 000000000..c881aded9 --- /dev/null +++ b/src/shared/micp.h @@ -0,0 +1,83 @@ +/* SPDX-License-Identifier: LGPL-2.1-or-later */ +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2023 NXP Semiconductors. All rights reserved. + * + */ +#include +#include + +#include "src/shared/io.h" +#include "src/shared/gatt-client.h" + +struct bt_mics; +struct bt_micp; + +typedef void (*bt_micp_ready_func_t)(struct bt_micp *micp, void *user_data); +typedef void (*bt_micp_destroy_func_t)(void *user_data); +typedef void (*bt_micp_debug_func_t)(const char *str, void *user_data); +typedef void (*bt_micp_func_t)(struct bt_micp *micp, void *user_data); + +struct bt_micp_db { + struct gatt_db *db; + struct bt_mics *mics; +}; + +struct bt_mics { + struct bt_micp_db *mdb; + uint8_t mute_stat; + struct gatt_db_attribute *service; + struct gatt_db_attribute *ms; + struct gatt_db_attribute *ms_ccc; +}; + +struct bt_micp { + int ref_count; + struct bt_micp_db *ldb; + struct bt_micp_db *rdb; + struct bt_gatt_client *client; + struct bt_att *att; + unsigned int mute_id; + + unsigned int idle_id; + uint8_t mute; + + struct queue *notify; + struct queue *pending; + struct queue *ready_cbs; + + bt_micp_debug_func_t debug_func; + bt_micp_destroy_func_t debug_destroy; + + void *debug_data; + void *user_data; +}; + +struct bt_micp *bt_micp_ref(struct bt_micp *micp); +void bt_micp_unref(struct bt_micp *micp); + +void bt_micp_add_db(struct gatt_db *db); + +bool bt_micp_attach(struct bt_micp *micp, struct bt_gatt_client *client); +void bt_micp_detach(struct bt_micp *micp); + +bool bt_micp_set_debug(struct bt_micp *micp, bt_micp_debug_func_t func, + void *user_data, bt_micp_destroy_func_t destroy); + +struct bt_att *bt_micp_get_att(struct bt_micp *micp); + +bool bt_micp_set_user_data(struct bt_micp *micp, void *user_data); + +/* session related functions */ +unsigned int bt_micp_register(bt_micp_func_t attached, bt_micp_func_t detached, + void *user_data); +unsigned int bt_micp_ready_register(struct bt_micp *micp, + bt_micp_ready_func_t func, void *user_data, + bt_micp_destroy_func_t destroy); +bool bt_micp_ready_unregister(struct bt_micp *micp, unsigned int id); + +bool bt_micp_unregister(unsigned int id); +struct bt_micp *bt_micp_new(struct gatt_db *ldb, struct gatt_db *rdb); +struct bt_mics *micp_get_mics(struct bt_micp *micp); From patchwork Tue Sep 5 07:09:11 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitin Jadhav X-Patchwork-Id: 720473 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 34731CA0FE2 for ; Tue, 5 Sep 2023 16:23:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234313AbjIEQWy (ORCPT ); Tue, 5 Sep 2023 12:22:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43272 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353670AbjIEHJ5 (ORCPT ); Tue, 5 Sep 2023 03:09:57 -0400 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2074.outbound.protection.outlook.com [40.107.7.74]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AE5C31B4 for ; Tue, 5 Sep 2023 00:09:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ZOAA8gaDOEU49PeA2KxImyGe/XPxVSL4FkJdGexKIrxncvP9T7ZTOz5vq2aWUUL9eJi2To0tL+5q8TGONoXitGsYiXl9Q372SBmtZ7RPKeNTIvgACFTbNBeDyyzu7EQkpocLjs9uhzU7ws1KwVBRu393gHlGppNqoUIR3zqnJPw7cdZws7vIL31++Td/6jZuLbuYhXlKRgX0jsPml/N3yG75EVgzauvdJY/uxp/CcZiuU2vffM+HaqF/ZoV35/HTGhWzR78R5of88AkDIHuCo5+EHTijzhUKEs8KUcqQnjzjZpYALWJZp0ctIG9vdC2zMMF19jRmUNCCM/i9Hn6xyA== 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=5QixYa73qMrOEn2y44yuyOC4vF8yJozPeyquUdBrhJw=; b=ZiusdtuJUTQwhF+kAng7PGMM6/PrWlhouDJ+sOWB0FrXJXkZag2taB7R4i8hkbbvpZu9LWZbHC7g1bQnkl/k1RogKpM1tFmc3Jtj7UeIj/bAlvvtUd80N+ju2uTG5+XeZeXGl3Bl2Hh1gCv0apl4SXgeuwPPGL82xmo824zbm8AzGvDMGE3ILOuM79HmAwPBB7UwZC1E0rtTo3EUnMomoWsVZXxlv7YDNmLYpoN35KbdfqFN0ArA0QHfxdrOCABzVgkrWUPo+p1pcauIAnuoIKraki9vJFAW2Wc4TwblB4RRy5k3tCLUPN2lMZUbO3ua3Q0EfuKBhaHs30hxmm23yw== 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=5QixYa73qMrOEn2y44yuyOC4vF8yJozPeyquUdBrhJw=; b=lRLmmTFQzI9IdhelBheos0zsjm8sePUfzy1hq+XVSrGjjNIJ6urdZjjI6jsvY1+k3wuLdBso7h7wzKp9TSlzqY4PtUSFExTN36xSYlktiiNlDsa46B/1PtY2wqUtHah+OawpiYin83FFnqbe07aCUUuvsuCTEKkhqdKSsXLRIaM= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB9126.eurprd04.prod.outlook.com (2603:10a6:20b:449::16) by DBBPR04MB8058.eurprd04.prod.outlook.com (2603:10a6:10:1e7::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Tue, 5 Sep 2023 07:09:51 +0000 Received: from AS8PR04MB9126.eurprd04.prod.outlook.com ([fe80::2320:fa57:8f7c:bb64]) by AS8PR04MB9126.eurprd04.prod.outlook.com ([fe80::2320:fa57:8f7c:bb64%6]) with mapi id 15.20.6745.030; Tue, 5 Sep 2023 07:09:51 +0000 From: Nitin Jadhav To: linux-bluetooth@vger.kernel.org Cc: devyani.godbole@nxp.com, mahesh.talewad@nxp.com, luiz.dentz@gmail.com, nitin.jadhav@nxp.com Subject: [PATCH BlueZ v2 3/4] profiles/audio/micp.c: To implement MICP plugin Date: Tue, 5 Sep 2023 10:09:11 +0300 Message-Id: <20230905070912.82340-4-nitin.jadhav@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230905070912.82340-1-nitin.jadhav@nxp.com> References: <20230905070912.82340-1-nitin.jadhav@nxp.com> X-ClientProxiedBy: SI2PR02CA0031.apcprd02.prod.outlook.com (2603:1096:4:195::16) To AS8PR04MB9126.eurprd04.prod.outlook.com (2603:10a6:20b:449::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB9126:EE_|DBBPR04MB8058:EE_ X-MS-Office365-Filtering-Correlation-Id: 95963ddf-4da9-4b23-7220-08dbaddf191b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: r62JeXrfxDNzxU2Cpiytsou4kTCZlg7+NTC/T6n0ah7P2RqYDUnNpmkGH91pF9eKTCYVHUiopAHvc5bd8cf2WKhOf0cOkcPzkoTEMCzZImfyptEEK5KwuIBhm3e+je72atC0/6+0LzBPSfC3w7UrbNVGcJ0xMZktFLxU3u8tBvPl+SrAp6ND2ANyEQGL9xyQTiARnz7FFmkdoTstk0ktXN+5W3ntndHGuJIc8appsVX/iRgc70gK6KxZ7YsAqwTh3Igv2LhTOFmzY2N244m+SUNTQnjyvI3mrR1/ST5UgE9M2c+5S42aHv2f8yBcVAZWI1JrlUIWvcAc1nguz06lyFB77rMjZE901TPHVR6Fv8Y9ty1d+pITJi1zCNDr6922jTY89ibh9ngAHEi7e1DtgdtKn9mpC+LFbtXzeeIHfO6GONWQmprre7wUfGVLZ2Ypwnt0D/nG8I5XY89cdY8fZ7M028r9XJstBtkH+YZbgw+qp0C2W0nQFBKt+KQranliuDVJHxz6OajGYFrjSnZzl3E6iSHBmhgPWYmH+AGsofIkPjHzHosyEAsVP1E5M36FOO6LAxHJOiA2xFCfZ6dA6Ns9I4RSm2FmGGMSRELxWQvIzyu9i4wF0+G6gYd/fK+Q X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR04MB9126.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(396003)(346002)(376002)(136003)(39860400002)(366004)(451199024)(1800799009)(186009)(66946007)(66556008)(66476007)(6916009)(478600001)(38100700002)(38350700002)(316002)(2906002)(41300700001)(86362001)(8936002)(8676002)(4326008)(5660300002)(44832011)(6506007)(6512007)(6666004)(6486002)(52116002)(55236004)(2616005)(26005)(1076003)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: p1bzOA8DeSQ1R+rcaVUeih1Om9ztiwQp3KA7ZWAweDRme9YYLX+KZqihpNySg2oOjKBlHZ1758u17h/wolEEBjnEdmjHZlWpsm2P42blB6vR32CfCSzMLkJ3tMzVssNYyS4t6nghbsyguKdThBFK+ibn0GewIfGJtIc2WV5FHOFouYOG1PSAkxtnX+aE5LwBZqniw/VjwSHcL7/kp8F++YVxRhj2fj9IGmTYNG+x/m5zHWAypNJLKgW1/qUEQFBXZ4mkhjYa/74I5uRto3OqdpIevzBKNy/M05QwN7Lq4D5eaieiUFy01Ho/kzdTYYbcfjVs4hUYFhUZCNMfdksND2k/Rudq93s6vdzpPf66cEfsuaUSsObfIyb2Ay76dXw60N6zzmZwafcD6tegVIt2vI5hrwbFUNjSMjs6pmGP8QsO54Wf8nAJOlO4TRdM+qQHi5EwLn0pLS06y3HvmUG4iDgu4yHE19DrU3+C/a4tC4OFywPT1E1j2I5Wqeo3Iao1xqOLLO2DdGRCAXbv2fC7QArAnKRiizIiyOudvrSglOADHxqyZN5ojD1slnaZLQRRg94l6ZV72vNwTNiaSvolutxAN4qfh0Q5OX6h4oLe2WTvb2QHuSGGuNiO3kvPYwRmDMrUUBfRbhgLtY/TWFYlusqPUrguNBYQ5GSoOxO5T6oGjIzoBRtgaoYVc9OLNetj89Wd7f5fNNOqwySaCX60Q6AD1MiMhp+ONMMtuHHJaJqYIGflsqUS3x1Woh4fIy7ML4ViBqKhZ/e45yJQPSM3HCA0UzKGYNnwHZeqUbcoJlIb+qthS/TATKCFkf08y/G1wco85hL0XCTWJHeX35PHq+zqrWy1bOoTAdFxR2Cl4NR5Il/qyqt0kQ2brKJ3XW7biADCB2nEhmpHu/mF+bsKFNcDItvRXKA7BrcP/noBRc6XtMd6izp1jEvFzmM53ZDcpq49d95gXTZ3hToNIJTP/FFWIecEdG/qDHPIKoMAYunJLgQzb+s2fyAYm0yCoSnH6rM0dcDnBICHjiQTYBWehjMJ9PFPQppHUtMgK8c3KHmnUNXW3G5Nkn6ynXgcMItxI6Z/bl9Ul/IGmk24m4NNdOTBDFinR5tX8Ga9IJ5rAnAJPY0wLhNbjsjPXtp2lZ/DHMnPxnUFo061JcuLhsZBtsVWIDyXQ+zYVUARR1uDRhQ0YxNKYbNqq9fM9JYbVQWlVei0X2TTpIIJbdSsmjy7/YTVogNmLeJEIKtAsW8R6jI/Bt2mawGT29YurGlUOf3viPt+uMLuFCxnX2PMW0kyoukG8nJToChQOEntwFkqQyhS2LWaCZHhBPNe/qeqYKJKOtek+/diLX5NNBLIWukXxz1eWp0a+Xw3k14JYb4fCjId/8BRUdpRZ3gBmjJTkVft2eqn/+4fXLKycLZ1bQJLtNyH7uq7gFIzT0aGv85clwDzWd1JO+6oZ053l2E8rwUJ6ctwlLANS9XrTo/qP0aUecCaTlRKp2e9Pyb5GfyO0t6aARvUYuAb9iT74dg2VJQlClAlMm7z7Yl3TwNTcPnRqZuGpL5WXULb5ftznxFYJX2nZY2W7G27IoWiN5LQA3Tj X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 95963ddf-4da9-4b23-7220-08dbaddf191b X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB9126.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2023 07:09:51.6450 (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: eNnL8mvXwowX4s4hrq0alHu3OJCuUkj+dKTqPSConFwccM7C8P/9vRjPBn1cEK0ti9jQ9TWdyH8lGkqpNJZzrg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB8058 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org MICP profile level interface function have been implemented This adds initial code for MICP plugin. Co-developed-by: Mahesh Talewad Signed-off-by: Mahesh Talewad Signed-off-by: Nitin Jadhav --- Makefile.plugins | 5 + configure.ac | 4 + profiles/audio/micp.c | 340 ++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 349 insertions(+) create mode 100644 profiles/audio/micp.c diff --git a/Makefile.plugins b/Makefile.plugins index fc19522e4..5880ed0df 100644 --- a/Makefile.plugins +++ b/Makefile.plugins @@ -137,6 +137,11 @@ builtin_modules += vcp builtin_sources += profiles/audio/vcp.c endif +if MICP +builtin_modules += micp +builtin_sources += profiles/audio/micp.c +endif + if CSIP builtin_modules += csip builtin_sources += profiles/audio/csip.c diff --git a/configure.ac b/configure.ac index bc7edfcd3..9a8856380 100644 --- a/configure.ac +++ b/configure.ac @@ -211,6 +211,10 @@ AC_ARG_ENABLE(vcp, AS_HELP_STRING([--disable-vcp], [disable VCP profile]), [enable_vcp=${enableval}]) AM_CONDITIONAL(VCP, test "${enable_vcp}" != "no") +AC_ARG_ENABLE(micp, AS_HELP_STRING([--disable-micp], + [disable MICP profile]), [enable_micp=${enableval}]) +AM_CONDITIONAL(MICP, test "${enable_micp}" != "no") + AC_ARG_ENABLE(csip, AS_HELP_STRING([--disable-csip], [disable CSIP profile]), [enable_csip=${enableval}]) AM_CONDITIONAL(CSIP, test "${enable_csip}" != "no") diff --git a/profiles/audio/micp.c b/profiles/audio/micp.c new file mode 100644 index 000000000..452027c75 --- /dev/null +++ b/profiles/audio/micp.c @@ -0,0 +1,340 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2023 NXP Semiconductors. All rights reserved. + * + * + */ +#ifdef HAVE_CONFIG_H +#include +#endif + +#define _GNU_SOURCE + +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "gdbus/gdbus.h" + +#include "lib/bluetooth.h" +#include "lib/hci.h" +#include "lib/sdp.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-server.h" +#include "src/shared/micp.h" + +#include "btio/btio.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 MICS_UUID_STR "0000184D-0000-1000-8000-00805f9b34fb" + +struct micp_data { + struct btd_device *device; + struct btd_service *service; + struct bt_micp *micp; + unsigned int ready_id; +}; + +static struct queue *sessions; + +static void micp_debug(const char *str, void *user_data) +{ + DBG_IDX(0xffff, "%s", str); +} + +static int micp_disconnect(struct btd_service *service) +{ + return 0; +} + +static struct micp_data *micp_data_new(struct btd_device *device) +{ + struct micp_data *data; + + data = new0(struct micp_data, 1); + g_assert(data); + data->device = device; + + return data; +} + +static void micp_data_add(struct micp_data *data) +{ + DBG("data %p", data); + + if (queue_find(sessions, NULL, data)) { + error("data %p allready added", data); + return; + } + + bt_micp_set_debug(data->micp, micp_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 micp_data *mdata = data; + const struct bt_micp *micp = match_data; + + return mdata->micp == micp; +} + +static void micp_data_free(struct micp_data *data) +{ + if (data->service) { + btd_service_set_user_data(data->service, NULL); + bt_micp_set_user_data(data->micp, NULL); + } + + bt_micp_ready_unregister(data->micp, data->ready_id); + bt_micp_unref(data->micp); + free(data); +} + +static void micp_data_remove(struct micp_data *data) +{ + DBG("data %p", data); + + if (!queue_remove(sessions, data)) + return; + + micp_data_free(data); + + if (queue_isempty(sessions)) { + queue_destroy(sessions, NULL); + sessions = NULL; + } +} + +static void micp_detached(struct bt_micp *micp, void *user_data) +{ + struct micp_data *data; + + DBG("%p", micp); + + data = queue_find(sessions, match_data, micp); + if (!data) { + error("unable to find sessio"); + return; + } + + micp_data_remove(data); +} + +static void micp_ready(struct bt_micp *micp, void *user_data) +{ + DBG("micp %p\n", micp); +} + +static void micp_attached(struct bt_micp *micp, void *user_data) +{ + struct micp_data *data; + struct bt_att *att; + struct btd_device *device; + + DBG("%p", micp); + + data = queue_find(sessions, match_data, micp); + if (data) + return; + + att = bt_micp_get_att(micp); + if (!att) + return; + + device = btd_adapter_find_device_by_fd(bt_att_get_fd(att)); + if (!device) { + error("unable to find device"); + return; + } + + data = micp_data_new(device); + g_assert(data); + data->micp = micp; + + micp_data_add(data); +} + +static int micp_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 micp_data *data = btd_service_get_user_data(service); + char addr[18]; + + ba2str(device_get_address(device), addr); + DBG("%s", addr); + + /*Ignore, if we probed for this device allready */ + if (data) { + error("Profile probed twice for this device"); + return -EINVAL; + } + + data = micp_data_new(device); + data->service = service; + + data->micp = bt_micp_new(btd_gatt_database_get_db(database), + btd_device_get_gatt_db(device)); + + if (!data->micp) { + error("unable to create MICP instance"); + free(data); + return -EINVAL; + } + + micp_data_add(data); + + data->ready_id = bt_micp_ready_register(data->micp, micp_ready, service, + NULL); + + bt_micp_set_user_data(data->micp, service); + + return 0; +} + +static void micp_remove(struct btd_service *service) +{ + struct btd_device *device = btd_service_get_device(service); + struct micp_data *data; + char addr[18]; + + ba2str(device_get_address(device), addr); + DBG("%s", addr); + + data = btd_service_get_user_data(service); + if (!data) { + error("MICP Service not handled by profile"); + return; + } + + micp_data_remove(data); +} + +static int micp_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 micp_data *data = btd_service_get_user_data(service); + char addr[18]; + + ba2str(device_get_address(device), addr); + DBG("%s", addr); + + if (!data) { + error("MICP Service not handled by profile"); + return -EINVAL; + } + + if (!bt_micp_attach(data->micp, client)) { + error("MICP unable to attach"); + return -EINVAL; + } + + btd_service_connecting_complete(service, 0); + + return 0; +} + +static int micp_connect(struct btd_service *service) +{ + struct btd_device *device = btd_service_get_device(service); + char addr[18]; + + ba2str(device_get_address(device), addr); + DBG("%s", addr); + + return 0; +} + +static int micp_server_probe(struct btd_profile *p, + struct btd_adapter *adapter) +{ + struct btd_gatt_database *database = btd_adapter_get_database(adapter); + + DBG("MICP path %s", adapter_get_path(adapter)); + + bt_micp_add_db(btd_gatt_database_get_db(database)); + + return 0; +} + +static void micp_server_remove(struct btd_profile *p, + struct btd_adapter *adapter) +{ + DBG("MICP remove adapter"); +} + +static struct btd_profile micp_profile = { + .name = "micp", + .priority = BTD_PROFILE_PRIORITY_MEDIUM, + .remote_uuid = MICS_UUID_STR, + + .device_probe = micp_probe, + .device_remove = micp_remove, + + .accept = micp_accept, + .connect = micp_connect, + .disconnect = micp_disconnect, + + .adapter_probe = micp_server_probe, + .adapter_remove = micp_server_remove, +}; + +static unsigned int micp_id; + +static int micp_init(void) +{ + if (!(g_dbus_get_flags() & G_DBUS_FLAG_ENABLE_EXPERIMENTAL)) { + warn("D-Bus experimental not enabled"); + return -ENOTSUP; + } + + btd_profile_register(&micp_profile); + micp_id = bt_micp_register(micp_attached, micp_detached, NULL); + + return 0; +} + +static void micp_exit(void) +{ + if (g_dbus_get_flags() & G_DBUS_FLAG_ENABLE_EXPERIMENTAL) { + btd_profile_unregister(&micp_profile); + bt_micp_unregister(micp_id); + } +} + +BLUETOOTH_PLUGIN_DEFINE(micp, VERSION, BLUETOOTH_PLUGIN_PRIORITY_DEFAULT, + micp_init, micp_exit) From patchwork Tue Sep 5 07:09:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nitin Jadhav X-Patchwork-Id: 720213 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 531F6CA0FFA for ; Tue, 5 Sep 2023 16:22:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349713AbjIEQWK (ORCPT ); Tue, 5 Sep 2023 12:22:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39226 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353671AbjIEHKC (ORCPT ); Tue, 5 Sep 2023 03:10:02 -0400 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2084.outbound.protection.outlook.com [40.107.14.84]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 058371B4 for ; Tue, 5 Sep 2023 00:09:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=ePgf0gH2Rxt93QWuLpLD35byTbktUlY2yfeAsi3qGxcMPtqAuxdA1J8mt8k3Cz/e1bphfpk/z+Ha1d3jTuGQfvGca7agJ5lNSthHCkrFNBYVSCgcBcixi4ySivwLSrt0J5b8g4wE4f1LsFa0EwdTzWzcjorDjFdKiiniu2LXj+2xlJHDe32iQlEjoMH5qC7kFisqggLTXNyTw4Gpy9Hb/XyhluOqv4gIV8t1R33Si2cEj8ijyj2wCW0AihgK9ZFcVEnA0/qrQFXRIpuLAKJs/RYJSRUdj35t3YaA9Rcw0DrB3gBBSBvi8hg0uexruwD9eb/ETuF07VnRuYRsEJ1Jfg== 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=H3zOJG/Tl6o4BkWw52KbeJfBXtdds9wHUT2KOWv2gYg=; b=k7rys7zBym8ob4u+anyKWfkE4Ojk4oT/1RPPkpljDvUT8VukvY5NbwWL7pqsXfQ49IpsU/DWHAMvetub+ZzyngfDWIuCj/7Zy/MWquE6PXCH+V/ywe/1X9gNrdzWsyzDF/YutT+fzjGosJoMMivihUQsmVRRAB79yU1qFrD+wjBI4RTwEnG/iWr/Xwp/DTbD2t8Gi3nFd42KzojsYbI2bhDSlzdXgMz0nLU4ayXPZddVgh429G1GENBpjhI66P9uh1Eg853LfW8bMplyoMKS8iyYDqVpvtOLKD6fqSFcLLBUI6bppQGPcFGVy7RE/svrD/LRFsHFPtUBNPUBQbPVeA== 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=H3zOJG/Tl6o4BkWw52KbeJfBXtdds9wHUT2KOWv2gYg=; b=SYQgZ+4DWGwvXVjRZUgk75/ifinMz/W3P2dx4R0W/JEsTDRUJCPLsVtRK/18m9xBg5tL2OiXXL2wxg30yLzhSooluK5U4cRakUzXwF63Qi/8ba4dvdgWzulrSnvZHS/sVmTEP5Ar+E1JX1U/lqYwgG90YwoLUjhr/zrAZ/aWmVE= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=nxp.com; Received: from AS8PR04MB9126.eurprd04.prod.outlook.com (2603:10a6:20b:449::16) by DBBPR04MB8058.eurprd04.prod.outlook.com (2603:10a6:10:1e7::20) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Tue, 5 Sep 2023 07:09:55 +0000 Received: from AS8PR04MB9126.eurprd04.prod.outlook.com ([fe80::2320:fa57:8f7c:bb64]) by AS8PR04MB9126.eurprd04.prod.outlook.com ([fe80::2320:fa57:8f7c:bb64%6]) with mapi id 15.20.6745.030; Tue, 5 Sep 2023 07:09:55 +0000 From: Nitin Jadhav To: linux-bluetooth@vger.kernel.org Cc: devyani.godbole@nxp.com, mahesh.talewad@nxp.com, luiz.dentz@gmail.com, nitin.jadhav@nxp.com Subject: [PATCH BlueZ v2 4/4] unit/test-micp-test-mics: To implement unit tester code Date: Tue, 5 Sep 2023 10:09:12 +0300 Message-Id: <20230905070912.82340-5-nitin.jadhav@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230905070912.82340-1-nitin.jadhav@nxp.com> References: <20230905070912.82340-1-nitin.jadhav@nxp.com> X-ClientProxiedBy: SI2PR02CA0031.apcprd02.prod.outlook.com (2603:1096:4:195::16) To AS8PR04MB9126.eurprd04.prod.outlook.com (2603:10a6:20b:449::16) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB9126:EE_|DBBPR04MB8058:EE_ X-MS-Office365-Filtering-Correlation-Id: 32be7bba-ad2c-4f7f-52d4-08dbaddf1b3d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: g8apolO8iemCWWrwgyZzEAVHI7ud+40KQ7VvaDudn7qhBIt1WszEgui01g6FQRTiSwVjxrzW+fpc3B2hmM8xAGcxIqAwp0iLnY2EbKeJxnJr6iTwYEAPlzrcFR5zi0l+IPXeDa5RWmxMTVTiTVr6QDThL48sHtwA3i51+q2QJPflVWboyPy1qJnsxumhuwp1lAiLtzXX+sty4aWq/IZZ3MauU4HT6D8CTjhL8RS9iLCAR9aB6bCxFs0hPIb3vRczlklikNLYW1ir/DRl22C+5YxZG9FaJgz8SM8hK/fmjIZyex4c+fHnb3HjP6tV8wQhNu1CB4dv1YZIoq+CxWTcAqYg+ygl6MDYc2LJ37avV0WkMn22NhhjKSsOs+ErlCReYunNYTRD4b+ThzxOs917OLWONqebhDliliriSoJ9op4D2NPhutIz4JAD3rn89i9ERU3GUY5LaxTIeCxJYTJH+uk9It2f8vQ3npV5L/GGJEl/GDVnt1GY4Qka8YEmzJWTeHrh4yWmQHDBs8hfgXXWp0eyqCGLeTnDBmFIDeOqrqkowfTBzOWctXTA//Bm+3StcHSOm7V/OtqEphf7M0GEIetadudU1+8d8ajek5FawG5wyrU4Un+fQwwfFN/H9VNH X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:AS8PR04MB9126.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230031)(396003)(346002)(376002)(136003)(39860400002)(366004)(451199024)(1800799009)(186009)(66946007)(66556008)(66476007)(6916009)(478600001)(38100700002)(38350700002)(316002)(30864003)(2906002)(41300700001)(86362001)(8936002)(8676002)(4326008)(5660300002)(44832011)(6506007)(83380400001)(6512007)(6666004)(6486002)(52116002)(55236004)(2616005)(26005)(1076003)(36756003); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: DMoEYFL4EemJIFZWaOehFBe8vke0+YkAtup+9qb4KoveITaqVyVRhS73RePNo7dskpkmWr6vXtRUyowaEBhnAFGPBPAFrhSZ4GIMOXX1Vv1ny4Vfci2N0dL8Fdh3Wq3FL9dK83RevO7QuQYbJzSXEUWHBZ/BDcmd8fPOutiW+pgMbI5aw95kCBxNA60d4ltyIHeUHr0mxV8GtjzQDLzrdhipdbsFZef3uA1bz6ZHGrYYWv+3F3A3+vwRwO73AhZglTYFaPN6U+yEH6vNk+Ta0mDqgtJFBR6hbHklk4CHZPMmcgsgAPFpdgMYCtHhVnJmN/IZ+6m1ouV0bS7103+6EI/u56lOUaJmGQU6ULnnLDfOfQKiCqMUv6kK9eMBsC6FKqZPu8o1Omt4LPdbUKmpYGCCOhXT49R9LuKyCAM78gYFNPa+YiLnO/6MD/Reio84EHh2/l7t6IakuxJqRspNx1i4fLbN8T4iFosX+cJNKwslb0FhuGi69O/aPogT9c+f5bkuOFkAKuJtSyCyXfI2wkFKA3TmGfJW5wEo0aOXiix6IOiybGrhbblckIJmYacHP6WyYfu4Os4AhznesS0cwFDBh0k6GYEyBeukYGsm9HUDAQZw6b3OzF9ZPO/8jVeh6tx9UJK7q3uRdd9BofhdgQm/83t3IrZgciAzfi2ud9QjLe5qIhiahcvn00wHePznCtoZzT1bEjQCNHN6ewTgpvALxgcsOXrtk0n8ITNX8R9QkUAlpPKe4AkJt7LM2y44/MgStaG8wCrBntKluT25N/lpllUIifMoh6e2PTL56psBgqtHJmkUDKPcHbh6ldohauynIRJW2gzoe0DOJt5pL2BJEVcdjmwNPPnpg1GpYBZWTPQg8+H55pLT/up6SST+WKmQ0gKSJDf9PhpLDJgKMh77Ts4smCNBmZ3lXJtJnUFt3UoVO0RdCHCNBx+OXQ5vx505J/PVLBRZ/krtGPPBzM6zb5IRsHTOB8JcxIN4jpHMNTn1t9drmKUvxn2A+kq369xwG8j/f8CIZHBCPGKOPK5kZ+MOZRExwHdCwwiKXSKG+qy8+1PLA44gHND41QSWSJ4u17BoncE2TazZj8uGMlVvJz8U0XnsRMOjulAQA82zkHl9+rZIfgsRyY6EDTTdVMvO+w1e+ks7rjXt3f+UZudOJ9lD3uhfv8s+pFz387AnN7SutgQPG4Qjru8EW/VjdkdkA3D1Z0Kcme8IN4qK0fNqoU/DShZl04iVKbjbWvB+d6HhLnWP4VMaQbSwVE/o4+xbSF80EGOfFSYHuMhWcIyEc8wIFRMrBiaw//AknnwWSUOjFOqrCQcM7RgtGhY/P2VYYal1obm0SGGLua5LloC02Nvhp8yT0Jf98AmcJg4jXPAkV98MD+lYm+97zeTYifEyqbfIH5xBbXkgjoDipQBelWnQbddBRjEPPZMkM+Jo1+9GwxEDaCfwhpU7irny4o9+UUGyF8syKEHuBHD0hvrWzgn35h5JtNOKbTKXiNymklzujICt7dZsJuv4VP6qRVaCOCaEUunMn0kFmkVP2bzyum5lD40hzbZmCTWRq9G93h/C0WS/+Y+XkoMtyk1B X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 32be7bba-ad2c-4f7f-52d4-08dbaddf1b3d X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB9126.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 05 Sep 2023 07:09:55.0836 (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: JjZ5r2nGYFv6moq9HRR7qmw5obmO9sriBJ4NyEugmzWTH77INRln7s1DkGh4qHIlf8k01wWEITuVnewOXXrnVA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DBBPR04MB8058 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Implemented Unit Testcases for MICS[test-micp.c] and MICP[test-mics.c]. Co-developed-by: Mahesh Talewad Signed-off-by: Mahesh Talewad Signed-off-by: Nitin Jadhav --- Makefile.am | 13 ++ unit/test-micp.c | 357 +++++++++++++++++++++++++++++++++++++++++++++++ unit/test-mics.c | 317 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 687 insertions(+) create mode 100644 unit/test-micp.c create mode 100644 unit/test-mics.c diff --git a/Makefile.am b/Makefile.am index 6f40f2a74..cde55bebf 100644 --- a/Makefile.am +++ b/Makefile.am @@ -573,6 +573,19 @@ unit_test_gattrib_LDADD = src/libshared-glib.la \ lib/libbluetooth-internal.la \ $(GLIB_LIBS) $(DBUS_LIBS) -ldl -lrt +unit_tests += unit/test-micp + +unit_test_micp_SOURCES = unit/test-micp.c + +unit_test_micp_LDADD = src/libshared-glib.la \ + lib/libbluetooth-internal.la $(GLIB_LIBS) + +unit_tests += unit/test-mics + +unit_test_mics_SOURCES = unit/test-mics.c +unit_test_mics_LDADD = src/libshared-glib.la \ + lib/libbluetooth-internal.la $(GLIB_LIBS) + unit_tests += unit/test-bap unit_test_bap_SOURCES = unit/test-bap.c diff --git a/unit/test-micp.c b/unit/test-micp.c new file mode 100644 index 000000000..3db32a4f7 --- /dev/null +++ b/unit/test-micp.c @@ -0,0 +1,357 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2023 NXP Semiconductors. All rights reserved. + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#define _GNU_SOURCE +#include +#include +#include +#include + + +#include + +#include "lib/bluetooth.h" +#include "lib/uuid.h" +#include "src/shared/util.h" +#include "src/shared/tester.h" +#include "src/shared/queue.h" +#include "src/shared/att.h" +#include "src/shared/gatt-db.h" +#include "src/shared/gatt-server.h" +#include "src/shared/micp.h" + +struct test_data { + struct gatt_db *db; + struct bt_micp *micp; + struct bt_gatt_server *server; + struct bt_gatt_client *client; + struct queue *ccc_states; + size_t iovcnt; + struct iovec *iov; + struct test_config *cfg; +}; + +struct ccc_state { + uint16_t handle; + uint16_t value; +}; + +struct notify { + uint16_t handle, ccc_handle; + uint8_t *value; + uint16_t len; + bt_gatt_server_conf_func_t conf; + void *user_data; +}; + +#define iov_data(args...) ((const struct iovec[]) { args }) + +#define define_test(name, function, _cfg, args...) \ + do { \ + const struct iovec iov[] = { args }; \ + static struct test_data data; \ + data.cfg = _cfg; \ + data.iovcnt = ARRAY_SIZE(iov_data(args)); \ + data.iov = util_iov_dup(iov, ARRAY_SIZE(iov_data(args))); \ + tester_add(name, &data, NULL, function, \ + test_teardown); \ + } while (0) + +static void print_debug(const char *str, void *user_data) +{ + const char *prefix = user_data; + + if (tester_use_debug()) + tester_debug("%s%s", prefix, str); +} + +static void test_teardown(const void *user_data) +{ + struct test_data *data = (void *)user_data; + + bt_micp_unref(data->micp); + bt_gatt_server_unref(data->server); + util_iov_free(data->iov, data->iovcnt); + gatt_db_unref(data->db); + + queue_destroy(data->ccc_states, free); + + tester_teardown_complete(); +} + +static void test_complete_cb(const void *user_data) +{ + tester_test_passed(); +} + +static bool ccc_state_match(const void *a, const void *b) +{ + const struct ccc_state *ccc = a; + uint16_t handle = PTR_TO_UINT(b); + + return ccc->handle == handle; +} + +static struct ccc_state *find_ccc_state(struct test_data *data, + uint16_t handle) +{ + return queue_find(data->ccc_states, ccc_state_match, + UINT_TO_PTR(handle)); +} + +static struct ccc_state *get_ccc_state(struct test_data *data, uint16_t handle) +{ + struct ccc_state *ccc; + + ccc = find_ccc_state(data, handle); + if (ccc) + return ccc; + + ccc = new0(struct ccc_state, 1); + ccc->handle = handle; + queue_push_tail(data->ccc_states, ccc); + + return ccc; +} + +static void gatt_notify_cb(struct gatt_db_attribute *attrib, + struct gatt_db_attribute *ccc, + const uint8_t *value, size_t len, + struct bt_att *att, void *user_data) +{ + struct test_data *data = user_data; + struct notify notify; + + memset(¬ify, 0, sizeof(notify)); + + notify.handle = gatt_db_attribute_get_handle(attrib); + notify.ccc_handle = gatt_db_attribute_get_handle(ccc); + notify.value = (void *) value; + notify.len = len; + + printf("%s: notify.value:%d notify->len:%d\n", __func__, + (int)*(notify.value), notify.len); + if (!bt_gatt_server_send_notification(data->server, + notify.handle, notify.value, + notify.len, false)) + printf("%s: Failed to send notification\n", __func__); +} + +static void gatt_ccc_read_cb(struct gatt_db_attribute *attrib, + unsigned int id, uint16_t offset, + uint8_t opcode, struct bt_att *att, + void *user_data) +{ + struct test_data *data = user_data; + struct ccc_state *ccc; + uint16_t handle; + uint8_t ecode = 0; + const uint8_t *value = NULL; + size_t len = 0; + + handle = gatt_db_attribute_get_handle(attrib); + + ccc = get_ccc_state(data, handle); + if (!ccc) { + ecode = BT_ATT_ERROR_UNLIKELY; + goto done; + } + + len = sizeof(ccc->value); + value = (void *) &ccc->value; + +done: + gatt_db_attribute_read_result(attrib, id, ecode, value, len); +} + +static void test_server(const void *user_data) +{ + struct test_data *data = (void *)user_data; + struct bt_att *att; + struct io *io; + + io = tester_setup_io(data->iov, data->iovcnt); + g_assert(io); + + tester_io_set_complete_func(test_complete_cb); + + att = bt_att_new(io_get_fd(io), false); + g_assert(att); + + bt_att_set_debug(att, BT_ATT_DEBUG, print_debug, "bt_att:", NULL); + + data->db = gatt_db_new(); + g_assert(data->db); + + gatt_db_ccc_register(data->db, gatt_ccc_read_cb, NULL, + gatt_notify_cb, data); + + data->micp = bt_micp_new(data->db, NULL); + g_assert(data->micp); + + data->server = bt_gatt_server_new(data->db, att, 64, 0); + g_assert(data->server); + + bt_gatt_server_set_debug(data->server, print_debug, "bt_gatt_server:", + NULL); + + data->ccc_states = queue_new(); + + tester_io_send(); + + bt_att_unref(att); +} + +#define EXCHANGE_MTU IOV_DATA(0x02, 0x40, 0x00), \ + IOV_DATA(0x03, 0x40, 0x00) + +#define MICS_MUTE_WRITE_VAL_00 \ + IOV_DATA(0x12, 0x03, 0x00, 0x00), \ + IOV_DATA(0x13) + +#define MICS_MUTE_WRITE_VAL_01 \ + IOV_DATA(0x12, 0x03, 0x00, 0x01), \ + IOV_DATA(0x13) + +#define MICS_MUTE_READ \ + IOV_DATA(0x0a, 0x03, 0x00), \ + IOV_DATA(0x0b, 0x01) + +#define DISCOVER_PRIM_SERV_NOTIF \ + IOV_DATA(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28), \ + IOV_DATA(0x11, 0x06, 0x01, 0x00, 0x04, 0x00, 0x4d, 0x18), \ + IOV_DATA(0x10, 0x05, 0x00, 0xff, 0xff, 0x00, 0x28), \ + IOV_DATA(0x01, 0x10, 0x05, 0x00, 0x0a) + +/* ATT: Read By Type Request (0x08) len 6 + * Handle range: 0x0001-0x0009 + * Attribute type: Characteristic (0x2803) + * ATT: Read By Type Response (0x09) len 22 + * Attribute data length: 7 + * Handle: 0x0002 + * Value: 1a0300c82b + * Properties: 0x1a + * Value Handle: 0x0003 + * Value UUID: Mute (0x2bc3) + */ +#define DISC_MICS_CHAR_1 \ + IOV_DATA(0x08, 0x01, 0x00, 0x05, 0x00, 0x03, 0x28), \ + IOV_DATA(0x09, 0x07, \ + 0x02, 0x00, 0x1a, 0x03, 0x00, 0xc3, 0x2b), \ + IOV_DATA(0x08, 0x05, 0x00, 0x05, 0x00, 0x03, 0x28), \ + IOV_DATA(0x01, 0x08, 0x05, 0x00, 0x0a) + + +#define MICS_FIND_BY_TYPE_VALUE \ + IOV_DATA(0x06, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28, 0x4d, 0x18), \ + IOV_DATA(0x07, 0x01, 0x00, 0x04, 0x00), \ + IOV_DATA(0x06, 0x05, 0x00, 0xff, 0xff, 0x00, 0x28, 0x4d, 0x18), \ + IOV_DATA(0x01, 0x06, 0x05, 0x00, 0x0a) + +#define DISC_MICS_CHAR_AFTER_TYPE \ + IOV_DATA(0x08, 0x01, 0x00, 0x05, 0x00, 0x03, 0x28), \ + IOV_DATA(0x09, 0x07, \ + 0x02, 0x00, 0x1a, 0x03, 0x00, 0xc3, 0x2b), \ + IOV_DATA(0x08, 0x03, 0x00, 0x05, 0x00, 0x03, 0x28), \ + IOV_DATA(0x01, 0x08, 0x03, 0x00, 0x0a) + +#define MICS_WRITE_CCD \ + IOV_DATA(0x12, 0x04, 0x00, 0x00, 0x00), \ + IOV_DATA(0x13), \ + IOV_DATA(0x12, 0x04, 0x00, 0x01, 0x00), \ + IOV_DATA(0x13) + +#define MICS_FIND_INFO \ + IOV_DATA(0x04, 0x04, 0x00, 0x05, 0x00), \ + IOV_DATA(0x05, 0x01, 0x04, 0x00, 0x02, 0x29), \ + IOV_DATA(0x04, 0x05, 0x00, 0x05, 0x00), \ + IOV_DATA(0x01, 0x04, 0x05, 0x00, 0x0a) + +#define MICS_SR_SPN_BV_01_C \ + EXCHANGE_MTU, \ + DISCOVER_PRIM_SERV_NOTIF, \ + DISC_MICS_CHAR_1, \ + MICS_FIND_BY_TYPE_VALUE, \ + DISC_MICS_CHAR_AFTER_TYPE, \ + MICS_FIND_INFO, \ + MICS_WRITE_CCD, \ + IOV_DATA(0x0a, 0x03, 0x00), \ + IOV_DATA(0x0b, 0x01), \ + MICS_MUTE_WRITE_VAL_00, \ + IOV_DATA(0x1b, 0x03, 0x00, 0x00), \ + MICS_MUTE_WRITE_VAL_01, \ + IOV_DATA(0x1b, 0x03, 0x00, 0x01), \ + IOV_DATA(0x0a, 0x03, 0x00), \ + IOV_DATA(0x0b, 0x01) + +#define MICS_SR_SGGIT_SER_BV_01_C \ + EXCHANGE_MTU, \ + DISCOVER_PRIM_SERV_NOTIF, \ + MICS_FIND_BY_TYPE_VALUE + +#define MICS_SR_SGGIT_CHA_BV_01_C \ + EXCHANGE_MTU, \ + DISCOVER_PRIM_SERV_NOTIF, \ + MICS_FIND_BY_TYPE_VALUE, \ + DISC_MICS_CHAR_AFTER_TYPE + +#define MICS_WRITE_MUTE_CHAR_INVALID \ + IOV_DATA(0x12, 0x03, 0x00, 0x02), \ + IOV_DATA(0x01, 0x12, 0x03, 0x00, 0x13), \ + IOV_DATA(0x12, 0x03, 0x00, 0x05), \ + IOV_DATA(0x01, 0x12, 0x03, 0x00, 0x13) + +#define MICS_SR_SPE_BI_1_C \ + EXCHANGE_MTU, \ + DISCOVER_PRIM_SERV_NOTIF, \ + MICS_FIND_BY_TYPE_VALUE, \ + MICS_WRITE_MUTE_CHAR_INVALID + +#define MICS_MUTE_READ_INVALID \ + IOV_DATA(0x0a, 0x03, 0x00), \ + IOV_DATA(0x0b, 0x02) + +#define MICS_MUTE_WRITE_1 \ + IOV_DATA(0x12, 0x03, 0x00, 0x01), \ + IOV_DATA(0x01, 0x12, 0x03, 0x00, 0x80) + +#define MICS_MUTE_WRITE_0 \ + IOV_DATA(0x12, 0x03, 0x00, 0x00), \ + IOV_DATA(0x01, 0x12, 0x03, 0x00, 0x80) + +#define MICS_SR_SPE_BI_02_C \ + EXCHANGE_MTU, \ + DISCOVER_PRIM_SERV_NOTIF, \ + MICS_FIND_BY_TYPE_VALUE, \ + MICS_MUTE_READ_INVALID, \ + MICS_MUTE_WRITE_0, \ + MICS_MUTE_WRITE_1 + +int main(int argc, char *argv[]) +{ + + tester_init(&argc, &argv); + + define_test("MICS/SR/SGGIT/SER/BV-01-C", test_server, NULL, + MICS_SR_SGGIT_SER_BV_01_C); + define_test("MICS/SR/SGGIT/CHA/BV-01-C", test_server, NULL, + MICS_SR_SGGIT_CHA_BV_01_C); + define_test("MICS/SR/SPE/BI-01-C", test_server, NULL, + MICS_SR_SPE_BI_1_C); + define_test("MICS/SR/SPE/BI-02-C", test_server, NULL, + MICS_SR_SPE_BI_02_C); + define_test("MICS/SR/SPN/BV-01-C", test_server, NULL, + MICS_SR_SPN_BV_01_C); + + return tester_run(); +} diff --git a/unit/test-mics.c b/unit/test-mics.c new file mode 100644 index 000000000..7a7d70bf3 --- /dev/null +++ b/unit/test-mics.c @@ -0,0 +1,317 @@ +// SPDX-License-Identifier: LGPL-2.1-or-later +/* + * + * BlueZ - Bluetooth protocol stack for Linux + * + * Copyright (C) 2023 NXP Semiconductors. All rights reserved. + * + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#define _GNU_SOURCE +#include +#include +#include +#include + + +#include + +#include "lib/bluetooth.h" +#include "lib/uuid.h" +#include "btio/btio.h" +#include "src/shared/util.h" +#include "src/shared/tester.h" +#include "src/shared/queue.h" +#include "src/shared/att.h" +#include "src/shared/gatt-db.h" +#include "src/shared/gatt-helpers.h" +#include "src/shared/micp.h" + +struct test_data { + struct gatt_db *db; + struct bt_mics *mics; + struct bt_micp *micp; + struct bt_gatt_client *client; + size_t iovcnt; + struct iovec *iov; + struct test_config *cfg; +}; + +struct db_attribute_micp_test_data { + struct gatt_db_attribute *match; + bool found; +}; + +#define MICP_GATT_CLIENT_MTU 64 +#define iov_data(args...) ((const struct iovec[]) { args }) + +#define define_test(name, function, _cfg, args...) \ + do { \ + const struct iovec iov[] = { args }; \ + static struct test_data data; \ + data.cfg = _cfg; \ + data.iovcnt = ARRAY_SIZE(iov_data(args)); \ + data.iov = util_iov_dup(iov, ARRAY_SIZE(iov_data(args))); \ + tester_add(name, &data, test_setup, function, \ + test_teardown); \ + } while (0) + +static void print_debug(const char *str, void *user_data) +{ + const char *prefix = user_data; + + if (tester_use_debug()) + tester_debug("%s %s", prefix, str); +} + +static void test_teardown(const void *user_data) +{ + struct test_data *data = (void *)user_data; + + bt_gatt_client_unref(data->client); + util_iov_free(data->iov, data->iovcnt); + gatt_db_unref(data->db); + + tester_teardown_complete(); +} + +static void test_complete_cb(const void *user_data) +{ + tester_test_passed(); +} + +static void client_ready_cb(bool success, uint8_t att_ecode, void *user_data) +{ + + if (!success) + tester_setup_failed(); + else + tester_setup_complete(); +} + +static void micp_write_cb(bool success, uint8_t att_ecode, void *user_data) +{ + if (success) + printf("MICP Write successful\n"); + else + printf("\nWrite failed: 0x%02x\n", att_ecode); +} + +static void micp_write_value(struct bt_micp *micp, void *user_data) +{ + struct bt_mics *mics = micp_get_mics(micp); + uint16_t value_handle; + int ret; + const uint16_t value = 0x0001; + + gatt_db_attribute_get_char_data(mics->ms, NULL, &value_handle, + NULL, NULL, NULL); + + printf("%s handle: %x\n", __func__, value_handle); + ret = bt_gatt_client_write_value(micp->client, value_handle, + (void *)&value, sizeof(value), micp_write_cb, NULL, NULL); + + if (!ret) + printf("bt_gatt_client_write_value() : Write FAILED"); +} + +static void micp_ready(struct bt_micp *micp, void *user_data) +{ + micp_write_value(micp, user_data); +} + +static void test_client(const void *user_data) +{ + struct test_data *data = (void *)user_data; + struct io *io; + + io = tester_setup_io(data->iov, data->iovcnt); + g_assert(io); + + tester_io_set_complete_func(test_complete_cb); + + data->db = gatt_db_new(); + g_assert(data->db); + + data->micp = bt_micp_new(data->db, bt_gatt_client_get_db(data->client)); + g_assert(data->micp); + + bt_micp_set_debug(data->micp, print_debug, "bt_mip: ", NULL); + + bt_micp_ready_register(data->micp, micp_ready, data, NULL); + + bt_micp_attach(data->micp, data->client); +} + + /* ATT: Exchange MTU Response (0x03) len 2 + * Server RX MTU: 64 + */ + /* ATT: Exchange MTU Request (0x02) len 2 + * Client RX MTU: 64 + */ +#define ATT_EXCHANGE_MTU IOV_DATA(0x02, 0x40, 0x00), \ + IOV_DATA(0x03, 0x40, 0x00) + +/* + * ATT: Read By Type Request (0x08) len 6 + * Handle range: 0x0001-0xffff + * Attribute type: Server Supported Features (0x2b3a) + */ +#define MICP_READ_SR_FEATURE IOV_DATA(0x08, 0x01, 0x00, 0Xff, 0xff, \ + 0x3a, 0x2b), \ + IOV_DATA(0x01, 0x08, 0x01, 0x00, 0x0a) + + /* + * ATT: Read By Group Type Request (0x10) len 6 + * Handle range: 0x0001-0xffff + * Attribute group type: Primary Service (0x2800) + */ + +/* + * ATT: Read By Group Type Response (0x11) len 7 + * Attribute data length: 6 + * Attribute group list: 1 entry + * Handle range: 0x00a0-0x00a4 + * UUID: Microphone Control (0x184d) + */ +#define MICP_READ_GROUP_TYPE \ + IOV_DATA(0x10, 0x01, 0x00, 0xff, 0xff, 0x00, 0x28), \ + IOV_DATA(0x11, 0x06, \ + 0x01, 0x00, 0x04, 0x00, 0x4d, 0x18), \ + IOV_DATA(0x10, 0x05, 0x00, 0xff, 0xff, 0x00, 0x28), \ + IOV_DATA(0x01, 0x10, 0x06, 0x00, 0x0a) + + /* ATT: Read By Group Type Request (0x10) len 6 + * Handle range: 0x0001-0xffff + * Attribute group type: Secondary Service (0x2801) + */ + /* ATT: Error Response (0x01) len 4 + * Read By Group Type Request (0x10) + * Handle: 0x0001 + * Error: Attribute Not Found (0x0a)08 01 00 05 00 02 28 + */ +#define MICP_READ_REQ_SECOND_SERVICE \ + IOV_DATA(0x10, 0x01, 0x00, 0xff, 0xff, 0x01, 0x28), \ + IOV_DATA(0x01, 0x10, 0x01, 0x00, 0x0a) + +#define MICP_READ_REQ_INCLUDE_SERVICE \ + IOV_DATA(0x08, 0x01, 0x00, 0x04, 0x00, 0x02, 0x28), \ + IOV_DATA(0x01, 0x08, 0x01, 0x00, 0x0a) + + /* ATT: Read By Type Request (0x08) len 6 + * Handle range: 0x0001-0x0004 + * Attribute type: Characteristic (0x2803) + */ + +/* ATT: Find Information Request (0x04) len 4 + * Handle range: 0x0004-0x0004 + */ +#define MICP_FIND_INFO_REQ \ + IOV_DATA(0x04, 0x04, 0x00, 0x04, 0x00), \ + IOV_DATA(0x05, 0x01, 0x04, 0x00, 0x02, 0x29) + +/* + * ATT: Read By Type Request (0x08) len 6 + * Handle range: 0x0001-0x0004 + * Attribute type: Characteristic (0x2803) + */ +#define MICP_READ_REQ_CHAR \ + IOV_DATA(0x08, 0x01, 0x00, 0x04, 0x00, 0x03, 0x28),\ + IOV_DATA(0x09, 0x07, \ + 0x02, 0x00, 0x1a, 0x03, 0x00, 0xc3, 0x2b), \ + IOV_DATA(0x08, 0x03, 0x00, 0x04, 0x00, 0x03, 0x28), \ + IOV_DATA(0x01, 0x08, 0x04, 0x00, 0x0a) + +#define MICS_MUTE_READ \ + IOV_DATA(0x0a, 0x03, 0x00), \ + IOV_DATA(0x0b, 0x01) + +#define MICS_EN_MUTE_DISCPTR \ + IOV_DATA(0x12, 0x04, 0x00, 0x01, 0x00), \ + IOV_DATA(0x13) + +#define MICS_MUTE_WRITE \ + IOV_DATA(0x12, 0x03, 0x00, 0x01),\ + IOV_DATA(0x13) + +#define MICP_CL_CGGIT_SER_BV_01_C \ + MICS_MUTE_READ, \ + MICS_EN_MUTE_DISCPTR, \ + IOV_DATA(0x12, 0x03, 0x00, 0x01, 0x00), \ + IOV_DATA(0x01, 0x12, 0x03, 0x00, 0x013) + +#define MICP_CL_CGGIT_CHA_BV_01_C \ + MICS_MUTE_READ, \ + MICS_EN_MUTE_DISCPTR, \ + IOV_DATA(0x12, 0x03, 0x00, 0x06, 0x00), \ + IOV_DATA(0x01, 0x12, 0x03, 0x00, 0x013), \ + MICS_MUTE_READ + +#define MICP_CL_SPE_BI_01_C \ + MICS_MUTE_READ, \ + MICS_EN_MUTE_DISCPTR, \ + IOV_DATA(0x12, 0x03, 0x00, 0x01, 0x00), \ + IOV_DATA(0x01, 0x12, 0x03, 0x00, 0x80) + +/* GATT Discover All procedure */ +static const struct iovec setup_data[] = { + ATT_EXCHANGE_MTU, + MICP_READ_SR_FEATURE, + MICP_READ_GROUP_TYPE, + MICP_READ_REQ_SECOND_SERVICE, + MICP_READ_REQ_INCLUDE_SERVICE, + MICP_READ_REQ_CHAR, + MICP_FIND_INFO_REQ +}; + +static void test_setup(const void *user_data) +{ + struct test_data *data = (void *)user_data; + struct bt_att *att; + struct gatt_db *db; + struct io *io; + + io = tester_setup_io(setup_data, ARRAY_SIZE(setup_data)); + g_assert(io); + + att = bt_att_new(io_get_fd(io), false); + g_assert(att); + + bt_att_set_debug(att, BT_ATT_DEBUG, print_debug, "bt_att:", NULL); + + db = gatt_db_new(); + g_assert(db); + + + data->client = bt_gatt_client_new(db, att, MICP_GATT_CLIENT_MTU, 0); + g_assert(data->client); + + bt_gatt_client_set_debug(data->client, print_debug, "bt_gatt_client:", + NULL); + + bt_gatt_client_ready_register(data->client, client_ready_cb, data, + NULL); + + bt_att_unref(att); + gatt_db_unref(db); +} + + +int main(int argc, char *argv[]) +{ + + tester_init(&argc, &argv); + + define_test("MICP/CL/CGGIT/SER/BV-01-C", test_client, NULL, + MICS_MUTE_READ); + define_test("MICP/CL/CGGIT/CHA/BV-01-C", test_client, NULL, + MICP_CL_CGGIT_SER_BV_01_C); + define_test("MICP/CL/SPE/BI-01-C", test_client, NULL, + MICP_CL_SPE_BI_01_C); + + return tester_run(); +}