From patchwork Tue Jun 13 14:16:24 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 13278880 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 8EF34EB64D7 for ; Tue, 13 Jun 2023 14:17:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S242582AbjFMOR2 (ORCPT ); Tue, 13 Jun 2023 10:17:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242281AbjFMORZ (ORCPT ); Tue, 13 Jun 2023 10:17:25 -0400 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2045.outbound.protection.outlook.com [40.107.14.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 517C0B7 for ; Tue, 13 Jun 2023 07:17:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=leu2zUCTBDLs2PDrw5WtKsk+ofswJaAP1zz4iyOcZAIGJWB1HqTJ/R8Lah9ESdn3r5r8YSwsUQbL0Ui4DD0nYqAvpyPTrn4GeF57VStrcKHu6gQ/hHdQsCPSRX0rYUJCTu1EAA55am9+aR8vjSuk6wtty2B+tNv1ghQfg6T1RaWqjpY1ic12H7Jd0U34Xxfq3KT6EyxT88cFu1yAH/dt4aYhNLJq/rHJ/0X8msa+L8Eo3TQypXf/Bjy+VpSqQKC1yCni2uxVAf+GuGlsy5Nvo/enF61jSexP3RXpJtlUQbR70MA9OMLh4qmdUhQMzr4sKkYuq97U9iuOZfxCoJbVFQ== 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=bsnZBCWoG1xN40lipUqZptw/TCoqRZ6nXBuRlDaxJkE=; b=m9kRCdUOoqpted9o4GivNsW9XPgYo7vjOyIVPhUy+8BFSqbhGbJUuKleszftuhxNP0Uw/3vcf9mCSNMHdyHkzU4lQKJUcoIIZkIiLljqc0RT+vnqPLmtAA67PrHqgw018+3BSxDt42+HiKh1bFmDwh9aZZd4JrRaagFqMMCJ1AiqAQZZDDw/Y8tjh8EbY0bGpR8FypYSSixsUKggZhqVqgHF8eFsDwWAeeJ73g9n07KZMw3XZnyUEba3U8aGWFL4/8d/lSxhNV7xydraOVOVtIfnA4kIaQQapDk7LaTF3uxoNvmgF0Z1TwlkJ8tAr+o2tIb5Mnc+yHyOZRa0vPlZ1A== 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=bsnZBCWoG1xN40lipUqZptw/TCoqRZ6nXBuRlDaxJkE=; b=Ru0rj6wBqdQD1ARkrKO855n5/33SUO5VHLoGQeQH6HxcGJ3TJaY9YNp7IjN/mUTVWpeYlpKYz+TXMCpYTz48zG0suqI+Lcb81QWMENYTMTKDrOg4QOkiIrULp2mRSCb3LcIjZFpZNmraPjD29VA3JxiaFlNEmm39rnAfiumrWJI= 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 VE1PR04MB7213.eurprd04.prod.outlook.com (2603:10a6:800:1b3::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.29; Tue, 13 Jun 2023 14:17:18 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7526:7510:9b32:e1fe]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7526:7510:9b32:e1fe%6]) with mapi id 15.20.6455.043; Tue, 13 Jun 2023 14:17:18 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, silviu.barbulescu@nxp.com, andrei.istodorescu@nxp.com, mihai-octavian.urzica@nxp.com, vlad.pruteanu@nxp.com, Iulia Tanasescu Subject: [PATCH BlueZ 1/2] gatt-server: Check pointer before memcpy Date: Tue, 13 Jun 2023 17:16:24 +0300 Message-Id: <20230613141625.9197-2-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230613141625.9197-1-iulia.tanasescu@nxp.com> References: <20230613141625.9197-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AM4PR0501CA0046.eurprd05.prod.outlook.com (2603:10a6:200:68::14) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|VE1PR04MB7213:EE_ X-MS-Office365-Filtering-Correlation-Id: b9b9f940-2466-4be2-9a08-08db6c18e527 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: s9F/w1ArFUcLCjxfE7fDOX4rjCvg34nx74QlJh6WSZfylAWo7q6PLme82gr7/Aiq1ZroF/Z/YonCKxgHDcDXR/09flO0PbYCqqkR/KQHzsw6kdHnkSTmrUrF6ByLZhHgdLxlTAwHdYFQnAcdNrtoEqxruvlWuhWx6Lv6mWui9PWZLK8zR4+Y7sRVUoSxgtnRBrsOebHqxDyUI/VtOr6Yn/leJzpKvszMD9Bk0g0QopMoKrYVstbPmp9ZEhjSN5OSWD7Yw8jNWHYPsMXU+LWdC4IJwTZNH6B4zBY1xfqbJ+rNIGRA0rlWduazM+QDHUh0CnrX/KjKjYaRA4YRo+llon9qF/M/NirsGUIq7xzP5TDMMPxLDYaPSIooUNvtgEo2UC5gLIHkcQJsANqxWAJ3KF8ZVFF566E++7E4/1J4kRAhGpCGyRxyjzIUPEdMvJRyhU2SxQ5d7QBoys09maW+SwGOgffxbr/zCUdEhewFlNmn54g5cl8jzjDbcByi77i6aFY2X0GiW1FDntzA+U5HyS108+43Zoeoojbsg9Qy3jhu6d95l8xeAWrpUzvPrQtE70OicjUje8GHWIybNyqrHb7ZcgJ/bl/OpBopQA5QU9/PB3Lgyy1Ukv87Mn8RuuIC X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR04MB8898.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(376002)(346002)(39860400002)(136003)(366004)(451199021)(5660300002)(52116002)(8676002)(8936002)(4744005)(2906002)(66946007)(66556008)(66476007)(44832011)(6486002)(6666004)(4326008)(26005)(1076003)(6506007)(6512007)(41300700001)(316002)(6916009)(186003)(83380400001)(2616005)(478600001)(86362001)(38100700002)(36756003)(38350700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yxkYIJLLJxyQsHX3nzhUcbCAjuRPYwyDUjq/uaggSZUClLl9HYb/8lPPtbD+rw9LyzqqIbUd6aA2lyJnT1//NnR7xH3cpPGLRbD4ne5Ab5TB5ScSVqTaq+YqX6hk0CjDV2DKk3XQ+lwrjDW8J259BDMzyiUXCYLb+nkR+WugTksHrG/wbsvk76kCis2g26y4etfhPRyw36CFWHyHdFZRk6oI9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/ifgr157BfkdpuJxv5bKSFb2699jCcpXdqFDdRL+JYFvRe6nWcCisXtIw8/v4PplHoga/ErgLMm5f7ANRNmh5IDCR71FW6fu/vGjDIpF/DrwoWNRQ+YXTt/iiovG+3230wK1FYGyrdDm2XycLEIBM2CO+sYXyaHlBywq0IarfJQxEP14vO75lDmw9aq/UDUSiX/sNvpEkhlW3i0044UBQEc6jsXCSjnd6n99Jj5cZWfrFXsmcGhb1v5B1Jx28l5I7A+ygUz3N/bAhzgeRz26lFj96oPQrLUCjLwrXInC+AtdaWBGSVdGw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: b9b9f940-2466-4be2-9a08-08db6c18e527 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2023 14:17:18.3955 (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: k/YSWqTMKvJMg+WHM80V0vBUtPZADhpNDc8DvgI7qJxivXG3UHUYy7ImWKfT4n3l2UX5cXZv3v2rhyeNRoEbMA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7213 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds a check before calling memcpy inside bt_gatt_server_send_notification, to avoid getting the following error in case the user wants to send an empty notification for an attribute: src/shared/gatt-server.c:1789:3: runtime error: null pointer passed as argument 2, which is declared to never be null --- src/shared/gatt-server.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/shared/gatt-server.c b/src/shared/gatt-server.c index 85cff30ec..0512d06f6 100644 --- a/src/shared/gatt-server.c +++ b/src/shared/gatt-server.c @@ -4,6 +4,7 @@ * BlueZ - Bluetooth protocol stack for Linux * * Copyright (C) 2014 Google Inc. + * Copyright 2023 NXP * * */ @@ -1785,7 +1786,9 @@ bool bt_gatt_server_send_notification(struct bt_gatt_server *server, length = MIN(data->len - data->offset, length); } - memcpy(data->pdu + data->offset, value, length); + if (value) + memcpy(data->pdu + data->offset, value, length); + data->offset += length; if (multiple) { From patchwork Tue Jun 13 14:16:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 13278881 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 B2607EB64D0 for ; Tue, 13 Jun 2023 14:17:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239740AbjFMOR3 (ORCPT ); Tue, 13 Jun 2023 10:17:29 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41684 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242587AbjFMOR2 (ORCPT ); Tue, 13 Jun 2023 10:17:28 -0400 Received: from EUR01-VE1-obe.outbound.protection.outlook.com (mail-ve1eur01on2045.outbound.protection.outlook.com [40.107.14.45]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5A5194 for ; Tue, 13 Jun 2023 07:17:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MxEE6+MifvsOuP9p0+KGvoZ+4Awzih3vpPRuK+1GyJw3h6zqxaAxYsI2QGoTr/gOIdomUVfZ504rwx9IOdPK5vRcVsYksCYb4zjmyGavH3JmeDQbKg1i1/AOqQZQtQjQZhJ00hfU9NqTU98Ff0oLMN4Kmd7/DpGXBce+yfKz64+DMKkHWRE6pxJTAdh5BBPJt51lVMYvRpEJtsz7zocWK85VkmuatHXPeJYZjnTvbr0RKJnerEXTWhkPK4rg/SX54KFMmUiFIBz9oENBLMvQEJ+WHiJdg/jAxZyjgoOG/DrkWIdSx78qvbm2JG6C/6YNCHoiKftvnoAIcerrmioM3g== 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=MbyLpPX5EjS/ZFm33P3s2yJVn3Zj6z2uBGzBXU2aw0g=; b=NgL0FsCWnLpFBJxpjFzsFe8QkYyn4h3MQ7Yc/qJATFtPJX4JwBx7H453Sfu0qbVjqpgw7KrKgM0U79cqeIZGuUQLl/zwnE3lhrKou9U2HzdW6CmsLlt7zValwy6d/Gr9aIhPZFZ/Ll2lIfkCRG1EDoqX199mEUTaKRrYdZMIJa9jTpXkmaTRyG/MG0H//N8rVJ0rLcm1FW4aWowFF6A0FUcz9eCW/gtCQjR3R7ErVnMCqkhhVKpL5aINGngUFHIaHb5uM1bzLWi9CZ3TqDQi/MQCREPTlMZ7NZBGNRlGxDfot/gUEAFiMG8x+HUG1CG5nV+VtFPc1wlsJ4i1onRPyw== 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=MbyLpPX5EjS/ZFm33P3s2yJVn3Zj6z2uBGzBXU2aw0g=; b=CapkCzyBdEPj6xu0zWbPGZMeZCVVF4NV4plJD30RoGXE3GvPrbqTHBRpVfyVEU0VRE6dsfyqYxNNF5NMZsYjsQRgHAT5ptz0Q49afK9NyZ7Yg1fcnzjJ9y7HYQq/tNIwlO4LDtYm4oBk2VdU0NCNTzg2FJK041N64qhC890nvnE= 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 VE1PR04MB7213.eurprd04.prod.outlook.com (2603:10a6:800:1b3::8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6477.29; Tue, 13 Jun 2023 14:17:22 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7526:7510:9b32:e1fe]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::7526:7510:9b32:e1fe%6]) with mapi id 15.20.6455.043; Tue, 13 Jun 2023 14:17:21 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, silviu.barbulescu@nxp.com, andrei.istodorescu@nxp.com, mihai-octavian.urzica@nxp.com, vlad.pruteanu@nxp.com, Iulia Tanasescu Subject: [PATCH BlueZ 2/2] shared/bass: Implement CP opcode handlers Date: Tue, 13 Jun 2023 17:16:25 +0300 Message-Id: <20230613141625.9197-3-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230613141625.9197-1-iulia.tanasescu@nxp.com> References: <20230613141625.9197-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AM4PR0501CA0046.eurprd05.prod.outlook.com (2603:10a6:200:68::14) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|VE1PR04MB7213:EE_ X-MS-Office365-Filtering-Correlation-Id: c8babfc0-bb0a-4585-4d96-08db6c18e6b3 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: d3JUaHs+ecNpKNuL41AQYSWgvgYiHOD7Hi/W7TwkBnjfuQ9okOv77wWcXW8nVgzYE/yItpTCH/e2RW2BzhmA8osHH8HvBU/ZYU/hfnSAgU/jaoH0V3iCmyoEn3zgWq1PVU3+sr9JI9cCVVMNHgrEuGPh5ns8GlPw5bn6JVtqNOeSaRyBA9OtX9VdHJZvTk6Aq7ZPOCm5D5wZ4Ee8+yE9KYvgbsz6SDcl73YGAUr3SHlLXd7+rfqDwpUAm8Lt+A+rX6r2UhyG+hqDpTU2BzxCoum7zm3uy7hdizZDY2EmGoAXq7mnaVPlXCFh3Mjz+efOx1ZnZ3w74j887H4k3vYxGq/H5rb1Sn48ijU7JX2WKQpxkNKZHN+sS6AbEHzcnsx2naKG3J46WqHga/in3EDGyw7C369a8NGTV5HRR46YLgu7VlcW0yjpYEppHgxOhMuQKA2TEhCbcivYUs87CcePU+fknD7PKEjM1PyWjnSeJ3qE5fUY7GSucCaTCGDx9xDstOodwQOPGe07uJTALNTXvgFeSsKiSdwgTAibmRh656A4TpRjtAb8u3EoiSAiTxFMol5R27dvnNbd1dcRGUv33IFRGDTmqWmf8ksMC87jeFClD6XRGizs07ANzAK1g8+T X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:AS8PR04MB8898.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230028)(4636009)(396003)(376002)(346002)(39860400002)(136003)(366004)(451199021)(5660300002)(52116002)(8676002)(8936002)(2906002)(66946007)(66556008)(66476007)(44832011)(6486002)(4326008)(26005)(1076003)(6506007)(6512007)(41300700001)(316002)(6916009)(186003)(83380400001)(2616005)(478600001)(86362001)(38100700002)(36756003)(38350700002);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: SauqVI2bCKpyiyFvgJ9mF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dZFxu0kwzOsXGs2Sp2xc6LJbjacxtfYiyIsM0EHzX6JOmnlckGj+qEob4rzynK4Lu/5uhqkK+afJRSu9BnhAL/P3s1w8vICaXZDDYAjwd3MV17tR9td00uRELI1nnVA5uuru4jGuMKtc5ijvHLSrRWmaLS1sCJjMt5PLNZcJqiEVEgbdP/VPVf5LkVPdGP7/Q+bFl5sYoD8lmDzjejyWyH5wKZvw9rWgVzZl6wa4KHuWCkfk56dEXQ3knXfsOTWCPX+hUQrZWy+irTWKeWrTHsWdkay83D2Uyv1lP+Ca5G/DAfEEj68N79gARXFF8yWxflArvAc4NmW+1Ip5u+5QJeJ/JdT5iA8wenWh/2qlvBufqPo12PgCT5DoVi1JmbvFluVjwnuCsuRidRSle4DhJeMTVXkYzaqLWbYxEjPSKfmQbVLithrUqv6PY4bg2CvAkQ0mvWX48OdZcHiVx7OMA8Aey6cPfVJ4fDVATt146eGmu96f4MSfZMb8Luw/FFBHYZAc1IygRyEHlBztZhlYA== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: c8babfc0-bb0a-4585-4d96-08db6c18e6b3 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 13 Jun 2023 14:17:20.9887 (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: lohAxsGrHIDyT9Y+iI90yzOD1C24G8JZbRRzxuaK4C0xFBYqRI89blKJsve0RAN0TSGYvxPI8Q7zQnUFQ2jsvQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1PR04MB7213 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org This adds handlers for the following BASS Broadcast Audio Scan Control Point opcodes: Remote Scan Stopped Remote Scan Started Remove Source --- src/shared/bass.c | 155 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 142 insertions(+), 13 deletions(-) diff --git a/src/shared/bass.c b/src/shared/bass.c index 8906ca1ef..423ab5bf7 100644 --- a/src/shared/bass.c +++ b/src/shared/bass.c @@ -82,6 +82,8 @@ static struct queue *bass_db; static struct queue *bass_cbs; static struct queue *sessions; +static void bass_bcast_src_free(void *data); + static void bass_debug(struct bt_bass *bass, const char *format, ...) { va_list ap; @@ -385,7 +387,7 @@ static bool bass_check_cp_command_subgroup_data_len(uint8_t num_subgroups, return true; } -static bool bass_check_cp_command_len(struct iovec *iov) +static bool bass_check_cp_command_len(const uint8_t *value, size_t len) { struct bt_bass_bcast_audio_scan_cp_hdr *hdr; union { @@ -395,8 +397,13 @@ static bool bass_check_cp_command_len(struct iovec *iov) struct bt_bass_remove_src_params *remove_src_params; } params; + struct iovec iov = { + .iov_base = (void *)value, + .iov_len = len, + }; + /* Get command header */ - hdr = util_iov_pull_mem(iov, sizeof(*hdr)); + hdr = util_iov_pull_mem(&iov, sizeof(*hdr)); if (!hdr) return false; @@ -404,38 +411,38 @@ static bool bass_check_cp_command_len(struct iovec *iov) /* Check command parameters */ switch (hdr->op) { case BT_BASS_ADD_SRC: - params.add_src_params = util_iov_pull_mem(iov, + params.add_src_params = util_iov_pull_mem(&iov, sizeof(*params.add_src_params)); if (!params.add_src_params) return false; if (!bass_check_cp_command_subgroup_data_len( params.add_src_params->num_subgroups, - iov)) + &iov)) return false; break; case BT_BASS_MOD_SRC: - params.mod_src_params = util_iov_pull_mem(iov, + params.mod_src_params = util_iov_pull_mem(&iov, sizeof(*params.mod_src_params)); if (!params.mod_src_params) return false; if (!bass_check_cp_command_subgroup_data_len( params.mod_src_params->num_subgroups, - iov)) + &iov)) return false; break; case BT_BASS_SET_BCAST_CODE: - params.set_bcast_code_params = util_iov_pull_mem(iov, + params.set_bcast_code_params = util_iov_pull_mem(&iov, sizeof(*params.set_bcast_code_params)); if (!params.set_bcast_code_params) return false; break; case BT_BASS_REMOVE_SRC: - params.remove_src_params = util_iov_pull_mem(iov, + params.remove_src_params = util_iov_pull_mem(&iov, sizeof(*params.remove_src_params)); if (!params.remove_src_params) return false; @@ -448,25 +455,134 @@ static bool bass_check_cp_command_len(struct iovec *iov) return true; } - if (iov->iov_len > 0) + if (iov.iov_len > 0) return false; return true; } +static void bass_handle_remote_scan_stopped_op(struct bt_bass_db *bdb, + struct gatt_db_attribute *attrib, + uint8_t opcode, + unsigned int id, + struct iovec *iov, + struct bt_att *att) +{ + if (opcode == BT_ATT_OP_WRITE_REQ) + gatt_db_attribute_write_result(attrib, id, 0x00); +} + +static void bass_handle_remote_scan_started_op(struct bt_bass_db *bdb, + struct gatt_db_attribute *attrib, + uint8_t opcode, + unsigned int id, + struct iovec *iov, + struct bt_att *att) +{ + if (opcode == BT_ATT_OP_WRITE_REQ) + gatt_db_attribute_write_result(attrib, id, 0x00); +} + +static bool bass_src_id_match(const void *data, const void *match_data) +{ + const struct bt_bcast_src *bcast_src = data; + const uint8_t *id = match_data; + + return (bcast_src->id == *id); +} + +static void bass_handle_remove_src_op(struct bt_bass_db *bdb, + struct gatt_db_attribute *attrib, + uint8_t opcode, + unsigned int id, + struct iovec *iov, + struct bt_att *att) +{ + struct bt_bass_remove_src_params *params; + struct bt_bcast_src *bcast_src; + + /* Get Remove Source command parameters */ + params = util_iov_pull_mem(iov, sizeof(*params)); + + bcast_src = queue_find(bdb->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; + } + + /* Ignore if server is synchronized to the PA + * of the source + */ + if (bcast_src->sync_state == BT_BASS_SYNCHRONIZED_TO_PA) + return; + + /* Ignore if server is synchronized to any BIS + * of the source + */ + for (int i = 0; i < bcast_src->num_subgroups; i++) + if (bcast_src->subgroup_data[i].bis_sync) + return; + + /* Accept the operation and remove source */ + queue_remove(bdb->bcast_srcs, bcast_src); + gatt_db_attribute_notify(bcast_src->attr, NULL, 0, att); + bass_bcast_src_free(bcast_src); + + if (opcode == BT_ATT_OP_WRITE_REQ) + gatt_db_attribute_write_result(attrib, id, 0x00); +} + +#define BASS_OP(_str, _op, _size, _func) \ + { \ + .str = _str, \ + .op = _op, \ + .size = _size, \ + .func = _func, \ + } + +struct bass_op_handler { + const char *str; + uint8_t op; + size_t size; + void (*func)(struct bt_bass_db *bdb, + struct gatt_db_attribute *attrib, + uint8_t opcode, + unsigned int id, + struct iovec *iov, + struct bt_att *att); +} bass_handlers[] = { + BASS_OP("Remote Scan Stopped", BT_BASS_REMOTE_SCAN_STOPPED, + 0, bass_handle_remote_scan_stopped_op), + BASS_OP("Remote Scan Started", BT_BASS_REMOTE_SCAN_STARTED, + 0, bass_handle_remote_scan_started_op), + BASS_OP("Remove Source", BT_BASS_REMOVE_SRC, + 0, bass_handle_remove_src_op), + {} +}; + static void bass_bcast_audio_scan_cp_write(struct gatt_db_attribute *attrib, unsigned int id, uint16_t offset, const uint8_t *value, size_t len, uint8_t opcode, struct bt_att *att, void *user_data) { + struct bt_bass_db *bdb = user_data; + struct bt_bass_bcast_audio_scan_cp_hdr *hdr; + struct bass_op_handler *handler; struct iovec iov = { .iov_base = (void *)value, .iov_len = len, }; /* Validate written command length */ - if (!bass_check_cp_command_len(&iov)) { + if (!bass_check_cp_command_len(value, len)) { if (opcode == BT_ATT_OP_WRITE_REQ) { gatt_db_attribute_write_result(attrib, id, BT_ERROR_WRITE_REQUEST_REJECTED); @@ -474,9 +590,22 @@ static void bass_bcast_audio_scan_cp_write(struct gatt_db_attribute *attrib, return; } - /* TODO: Implement handlers for the written opcodes */ - gatt_db_attribute_write_result(attrib, id, - BT_BASS_ERROR_OPCODE_NOT_SUPPORTED); + /* Get command header */ + hdr = util_iov_pull_mem(&iov, sizeof(*hdr)); + + /* Call the appropriate opcode handler */ + for (handler = bass_handlers; handler && handler->str; handler++) { + if (handler->op == hdr->op) { + handler->func(bdb, attrib, opcode, id, &iov, att); + return; + } + } + + /* Send error response if unsupported opcode was written */ + if (opcode == BT_ATT_OP_WRITE_REQ) { + gatt_db_attribute_write_result(attrib, id, + BT_BASS_ERROR_OPCODE_NOT_SUPPORTED); + } } static bool bass_src_match_attrib(const void *data, const void *match_data)