From patchwork Thu Sep 7 15:12:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 13376528 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 A3913EC873F for ; Thu, 7 Sep 2023 15:42:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230051AbjIGPmc (ORCPT ); Thu, 7 Sep 2023 11:42:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33856 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240389AbjIGPYP (ORCPT ); Thu, 7 Sep 2023 11:24:15 -0400 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2073.outbound.protection.outlook.com [40.107.7.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC39819C for ; Thu, 7 Sep 2023 08:24:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IE0b717fUDReDilsf70M1Gp9YUNv36fufdvY1r/eFkwJES1cqiXGfOOjB3o/8noZWZ2JyZL1STziFKS7hR4OLB1gpQ8DXPZ9IE75dphhZwvPMuSCHHBCK9z3XoeiQJ4KsJdiye765Mew72C+zflIZs/dT1W7Cfm6852tpt3II/z6M1m/Pi6fNjC5LmlxY1kxZWKJUGFeyEFQGEEosCsC/7aVFIr7YAZBg/vj0X12eDgbWep+9xWQbov+bAGLQwsqF2+05L+tBDsXUh2+wfQSNDdIkwkq6sTaF+FUxy5AWsIkvL1bgp1koIzOOXna+CbVzqFKc7Y4w4IDQAXMxf/W9g== 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=FTFygz+BDL8tnpjC5ZKbhoNm4dXQ1utYN8z3DpGnhk0=; b=dd9NuNG2/St+7Xt0qqVEon7LOkbh5BaKMbRbJO/I0sI+8jm1xCz8oIvSktH7FVPrY/D4GaZ9+O0r3jZzgzIzSGcnCaszSmHmfk6hbNcnkDgGE4LhO6eZ9O52qihjRt1Dz9azpxJLLC0TlYiXycIWkEiNyXAhsV6e7GoXZ/x7/hKv//9CoIEWl5SAxuBXk7p2NefgAQb8S0zULRhkIN/p/GLwc3p/ftwDvyt6cppSNTFxhS3GnYg+C6n9E6h8uM1+gTtKNLkEfZIhl9bkydN4NQZXEAqMPaV3QBgQDl2/H6LhoQEHeZlYzB1gQHrz8KmaPUrn6T7ZJ5yTSotg052jjw== 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=FTFygz+BDL8tnpjC5ZKbhoNm4dXQ1utYN8z3DpGnhk0=; b=QYslRFgb7jJkr2fXENhcST9DU9ixLCcKS3/s1JcIfw3iUKE14/mlYNg1TQorhjTdwq4AZdItwyTDepNI5euyOzfbsgEvn4L4IyRlN1hx4pTpKrgjgy/eqepoN/oE5yZpB6QHMxvlfvGlrY7EWOm6fFU6aFRcIXss7Bwd4bBjR9U= 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 GVXPR04MB9759.eurprd04.prod.outlook.com (2603:10a6:150:111::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Thu, 7 Sep 2023 15:12:53 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::6e75:56f3:fc37:277b]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::6e75:56f3:fc37:277b%7]) with mapi id 15.20.6745.034; Thu, 7 Sep 2023 15:12:53 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, silviu.barbulescu@nxp.com, vlad.pruteanu@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Iulia Tanasescu Subject: [PATCH BlueZ 1/3] btio: Add support for accepting BIS after defer setup Date: Thu, 7 Sep 2023 18:12:27 +0300 Message-Id: <20230907151229.7306-2-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230907151229.7306-1-iulia.tanasescu@nxp.com> References: <20230907151229.7306-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AM0PR02CA0195.eurprd02.prod.outlook.com (2603:10a6:20b:28e::32) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|GVXPR04MB9759:EE_ X-MS-Office365-Filtering-Correlation-Id: 71b37be8-0057-4f07-a685-08dbafb4e895 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: LHk3A21Hlo7Gko/lAGf7BsqjKUOMIwAdwoemQCM1tWqvvtoDx02zY/0c/OZkxTbguMbjRbInx+6uPicxKqIiCGe0u+ef+GHYwCt8oS+fv5tzS0Vj9cV5ArIQ72zlCZWy0UlqIEO/g9LWsiML8dueQcEBO5yKq5VLLH3+dJjJo8nqwN1ubuO89giUUXp/mnZVuF2at7GWUTou5yLa/0XwqL/9/XpEVYB+pOROdD1rkXrP2Nyww4PFvwY4EyA5JVFsDXZh5HG1ZlZw6EI2PTvalE5nz1opMibasqJgEL95fxB+xztTn4DOa/KcaXeqt/+28EQysILoUWCnwSz/7Z25+xcl/R4dVgx+fqheTNs4jFdJpM5/ghvnHhzsI+5rpDEvevlV+zYHsQEUl0wRwPby5JOxMsT6OyhAdL2kThdghI89GJymWyPH0kymXufn7Cn6SUOLEB5SExD4iszhB0LND9rO9XTos5ufb1FKWDvQkaM/m/t+w26oFgfvjwgq4LCvkYDf9t99m3gzoXXNUwkafZvkrTkp4R66lXxVrPYTUA9jQYljyQKBy5naOgx+cPIZE2qV3yqOIr7OA22quAUK9jvs6XK0BgKQFNWNX9nwtnRGvSeIn1q50woW79scEuTs 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:(13230031)(136003)(39860400002)(396003)(346002)(366004)(376002)(1800799009)(186009)(451199024)(2906002)(36756003)(38100700002)(38350700002)(86362001)(55236004)(52116002)(1076003)(4326008)(8676002)(8936002)(6666004)(66476007)(44832011)(26005)(5660300002)(316002)(41300700001)(66946007)(66556008)(6916009)(6512007)(6506007)(2616005)(6486002)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZxMzVIzBDAMp/PoIWR1Qg8HC9QufyRdoacyndbhl6/3+yHHeQVpko4/5zwL0otfG63Hdabex+2SoOmH84ERGDCL+Z5GbTsCXl3rXRN46PDyXbC+nwu4aEinqCbnT5f+MgOgUMy1i6m2s8Zk2Bvy6WzHzafqi6tLfpOp+I6NvAiMZgNCYmOlbBZBoA4ysXKyd9bmftCd/04Z+UCMEL+xzyOsbtV8cB6OMx/IpbYFXL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a/T4GhPrXnQYxED1V7NKZdQbjkqDXxOHmyExP2Z5xdo4oGrn5RfVd3ZGHL8E5cx3k/hI89wz+BoX+nCZiU2ipf5STUeWj2spG2y/KG0C6On8beCCxmvwTe2M27fL4pSTfM0oCzs4jGrrSTXRHrWfJtGjy7o4ZDv9BQ323F6Sa+pMzvc6tV8TwVNBJHBUYKBwJb86/U21c21Md4V8zbnoHg3TMmEnuVrYdux+ZaYmvBYsz6LD9jgPZKaSi+LsJvFT0xF+5M9BhUHSiH+J4fDa4177jKW34rPWLmYPkQxsvrlZ70vsaFKS2BRuy264w== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 71b37be8-0057-4f07-a685-08dbafb4e895 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2023 15:12:53.5374 (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: ZKy4j3lfW12qZ64TRc3rSA0ZRgM9gLuJJgMF91XT08rUWM9KQLujas+HSs+6TnToLfM+AHMNsIXCiBim+O/XAQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB9759 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds btio support for accepting BIS connections when defer setup is enabled on a Broadcast Receiver socket. --- btio/btio.c | 31 +++++++++++++++++++++++++++++++ btio/btio.h | 4 ++++ 2 files changed, 35 insertions(+) diff --git a/btio/btio.c b/btio/btio.c index 8d9959038..c6d056b89 100644 --- a/btio/btio.c +++ b/btio/btio.c @@ -1789,6 +1789,37 @@ gboolean bt_io_accept(GIOChannel *io, BtIOConnect connect, gpointer user_data, return TRUE; } +gboolean bt_io_bcast_accept(GIOChannel *io, BtIOConnect connect, + gpointer user_data, GDestroyNotify destroy, + GError * *err) +{ + int sock; + char c; + struct pollfd pfd; + + sock = g_io_channel_unix_get_fd(io); + + memset(&pfd, 0, sizeof(pfd)); + pfd.fd = sock; + pfd.events = POLLOUT; + + if (poll(&pfd, 1, 0) < 0) { + ERROR_FAILED(err, "poll", errno); + return FALSE; + } + + if (!(pfd.revents & POLLOUT)) { + if (read(sock, &c, 1) < 0) { + ERROR_FAILED(err, "read", errno); + return FALSE; + } + } + + server_add(io, connect, NULL, user_data, destroy); + + return TRUE; +} + gboolean bt_io_set(GIOChannel *io, GError **err, BtIOOption opt1, ...) { va_list args; diff --git a/btio/btio.h b/btio/btio.h index 642af2e22..3169bebf3 100644 --- a/btio/btio.h +++ b/btio/btio.h @@ -75,6 +75,10 @@ typedef void (*BtIOConnect)(GIOChannel *io, GError *err, gpointer user_data); gboolean bt_io_accept(GIOChannel *io, BtIOConnect connect, gpointer user_data, GDestroyNotify destroy, GError **err); +gboolean bt_io_bcast_accept(GIOChannel *io, BtIOConnect connect, + gpointer user_data, GDestroyNotify destroy, + GError **err); + gboolean bt_io_set(GIOChannel *io, GError **err, BtIOOption opt1, ...); gboolean bt_io_get(GIOChannel *io, GError **err, BtIOOption opt1, ...); From patchwork Thu Sep 7 15:12:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 13376522 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 E2B37EC873A for ; Thu, 7 Sep 2023 15:42:12 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229784AbjIGPmE (ORCPT ); Thu, 7 Sep 2023 11:42:04 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33940 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241284AbjIGPYW (ORCPT ); Thu, 7 Sep 2023 11:24:22 -0400 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2073.outbound.protection.outlook.com [40.107.7.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0FD92E66 for ; Thu, 7 Sep 2023 08:24:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=cPsQMALSYIS9LYxtHzMSJLPYoiNcV3YEtEUeGXCOuZP9c2/nHhKWnKY1JPYMkKZSCQBKHkEOdQdLBxWufMkPaKDv9MDjhPmYJ89nNewdZG81FJ39SQ+jMLY1UDnmTa9ffbGY95a6AaooRL89llxVQsBpaWMpTdFPueAXOUCPn1W8Ri4pX6B4REwDfSyOsJpT4lV4iKXfFo2dyNGJsY17/DLd/OICP5imOs0fFZ3bQkDy/qDCWhRSjjUzzWBpjiapNU+95MsQzVVZvELxCOmVeETQuJlR+8jxYzmCcZkQabSCEma1ucy0NdppwiES860h8/17I5GNICccMkTKsArVxg== 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=16NfLCBZnk/qFbwvyJzRC2y4cIcGDt56EekY4yh0lL0=; b=hcPTGdMjhBFx0k8z6uSnNOhuGX/p142vzxwYvsk0gK860yKMZTmd6TGcfRe/E9W12mrJztwfSJN2ZbmVQcJibuHES+Xna1yMURzS+apc6c9fg5wa+bDDlrN1V6YpSYl7rIxdYuXCSXusKm6nAC2jdui5o67Cn6MiwS20/FnxbFntw1EmgRfZknIzEIDbLcczuTg3j2TzrM04AZ/HC6J3bdO1KLCoUOCSqQoFhlJkDgJof0kLynU0S/OZZQhkb7hqQMiSuwtTw9bvZaBMGdFfuVSlfRikPv8VCmv53ZT4m4SuiAAiyzmaF2Ko+D4VNn0HnzahtX1hDWreXUsU/uwCAw== 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=16NfLCBZnk/qFbwvyJzRC2y4cIcGDt56EekY4yh0lL0=; b=T2InO6hwNL1wZyh2OuLGehXEX/sR3MVQUZdK9vm8+1QGnkEhDEhi+I/Tc8lKtcAFl0fFEMor6uo3gOYaZ+zE1IdGdtCjuv/xfq+yrMwwJi0MKG7nWTmdBOSpoNogFjVFip14i83ULrMTTWF6UZQUYM4yieT/xzVVNBjYOWgfIwM= 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 GVXPR04MB9759.eurprd04.prod.outlook.com (2603:10a6:150:111::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Thu, 7 Sep 2023 15:12:55 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::6e75:56f3:fc37:277b]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::6e75:56f3:fc37:277b%7]) with mapi id 15.20.6745.034; Thu, 7 Sep 2023 15:12:55 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, silviu.barbulescu@nxp.com, vlad.pruteanu@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Iulia Tanasescu Subject: [PATCH BlueZ 2/3] monitor: Fix ATT decoding issue Date: Thu, 7 Sep 2023 18:12:28 +0300 Message-Id: <20230907151229.7306-3-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230907151229.7306-1-iulia.tanasescu@nxp.com> References: <20230907151229.7306-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AM0PR02CA0195.eurprd02.prod.outlook.com (2603:10a6:20b:28e::32) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|GVXPR04MB9759:EE_ X-MS-Office365-Filtering-Correlation-Id: 5bc492cb-a0c5-4ac9-587c-08dbafb4e973 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: KqEtYIZjO7pH6rTfPPhxj5oRGeWEDlE9bDzzUKWRjLk+bnvS+2gGJvfZXuA87i/bU9TLLKGm0cVrwfdmqMVXkQycW/38naejI5Vks5kp07hnAc2E+glaACok8QIVFoMtMakn6rfDxNZ7LegvEZwkko/N7/jZI4vEJsBxQ7KCxPkhewlGZzIiXKD9AajZHPX8VyleksCSgqUx7rQajBJohTZdAjA6jLoiIGRbRPHykIOmJN0MyZi5PSPjr25mvJwMQq5Ql5iWbbkUd80V3oV2r4baJd4Im5se+dT/Ikljz1mgYgZLdRQK8P45h5E6fyIR3x5MiIS4UjNHLHwXJ9119+2IVKxXcYnhR6O9glYJo00H+BgTJfkt/m4kBYMLIw1hrba9kHAA/HYWgIAcLu+/dEYAvPqVzr4U6WYKqjYukVFg06DRMx43tRLQw22b3lhpB/R/wqmxi6e8gnduJ7VFBxGH6p2F19TRdl/dTBcR4T3yvJ6IbMbMirsb94l+gsztV/3XqjvDzjsTjiCVlCKp6eZxeXT4hSn+DHFdUobKaW85KkCSqbuXVeuiTsct0rNRBUCeIQedJNy6KnrSczT3fnGw3hXyOptCoLGayTOd20X2BwGGl8aPMZg0qoErx9Fv 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:(13230031)(136003)(39860400002)(396003)(346002)(366004)(376002)(1800799009)(186009)(451199024)(2906002)(36756003)(38100700002)(38350700002)(86362001)(55236004)(52116002)(1076003)(4326008)(8676002)(8936002)(6666004)(66476007)(44832011)(26005)(5660300002)(316002)(41300700001)(66946007)(66556008)(6916009)(6512007)(6506007)(2616005)(6486002)(83380400001)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 3bAF/Vx9o1DBIrZQeY6CKPF/Su0wdaUxiu1aMEo1OWoKdi2QubNM8LjMNGHfJ3v64kPSE9AR4jALuK+MclARfpXBmeELKBZIuqXocSbE6L+NlAcW837WqXAOdG5itUbnlepiL58OYyuR3GmQJJEIRK02blJd6Wprnb4LgEpDK55dfg+ibG+V5UQl0p8bYXvtPsPOwoDTdCVRU7jGc1AddYO947YTsZf1fnOZdmQWEwfHCifs/jNDAdhsIl6Orxf/WxRduVwmOh9frd+2vqQgcJTWWXoE2bRZ6wyOqngAqxOcbvOGju0viWTJlNHfBnnPGK4KofUYhtNEsCwxyKHb0/B6sX7j3Ufv2+6uNeBHeISjss7XUuaUCUzb9LimZvtHtEPN0Wk2fOfKVuJjBMugtlavMhC1JcR1s3HRdNPjoO1hi7M35xK2PLo2t+IN58hNa5rnUMMCYptd1eC4pD7d7OmkL3NTzOBwi7THKfjvayPnYIMxr1w/p2WuDDllmCMi670MeCw7elSI/oBqfjbX3TS9DbMzoAhJ7R7BRHd6ynEF3cfrKEEqyItRbckA/uehpbH/HOOGyA+CXTgBrHjybEiQPh9LvpZ2vn4JHf2/87teH61wK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-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2023 15:12:55.0115 (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: M8atDxp1tQnEEHTJrux0NtAz6dJVdQcupSdWuqXRSxYZJF1YVv5e+LJ9BGcL6nu+2YuuKbiRXWVNIoj9y5YgIw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB9759 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This fixes the way conn handles are marked as unused in the conn_list array, so that valid conn entries are not overwritten by new ones. --- monitor/packet.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/monitor/packet.c b/monitor/packet.c index 279f5408d..f88a11539 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -172,7 +172,9 @@ static uint16_t get_format(uint32_t cookie) #define MAX_CONN 16 -static struct packet_conn_data conn_list[MAX_CONN]; +static struct packet_conn_data conn_list[MAX_CONN] = { + [0 ... MAX_CONN - 1].handle = 0xffff +}; static struct packet_conn_data *lookup_parent(uint16_t handle) { @@ -192,7 +194,7 @@ static void assign_handle(uint16_t index, uint16_t handle, uint8_t type, int i; for (i = 0; i < MAX_CONN; i++) { - if (conn_list[i].handle == 0x0000) { + if (conn_list[i].handle == 0xffff) { hci_devba(index, (bdaddr_t *)conn_list[i].src); conn_list[i].index = index; @@ -236,6 +238,7 @@ static void release_handle(uint16_t handle) queue_destroy(conn->tx_q, free); queue_destroy(conn->chan_q, free); memset(conn, 0, sizeof(*conn)); + conn->handle = 0xffff; break; } } From patchwork Thu Sep 7 15:12:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 13376525 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 8B1C2EC873A for ; Thu, 7 Sep 2023 15:42:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233455AbjIGPmZ (ORCPT ); Thu, 7 Sep 2023 11:42:25 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57308 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231205AbjIGPYd (ORCPT ); Thu, 7 Sep 2023 11:24:33 -0400 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2073.outbound.protection.outlook.com [40.107.7.73]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D8C271B2 for ; Thu, 7 Sep 2023 08:24:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=L5YEadlkXbWLPEUfqZePqQVOuV1VAQf50ee/IbHzEVGUlz5miLAyFZP0KFwcBo3x24zWcdqnBqtlDT6SteE5Ec46lCLJrSZNLDgDm608zM7cEQWkuxMF4JSb096Gbd2yKW36uXJsWgaXqrjwX63WMqcLjI34D/BqvtDpDC+rsoGcsIqclQfWrV2TynWeYUdzOG0+H4lhoO5U9SDJX7hzmAflv1qbQl6zDfuySvFMa2Ymr5XK7We0oaAIY9LOISsdBkhv/w++ffN08Yje9tU/EelVuBt5jEJa7XY3KdqgUYMr+obmcS99BgZQSB782KMzL6YS+JuqrYdS8DJW4E7WSg== 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=5ns5bZyDE+Fsxjlx5eaGnJRzyQg2H9HFfjbK/gPJ5wU=; b=TbhqmVm+jpKSr5tz2Kjx89siu7JswcBVWrpJm/fZY81d0B/N1ODIO6KaGvVO14ItRXWamBGTkmmJcW5wJnhlD7OTfwhMY3iCmKvqeKnY0Y8fVcnETtgAdYg4hULjR7mmavQUgaOhwvPnpNeorEBZLJz1GvQKRTArIFMqfExm4hfSzErowepTF/iaRtA7ddXit9oqbLADRashk/wNvKtCjY5DPHum4XtpxVIMKpbjxpEmIXPy/anz7bMHKByuiz5VMNLfV5C6mDnBmUEOQ8duQ9wXe0Bl9HoOXj7Fvts6i75pMoeY3cYCOhuWk1pMwUJh9mAhdH/SW4XCnaJGmLsO8w== 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=5ns5bZyDE+Fsxjlx5eaGnJRzyQg2H9HFfjbK/gPJ5wU=; b=R/A/HCKzxfD7coKV74hTM/aFwYhK2AGLmtfZag0GpIDoPWQBPpyLI3hwHGLQfymButOWUl0hXbNXEWRYPwXAtoBkDDxoN7waPvUU5Z9VkwOrft3lGLDR/qnMZw4ILD+Kw0pSN29WyBEIHIBaBc+BC27lK1snlXBOLKbrcj3vPnM= 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 GVXPR04MB9759.eurprd04.prod.outlook.com (2603:10a6:150:111::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6745.33; Thu, 7 Sep 2023 15:12:56 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::6e75:56f3:fc37:277b]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::6e75:56f3:fc37:277b%7]) with mapi id 15.20.6745.034; Thu, 7 Sep 2023 15:12:56 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, silviu.barbulescu@nxp.com, vlad.pruteanu@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Iulia Tanasescu Subject: [PATCH BlueZ 3/3] shared/bass: Add Set Broadcast_Code opcode handler Date: Thu, 7 Sep 2023 18:12:29 +0300 Message-Id: <20230907151229.7306-4-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230907151229.7306-1-iulia.tanasescu@nxp.com> References: <20230907151229.7306-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AM0PR02CA0195.eurprd02.prod.outlook.com (2603:10a6:20b:28e::32) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|GVXPR04MB9759:EE_ X-MS-Office365-Filtering-Correlation-Id: 4a003328-00f3-4642-a80c-08dbafb4ea4e X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JVrNt/itKqwKhPrIBqqI6o3GNSdgq1I5BbCwyFPLSCXdQsZlK8Jy8y5Y2RmBA/hbCLpRHJaFimVYThpHInye/ixAXxS37p1FMExguXrj4YhyLCZpgxrED2rF7e6orqExqi8Qvv7Yk+zbuZkiim8w+egkz/kKjn1kjfUpanaQRCvzHkMn42mMT/QRvlgjcqsdbtukWT4FFt41URHZyjbupjtGQRvv/IrCTGKVwwAIFHn1xCRRgIuOfb/1OR9lrkvIOb6de08Yn91QnqC3c8KtOFGJ0M/5eIxarDjYvHMPCvd8q6rFCllGGkR8A/gqnfSVj/5tsc03NX7smKdhknaI8LwNbXHCwWWY+ypGciEyfHGwvDkqTlhlOH51I9irds7xt9NAH64mUTyW+U9ejB9hgyzokMRGOsOHxkHj6MTs8h32pZZI5pbHvxmTn6l1kghkjpVdKcZkS61mcBkfHmI3zrQmSdNDgTRg6on3eUgl2mKY1O4GhSWOPFdqJYMP0Mt0nDKV3PESGDMcWADB877Rd6z0PWCnUE1U8vaOb8zsDP9AeBsANDCCljeqiuZhodxFBuzb5M3bs7RzZeKpob/LXg4aVbuaZQUb8VcvCBfTsGj18v0IBzdRyZViHpAHv9E8 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:(13230031)(136003)(39860400002)(396003)(346002)(366004)(376002)(1800799009)(186009)(451199024)(2906002)(36756003)(38100700002)(38350700002)(86362001)(55236004)(52116002)(1076003)(4326008)(8676002)(8936002)(6666004)(66476007)(44832011)(26005)(5660300002)(316002)(41300700001)(66946007)(66556008)(6916009)(6512007)(6506007)(2616005)(6486002)(83380400001)(478600001);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: 0EOZ81CXFiEDVh90Npv680xqIA0HMH47nae1b7RZuFStKalYwxkVG1aNXLU6DmRuSXiOr75k5gMfq9Ixl8SiGVzJbI2eCZkgc45vhHygPYPLtslJp8qeBc7o1zQwPBGD7BLn2EH9YPCxcTyY3mQgT5Gx0ztATyxTlYU61b6CM6nAVG/1XpdDLVdmho1piunbTVIDuj35vMqbhl5CfICVijUkLA5lglU6vGzBFN6pZQfcOsz4iJlO9yMQBpE+RT/aoATQG/X30LgNUsDJiTlikVkP2Geyp6cV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zNyPRYnLk+SASg1pmNtPvbjcn4LIwpUjrYgg7LYj3TK/kthGcNKU1rf0idEH06VjVp2ZU5060PTEgyZRuq47617lg/oiyIhth4ySh/vnha+6oest/q3AV0QBf9ISEKr1Ix1N8XWFLI2r/qwwmtUris7/FPCmbmOQSy1t6M8edsCB2xXSKi0WdrB3kp8QLnhv01KLQ532vYDZKRVEEcp2ktPixFxESyPM9+yuYNNFB2ur06K4IlPEkfTA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4a003328-00f3-4642-a80c-08dbafb4ea4e X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 07 Sep 2023 15:12:56.5102 (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: p1ukWST8tO0cQFcN4d8Iy15HQht/UheBkmmphkaJEVD58Evcqc7eE9LHUAT5RtJe4UHf/HGqKviv63CgGgS7fQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: GVXPR04MB9759 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds the Set Broadcast_Code opcode handler, enabling a BASS Server to sync to an encrypted BIG. --- src/shared/bass.c | 159 +++++++++++++++++++++++++++++++++++++++++++--- src/shared/bass.h | 1 + 2 files changed, 151 insertions(+), 9 deletions(-) diff --git a/src/shared/bass.c b/src/shared/bass.c index 1bb40877f..86dab03e3 100644 --- a/src/shared/bass.c +++ b/src/shared/bass.c @@ -613,9 +613,6 @@ static void connect_cb(GIOChannel *io, GError *gerr, int bis_idx; int i; - if (bcast_src->sync_state == BT_BASS_NOT_SYNCHRONIZED_TO_PA) - bcast_src->sync_state = BT_BASS_SYNCHRONIZED_TO_PA; - /* Keep io reference */ g_io_channel_ref(io); queue_push_tail(bcast_src->bises, io); @@ -661,9 +658,26 @@ static void connect_cb(GIOChannel *io, GError *gerr, g_io_channel_unref(bcast_src->listen_io); bcast_src->listen_io = NULL; + /* Close pa sync io */ + if (bcast_src->pa_sync_io) { + g_io_channel_shutdown(bcast_src->pa_sync_io, + TRUE, NULL); + g_io_channel_unref(bcast_src->pa_sync_io); + bcast_src->pa_sync_io = NULL; + } + for (i = 0; i < bcast_src->num_subgroups; i++) bcast_src->subgroup_data[i].bis_sync = BT_BASS_BIG_SYNC_FAILED_BITMASK; + + /* If BIG sync failed because of an incorrect broadcast code, + * inform client + */ + if (bcast_src->enc == BT_BASS_BIG_ENC_STATE_BCODE_REQ) + bcast_src->enc = BT_BASS_BIG_ENC_STATE_BAD_CODE; + } else { + if (bcast_src->enc == BT_BASS_BIG_ENC_STATE_BCODE_REQ) + bcast_src->enc = BT_BASS_BIG_ENC_STATE_DEC; } /* Send notification to client */ @@ -678,6 +692,66 @@ static void connect_cb(GIOChannel *io, GError *gerr, free(notify_data); } +static void confirm_cb(GIOChannel *io, gpointer user_data) +{ + struct bt_bcast_src *bcast_src = user_data; + int sk, err; + socklen_t len; + struct bt_iso_qos qos; + uint8_t *notify_data; + size_t notify_data_len; + GError *gerr = NULL; + + if (check_io_err(io)) { + DBG(bcast_src->bass, "PA sync failed"); + + /* Mark PA sync as failed and notify client */ + bcast_src->sync_state = BT_BASS_FAILED_TO_SYNCHRONIZE_TO_PA; + goto notify; + } + + bcast_src->sync_state = BT_BASS_SYNCHRONIZED_TO_PA; + bcast_src->pa_sync_io = io; + g_io_channel_ref(bcast_src->pa_sync_io); + + len = sizeof(qos); + memset(&qos, 0, len); + + sk = g_io_channel_unix_get_fd(io); + + err = getsockopt(sk, SOL_BLUETOOTH, BT_ISO_QOS, &qos, &len); + if (err < 0) { + DBG(bcast_src->bass, "Failed to get iso qos"); + return; + } + + if (!qos.bcast.encryption) { + /* BIG is not encrypted. Try to synchronize */ + bcast_src->enc = BT_BASS_BIG_ENC_STATE_NO_ENC; + + if (!bt_io_bcast_accept(bcast_src->pa_sync_io, + connect_cb, bcast_src, NULL, &gerr)) { + DBG(bcast_src->bass, "bt_io_accept: %s", gerr->message); + g_error_free(gerr); + } + return; + } + + /* BIG is encrypted. Wait for Client to provide the Broadcast_Code */ + bcast_src->enc = BT_BASS_BIG_ENC_STATE_BCODE_REQ; + +notify: + notify_data = bass_build_notif_from_bcast_src(bcast_src, + ¬ify_data_len); + + gatt_db_attribute_notify(bcast_src->attr, + (void *)notify_data, + notify_data_len, + bt_bass_get_att(bcast_src->bass)); + + free(notify_data); +} + static struct bt_bass *bass_get_session(struct bt_att *att, struct gatt_db *db, const bdaddr_t *adapter_bdaddr) { @@ -796,11 +870,6 @@ static void bass_handle_add_src_op(struct bt_bass *bass, pa_sync = util_iov_pull_mem(iov, sizeof(*pa_sync)); bcast_src->sync_state = BT_BASS_NOT_SYNCHRONIZED_TO_PA; - /* TODO: Set the encryption field based on observed BIGInfo reports, - * after PA sync establishment - */ - bcast_src->enc = BT_BASS_BIG_ENC_STATE_NO_ENC; - /* TODO: Use the pa_interval field for the sync transfer procedure */ util_iov_pull_mem(iov, sizeof(uint16_t)); @@ -852,7 +921,7 @@ static void bass_handle_add_src_op(struct bt_bass *bass, if (pa_sync != PA_SYNC_NO_SYNC && num_bis > 0) { /* If requested by client, try to synchronize to the source */ - io = bt_io_listen(connect_cb, NULL, bcast_src, NULL, &err, + io = bt_io_listen(NULL, confirm_cb, bcast_src, NULL, &err, BT_IO_OPT_SOURCE_BDADDR, &bass->ldb->adapter_bdaddr, BT_IO_OPT_DEST_BDADDR, @@ -906,6 +975,71 @@ err: free(bcast_src); } +static void bass_handle_set_bcast_code_op(struct bt_bass *bass, + struct gatt_db_attribute *attrib, + uint8_t opcode, + unsigned int id, + struct iovec *iov, + struct bt_att *att) +{ + struct bt_bass_set_bcast_code_params *params; + struct bt_bcast_src *bcast_src; + int sk, err; + socklen_t len; + struct bt_iso_qos qos; + GError *gerr = NULL; + + if (opcode == BT_ATT_OP_WRITE_REQ) + gatt_db_attribute_write_result(attrib, id, 0x00); + + /* Get Set Broadcast Code command parameters */ + params = util_iov_pull_mem(iov, sizeof(*params)); + + bcast_src = queue_find(bass->ldb->bcast_srcs, + bass_src_id_match, + ¶ms->id); + + if (!bcast_src) { + /* No source matches the written source id */ + if (opcode == BT_ATT_OP_WRITE_REQ) + gatt_db_attribute_write_result(attrib, id, + BT_BASS_ERROR_INVALID_SOURCE_ID); + + return; + } + + /* Try to sync to the source using the + * received broadcast code + */ + len = sizeof(qos); + memset(&qos, 0, len); + + if (!bcast_src->pa_sync_io) + return; + + sk = g_io_channel_unix_get_fd(bcast_src->pa_sync_io); + + err = getsockopt(sk, SOL_BLUETOOTH, BT_ISO_QOS, &qos, &len); + if (err < 0) { + DBG(bcast_src->bass, "Failed to get iso qos"); + return; + } + + /* Update socket QoS with Broadcast Code */ + memcpy(qos.bcast.bcode, params->bcast_code, BT_BASS_BCAST_CODE_SIZE); + + if (setsockopt(sk, SOL_BLUETOOTH, BT_ISO_QOS, &qos, + sizeof(qos)) < 0) { + DBG(bcast_src->bass, "Failed to set iso qos"); + return; + } + + if (!bt_io_bcast_accept(bcast_src->pa_sync_io, connect_cb, + bcast_src, NULL, &gerr)) { + DBG(bcast_src->bass, "bt_io_accept: %s", gerr->message); + g_error_free(gerr); + } +} #define BASS_OP(_str, _op, _size, _func) \ { \ @@ -934,6 +1068,8 @@ struct bass_op_handler { 0, bass_handle_remove_src_op), BASS_OP("Add Source", BT_BASS_ADD_SRC, 0, bass_handle_add_src_op), + BASS_OP("Set Broadcast Code", BT_BASS_SET_BCAST_CODE, + 0, bass_handle_set_bcast_code_op), {} }; @@ -1092,6 +1228,11 @@ static void bass_bcast_src_free(void *data) g_io_channel_unref(bcast_src->listen_io); } + if (bcast_src->pa_sync_io) { + g_io_channel_shutdown(bcast_src->pa_sync_io, TRUE, NULL); + g_io_channel_unref(bcast_src->pa_sync_io); + } + queue_destroy(bcast_src->bises, bass_bis_unref); free(bcast_src); diff --git a/src/shared/bass.h b/src/shared/bass.h index fb4b72d7d..b3f83b32e 100644 --- a/src/shared/bass.h +++ b/src/shared/bass.h @@ -57,6 +57,7 @@ struct bt_bcast_src { uint8_t num_subgroups; struct bt_bass_subgroup_data *subgroup_data; GIOChannel *listen_io; + GIOChannel *pa_sync_io; struct queue *bises; };