From patchwork Mon Oct 16 15:48:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 734068 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 10A17CDB474 for ; Mon, 16 Oct 2023 15:49:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232365AbjJPPtN (ORCPT ); Mon, 16 Oct 2023 11:49:13 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57078 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232310AbjJPPtL (ORCPT ); Mon, 16 Oct 2023 11:49:11 -0400 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2044.outbound.protection.outlook.com [40.107.7.44]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7236DAB for ; Mon, 16 Oct 2023 08:49:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=SNbEvm40i8trzT0vkjfFU++/s/1j/Lbw5IDyqMS+QF0aY7EROmqd2l6JljhF/AdcYtZrhMsHrhpjBB1fnrFKzUy/6wGbki723iCsTQkipY5bjWY8+lE13lbtAaNuNAPcawvhozmzjSj3UiumHt93bYHsuXh0vJOlrG8ncNR0aupCxBHf2+h/1X63nhCwtGzfyA7fsOfcWcoXHcZDuVQDYsAQJyN2htspX/v1+xTXonfDKL/858sEtf4BRBUQWDX58650PKqj6gUp9uRdbpINzLpy0SRlBbEM9dUbM2P24vT2hiDALARsfuOXLFtPXjjwSAU3aTLqqs1zn3F7lDCFrw== 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=jGS69yGwOfg0Qsm8CLpeUQxjDhGNaIeIb76iH/MTu30=; b=N64zh1oW9mU580Fr9/H3IOy5XgevMqzozlS4BvYYvIH+6XEj0KiL6/3AeAn02R0RJWxFVj1rpYm/c5kmXFARa9TlgZnqOpNR9s9UMqFfW1i9AeSFBFVY6OFVPVyykZpnxj00qCpIwKYHW8cXnO7WX/WD2zonba99A7a83apIGjKMpDQmlwqnoORuQdO4HqysyM61C/Zm1UuTJE6vqaUTY0V8KniakTqAKMbHkbMPiu94Vkopt0K1SqVafq5YlgJxv9n/AsH/ZO7c17SbvSUvom6OwKqpvpBmEy7fkEsizo204tFtqpweE8EHC+jUIzMGGXWCMaXJKuvnmUlO6mtYeg== 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=jGS69yGwOfg0Qsm8CLpeUQxjDhGNaIeIb76iH/MTu30=; b=JkRlKEd1t0KxHpvm3tzVfF8MP6+FkwvUOmRYrUzHMZ6SNMCO9Y7ksV16ts8M+sniYpZg69ATIhwaXFBtvWJGQxffPaWfbg3UaTy9ik2zuXyj49HYKTrgQkzXdk10i7EZ3a+cXeAi3N6c40DCIXyiNcSkXruDk0ZMfXJt/nTsEPI= 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 VE1PR04MB7423.eurprd04.prod.outlook.com (2603:10a6:800:1a0::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35; Mon, 16 Oct 2023 15:49:09 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7763:779b:1a89:47da]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7763:779b:1a89:47da%3]) with mapi id 15.20.6863.046; Mon, 16 Oct 2023 15:49:09 +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/4] btio: Handle closed channel in server_cb Date: Mon, 16 Oct 2023 18:48:57 +0300 Message-Id: <20231016154900.3094-2-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231016154900.3094-1-iulia.tanasescu@nxp.com> References: <20231016154900.3094-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: VI1PR0102CA0102.eurprd01.prod.exchangelabs.com (2603:10a6:803:15::43) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|VE1PR04MB7423:EE_ X-MS-Office365-Filtering-Correlation-Id: fda69e90-e83f-482a-81ba-08dbce5f6f87 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: JDOm8qREBJM87h7Aicp+n8fixMIKxqHW6fTRl4TDNzVlBV8RMmHD6P+6TBIr0hZj4bAvIFZHGNqFbQAECtb6jAm/CQFJIOHW8HsFHeYcWhFUSBCGG0lStTQJ7rRc3/zX//gBIzFublvdXmGvspdjs1SMQjOMGk1wcQYIKZQEODQvUfqofG7Xt4mXCy2drr/PYUXjF49FS3teUISk4P/b/ae9c1eQ/Gzz8e+m8NutNT9gyqBdlSeBehTHt3bh62DzkHoTeg2lhuk4aX/SA78xaoyv60BOPOVSOX7stg+GJbKwMGnqFgsnTSrtZoEE6w0cRJGVcO1auGjzzixJ9RdJjLyX5gJaRcKBY7QmXWbPYD50ShA4IDZ47jyLCmPUUGvof0cB9G+hNd6LoPQ9K2tOWA84xXMsUl7paHrmcvHZT65wElmbApG1oPfsVLLmM3NRgx63RnA2Db+oxAEHnM85uvrm85Y8RBoMzX7ysrTDY31dkNbMHq3zNQ6fAhZj/4GJz5inq2HpA2SpjzfnicwcvPh8jtmtoYgx9kklRxerHCPMpwxGowEAoNnUYEbhp/gx 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)(376002)(366004)(136003)(396003)(346002)(39860400002)(230922051799003)(64100799003)(451199024)(1800799009)(186009)(36756003)(66946007)(66556008)(6916009)(316002)(66476007)(86362001)(38100700002)(5660300002)(44832011)(8676002)(8936002)(2906002)(4744005)(41300700001)(6512007)(6666004)(6506007)(4326008)(2616005)(26005)(1076003)(83380400001)(6486002)(478600001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: bsM/mJho3SYLzi5rX1CmMQXpPAtoM+iW91PQSv/7nxZKjcaupHp1HjCj3II3tjQAZznPkNg7cfoH9j8b38BMLxWtiLvU8DBdvph3J7REz7I5IC7HUzB0EO2rhWRlFa/XR/nxWYzMz3ZBIT/UJYOU/2CcajAzqS/iVastIz+CzhLmbDf+MpCr7dMCZHGtYuKrh3w4qhyDCf/tmXUytTNYMubIZcUkNx/DsR/Uei8qw26+B/9tjPar+CSVem7QHRiB5xQ6zKGYfEm8tr/NXZ5G2BNBUAsyknv9hGZpH4j8n8iahlbKJ/v41Bic+5CE7J8zxm/X63hHuCjiNiYiBsyKZprZCbtY0CUg0+TWqv59Hys/9dfXXvWomH4rWW8PqgAfx19Rs/aWH1v9ADc/F3SurFJOg3DkAvAL9DCgp68loSYC2+Vln/nUIRFl2myPv3WZ5UrmitZgaxKghs2h9biUEm+czl0hKkwoEb03BCte7qM7NmmfD03ab8o53ZUceTgLDhBMKF19jYt1LKch93Gl2Os71Vuq1Y0lSKasai9pDaLjhfayprD9SwdEWkb3FHHfC3bXyXPBp9OiZeE4a7DmPkGfCOfJjRiovxJVqp4P9KEQ0E5mUrHd5YzDQbtml3Y2tBCQ49bOUiR46a52eGd4EYLpL+K3gz0KlSHkTU/83WLH2ctEZk+nRTfOoCS6lsXyDBnrOUdiWcx045LiwnFTNVVZSUJavacSvIW4dZBu6Lkgq9IWdlRnlXnWvOYx+ET74OrtYYpSNDCiD7UiO6NQbuF9r+KwKFfWOwv5hTjKi3rScbuMS7yjURRTuVtRqiP3yZN5X9wVGeazFx7q8qM9PsRpRoTy6q2qrzX9kPRr9+cwVtLhGsRijhRRMmTlMydY0Gi0ZSEEjuUmmMU3xm0ArZ9rUQlLn4qeHuOohD4HYJ/dchbDbSjkIp/TpfjhYkr2q+Y+02m3+dNfOd8klFBpuMSp7nCmiqiKyH/rUCFQB4K9pshqxqwa/6U1T3jTM2LXh7Cqd74CEpkmJ3VaPDf611lln1h3Td/op2YujOH+vTIzTJ80+aBSWc/Ay0bLRWqm3WKdtsuqXockmB9h1KSbPwLJVM/RR36/fnDsLvlZ4rKVeeaD5+ArBuMjt1Brzn2fFZV3e1uzmkxSKAS23MV3OT59CAkILEtgoqVxakVRcH2K3CsBQ6lkNpxQfoGHzmot48LLTuKd4Ct8enx2OKZ0PJJCGf8LNFU4ggoJni7hu2DCwd4axol2LLTJVXVSSMPcNlpJyNUQBEPHAHrE+61muHwiWJkjVNAZZCDmQBW9kiDfkXyxYfjf1lLtdspWug7UefTBz+XXhbF92s1JKIZYomFUS1MYzMQXU/p4f0xu+Q1nn/PLfVvmKJoIrgoQyhUyIvv45LJlsSOYyzQHCgNXy7rn1UpOPoTGofQOxmfKfqdBnQ9GQD/srLGAvAQLa5P7J3v3g+3DJJ7/+nSBmGDRgXUMDyEV4O9gZ0DCMzqx8GjLOEEWb6metl5HJuNgIz21qUYryMAymkhtNln4DjpsEujXAg6Tr+f7gVTmxV5q8VAj3hmCoRsqeXPtgZU06UKG7ohnFt9sWCijKsWmYM/hwg== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: fda69e90-e83f-482a-81ba-08dbce5f6f87 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 15:49:09.2401 (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: o8XYfzrP49EG4kSJptoO6KEbZETfC1BfjFH+exPpWJKQu3ZlWBG15qSoRXJX8zeukXe43rdyP2+jZVB2WWJE4Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7423 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This handles G_IO_ERR and G_IO_HUP conditions in server_cb --- btio/btio.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/btio/btio.c b/btio/btio.c index d45b8240d..c63a6d1df 100644 --- a/btio/btio.c +++ b/btio/btio.c @@ -247,7 +247,8 @@ static gboolean server_cb(GIOChannel *io, GIOCondition cond, GIOChannel *cli_io; /* If the user closed the server */ - if ((cond & G_IO_NVAL) || check_nval(io)) + if ((cond & (G_IO_NVAL | G_IO_ERR | G_IO_HUP)) || + check_nval(io)) return FALSE; srv_sock = g_io_channel_unix_get_fd(io); From patchwork Mon Oct 16 15:48:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 737404 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 79794CDB474 for ; Mon, 16 Oct 2023 15:49:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233812AbjJPPtR (ORCPT ); Mon, 16 Oct 2023 11:49:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46916 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232310AbjJPPtQ (ORCPT ); Mon, 16 Oct 2023 11:49:16 -0400 Received: from EUR04-HE1-obe.outbound.protection.outlook.com (mail-he1eur04on2057.outbound.protection.outlook.com [40.107.7.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A377DE6 for ; Mon, 16 Oct 2023 08:49:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kAB45zxqQrJHYwvlegSkqjcc1Wm7Sgc/BuNUMgVr/BB65zmR1MGPV43PKmxTkjF/8Dv96v0VNcxQtGUC611216FeCNs88BLwTAtfRhtIE8tgOgr0neYy0dOFhOTWtrZ39nGtD9x/3RcPUyEMoayWCFlag/UXtXugGfzExh1gnfymW437wkmNSKE14zCnxcZK/dLDLecx2PUaZuqQCvjOQeFU0ZOGehnwje5DdI61OyweUSDFKxfAYCwZrFQyBnvnt818RuavOo4fFNIhN8k6AHFkqj/hrkeLZmQ3dr/+yyv+od0Uh/2nNlTd/ROsR1dQz8Fg/dcdBb9DttvMgb2lyQ== 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=tbyYR8m4Zqs2O3cFeKwsVcuYwv9OeWAHuEYTp8xEBVs=; b=nBgr1/RG3PNPqynrSn7gH5kd3AJsru6gZ+OfQszfCM0RkbPRs26I1vQVHAcNEMpLI6ya81ZgJWIqM3gUJ89SJ80sYAGJrGbQ+0le+QuQgRuYiE5y2TS5yDeza/ljNUhmXmk14G07wnx0OC+Lej7kkIs5Eo6nUFfMAlgDFo2TrTHsZen//lUoZtSesOp52e+igmTyn7eN0vtM9veK6W2/TUp1dNum7XbVQLOX1F2QZBArsdUJ2kNgqG/yhzEDN40U5c03xSY1NniCg2xe1TEQLQ/rh67hglZ8ewCacDLtXR2LUFMpmUER+/CrBPwNqq6VnolwK4Kvp/oF9yAV7Hj6Vg== 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=tbyYR8m4Zqs2O3cFeKwsVcuYwv9OeWAHuEYTp8xEBVs=; b=gsiIrmMN31RCq/D9dfRYcRzK6QxDzBw0ONR2mg+EWzMwGi21LzCgOiyWCQmCLa3qP8qSix7vvLSFnQkBjD2OXqCcWSHtuG37VLBes0BDhwWD7c3EOagVlWMU2LzBVH7Jq5kfmywIFf+53DMUaYwddZxdmopOg/MQsDoSwIsT/Hg= 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 VE1PR04MB7423.eurprd04.prod.outlook.com (2603:10a6:800:1a0::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35; Mon, 16 Oct 2023 15:49:12 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7763:779b:1a89:47da]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7763:779b:1a89:47da%3]) with mapi id 15.20.6863.046; Mon, 16 Oct 2023 15:49:12 +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/4] shared/bass: Handle G_IO_HUP on io channels Date: Mon, 16 Oct 2023 18:48:58 +0300 Message-Id: <20231016154900.3094-3-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231016154900.3094-1-iulia.tanasescu@nxp.com> References: <20231016154900.3094-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: VI1PR04CA0045.eurprd04.prod.outlook.com (2603:10a6:802:2::16) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|VE1PR04MB7423:EE_ X-MS-Office365-Filtering-Correlation-Id: 0c95b0f5-6277-4c95-0b9d-08dbce5f712b X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: e4mGIG/M6KI0PS+l5ZHOSXVe7yPTqqhPLBypnYFMh1t8aBuUA9jqQLA/GKgeK3FEKL2RnNRkLrqDg0QFP8FZaNJKdEnD/YhXLM0iGliB+nWcSdPnr7Krj1wVjM6SoZnjHCff0V0b07GmMPJSYBfNpee0VO0x25dk51s/pJx5+gQypI3kTTwSPDquqZkxeyVIdGtCULwxK7oUkMplNU/dGOVKxHcifzTO03iVaZcNo9nqGCqsBdq3KZbe/kPzAO8U6PAK5s9D3Cc8wiXOmSPscjkzXKPFmLKns2961A+iVTw8ptvN2oXUydDyQ87CrBHOdT6IbVsoM/5wvo/ZuX3hhb0fYXFrsIxVmQMiNkcl2yZxfLj3K4t4X67O6vhjDhCENOLkDb6ucZlW0RPdEQHGym7u0oEuzmL1Sk7nESNNGcyRdtpgAvf7et/iFiAu/ym9fYaVx6VEWkuk1FBq9eRhNWBhJ9diZV83F2t+zrzc3pdILKkhk6Utr6ND0hOhzqqU+gsA8xTKfcE+O0YqwDbCSG2nXTuXz1kGjaI9D2PjJotaiC3nTEFMK9NrKI/Jqdes 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)(376002)(366004)(136003)(396003)(346002)(39860400002)(230922051799003)(64100799003)(451199024)(1800799009)(186009)(36756003)(66946007)(66556008)(6916009)(316002)(66476007)(86362001)(38100700002)(5660300002)(44832011)(8676002)(8936002)(2906002)(41300700001)(6512007)(6666004)(6506007)(4326008)(2616005)(26005)(1076003)(83380400001)(6486002)(478600001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: qtz9R6aDsUq/BLNOf7yC8hv1S9C9/xCjgW8MlTQXYoXhcWJb4puGCV7X8DM7mplKmWSVNDRpvC/rtGA3pDQemJa8Wxry9ajG49rYd7IGA5lydJN5MWp9J5quChtJ9hQfPVMHbN7mi2tA7ZyH4iMydQ/8r5J0k3oPxH2NwBeqZON1lLIM961iwJUZTybCFLhPBwH1NFDtTJ5u/w78QoXYgyera1Ya/i0Zh5FL/YGTZZ4N4gjji01WgZ67ml23e/fxmzpb/v1PnEbWgYnGTNh6VsZtGNWxL64ej9+UNdBS3qH8BoqzDgTi/lqQcqXfPVbbfdnpeOrulP2NHiF4o92bQLgd0fsLZ3AFrfFH+ePYSPooN0dH6fNLyYFte34uryEJ2dQHq4aV7LigOD5ksgyue/svO9n+yDSyb84m+YnmyNsAUeTcL56v3jIHrtOjTkVb0eGX7lOTjm9si1vnon4kMW/+f9pvGUMM83rW/Mixxmon+mYgZgQi78ZnW6YWPoJaDZdgZe2tIojyVIg0evk+KXGQiYkpcupwrpojIXwpWEPDuoCD240ZtllsNnDWCq7mR1UneTj2777xjfBEEQISCs46jT1JYvBMdrwv5FdKQPyOtP7k2gW25pAS+YrbpByjQcBf1sl2MA8PWm9nOExMJWOGJu/ulD2H+Yzlc79/t+PDToCsT74VMCRoSut5jzZstvV85/fKCVcx2emmfv+kaBrMoeCFmjjIGdOA3h5B5SkUwE9hGbSt4pitVdvZ0fcuF6ltErIBF7cUsbgRITnvNMf3CJwxdachgbTNGw0mVCPU5pH4iGBrT9A8aZv3xjSKo9Crbhn8Xq91uztOYHVD3MsLzsGG5+lRMMQ5ZZUk4TD3Hfqy0upsRiLMC38K3p+B940Y62M8utijmasUd8gm4w6/xXyNFS28SSRyjBuLvD9X27zzEgudklhWu3zby/p/IPJKvAhfpwdyxDa1ooc8zl+Lk5kPtfNt0V1R/C/PXE6NnOSmR51wbkIj8N6RBspV5lDF6jPJm2hMAt4JvxrN4P20DwmRLeiArF6vphnmI3r30WDAfVMsvMDp++p1MMRtAw7f+IK6odZlGC3b83gA52cN1fh1sfyrU+SihYVl7B38hfXfENXHEcV65631QIJnqTzm98RAAeFNrUddsV9VUyr/A6QOV0Ln7tib248fEI/AWjWn9xhNM0p4Fvv3z849j4FkJVqQ3P8PMI/i3nLCm+XJf3duytX0cQiHmFDW/r6s9UuBhqy6PKBOBFDDfYmrvTC+Y1IpOWE3jzUOfYKEjops6A8GEOszsvFAYp/NN6sx1O6a4VptxKELr6eLu0LUwuTbGGrXJrHeU9p6cN/B1BtaZU2GcqCkWTM/IrN84vhFgEGnIFi1LHd58lDm68BQ8uBCVaAPN7eq/dlBTTAsHRhY3WeDCFRdocidUMdyKDE1+PE0r1P3SqCKgp+IqcPhuLtZnn1u1ndu8vtad/utffrWxX1Nuw6OLOtuNpJOzJXxhi4yibszitCnx7JWKNAj5B7fJDzenLbhIiSfIaV4JL8Srn7157Ck4Ct+4mg/QNY3a8t6jB9G/WNYjuNetWtYJQo73wj1mAENbHWkpMGFjA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0c95b0f5-6277-4c95-0b9d-08dbce5f712b X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 15:49:11.9852 (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: TTyGm5kpgdBMjpNVGWSgk07SOuqlWTh2y9OLnmQjkp+UsILE33P4L6rs1D0kDnQOh1Rr+cCiLYtPEEAjzlLv6Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7423 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds watches to handle closed sockets --- src/shared/bass.c | 59 +++++++++++++++++++++++++++++++++++++++++++++++ src/shared/bass.h | 2 ++ 2 files changed, 61 insertions(+) diff --git a/src/shared/bass.c b/src/shared/bass.c index 0ee3187d1..78103d463 100644 --- a/src/shared/bass.c +++ b/src/shared/bass.c @@ -655,6 +655,11 @@ static void connect_cb(GIOChannel *io, GError *gerr, g_io_channel_unref(bcast_src->listen_io); bcast_src->listen_io = NULL; + if (bcast_src->listen_io_id > 0) { + g_source_remove(bcast_src->listen_io_id); + bcast_src->listen_io_id = 0; + } + /* Close pa sync io */ if (bcast_src->pa_sync_io) { g_io_channel_shutdown(bcast_src->pa_sync_io, @@ -663,6 +668,11 @@ static void connect_cb(GIOChannel *io, GError *gerr, bcast_src->pa_sync_io = NULL; } + if (bcast_src->pa_sync_io_id > 0) { + g_source_remove(bcast_src->pa_sync_io_id); + bcast_src->pa_sync_io_id = 0; + } + for (i = 0; i < bcast_src->num_subgroups; i++) bcast_src->subgroup_data[i].bis_sync = BT_BASS_BIG_SYNC_FAILED_BITMASK; @@ -703,6 +713,18 @@ static bool bass_trigger_big_sync(struct bt_bcast_src *bcast_src) return false; } +static gboolean pa_sync_io_disconnect_cb(GIOChannel *io, GIOCondition cond, + gpointer data) +{ + struct bt_bcast_src *bcast_src = data; + + DBG(bcast_src->bass, "PA sync io has been disconnected"); + + bcast_src->pa_sync_io_id = 0; + bcast_src->pa_sync_io = NULL; + + return FALSE; +} static void confirm_cb(GIOChannel *io, gpointer user_data) { @@ -726,6 +748,15 @@ static void confirm_cb(GIOChannel *io, gpointer user_data) bcast_src->pa_sync_io = io; g_io_channel_ref(bcast_src->pa_sync_io); + if (bcast_src->pa_sync_io_id > 0) { + g_source_remove(bcast_src->pa_sync_io_id); + bcast_src->pa_sync_io_id = 0; + } + + bcast_src->pa_sync_io_id = g_io_add_watch(io, G_IO_ERR | G_IO_HUP | + G_IO_NVAL, (GIOFunc) pa_sync_io_disconnect_cb, + bcast_src); + len = sizeof(qos); memset(&qos, 0, len); @@ -844,6 +875,19 @@ static bool bass_validate_add_src_params(uint8_t *value, size_t len) return true; } +static gboolean listen_io_disconnect_cb(GIOChannel *io, GIOCondition cond, + gpointer data) +{ + struct bt_bcast_src *bcast_src = data; + + DBG(bcast_src->bass, "Listen io has been disconnected"); + + bcast_src->listen_io_id = 0; + bcast_src->listen_io = NULL; + + return FALSE; +} + static void bass_handle_add_src_op(struct bt_bass *bass, struct gatt_db_attribute *attrib, uint8_t opcode, @@ -1023,6 +1067,11 @@ static void bass_handle_add_src_op(struct bt_bass *bass, bcast_src->listen_io = io; g_io_channel_ref(bcast_src->listen_io); + bcast_src->listen_io_id = g_io_add_watch(io, G_IO_ERR | + G_IO_HUP | G_IO_NVAL, + (GIOFunc)listen_io_disconnect_cb, + bcast_src); + if (num_bis > 0 && !bcast_src->bises) bcast_src->bises = queue_new(); } else { @@ -1318,11 +1367,21 @@ static void bass_bcast_src_free(void *data) g_io_channel_unref(bcast_src->listen_io); } + if (bcast_src->listen_io_id > 0) { + g_source_remove(bcast_src->listen_io_id); + bcast_src->listen_io_id = 0; + } + 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); } + if (bcast_src->pa_sync_io_id > 0) { + g_source_remove(bcast_src->pa_sync_io_id); + bcast_src->pa_sync_io_id = 0; + } + queue_destroy(bcast_src->bises, bass_bis_unref); free(bcast_src); diff --git a/src/shared/bass.h b/src/shared/bass.h index c4b5b76ba..bd3fe900b 100644 --- a/src/shared/bass.h +++ b/src/shared/bass.h @@ -57,7 +57,9 @@ struct bt_bcast_src { uint8_t num_subgroups; struct bt_bass_subgroup_data *subgroup_data; GIOChannel *listen_io; + guint listen_io_id; GIOChannel *pa_sync_io; + guint pa_sync_io_id; struct queue *bises; }; From patchwork Mon Oct 16 15:48:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 734067 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 D2178CDB465 for ; Mon, 16 Oct 2023 15:49:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233913AbjJPPtW (ORCPT ); Mon, 16 Oct 2023 11:49:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47044 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233855AbjJPPtV (ORCPT ); Mon, 16 Oct 2023 11:49:21 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2077.outbound.protection.outlook.com [40.107.20.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2FC39AB for ; Mon, 16 Oct 2023 08:49:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=XToQ6f+KL+/vrABaDpB3bgB6W2ESJmh60cL+1ANpPWzf5wh01pk5FLAGh2JGxXPl3DQeeqmLgU7xTBjF1lvT4enSDAoLJr65Lpbn8q6gPx7OmUMJztP0lYIL8yNIJ7wQTv/fCuYbi10rT+USLAPqM4BphxCPnjnSiAQhwEs7v6pQHsghCPI+zPZo2oA0e3OZ7I2xDdegyEDC0azf7xnRq3Q5aqILtR1CILqF+wc20sxM4cpZekHHmIw9hOIVKsvZxPVKht0VkZKTaQcJYLc3LAmUMSu5YDV0aaJWXPqQIdpPQFPCwO5ut2QxmU6VaEgwAoi8r+88i0sZ0JzufDw55A== 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=KxDEy7QzjgfLJ8MMNyJBSiKoXHpjrym6a+uRYUneKgM=; b=XrD6guSWydH8QMsQ9ePyXiqJZqPEcmHyxKbi76gHvDW8QO+YdkalbgI+kt8H791NvyZnZGCTfw+7jWEAI6m97XIs0xe0heb7XJRtQGIlnqvVL/H0XAT7VjE43ougIHUUAJrWVW7QCVi+SCb1JhBVPcai/SXODC11v5QFrHygDI6ShiMFO8OsynDCzWJk5ReYsQHQEy8J6KlfJ1r+2xVqbWmOJ0OU9dku7SY5uL/ocuXx8nuJwR6KAOfpB6a6yC2rhBevPG5MWBqgxV+yVRyHcllysL6AVp1LkE4GbrLY4gIUWB9uV42LBKZsbNQ6QtQnFX1WfPbfyNyR74/4qHfEBQ== 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=KxDEy7QzjgfLJ8MMNyJBSiKoXHpjrym6a+uRYUneKgM=; b=GITPdFdpPtV//BQH/XYEJCSgRENgI6+HfpBmyn5Tfwl1k+KF6sdfBlJ8Pc+zDil1F/HBCqgzndcWT5SeBl4BwhphrAkRCIV8EWo83hw4FjELD7yVxG07s0LL5wNXykCPiwTq+KSP1DyVD/qh7EltTyQHzZpMewG90lEOGjv4q6Y= 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 DU2PR04MB9049.eurprd04.prod.outlook.com (2603:10a6:10:2e4::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35; Mon, 16 Oct 2023 15:49:15 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7763:779b:1a89:47da]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7763:779b:1a89:47da%3]) with mapi id 15.20.6863.046; Mon, 16 Oct 2023 15:49:15 +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/4] btio: Allow binding a bcast listener before accept Date: Mon, 16 Oct 2023 18:48:59 +0300 Message-Id: <20231016154900.3094-4-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231016154900.3094-1-iulia.tanasescu@nxp.com> References: <20231016154900.3094-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: VI1PR06CA0135.eurprd06.prod.outlook.com (2603:10a6:803:a0::28) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|DU2PR04MB9049:EE_ X-MS-Office365-Filtering-Correlation-Id: 8e07dc35-bf3e-447a-1b9a-08dbce5f72f7 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: dGSJk8Vd3jil1WOtgLn+/83cKEnP+QYb0lBr5MuBSpci0NQRHHTidUdG+rqi/Z+knNivDb0zocEF4pXRFfX68tpxnN7gjl+xtFJgiNaje0aUkt0/qBiNzLeANg9uXy+P/vbTVN/73SJFx3m66HB9MsFpTPZViB43LIVOJSvHzMf6gkGXb0tlPJZbv2HMW51R9eLMdobRzpfNxo7ull9FtnY3HLL0IpyDKJPYs4GITdY9vUfLJbaoAPKBxn18yCp2yEe5hxx92b69I8va2P1jFPf/DwXXwMCfv2D3FtKf8mhS/UzDHoNyQNNQOxPRkuk0AIrCdKmn2XxkErv76vZ9QaKHeKhfeMEAq6ZPS5j2vDUFRIpGiga4K19wblfEMFEajeonhZqIC7i+2cFpYP/e7IddYbrn6xNZ+Of0E8eEpwc7Z7STQO8jOXMRMiKD/t/C+jicDuZ24PiODXwZRH0tObSEGn2V5qlmHXk64o62akNhQHQjFLus/qz/c2lHYXoisvlC6ev0T4zl4f8YeTVTSX22xJd959IiArIpKVrXqlLki0fXV5n+rjNTB6K3rD2srV2/zzj/Ndtf5S2syVmKN5YpsCw78ELLI3KtPITJ8/G7elFzbW9K9Fodlrp8qkLz 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)(366004)(346002)(39860400002)(396003)(136003)(376002)(230922051799003)(1800799009)(186009)(64100799003)(451199024)(2013699003)(6486002)(38100700002)(478600001)(2906002)(6512007)(6506007)(6666004)(316002)(66946007)(66476007)(66556008)(6916009)(4326008)(5660300002)(41300700001)(8936002)(44832011)(8676002)(83380400001)(1076003)(26005)(2616005)(36756003)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: UMpq4K0Hc1uz7wfyQImFf6qTgpPlNCz+rCbggb4I0bdIYNbqta+VdPJjjSYDdAwIJzpvyXytAy20N1unKM2pnZOBIy1BHkIVSgNaNU7bxzukYaj7B7iKkpLsdE7I2ouIGvZYGcGVlef5PBkx/ax/LQx6wTuejuNZ2BOQu34NI47OAMzD3V8/tlLWKl8GzWUdAIl3pgiJmKLPCzazRSw9ndI2FDDqChFl7ryVx4a5tqZ9axvYLjAJeBmLX29NIvHn5GSd26UzL5DU0islXlABxGnSSzkau5nmWpDtEdNuax/sNeJd+T32tAohKYACsqPp+QLTs6VCEJWK1a08hLZRF1ykxcTCpXFDtN7u5kkDxAt72XvPFyQMGbMGaZ+TGZOTDOuVMUyR4IIRYmIAWaWHProqiDw2X63R/91OuhNr5DK52ywgn90UPWO+qgH/9Y8nVuo2Zyh/EEdI281WeSeuPu1GIOXauynd8KsY9CbVRdDpxS+/7xuYqfwzrsgfpaC/GdRhLtRev4IyGJQPNAy/Q7Z0Zw8yem9jDl6pxkpfud7asf0MNImMT+1M3N7Ia0QfEhSlksp/cr5ELNwzdb0azWWxS+wNdC384Wc++FolHAW+s+BW4PpEBPLxG5Kw7gq89k7A8aKxvCsH5kww0/Dn3HxfwnFYSBEmYz8+1leMzjZ3vgU0yesaaADkaZoBFMQO63fu0y8lhjjTIxgJuVSO+ZWCntkCl4FS+vLSafW3eAGgTxD2dQzzRX8d/vaUtXrEsAPjo9Rk98gzO9LhroG9GOaEWgtqC1zMEa2Pqn/U1mo+hps7qgqnoU9hN+Gmij7VfyMeYU7MZg5xj5m7eGTvnjZHVMMiJbpalDoUm98ETO+I8bwCUyKXJbaMZYoBK27gXUHmNeR6euKZT7RDx1Ll2BkiykP2AIYLfIMtzPhFbkiTV/jz/sLD5jr3pQQEiC3NWkIw87ABdVxz9ahCyC/yCJwomujy0bSCnundOvS0V4SwpixwJ7gRbkmKCDfYnnK+je1TD4VMXgy+Nm8WJSSkgZh+yF5rZtsfNmwYWjXGSZICbeDAxHQ7GhI8N6lNW+xBsO96L/yulyQLQ99JHqEoR6e1mTPopb88TuAXxThmG0I9AvcTIhpHP7a1a5EX7qJLn+srpZQlr7HNi9YT5i7nouFXPbuH2iomyJcOg8AZgokoDYnfmcMeGVbFWd5Mtu5+Z7em+iPG1bFbZiP2i3VsL2E3/I4TYvvKqdVsHxlFYAjuteNTfv9CmxUf7AEtHzbYhWFqFKjqUxz3EkwyJ67SL7ltRbkpr2yuPmy7ehAMas/SiP5AqL0WObiU5hArL7x5cSWNxUHcGShDH/8mlVQLfdsa6AZkx5AFrbiJvs1tRwCTvJ66tLWSYYzjKPQk6XkbVxOKhUVd2GQg0isgOFVgkJlr8tyImBwUHkIimZVQQSJfPR3moU0cj5jdm9ipvnr7s0V1GDd3bnEGEe/5578GV5FOCjd6oFev3W7j9BJrJYyBgtJgCDnDIfze2pfVeNXMrSMp7VjZPqcZ31I8i8A62wSReYEdXcgsJ1S09kE7zbU0hxGDLRFQoJQoefNxxIXY2trsq/tTsuptprrleD6Y2g== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 8e07dc35-bf3e-447a-1b9a-08dbce5f72f7 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 15:49:15.0531 (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: 92Wz+U02N2caXyznLEa2sWJVmeDGRP3Hu/tvaSiDXULFA7EOIVUzsDrIJpzDxafa2PV75u5Ox5Jch1NsFNYR/g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB9049 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds btio support for binding a PA sync io to a number of BISes, before proceeding with BIG Create Sync --- btio/btio.c | 51 +++++++++++++++++++++++++++++++++++++++++++- btio/btio.h | 2 +- profiles/audio/bap.c | 2 +- src/shared/bass.c | 9 ++++---- 4 files changed, 57 insertions(+), 7 deletions(-) diff --git a/btio/btio.c b/btio/btio.c index c63a6d1df..338f24916 100644 --- a/btio/btio.c +++ b/btio/btio.c @@ -1797,14 +1797,63 @@ gboolean bt_io_accept(GIOChannel *io, BtIOConnect connect, gpointer user_data, gboolean bt_io_bcast_accept(GIOChannel *io, BtIOConnect connect, gpointer user_data, GDestroyNotify destroy, - GError * *err) + GError * *err, BtIOOption opt1, ...) { int sock; char c; struct pollfd pfd; + va_list args; + struct sockaddr_iso *addr = NULL; + uint8_t bc_num_bis = 0; + uint8_t bc_bis[ISO_MAX_NUM_BIS] = {0}; + BtIOOption opt = opt1; + + va_start(args, opt1); + + while (opt != BT_IO_OPT_INVALID) { + if (opt == BT_IO_OPT_ISO_BC_NUM_BIS) { + bc_num_bis = va_arg(args, int); + } else if (opt == BT_IO_OPT_ISO_BC_BIS) { + memcpy(bc_bis, va_arg(args, uint8_t *), + bc_num_bis); + } else { + g_set_error(err, BT_IO_ERROR, EINVAL, + "Invalid option %d", opt); + break; + } + + opt = va_arg(args, int); + } + + va_end(args); + + if (*err) + return FALSE; sock = g_io_channel_unix_get_fd(io); + if (bc_num_bis) { + addr = malloc(sizeof(*addr) + sizeof(*addr->iso_bc)); + + if (!addr) { + ERROR_FAILED(err, "poll", ENOMEM); + return FALSE; + } + + memset(addr, 0, sizeof(*addr) + sizeof(*addr->iso_bc)); + addr->iso_family = AF_BLUETOOTH; + + addr->iso_bc->bc_num_bis = bc_num_bis; + memcpy(addr->iso_bc->bc_bis, bc_bis, + addr->iso_bc->bc_num_bis); + + if (bind(sock, (struct sockaddr *)addr, + sizeof(*addr) + sizeof(*addr->iso_bc)) < 0) { + ERROR_FAILED(err, "bind", errno); + return FALSE; + } + } + memset(&pfd, 0, sizeof(pfd)); pfd.fd = sock; pfd.events = POLLOUT; diff --git a/btio/btio.h b/btio/btio.h index 3169bebf3..3e69092b1 100644 --- a/btio/btio.h +++ b/btio/btio.h @@ -77,7 +77,7 @@ gboolean bt_io_accept(GIOChannel *io, BtIOConnect connect, gpointer user_data, gboolean bt_io_bcast_accept(GIOChannel *io, BtIOConnect connect, gpointer user_data, GDestroyNotify destroy, - GError **err); + GError **err, BtIOOption opt1, ...); gboolean bt_io_set(GIOChannel *io, GError **err, BtIOOption opt1, ...); diff --git a/profiles/audio/bap.c b/profiles/audio/bap.c index fa5cf1f54..b74498c4c 100644 --- a/profiles/audio/bap.c +++ b/profiles/audio/bap.c @@ -981,7 +981,7 @@ static void iso_pa_sync_confirm_cb(GIOChannel *io, void *user_data) GError *err = NULL; if (!bt_io_bcast_accept(io, iso_bcast_confirm_cb, - user_data, NULL, &err)) { + user_data, NULL, &err, BT_IO_OPT_INVALID)) { error("bt_io_bcast_accept: %s", err->message); g_error_free(err); g_io_channel_shutdown(io, TRUE, NULL); diff --git a/src/shared/bass.c b/src/shared/bass.c index 78103d463..326ce6dae 100644 --- a/src/shared/bass.c +++ b/src/shared/bass.c @@ -774,8 +774,9 @@ static void confirm_cb(GIOChannel *io, gpointer user_data) if (bass_trigger_big_sync(bcast_src)) { if (!bt_io_bcast_accept(bcast_src->pa_sync_io, - connect_cb, bcast_src, NULL, &gerr)) { - DBG(bcast_src->bass, "bt_io_accept: %s", + connect_cb, bcast_src, NULL, &gerr, + BT_IO_OPT_INVALID)) { + DBG(bcast_src->bass, "bt_io_bcast_accept: %s", gerr->message); g_error_free(gerr); } @@ -1178,8 +1179,8 @@ static void bass_handle_set_bcast_code_op(struct bt_bass *bass, } 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); + bcast_src, NULL, &gerr, BT_IO_OPT_INVALID)) { + DBG(bcast_src->bass, "bt_io_bcast_accept: %s", gerr->message); g_error_free(gerr); } } From patchwork Mon Oct 16 15:49:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 737403 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 B2618CDB482 for ; Mon, 16 Oct 2023 15:49:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233909AbjJPPtY (ORCPT ); Mon, 16 Oct 2023 11:49:24 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47122 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233899AbjJPPtX (ORCPT ); Mon, 16 Oct 2023 11:49:23 -0400 Received: from EUR05-DB8-obe.outbound.protection.outlook.com (mail-db8eur05on2077.outbound.protection.outlook.com [40.107.20.77]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B44B2F5 for ; Mon, 16 Oct 2023 08:49:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Wgv+TKmKTjpKwRgIIvXFsKZ1+1c4iRW27tVivJqPBTyikRbxMaWALG0KoA0/X03eCB/zJOIJO+MisXnyIAFYwtvEYWpo2jJXjS/u+RPRXIvYrXQgZ+ghNJx5f3MhNIvZ6pGhwcsuyNEWFqbnfxAmwNy+owHe9JM6QmruHBG/LYnIBJ7nQldThAlXcN+RW1Yw+0m1MBrMH0+WHipe386uGP7i0YU3ZbSueJpkgoktOgLVJIRkgKksUsUuaQiVqvHt63F+FPxRaHqN1Kj3IH/WWCvuJxwhBDMnN1OftFJEubytfDY6mR2K7CjldOaFJGEjpz+LopUf3Qv6wiFxmMh7BA== 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=fmFJwwJzDq2bxlaxQEjn8WRM8sA42SO83zvngMOaLxA=; b=jrNtMsU/oDvmVO/4EdZjxIDLAgBEgs7it/JS53guY8gqbEd9iZrJOgF1kz7V7T1xAGwynjWGd4QnHz7NrcDiJv2TvEbYnr79aCG2LAoT+wXQcXwwTfMetOaBwnlB9GDKSF8+2aZbIZbJyxn6T1scqC+R/0ZDzGR+HPjB6lWq5zqBShSlj8Z8NusStrLrbUeHUj+er70+XRodaRDkwYJD/ZR2CADuIHo6udZfA0x8RoyVnRsS6gdZKOYQ1+7IPO6s4DOg0+8xo/wkvcIzo2d5J59KGrUZpZztDlW02LtxowUCVQvHrAGgDDFjMyZtXPayY6qnfZ5y4lc96OQ6FlhiaQ== 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=fmFJwwJzDq2bxlaxQEjn8WRM8sA42SO83zvngMOaLxA=; b=PKVO2VgyzoBNRLCptYNWn56yCsdBCD/1zjwLMuan8KUIAC4NR+l/RbFNQYn9tcoHEDcE19B72Y02CQVotSChBGVSgG2FMwvAx+kZEmZlISc6D3OH3h8nmz7NPMp/RbtiuUqzyhbRFe1PHrZRZcOuagBDzSad7xl3hWXy1g29GL0= 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 DU2PR04MB9049.eurprd04.prod.outlook.com (2603:10a6:10:2e4::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6886.35; Mon, 16 Oct 2023 15:49:18 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7763:779b:1a89:47da]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7763:779b:1a89:47da%3]) with mapi id 15.20.6863.046; Mon, 16 Oct 2023 15:49:18 +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 4/4] shared/bass: Add Modify Source initial implementation Date: Mon, 16 Oct 2023 18:49:00 +0300 Message-Id: <20231016154900.3094-5-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231016154900.3094-1-iulia.tanasescu@nxp.com> References: <20231016154900.3094-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: VI1P195CA0089.EURP195.PROD.OUTLOOK.COM (2603:10a6:802:59::42) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|DU2PR04MB9049:EE_ X-MS-Office365-Filtering-Correlation-Id: 3993c944-d800-4e62-a29f-08dbce5f74b9 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: 2XCdVpfdkQA1F7G0sl9a/zTH4ylAWwUzRHDBWaNCO6ZUnnZeNZPve1LaxvK/KhxN6IlcQeGGREFOsboILMXtRe8eEkttmvYauWhAHwNW25rQ3dgHtEueVSiDeW4Df5Wwq13bwm1Wxq11hKAXLkORrFDAFNCMm/ACI+3XZ/SxwwIHLfjTquYv4zzpkhAU3v1+RzFJZSbnJkG0qEMxZHnMu/mzrICdgntIOivowvkAB0ZuNMRatN/PbdzisnT9qHBcD1wwttf8DPuQdaYZCpFtkJikm4gDbrve7p2wCg+19C3Q4aejNt80wONTJnDBk628YrDoLCNtFqzxjPJky1dQPFIX4txT1VtmGMcj56mIzBlvoIPoiUoQVOJ0ZkUzou2K9C5DmWneSiJadFoN2GFpXgiavn9avdoTYZQtKIK3m2ifEPRO/W6LH++UoxFKwpRg5C6OEgLphXs3DCaVoXE6NK3u5aZfOugvRNKWO0LUBTNxJJKpmVY/CiQ0o44uUvB4+vMwyqulapPQ/NvxIj8/M4ylb9FxlMiSJaOetS2UrWzRaIGHDHSFogvQCsT1Pwhp 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)(366004)(346002)(39860400002)(396003)(136003)(376002)(230922051799003)(1800799009)(186009)(64100799003)(451199024)(6486002)(38100700002)(478600001)(2906002)(6512007)(6506007)(6666004)(316002)(66946007)(66476007)(66556008)(6916009)(4326008)(5660300002)(41300700001)(8936002)(44832011)(8676002)(83380400001)(1076003)(26005)(2616005)(36756003)(86362001); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: oTp/K3qrYwwLFR32GwRcuLqvYLDaXRk5TxOZKdIAw3EofYlQg24VhJ45GDfEfYkYSi64yrbgXNTUiexCG7txvglXyl/t70CyZ4eUbXa2pmYKETn7bgPkMqCvCJAphFFxIHQzS6SIsrsg3Rd24OqKiFs+1PjXm086GThYzMibE68Vp/1y1e+6UFrfyUDvuzjsZc9ua3xQo9kOET3/n+d5kki7nuHCv+8BLxDAgS4PE9s3/4uVxFOflEpGCGIOA7qy5EXrrcQ8Uof5QPOO2URjGnHAcuQ4P5V9Uc98QEtz1s204/EIVIqA4zTf+yxj1J3eO0iVLo8E9CKwM6vTgBNmXq+mvU5x590s+91a2QcDbUMv/vxrHLC/QyYrxjOqaYpITaPSm7h5WZLIEaRzfl9xwrjM+UnJO4fYWgjfiwY5icKO4akexYb05X3vFqbcWfhxPs2grtBAnm7xgcd61LTvUUyYKS1EHZGok/9xErZU0MbYuTYrwOFMUaW6UosdsaRijzodzKNT2ws6Ey2NyaSIBVWiPF69PoSKxYfZC3hzEfTzj9ddx2KmpyFnBwODFuK0/nhILQT7FUBoN6hquVBn5io+8h6Dn4tILwsPwybxpm+pr2Djm/Q0gS6haBrJHEYrH+QYUw7U6TamrJMc4K8bpuU4T0oqEogm0kIlIImftsXwWjdlLn7/qZvonLa1vvSz7tmXn9xNhp31oc0XgUoPcJHLZSF5ot7Ups5dQmHMlRawkxeTe9oz2Fms1VP6pVABmDuCcNtvs+W2QtQSVirh+aMsHIllo76xy8g5PLnt/zg1VjeDAt5uR7EfNrcidhVFe+rEANHEDElkDW9B0H6kxg75OkrFOH6QK6dg2Dsn6xAmiCEq1yEmrjXiVKlKR0MuskqcSXPL0WiXJHWw2zt+WWxx0XSaNPoFzfUvlAQJ5EvJtJADCPvKU5gaTHY1Xeq0z0c7+vM5ANtOj9J2UQ7HgXMNIKvJ3fS/gPrUV7uP8HhOjyByeqogfjNqHn8WBg7CWt74PBIrZgnD38xWzx7SPGMqH3LVbVh+T7kLbI0LQihzFh78GqswktYljlzByiJv281+IbANs6j3pZKp5ho5EyOtEKFQP8S3WtXEsumdPcHFIJ75pmUIYkPQrdzalm6fpzia/KfvoMg8CTrbolWVT6H7pb0/nCELRbTRz5Z6cu6e4n4b9e4REWmlUHFo6SIIuOn2DSYMTeFFJe3Z+RVEMaFfCwTSX5+X7wliO7jY6+G7tPJfqHZ7reJaRjIHYjZiYscTNf4g3JEZuzbt5Q31meqeDf63K+6Q0LasO0gs1xXxjx0cUmSgTtlMQI9iYhZaPamYTh2PdSX/BoPeWKvkcGqJp5ws6C/wbVS33+uBMdON+TgPc1ZE/uSNOnJO/bLfJXnuI89k69q3JXNC67wg8mIKAHG7Lqm7E2/kk7ETm+ppzi1qp2Y2OUDHlxds/TViMJqyxX6xd3z5oogky/sdjIQLCVyd6rdSQ32bS1zJARuXiDTnk+vxQf08ULaw6mcqnCoMj2MBq7xWEt6Sf9CCzsfYv0hO+6FAfTdywz0bcsdtKnrzrBKsrLW3g01g4lLNnI33EQJK5dAZgEJxK+Dhlw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 3993c944-d800-4e62-a29f-08dbce5f74b9 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 16 Oct 2023 15:49:17.9513 (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: ipkFT57Rskx6eY0b2mFu/O1/EVWA6uh/lr07EUMjPpzoI5sn4EuME7gAKDSoWyDku1UptxPljrpLoI+QVujWCA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DU2PR04MB9049 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds an initial implementation for the BASS Modify Source procedure --- src/shared/bass.c | 289 +++++++++++++++++++++++++++++++++++++++++----- src/shared/bass.h | 2 + 2 files changed, 263 insertions(+), 28 deletions(-) diff --git a/src/shared/bass.c b/src/shared/bass.c index 326ce6dae..5765ef6ed 100644 --- a/src/shared/bass.c +++ b/src/shared/bass.c @@ -614,6 +614,9 @@ static void connect_cb(GIOChannel *io, GError *gerr, g_io_channel_ref(io); queue_push_tail(bcast_src->bises, io); + if (!bcast_src->bises) + bcast_src->bises = queue_new(); + for (i = 0; i < bcast_src->num_subgroups; i++) { struct bt_bass_subgroup_data *data = &bcast_src->subgroup_data[i]; @@ -650,29 +653,6 @@ static void connect_cb(GIOChannel *io, GError *gerr, queue_destroy(bcast_src->bises, bass_bis_unref); bcast_src->bises = NULL; - /* Close listen io */ - g_io_channel_shutdown(bcast_src->listen_io, TRUE, NULL); - g_io_channel_unref(bcast_src->listen_io); - bcast_src->listen_io = NULL; - - if (bcast_src->listen_io_id > 0) { - g_source_remove(bcast_src->listen_io_id); - bcast_src->listen_io_id = 0; - } - - /* 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; - } - - if (bcast_src->pa_sync_io_id > 0) { - g_source_remove(bcast_src->pa_sync_io_id); - bcast_src->pa_sync_io_id = 0; - } - for (i = 0; i < bcast_src->num_subgroups; i++) bcast_src->subgroup_data[i].bis_sync = BT_BASS_BIG_SYNC_FAILED_BITMASK; @@ -741,6 +721,17 @@ static void confirm_cb(GIOChannel *io, gpointer user_data) /* Mark PA sync as failed and notify client */ bcast_src->sync_state = BT_BASS_FAILED_TO_SYNCHRONIZE_TO_PA; + + /* Close listen io */ + g_io_channel_shutdown(bcast_src->listen_io, TRUE, NULL); + g_io_channel_unref(bcast_src->listen_io); + bcast_src->listen_io = NULL; + + if (bcast_src->listen_io_id > 0) { + g_source_remove(bcast_src->listen_io_id); + bcast_src->listen_io_id = 0; + } + goto notify; } @@ -1037,7 +1028,7 @@ static void bass_handle_add_src_op(struct bt_bass *bass, data->meta_len), data->meta_len); } - if (pa_sync != PA_SYNC_NO_SYNC) { + if (*pa_sync != PA_SYNC_NO_SYNC) { /* Convert to three-value type */ if (bcast_src->addr_type) addr_type = BDADDR_LE_RANDOM; @@ -1072,9 +1063,6 @@ static void bass_handle_add_src_op(struct bt_bass *bass, G_IO_HUP | G_IO_NVAL, (GIOFunc)listen_io_disconnect_cb, bcast_src); - - if (num_bis > 0 && !bcast_src->bises) - bcast_src->bises = queue_new(); } else { for (int i = 0; i < bcast_src->num_subgroups; i++) bcast_src->subgroup_data[i].bis_sync = @@ -1179,12 +1167,255 @@ static void bass_handle_set_bcast_code_op(struct bt_bass *bass, } if (!bt_io_bcast_accept(bcast_src->pa_sync_io, connect_cb, - bcast_src, NULL, &gerr, BT_IO_OPT_INVALID)) { + bcast_src, NULL, &gerr, BT_IO_OPT_INVALID)) { DBG(bcast_src->bass, "bt_io_bcast_accept: %s", gerr->message); g_error_free(gerr); } } +static bool bass_validate_mod_src_params(struct bt_bass_mod_src_params *params, + struct iovec *iov) +{ + struct iovec subgroup_data = { + .iov_base = iov->iov_base, + .iov_len = iov->iov_len, + }; + + if (params->pa_sync > PA_SYNC_NO_PAST) + return false; + + if (!bass_validate_bis_sync(params->num_subgroups, + &subgroup_data)) + return false; + + return true; +} + +static void bass_handle_mod_src_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_mod_src_params *params; + struct bt_bcast_src *bcast_src; + uint8_t num_bis = 0; + uint8_t bis[ISO_MAX_NUM_BIS]; + uint8_t addr_type; + GIOChannel *io; + GError *err = NULL; + struct bt_iso_qos iso_qos = default_qos; + struct bt_bass_subgroup_data *subgroup_data = NULL; + uint8_t *notify_data; + size_t notify_data_len; + bool changed = false; + + /* Get Modify Source 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 */ + gatt_db_attribute_write_result(attrib, id, + BT_BASS_ERROR_INVALID_SOURCE_ID); + + return; + } + + gatt_db_attribute_write_result(attrib, id, 0x00); + + /* Ignore operation if parameters are invalid */ + if (!bass_validate_mod_src_params(params, iov)) + return; + + /* Only subgroup metadata can change */ + if (params->num_subgroups != bcast_src->num_subgroups) + return; + + /* Extract subgroup information */ + subgroup_data = malloc(params->num_subgroups * sizeof(*subgroup_data)); + if (!subgroup_data) + return; + + memset(subgroup_data, 0, params->num_subgroups * + sizeof(*subgroup_data)); + + for (int i = 0; i < params->num_subgroups; i++) { + struct bt_bass_subgroup_data *data = &subgroup_data[i]; + struct bt_bass_subgroup_data *old_data = + &bcast_src->subgroup_data[i]; + + util_iov_pull_le32(iov, &data->pending_bis_sync); + + if (old_data->pending_bis_sync) + goto err; + + if (old_data->bis_sync && data->pending_bis_sync && + data->pending_bis_sync != old_data->bis_sync) + /* The Server cannot resync to different BIS indxes */ + goto err; + + if (data->pending_bis_sync == BIS_SYNC_NO_PREF) + data->pending_bis_sync = DEFAULT_BIS_SYNC_BITMASK; + + if (data->pending_bis_sync != 0) { + /* Client instructs Server to sync to some BISes */ + for (int bis_idx = 0; bis_idx < 31; bis_idx++) { + if (data->pending_bis_sync & (1 << bis_idx)) { + bis[num_bis] = bis_idx + 1; + num_bis++; + } + } + } + + data->meta_len = *(uint8_t *)util_iov_pull_mem(iov, + sizeof(data->meta_len)); + if (!data->meta_len) + continue; + + data->meta = malloc(data->meta_len); + if (!data->meta) + goto err; + + memcpy(data->meta, (uint8_t *)util_iov_pull_mem(iov, + data->meta_len), data->meta_len); + + if (old_data->meta_len != data->meta_len || + memcmp(old_data->meta, data->meta, old_data->meta_len)) + changed = true; + } + + if (bcast_src->sync_state == BT_BASS_NOT_SYNCHRONIZED_TO_PA && + bcast_src->listen_io) + return; + + /* If subgroup information has been extracted successfully, + * update broadcast source + */ + if (bcast_src->subgroup_data) { + for (int i = 0; i < bcast_src->num_subgroups; i++) + free(bcast_src->subgroup_data[i].meta); + + free(bcast_src->subgroup_data); + } + + bcast_src->subgroup_data = subgroup_data; + + /* Client instructs Server to sync to PA */ + if (bcast_src->sync_state == BT_BASS_NOT_SYNCHRONIZED_TO_PA) { + if (params->pa_sync == PA_SYNC_NO_PAST) { + /* Convert to three-value type */ + if (bcast_src->addr_type) + addr_type = BDADDR_LE_RANDOM; + else + addr_type = BDADDR_LE_PUBLIC; + + /* Try to synchronize to the source */ + 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, + &bcast_src->addr, + BT_IO_OPT_DEST_TYPE, + addr_type, + BT_IO_OPT_MODE, BT_IO_MODE_ISO, + BT_IO_OPT_QOS, &iso_qos, + BT_IO_OPT_ISO_BC_SID, + bcast_src->sid, + BT_IO_OPT_ISO_BC_NUM_BIS, + num_bis, + BT_IO_OPT_ISO_BC_BIS, bis, + BT_IO_OPT_INVALID); + + if (!io) { + DBG(bass, "%s", err->message); + g_error_free(err); + return; + } + + bcast_src->listen_io = io; + g_io_channel_ref(bcast_src->listen_io); + + if (bcast_src->listen_io_id > 0) { + g_source_remove(bcast_src->listen_io_id); + bcast_src->listen_io_id = 0; + } + + bcast_src->listen_io_id = g_io_add_watch(io, G_IO_ERR | + G_IO_HUP | G_IO_NVAL, + (GIOFunc)listen_io_disconnect_cb, + bcast_src); + } + + if (changed) + goto notify; + + return; + } + + /* Client instructs Server to stop PA sync */ + if (params->pa_sync == PA_SYNC_NO_SYNC) { + /* TODO */ + return; + } + + /* Server is already synchronized to PA, and Client now + * instructs the Server to also sync to some BISes + */ + if (num_bis && !queue_length(bcast_src->bises)) { + /* Since the Server has never been synced to any BIS before, + * the PA sync socket must be bound to the num_bis to sync with + */ + if (!bt_io_bcast_accept(bcast_src->pa_sync_io, connect_cb, + bcast_src, NULL, &err, + BT_IO_OPT_ISO_BC_NUM_BIS, num_bis, + BT_IO_OPT_ISO_BC_BIS, bis, + BT_IO_OPT_INVALID)) { + DBG(bcast_src->bass, "bt_io_bcast_accept: %s", + err->message); + g_error_free(err); + } + + return; + } + + /* Client instructs Server to keep PA sync but stop BIG sync */ + if (!num_bis && queue_length(bcast_src->bises)) { + /* TODO */ + return; + } + + /* If no change has occurred, just return */ + if (!changed) + return; + +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); + + return; + +err: + if (subgroup_data) { + for (int i = 0; i < params->num_subgroups; i++) + free(subgroup_data[i].meta); + + free(subgroup_data); + } +} + #define BASS_OP(_str, _op, _size, _func) \ { \ .str = _str, \ @@ -1214,6 +1445,8 @@ struct bass_op_handler { 0, bass_handle_add_src_op), BASS_OP("Set Broadcast Code", BT_BASS_SET_BCAST_CODE, 0, bass_handle_set_bcast_code_op), + BASS_OP("Modify Source", BT_BASS_MOD_SRC, + 0, bass_handle_mod_src_op), {} }; diff --git a/src/shared/bass.h b/src/shared/bass.h index bd3fe900b..ee958bf7a 100644 --- a/src/shared/bass.h +++ b/src/shared/bass.h @@ -32,6 +32,8 @@ struct bt_bass; #define BT_BASS_BIG_ENC_STATE_DEC 0x02 #define BT_BASS_BIG_ENC_STATE_BAD_CODE 0x03 +#define DEFAULT_BIS_SYNC_BITMASK 0x00000001 + /* BASS subgroup field of the Broadcast * Receive State characteristic */