From patchwork Fri Nov 1 08:31:15 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 840170 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2044.outbound.protection.outlook.com [40.107.105.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5A96156F4A for ; Fri, 1 Nov 2024 08:31:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.105.44 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449911; cv=fail; b=q/q45h3PqJc/f6Weh0k3jc/IZYhUPyZzC+C3dgStL80+Nyztf06Ku30ZKiU03TSi2U/QD/TK4LOHtvoWWPrhjeV9cd81fMdmfovQpClwFnV2li3Wyu+P3LEfC+Fwrp9IeL5U6J4q2w+tWimlA1qbaH+azTRz/YxVDIYIW/D2mio= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449911; c=relaxed/simple; bh=36PcaJ/+ROEQXtTGmyMwot4azT8EnM10ufmINSBeeWE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=QYFkk7GG4WS5P9w6k7mcMl0TpJe2qaALxnpcrfK2BZcTbzvw4Dn+xQzkQ+xAH48wooYA9QRXaR4CzNd0DfRfnJCz94OTN9Zo7QF9qOqmx+DpFSvJizJT5gmnROikmHBQSh67mXA7eSjx18Ag+xXV4WfanWWKznZfwJi10GWmzIM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=h9OIwg9q; arc=fail smtp.client-ip=40.107.105.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="h9OIwg9q" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=SKNlxGWrVsAgYcE/SuNavpmaDtVPP7LJYnkc5tB5fcCg79i4S/bx3V6+p4GB/sxP1oYJ+ABmKYWjv36jnnl8VP24x/igDxbKTDDf450TlYbvW+JMjLd4qEMDkMqjyJtkguoGfnIrfbXZw4nShQ6bK8hi6fF1NymsVO59Hfg9TrVnHE0P/uEzzf5ExAQLD0yiylAxCaMnwBBm3exyAw8LFK/FIRHbsn+1c1SjPVVNGrgLu19qpcuPKjk0VY+8jHZPoEPHhcGxSmxCEY8D1evZkwcKJbB6jT+XYe9h5umnsRwpzzdSALstW7IdyPgQ9Ivo7PyQP73wHMGYjqJcHI4nBA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=w0nas5snKGgsLGrOh2GmmxUX4gyvgEyKoYn/56M+oRA=; b=cfRl7cQuvA2ThH9+6YN8Ko/xXgaObpa3eucNPGMGWyRx+l+Zee+Wj5IzPuATFcgO/lkdjmDh1chNbAm1GvpMr2oPtzTyP67xFgqd6JPGOnixoI0zy3Hv/cVEHTAR4B7gioXCDwT4TAm8SP1pbdsWvjOiNpd+/Jx4ovUqqPzf/YdIIXiNZX23fJJCA5pA/vKAgnUonht9fg+p4zOacNoEDdYt58L/4pn+x418qAh2VKB2xUNCfC4X8SfBB30N+bu4jPGi5GzP3xoyyqhVt0JbpR+ambSqMjCgfNr97YVEKz+TWjdsLbBEr2Rh2phXOXIwewKXmjeb6Ro0uYsfpSkZYQ== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w0nas5snKGgsLGrOh2GmmxUX4gyvgEyKoYn/56M+oRA=; b=h9OIwg9qx5ViFkCzWX4m+gWsl8kWOCylDvjaZVlx2ya2/b1klDjQMHoOMFef4Jv4zouj6sTRoxRl/zg43vhJ7SWuG1Uy1TNAXWGdcZJxkoahs1YF0ugVLwmdnvfuK4L4kneUQoEE1+L2knLC4LM3g2dG1jzLueLcLoLK3+3f1ZIlSq0bg8Tg30wvDx6+QheMDl+IwS2N/NdHYaAsa/VODELfrGs2bIpUs1/d2GM4kixb8OYJh8gpxtkxBJZtEpodJWIZ4uDCk02iQyZ6rHF1+BaN6Idz/pAj5IKq+vZDMMqXA33lv4ti5rWrD4uO1EDw/Krt50sYkZv6nSaJQd5eqw== 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 PA2PR04MB10215.eurprd04.prod.outlook.com (2603:10a6:102:409::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Fri, 1 Nov 2024 08:31:45 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::5e22:869c:33c:9654]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::5e22:869c:33c:9654%4]) with mapi id 15.20.8093.027; Fri, 1 Nov 2024 08:31:45 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Iulia Tanasescu Subject: [PATCH BlueZ 1/5] btdev: Add support for syncing to multiple PA trains Date: Fri, 1 Nov 2024 10:31:15 +0200 Message-ID: <20241101083119.4510-2-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241101083119.4510-1-iulia.tanasescu@nxp.com> References: <20241101083119.4510-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AM4PR07CA0033.eurprd07.prod.outlook.com (2603:10a6:205:1::46) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|PA2PR04MB10215:EE_ X-MS-Office365-Filtering-Correlation-Id: 96d3f4a4-c2ed-45de-4da3-08dcfa4f9ed6 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|376014|52116014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: qwy6bMtLo+q88peptqYzH2l90BGSMDKgLKV9KzCC6pCNnWVFUr7mxJbU1X/y2ndpAyhuNhf6fG3s5YrO4x3NSuFUggmqMCpxH861OEBdtcXAikRu4MZVkqX2WB/DNNkuzu4MoQOuDHZYxsIuhxdm81mRIxiIhuKGF5lp4pfLuS2h5GLooADJ0pKWma0wHu+uzqKq7Ni1YJzbQk/mm5IYWeNpXXiQzJ6V1IwTROar45PWTPLH8+npNIYiTT1wzzb0K7KDeQpaZtFaRL6Vm6seSNYHRxC4ExbDyg+7v7eRw3l6ZSKrFRiZW2FhgUdWnINvr0pNOypCIx8T5pQ9U6fTQ0fvQ7qj15ZbSoCp/0RStQ+N7hwK/7/Rw9x2f7frt2ex08R8MXA47z7J4EMOLqSKg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MB8898.eurprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(13230040)(366016)(376014)(52116014)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: gv2YUn9K1RVW+2Lil+Wycf0LnKLzTXmPH6Ks1Pb4Ioug1xvZle8/UN6mtGSfb2H4FtT40ztSfKEAPyu+aWAda14BXgbQkkNhNJ/ZjxI2BIvvQyMcPVYh1CFII75+TLphVNQh+omtImdStNYZ+NO1nAH+7PWuhcbpe/hDEdiQglmLVGMZBU14W5/epYkMBr7koWEsFsKqMXbdIEADuj8aEXNUW2DAYuCocn3F4Qn52vr75r0nF+CJJ5HC1cHxQzVZNVOZnLj7tejCrQl2if3oaFaklx26YAykhlVmSapHtAJjmm1FaF8/c1vOQHY3HTqdZZE8WjwfD/k6VdVaev80/M2rxQQahJH+TDDtORp2Ti3me7+KthrlfB8t7b2L3UpDsLH2YTqnGsV/W5DRNvbqZQfEmiqkI3/nufS6D3kuED0Wwv7oYl6Ezmcw8cBURngoYPsQLkIwOmKyswz7c8fw7EO2HsIl3InbBPfnVY5EBrzeQoumwiU3tL06/3bSVZlAb4O10NDfVrR2HDxRESRtkHtIXpoFp6odYX6DuXXtYbRCjpKF0eRJeLxJOb50hgbFLfqMWIOx8coUfXoeUOxE6OPCHbIFJ26Kvrb0jj9Sy1/r0A5+1iDahk+KAqV2xbgAK6L/J38zhhdiieU20XDimgbfwEr3Q+9jOS9gJLYNhaNvq+ZkBuS2EQZobHe1wBhkpfHRbMVAYKywJGVZjaH83gmlFdexNIvHXITjr2RUSi0TMWT0DQn6tWhbR6siPe4TE4verdDClbtCRzWMi6H6ldUL5qYVEnd46gEvlHgQdw4iKY3E9L7vPwM+o02MfxS9c13Lxu/n0LWs6y+Ref7urXf+zAChVYxsYJ9PypXFTFDwriMZXfOnSVUv+ybIpVblw8IvJwyq+TOb6o2bIKtt54inyGbw2iCL0CuUR+Uow84hU5+u7EA3N7jTDHr3z69UDfSOwYBOLJCyKkiMMUdsoDGCf2Ib0CJ2Vlx0R4aRz5xbKZ7nZ2ZRT/dN+WxwoUHVmsKBA8J64HTXm1hkSgcemMNdYk8rD7CZckkJHk1+LzoY5TpZoihfhCmlxp7uClKS0KeFhELiDQU7vD8I5MHRSRBDRIyfMloDsbI4LqCN8OOPxr4zuYPHURkqPdi927Crbq42Dfh8bMRhtfn/yndkgbmBzauM4M1MGfLk7awArsmqtsQjAIHcumHziAjwOV5MCtVj6KMc2QMYXZD1NfhG4G0t5hP+Zfxbl5roiEgwCJrKuueFCz+Ny23l5VJClFlcvVkEA1bmQqJouiCy6kkj+sjqUwJJDVn+sKl0yztoqayhK4fustQSDSIKRuBAQtmr70eKcFHOhFB9o8PtkHfslzFMklH+wXWAMx6uKWO/M6HS91q9ET8Q76PWfdfzXzg1HpvqPyQm5drC5Fpy+mJ7qjgujCjstjVmvUt4OMUt9isLeOJzPogZnsmpfpy7syN9l2U/f00ZBIbOvnZM4EtXYkKJMy14vl10p+d1b/r0SDIQ00WCjvQqm5ZfuBYlowt5zonwVKtjo1gxO3GkgcnY0SqqYmITKH34ja/zCx3kSVn0943C5/bZrvnaaAaVOCtLp0ogeLWH/NFd2s+inkbzew== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 96d3f4a4-c2ed-45de-4da3-08dcfa4f9ed6 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 08:31:45.5201 (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: orJR+E00Sh4i+Qa6xtwc0IB9Lg9qo7d0I65OPlmee8/fyLBkWjBcPJ6C1lpLeFyVII9+Vqo/FNOUT7OfG3CbJg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA2PR04MB10215 This adds support for synchronizing to multiple PA trains. --- emulator/btdev.c | 131 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 100 insertions(+), 31 deletions(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index 5752a2fb0..3b0a267d1 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -52,7 +52,7 @@ #define ACL_HANDLE 42 #define ISO_HANDLE 257 #define SCO_HANDLE 257 -#define SYC_HANDLE 1 +#define SYNC_HANDLE 1 #define INV_HANDLE 0xffff struct hook { @@ -105,6 +105,13 @@ struct le_ext_adv { unsigned int id; }; +struct le_per_adv { + struct btdev *dev; + uint8_t addr_type; + uint8_t addr[6]; + uint16_t sync_handle; +}; + struct le_cig { struct bt_hci_cmd_le_set_cig_params params; struct bt_hci_cis_params cis[CIS_SIZE]; @@ -212,8 +219,6 @@ struct btdev { uint16_t le_pa_max_interval; uint8_t le_pa_data_len; uint8_t le_pa_data[MAX_PA_DATA_LEN]; - struct bt_hci_cmd_le_pa_create_sync pa_sync_cmd; - uint16_t le_pa_sync_handle; uint8_t big_handle; uint8_t le_ltk[16]; struct le_cig le_cig[CIG_SIZE]; @@ -239,6 +244,7 @@ struct btdev { uint16_t le_ext_adv_type; struct queue *le_ext_adv; + struct queue *le_per_adv; btdev_debug_func_t debug_callback; btdev_destroy_func_t debug_destroy; @@ -578,7 +584,6 @@ static void btdev_reset(struct btdev *btdev) btdev->le_scan_enable = 0x00; btdev->le_adv_enable = 0x00; btdev->le_pa_enable = 0x00; - btdev->le_pa_sync_handle = 0x0000; btdev->big_handle = 0xff; al_clear(btdev); @@ -589,6 +594,7 @@ static void btdev_reset(struct btdev *btdev) queue_remove_all(btdev->conns, NULL, NULL, conn_remove); queue_remove_all(btdev->le_ext_adv, NULL, NULL, le_ext_adv_free); + queue_remove_all(btdev->le_per_adv, NULL, NULL, free); } static int cmd_reset(struct btdev *dev, const void *data, uint8_t len) @@ -5246,7 +5252,8 @@ static int cmd_set_pa_data(struct btdev *dev, const void *data, return 0; } -static void send_biginfo(struct btdev *dev, const struct btdev *remote) +static void send_biginfo(struct btdev *dev, const struct btdev *remote, + uint16_t sync_handle) { struct bt_hci_evt_le_big_info_adv_report ev; const struct btdev_conn *conn; @@ -5259,7 +5266,7 @@ static void send_biginfo(struct btdev *dev, const struct btdev *remote) bis = conn->data; memset(&ev, 0, sizeof(ev)); - ev.sync_handle = cpu_to_le16(dev->le_pa_sync_handle); + ev.sync_handle = cpu_to_le16(sync_handle); ev.num_bis = 1; while (find_bis_index(remote, ev.num_bis)) @@ -5281,7 +5288,7 @@ static void send_biginfo(struct btdev *dev, const struct btdev *remote) } static void send_pa(struct btdev *dev, const struct btdev *remote, - uint8_t offset) + uint8_t offset, uint16_t sync_handle) { struct __packed { struct bt_hci_le_pa_report ev; @@ -5289,7 +5296,7 @@ static void send_pa(struct btdev *dev, const struct btdev *remote, } pdu; memset(&pdu.ev, 0, sizeof(pdu.ev)); - pdu.ev.handle = cpu_to_le16(dev->le_pa_sync_handle); + pdu.ev.handle = cpu_to_le16(sync_handle); pdu.ev.tx_power = 127; pdu.ev.rssi = 127; pdu.ev.cte_type = 0x0ff; @@ -5309,41 +5316,67 @@ static void send_pa(struct btdev *dev, const struct btdev *remote, if (pdu.ev.data_status == 0x01) { offset += pdu.ev.data_len; - send_pa(dev, remote, offset); + send_pa(dev, remote, offset, sync_handle); return; } - send_biginfo(dev, remote); + send_biginfo(dev, remote, sync_handle); +} + +static bool match_sync_handle(const void *data, const void *match_data) +{ + const struct le_per_adv *per_adv = data; + uint16_t sync_handle = PTR_TO_UINT(match_data); + + return per_adv->sync_handle == sync_handle; +} + +static bool match_dev(const void *data, const void *match_data) +{ + const struct le_per_adv *per_adv = data; + const struct btdev *dev = match_data; + + return dev == find_btdev_by_bdaddr_type(per_adv->addr, + per_adv->addr_type); } static void le_pa_sync_estabilished(struct btdev *dev, struct btdev *remote, uint8_t status) { struct bt_hci_evt_le_per_sync_established ev; - struct bt_hci_cmd_le_pa_create_sync *cmd = &dev->pa_sync_cmd; + struct le_per_adv *per_adv; + uint16_t sync_handle = SYNC_HANDLE; + + per_adv = queue_find(dev->le_per_adv, match_dev, remote); + if (!per_adv) + return; memset(&ev, 0, sizeof(ev)); ev.status = status; if (status) { - memset(&dev->pa_sync_cmd, 0, sizeof(dev->pa_sync_cmd)); - dev->le_pa_sync_handle = 0x0000; + queue_remove(dev->le_per_adv, per_adv); + free(per_adv); le_meta_event(dev, BT_HCI_EVT_LE_PA_SYNC_ESTABLISHED, &ev, sizeof(ev)); return; } - dev->le_pa_sync_handle = SYC_HANDLE; + while (queue_find(dev->le_per_adv, match_sync_handle, + UINT_TO_PTR(sync_handle))) + sync_handle++; + + per_adv->sync_handle = sync_handle; - ev.handle = cpu_to_le16(dev->le_pa_sync_handle); - ev.addr_type = cmd->addr_type; - memcpy(ev.addr, cmd->addr, sizeof(ev.addr)); + ev.handle = cpu_to_le16(per_adv->sync_handle); + ev.addr_type = per_adv->addr_type; + memcpy(ev.addr, per_adv->addr, sizeof(ev.addr)); ev.phy = 0x01; ev.interval = remote->le_pa_min_interval; ev.clock_accuracy = 0x07; le_meta_event(dev, BT_HCI_EVT_LE_PA_SYNC_ESTABLISHED, &ev, sizeof(ev)); - send_pa(dev, remote, 0); + send_pa(dev, remote, 0, per_adv->sync_handle); } static int cmd_set_pa_enable(struct btdev *dev, const void *data, uint8_t len) @@ -5369,7 +5402,8 @@ static int cmd_set_pa_enable(struct btdev *dev, const void *data, uint8_t len) continue; if (remote->le_scan_enable && - remote->le_pa_sync_handle == INV_HANDLE) + queue_find(remote->le_per_adv, match_sync_handle, + UINT_TO_PTR(INV_HANDLE))) le_pa_sync_estabilished(remote, dev, BT_HCI_ERR_SUCCESS); } @@ -5477,11 +5511,14 @@ static void scan_ext_adv(struct btdev *dev, struct btdev *remote) static void scan_pa(struct btdev *dev, struct btdev *remote) { - if (dev->le_pa_sync_handle != INV_HANDLE || !remote->le_pa_enable) + struct le_per_adv *per_adv = queue_find(dev->le_per_adv, + match_sync_handle, UINT_TO_PTR(INV_HANDLE)); + + if (!per_adv || !remote->le_pa_enable) return; - if (remote != find_btdev_by_bdaddr_type(dev->pa_sync_cmd.addr, - dev->pa_sync_cmd.addr_type)) + if (remote != find_btdev_by_bdaddr_type(per_adv->addr, + per_adv->addr_type)) return; le_pa_sync_estabilished(dev, remote, BT_HCI_ERR_SUCCESS); @@ -5622,16 +5659,37 @@ static int cmd_ext_create_conn_complete(struct btdev *dev, const void *data, return 0; } +static struct le_per_adv *le_per_adv_new(struct btdev *btdev, + uint8_t addr_type, const uint8_t *addr) +{ + struct le_per_adv *per_adv; + + per_adv = new0(struct le_per_adv, 1); + + per_adv->dev = btdev; + per_adv->addr_type = addr_type; + memcpy(per_adv->addr, addr, 6); + per_adv->sync_handle = INV_HANDLE; + + /* Add to queue */ + if (!queue_push_tail(btdev->le_per_adv, per_adv)) { + free(per_adv); + return NULL; + } + + return per_adv; +} + static int cmd_pa_create_sync(struct btdev *dev, const void *data, uint8_t len) { + const struct bt_hci_cmd_le_pa_create_sync *cmd = data; uint8_t status = BT_HCI_ERR_SUCCESS; + struct le_per_adv *per_adv; - if (dev->le_pa_sync_handle) + /* Create new train */ + per_adv = le_per_adv_new(dev, cmd->addr_type, cmd->addr); + if (!per_adv) status = BT_HCI_ERR_MEM_CAPACITY_EXCEEDED; - else { - dev->le_pa_sync_handle = INV_HANDLE; - memcpy(&dev->pa_sync_cmd, data, len); - } cmd_status(dev, status, BT_HCI_CMD_LE_PA_CREATE_SYNC); @@ -5671,7 +5729,8 @@ static int cmd_pa_create_sync_cancel(struct btdev *dev, const void *data, * HCI_LE_Periodic_Advertising_Create_Sync command is pending, the * Controller shall return the error code Command Disallowed (0x0C). */ - if (dev->le_pa_sync_handle != INV_HANDLE) + if (!queue_find(dev->le_per_adv, match_sync_handle, + UINT_TO_PTR(INV_HANDLE))) status = BT_HCI_ERR_COMMAND_DISALLOWED; cmd_complete(dev, BT_HCI_CMD_LE_PA_CREATE_SYNC_CANCEL, @@ -5690,16 +5749,24 @@ static int cmd_pa_create_sync_cancel(struct btdev *dev, const void *data, static int cmd_pa_term_sync(struct btdev *dev, const void *data, uint8_t len) { + const struct bt_hci_cmd_le_pa_term_sync *cmd = data; + struct le_per_adv *per_adv; + uint16_t sync_handle = le16_to_cpu(cmd->sync_handle); uint8_t status = BT_HCI_ERR_SUCCESS; + per_adv = queue_find(dev->le_per_adv, match_sync_handle, + UINT_TO_PTR(sync_handle)); + /* If the periodic advertising train corresponding to the Sync_Handle * parameter does not exist, then the Controller shall return the error * code Unknown Advertising Identifier (0x42). */ - if (dev->le_pa_sync_handle != SYC_HANDLE) + if (!per_adv) { status = BT_HCI_ERR_UNKNOWN_ADVERTISING_ID; - else - dev->le_pa_sync_handle = 0x0000; + } else { + queue_remove(dev->le_per_adv, per_adv); + free(per_adv); + } cmd_complete(dev, BT_HCI_CMD_LE_PA_TERM_SYNC, &status, sizeof(status)); @@ -7200,6 +7267,7 @@ struct btdev *btdev_create(enum btdev_type type, uint16_t id) btdev->conns = queue_new(); btdev->le_ext_adv = queue_new(); + btdev->le_per_adv = queue_new(); btdev->le_al_len = AL_SIZE; btdev->le_rl_len = RL_SIZE; @@ -7219,6 +7287,7 @@ void btdev_destroy(struct btdev *btdev) queue_destroy(btdev->conns, conn_remove); queue_destroy(btdev->le_ext_adv, le_ext_adv_free); + queue_destroy(btdev->le_per_adv, free); free(btdev); } From patchwork Fri Nov 1 08:31:16 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 840442 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2044.outbound.protection.outlook.com [40.107.105.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 03DAC144304 for ; Fri, 1 Nov 2024 08:31:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.105.44 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449914; cv=fail; b=MFrblCuvzAX+tiA+1QCG3SKrACNz+sfmVDw3ymPQ+/MuSGk66wnbeUvvLTbE436Gxn5AK7puXhlMsbUOKl0gJheavGacvikYq1yXGLHrFmPwNa/Bd03Zzdn7Yltma9hpSJlhtW6EOHspr2fkkR26AjQL7YoKi4tb7KpTq9EJOeg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449914; c=relaxed/simple; bh=INoxnH5G8E5iNRM/EDi69NxOoE9cGBC9KUQfjD5C8P8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=baILkKT9/kntYLRg9besiyJROLGsaSsvp/FrGAJe+5ak9L4bGACgzN57c9sW2809VrV78sXurzEoNcbib0SjZzogPiBaK4dyA1LD5ckyMMCl4vV9fEJC9v7mrc/mjUwh/Bf7IKKcXMakrPrZj+wXlGIkHxkIA0HyZ6tzMjsYaSQ= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=bh+JSH3Y; arc=fail smtp.client-ip=40.107.105.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="bh+JSH3Y" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=mHcvGyy/1oNW+9LAqKEg/Empka7usQy4+HnHBUpR9i50FObJsoCvvy059kD0IzAfeqoIIadUgFb9WV5VflbiIWpjJl1p7Z8BnJf1MhD0Hff557oyYPCCBfS6gHnFcJO11FnGMsq3s9Zd9uIlK7d/s1awTSlE1ao9y6t8Fb6SXeagS4lNu+a9xNIVORBfMSXtEgI5lZz2MdR2CR4EBZE3YwI4AJ+1km8iI2+Lsik/rKGEZf8Z+45FxJb45h9dWXJARfH9x2kXefaMGE/nUD1bKGkfoHUcODJ5xRUPhkZ/Nz0fOifamRROL1LUCu/zRfBQLYaCJu6kKHymwzlMR/XsOQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=UCwaQ9Hq09SsVPxUlzYSO1XtPgXK4Li2xaEVsOmxTMg=; b=H0lYbBqW1FZK86TCatnTERWKbtFHPFY8r65yJYUnFY9KE8AtOEeJs3RilOSs64FWi1Or3Jz3oRm8DC+a6f5JyFgS1z094DF1aSybmYd3xLIqqT8eiZUPZ6listF1OWWdHEuB6pX17+WW0DyRKwzaA6tbrpWZfaW4U7PJwSFqQY+rJF08j5iIUyybXHd/vCNqRaOzusIRDvZBNxgmMygYgGsR/GOe0FAAosdD6pwWVVudrIDG8cNHci2Xxeu72xta0DkVQ8YQN7tqNaWZG+1FwrvHqpuBJS1GlF88KzjAt91Ex+sfM1mED5h2B9zCoYMZR056WoOxoICe8AVcmKGTnw== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UCwaQ9Hq09SsVPxUlzYSO1XtPgXK4Li2xaEVsOmxTMg=; b=bh+JSH3Yi6aik+oYNhdHT4Un/Mn6BLm71rXqNlWmfnsIAmCJ4rTM5or87rXeAL4vnfiAz4VyQEl/Bm19Di+8I0O6+hDimcvDSKfel4iML3uZQGZgN70nLgVrvNvNTDJHMpawzR9bKPQYoIp8gqXY7yoBn61/h7ZB//IOPOKttOJ2I8Tk7Z0tRrmPQ++sOufNBgObYaLYdpWzeCh6uDJND6ZW9av4+0JYDzR2tGixGixyioRzidKjLlmxFEoZ5PvaM/4UVloIz56nhxVTdMCJUfkE0YqgOtBqaTQrYIFoti8MdPGaUuHT+OhZ6a7OeB/BaPkBoXwbM5gUZHfzj1QPkA== 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 PA2PR04MB10215.eurprd04.prod.outlook.com (2603:10a6:102:409::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Fri, 1 Nov 2024 08:31:47 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::5e22:869c:33c:9654]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::5e22:869c:33c:9654%4]) with mapi id 15.20.8093.027; Fri, 1 Nov 2024 08:31:47 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Iulia Tanasescu Subject: [PATCH BlueZ 2/5] btdev: Add support for syncing to multiple BIGs Date: Fri, 1 Nov 2024 10:31:16 +0200 Message-ID: <20241101083119.4510-3-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241101083119.4510-1-iulia.tanasescu@nxp.com> References: <20241101083119.4510-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AM4PR07CA0033.eurprd07.prod.outlook.com (2603:10a6:205:1::46) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|PA2PR04MB10215:EE_ X-MS-Office365-Filtering-Correlation-Id: 4ecb1166-3722-4fb4-9fa7-08dcfa4f9fb1 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|376014|52116014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: LD6suuOjb1k9OIcM9HEMYOPv+LW6ofqnd8ua0VqRQvSrV8L79jhACD35a+PQa2VRLbjhvn2ASK3VGZEiBmP/30T75ymu2eVsl8PxP1QgcA/wFDSHaM4xBrtiIMD3Lbr9ecg18DZqULiMvzDZxcj5w0FM+B0b+fy9h1UWKMIVUyG4uaiw8HDGRpa6FaUCI2J8N/1C6zisjbirDwaapBplHwitCMDqh3F56lk9D+fMVTjKoDCftCDEb3CrxIS7gKKtTmIW7H0uBXo/noEizJiFlim5utnbLK82lEiWLhJ5Dd8HTxmLXsaGJHDfGCrFucEECqwRr5HF4BsFSjRNozE/TfhKxEjzW1vgmv9tMiUTiwrjLWzI1n/tP59DmZJGYwvwih4DWHQXTtEcTwC2FAxMeJY3pUe1VJBsZUKYa8TmINpf6X4ICcmNFmNOcDP6C3BtH3rKTkFJEhrbwod/WGMKwa20sUENw2uAkzK6oQsDRBdCuavdA0BcvmtVFOxj3bTaaNbrXL7yTNSv5u/X4OVQxoVdrVd0y1McYOLixWWXOX4G0EiHyDTcgMpuLlLGtkYzUYFI+oN8ntZDoTLhrK+MglZiD3bcrlGEN+G6lF5+kqfF8faD2Ce07L+WfUpMU69pRNTpGpty1EI3UDMO3ELkWO9QkI54DX2T4BM7+ddPNahJraiDo7eKu7c6vf2sFtUaJQQPjVAmgk0ilAs/Io7HN7CO98ti35Nn60aMfHT84X2kSB2L8qb5NAiQ1Q88A9TI1GvbwKtFBzfnRtAUNMcJu9ZooWDtNA2vCNHjXbzg6zLys1m8r1yha+7vTaSPC6taTkWFfFAEaA3gNntPgdNDnkQryuzpft9sVFQOPG/Agb0lZe/4o+K9OsNL5f0/axMZaJLpMVg6CQjaZjQjFpYsiP8nGHVOAQsfgJsWR35ilnGEi2WOFHM0XddSGxYWkLnykqrRL5gKS87DdGfG0XgkIPPIu71ERO8KLGzkcr73iF99Ufa36N3r9A/TkCmNsVkCsLRZeZ25hs4R8M/dVX496OoYvsa7ORhtEBeXG47LI0/LPXd36u7DxupWxgPq8J7eKOkUJV/sNQU/NSCs7LnZOlFjL7e4i9xU/NdW8CtUN7JaMHm98kJnyZrIYST3L/F4sLo4ow2VA8e5WTswBkYHOkaOjZC2TrnGVEszCiROsKpBSs9oIQn5X0F4YwqeibAqLzTmTwrQ80aIKrrK+bLlxaKxY/7jBkhVfhS/2LsDFP4fRragutArh3J+DixXfMj06qSKr4UaIm/ipfUa7RlIH69I8Iodl6eAGUustJ6urBOIN0hhdCenQH+BYiECEXyLHhHF6jQ59bquvprKB5P14GEWP8IJvo1ACqQGH+q2awE= 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:(13230040)(366016)(376014)(52116014)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: cQ30L154b1J/IeAAnRMITdEwCui66UJ2OBQt0e77DwZWt5IS5+Es5i3ISZ23Pjgae416hwpqcKK76YXBOiQnIRvVuMgqCNMeT3q9RPaud4YKj02oyJYmrixC3iZYje/xul6xBM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jdXbdT1hQZ8z/ZyPhzgiLVrI73wMXBGyGfo8/jKbDEW48faeJnFUxy+bqUJSLGOfYwH6zp5OBtc1X/0m0b0gny/Xh/aVuMBKpghoGMP99NBHEyb8TGyKe8qjFl4uQhBQ8zmudpYO7vCCYtnX5RuK5097MNLzpNiJWO2kbcUZsUNEofPrj+Ys0G2NYt6OnK4LmhbqDqpQh91qnAChVnzy9FQFQORKQXHamgpC6CDMxlUtyis0/gN9aedMcHlMuV2LqC4YLqdPGRpAvG5c6wjbco5W4AFJ3mJWPeAzQsPRON+e4ithk9LUSPq5YYJ/O3SqO5+vv6B2z5QizOBdoORqyaQkFwIoNSTxn8xWw8DsaQhq7/y2Xtlf+plvfVBkmlLwOU7mLDHVIVO3ShbBpCIXqYI3MUIClmjMzZhOu9A== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4ecb1166-3722-4fb4-9fa7-08dcfa4f9fb1 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 08:31:47.0091 (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: 0rVDf1wGi4RfRjXpa4I9IFGF2HWe1G1U14D30sZl7X7JQ3/ym5q0MFSTOddNuSWkAg+XPzIa2++29YlWIEBuBw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA2PR04MB10215 This adds support for synchronizing to multiple BIGs. --- emulator/btdev.c | 102 ++++++++++++++++++++++++++++++++++++----------- 1 file changed, 79 insertions(+), 23 deletions(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index 3b0a267d1..08af873a2 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -112,6 +112,12 @@ struct le_per_adv { uint16_t sync_handle; }; +struct le_big { + struct btdev *dev; + uint8_t handle; + struct queue *bis; +}; + struct le_cig { struct bt_hci_cmd_le_set_cig_params params; struct bt_hci_cis_params cis[CIS_SIZE]; @@ -219,7 +225,6 @@ struct btdev { uint16_t le_pa_max_interval; uint8_t le_pa_data_len; uint8_t le_pa_data[MAX_PA_DATA_LEN]; - uint8_t big_handle; uint8_t le_ltk[16]; struct le_cig le_cig[CIG_SIZE]; uint8_t le_iso_path[2]; @@ -245,6 +250,7 @@ struct btdev { struct queue *le_ext_adv; struct queue *le_per_adv; + struct queue *le_big; btdev_debug_func_t debug_callback; btdev_destroy_func_t debug_destroy; @@ -575,6 +581,15 @@ static void le_ext_adv_free(void *data) free(ext_adv); } +static void le_big_free(void *data) +{ + struct le_big *big = data; + + queue_destroy(big->bis, NULL); + + free(big); +} + static void btdev_reset(struct btdev *btdev) { /* FIXME: include here clearing of all states that should be @@ -584,7 +599,6 @@ static void btdev_reset(struct btdev *btdev) btdev->le_scan_enable = 0x00; btdev->le_adv_enable = 0x00; btdev->le_pa_enable = 0x00; - btdev->big_handle = 0xff; al_clear(btdev); rl_clear(btdev); @@ -595,6 +609,7 @@ static void btdev_reset(struct btdev *btdev) queue_remove_all(btdev->conns, NULL, NULL, conn_remove); queue_remove_all(btdev->le_ext_adv, NULL, NULL, le_ext_adv_free); queue_remove_all(btdev->le_per_adv, NULL, NULL, free); + queue_remove_all(btdev->le_big, NULL, NULL, le_big_free); } static int cmd_reset(struct btdev *dev, const void *data, uint8_t len) @@ -5331,6 +5346,14 @@ static bool match_sync_handle(const void *data, const void *match_data) return per_adv->sync_handle == sync_handle; } +static bool match_big_handle(const void *data, const void *match_data) +{ + const struct le_big *big = data; + uint8_t handle = PTR_TO_UINT(match_data); + + return big->handle == handle; +} + static bool match_dev(const void *data, const void *match_data) { const struct le_per_adv *per_adv = data; @@ -6426,11 +6449,13 @@ static int cmd_big_create_sync(struct btdev *dev, const void *data, uint8_t len) { const struct bt_hci_cmd_le_big_create_sync *cmd = data; uint8_t status = BT_HCI_ERR_SUCCESS; + uint16_t sync_handle = le16_to_cpu(cmd->sync_handle); /* If the Sync_Handle does not exist, the Controller shall return the * error code Unknown Advertising Identifier (0x42). */ - if (dev->le_pa_sync_handle != le16_to_cpu(cmd->sync_handle)) { + if (!queue_find(dev->le_per_adv, match_sync_handle, + UINT_TO_PTR(sync_handle))) { status = BT_HCI_ERR_UNKNOWN_ADVERTISING_ID; goto done; } @@ -6439,7 +6464,8 @@ static int cmd_big_create_sync(struct btdev *dev, const void *data, uint8_t len) * allocated, the Controller shall return the error code Command * Disallowed (0x0C). */ - if (dev->big_handle == cmd->handle) { + if (queue_find(dev->le_big, match_big_handle, + UINT_TO_PTR(cmd->handle))) { status = BT_HCI_ERR_COMMAND_DISALLOWED; goto done; } @@ -6457,6 +6483,25 @@ done: return 0; } +static struct le_big *le_big_new(struct btdev *btdev, uint8_t handle) +{ + struct le_big *big; + + big = new0(struct le_big, 1); + + big->dev = btdev; + big->handle = handle; + big->bis = queue_new(); + + /* Add to queue */ + if (!queue_push_tail(btdev->le_big, big)) { + le_big_free(big); + return NULL; + } + + return big; +} + static int cmd_big_create_sync_complete(struct btdev *dev, const void *data, uint8_t len) { @@ -6469,12 +6514,27 @@ static int cmd_big_create_sync_complete(struct btdev *dev, const void *data, struct btdev_conn *conn = NULL; struct bt_hci_bis *bis; int i; + uint16_t sync_handle = le16_to_cpu(cmd->sync_handle); + struct le_per_adv *per_adv = queue_find(dev->le_per_adv, + match_sync_handle, UINT_TO_PTR(sync_handle)); + struct le_big *big; + + if (!per_adv) + return 0; - remote = find_btdev_by_bdaddr_type(dev->pa_sync_cmd.addr, - dev->pa_sync_cmd.addr_type); + remote = find_btdev_by_bdaddr_type(per_adv->addr, + per_adv->addr_type); if (!remote) return 0; + big = le_big_new(dev, cmd->handle); + if (!big) { + pdu.ev.status = BT_HCI_ERR_MEM_CAPACITY_EXCEEDED; + le_meta_event(dev, BT_HCI_EVT_LE_BIG_SYNC_ESTABILISHED, &pdu, + sizeof(pdu.ev)); + return 0; + } + memset(&pdu.ev, 0, sizeof(pdu.ev)); for (i = 0; i < cmd->num_bis; i++) { @@ -6483,6 +6543,8 @@ static int cmd_big_create_sync_complete(struct btdev *dev, const void *data, break; pdu.bis[i] = cpu_to_le16(conn->handle); + + queue_push_tail(big->bis, conn); } if (i != cmd->num_bis || !conn) { @@ -6492,7 +6554,6 @@ static int cmd_big_create_sync_complete(struct btdev *dev, const void *data, return 0; } - dev->big_handle = cmd->handle; bis = conn->data; if (bis->encryption != cmd->encryption) { @@ -6522,7 +6583,9 @@ static int cmd_big_term_sync(struct btdev *dev, const void *data, uint8_t len) { const struct bt_hci_cmd_le_big_term_sync *cmd = data; struct bt_hci_rsp_le_big_term_sync rsp; - const struct queue_entry *entry; + struct btdev_conn *conn; + struct le_big *big = queue_find(dev->le_big, match_big_handle, + UINT_TO_PTR(cmd->handle)); memset(&rsp, 0, sizeof(rsp)); @@ -6530,7 +6593,7 @@ static int cmd_big_term_sync(struct btdev *dev, const void *data, uint8_t len) * exist, the Controller shall return the error code Unknown * Advertising Identifier (0x42). */ - if (dev->big_handle != cmd->handle) { + if (!big) { rsp.status = BT_HCI_ERR_UNKNOWN_ADVERTISING_ID; goto done; } @@ -6539,24 +6602,16 @@ static int cmd_big_term_sync(struct btdev *dev, const void *data, uint8_t len) rsp.handle = cmd->handle; /* Cleanup existing connections */ - for (entry = queue_get_entries(dev->conns); entry; - entry = entry->next) { - struct btdev_conn *conn = entry->data; - - if (!conn->data) - continue; - + while ((conn = queue_pop_head(big->bis))) { rsp.status = BT_HCI_ERR_SUCCESS; - disconnect_complete(dev, conn->handle, BT_HCI_ERR_SUCCESS, - 0x16); - conn_remove(conn); - break; } done: - if (rsp.status == BT_HCI_ERR_SUCCESS) - dev->big_handle = 0xff; + if (rsp.status == BT_HCI_ERR_SUCCESS) { + queue_remove(dev->le_big, big); + le_big_free(big); + } cmd_complete(dev, BT_HCI_CMD_LE_BIG_TERM_SYNC, &rsp, sizeof(rsp)); @@ -7249,7 +7304,6 @@ struct btdev *btdev_create(enum btdev_type type, uint16_t id) btdev->iso_mtu = 251; btdev->iso_max_pkt = 1; - btdev->big_handle = 0xff; for (i = 0; i < ARRAY_SIZE(btdev->le_cig); ++i) btdev->le_cig[i].params.cig_id = 0xff; @@ -7268,6 +7322,7 @@ struct btdev *btdev_create(enum btdev_type type, uint16_t id) btdev->conns = queue_new(); btdev->le_ext_adv = queue_new(); btdev->le_per_adv = queue_new(); + btdev->le_big = queue_new(); btdev->le_al_len = AL_SIZE; btdev->le_rl_len = RL_SIZE; @@ -7288,6 +7343,7 @@ void btdev_destroy(struct btdev *btdev) queue_destroy(btdev->conns, conn_remove); queue_destroy(btdev->le_ext_adv, le_ext_adv_free); queue_destroy(btdev->le_per_adv, free); + queue_destroy(btdev->le_big, le_big_free); free(btdev); } From patchwork Fri Nov 1 08:31:17 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 840169 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2044.outbound.protection.outlook.com [40.107.105.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0C8CA156968 for ; Fri, 1 Nov 2024 08:31:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.105.44 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449917; cv=fail; b=GPKTFxt5G7fA34s485YQuIa+gZBBCsVrNKhcFz0AFYlLY6w86jat6HJfOI8asXaGavcjXXMxl8tsUc27hovKNPhHTAXJ6Q8Np56Uh0D+8Appp+jOBrzfVh2GpljvT4g1ORrHV8QgrjboKa/WB0d9mh/CuX8KCb1iWfjs8SF+ue0= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449917; c=relaxed/simple; bh=fmVg7XgrkQ0RmGn5WMTBWeDUIbvmWAl0cnmR5SkTtnw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=tPggebPIF/K++TVXTUn9xwppEi175iuFQuYuyLdxsM7GS/EYlVp9jlAIxCymtUR3ceMFdfr6yY5iSXLAIpCLRxNTo0YRLKD0RzW2gCF7rLi/tgKhl2aktujbNSxRoAzPbR+TikzA+yVHiyeuVz1HGw3q83we2obtjO3Mhs45bRA= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=cax4tal6; arc=fail smtp.client-ip=40.107.105.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="cax4tal6" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=dbD6yEsde4IRpShNxRdTgFpRREJn+DmPuF8S3rb1LtqPoq7UfYSDCJhwL1rnhEL42DhSgY9n86ztF0FGINZUAP+bRsAXlVnoXDf7PjmlzRswPrb0f4DB0spRrCzKMuh/Xedb+raWQRQXSpoG2355bjE0u6v0y+GNbNqQBeqX8kASz33y58CSQ6UFdmAkK6bq2tlDSndCf5HkN+11YlsTEONog2Tkii51Sq/BiqH85X8eptsgIU+yEvAp20XcQKFSzkjh1XyyUj4CUmxI74mlBQ6HWF0YocofflQtOAOk8UOhuaFyfMhk6DQEFTQ/Dkh7SxYcu/RQtn57hkWaIBqhMg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=IscxfkjRIQH4lZLX4mtCT8uvJCa/qmHE+7gNHnkd61Y=; b=uVjQeF09Hj2XAr71C4Bw8MDfgyM2RRZF+JUI2m+MFF5XjSDvFSeKmPN0LhitkqF6tqOMUsaNoBb1GQXK1/WeFaUdgsRpJJ7z1nysrQv0qu1AqjgXpECMf+Icbwd/N/t2tOb2yfkPM+VC0P/ZhIy8JRe3UsGuuVvA+EpPy4alRJLMBGUaOZkFX9C7PzZiDPNYkLVfOWRzdL30pU43StrX/IYrce+yLkBpEZpxZAT+hvXAPy7Y02TSZ8JdBbwKhz39NWV3wgw7DTe+JJCn9p1QYi9i0L/0YkHui5Yx+cAYLAWbItCEqbQPTYXdu8NWGoYMV7+1qqIPactdaWIFm0MS5Q== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=IscxfkjRIQH4lZLX4mtCT8uvJCa/qmHE+7gNHnkd61Y=; b=cax4tal63tY3gPWEBCUb0bGAy+TnzMM6ChFQGf1gQVBtvC0alWTmi4eaiQb8J5uKkLxZHhNDgDIhey8Hxv9bxkY/0Wkv0EkpXd9M+kYEXt7R6tRYgzNwQAmw8zdH7i1ii0l8DqzOJPeD/rA8F8A1eLzd7Qm/hpO3KH24fBl0sWbnOJVsE3aF+f36s+d8d6Hm4g51GB8JP+gW7SYXE1OGTiRI9hMnIXn/GYhUETjLueNupsWvuilbUXXoZ1aYk6EK5EkFPtCvPi+WHLWB7oaLxZwSk3jNmTeyb4N+TsBWi7qNYr/3EXI47lA8fnRx9eZuZqWyV5Ep2S1ui3gdAHbtmw== 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 PA2PR04MB10215.eurprd04.prod.outlook.com (2603:10a6:102:409::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Fri, 1 Nov 2024 08:31:48 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::5e22:869c:33c:9654]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::5e22:869c:33c:9654%4]) with mapi id 15.20.8093.027; Fri, 1 Nov 2024 08:31:48 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Iulia Tanasescu Subject: [PATCH BlueZ 3/5] iso-tester: Fix memory leaks in iso_accept_cb Date: Fri, 1 Nov 2024 10:31:17 +0200 Message-ID: <20241101083119.4510-4-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241101083119.4510-1-iulia.tanasescu@nxp.com> References: <20241101083119.4510-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AM4PR07CA0033.eurprd07.prod.outlook.com (2603:10a6:205:1::46) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|PA2PR04MB10215:EE_ X-MS-Office365-Filtering-Correlation-Id: 0a7962a0-0362-4ad0-f306-08dcfa4fa087 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|376014|52116014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: URaXnWMkryaKwlIgNHrS/hM8hjM0xOUeyPYFiP4uJm+vGMknub+2QCSAS+1ntLT4dYcEucuUcW93f0PDHetueptKs6TCBnHDvR3/XFOnDrwrKvsW3xMbtNMENTA4awgPw/w/uP4CTbMVPd/wqMvMjt4egplfq/u+KTbmY2jPlr6DRRDiFUGRXBI/Q+agleuTOxz7WZLgx5yB6nG2HFfABDJ0RTcwUeLp4nAxFDJiLoOWEdmkcojuY5deqUNcb2NUJX35huQnBiOeIxoHMfi5cZC8qjoKqLsJiI7NHRfSkWDfPCqJoQrJfdnn9LMLMvaBHVNqxh/uUB/T/ez43B6xNEmTcXEpzExhC+n0nJrb/Zc38wwipxeoslkQ7keIlHhcWFzswBbMStNL9zml/CIixNxnDTPeZTb3blVSHlJpLG8ELVMQx+M5+4cw8IyZLhtNE16VjOiM8vsmgIcyWgU9MhEANaLqNn9YGj2xK6O2BWTfzKXOgoQXa7y7vCPOK+iRtL72QlYBO2Ob8dSJyfebfTqHgKqxFBF6sS2zcP2MVHYKVhto49MHNMimECX2zR/FaE6bkNTtsDKc0VWpR3ZCQCoNvRRuWOa2+WvnAa2QK2HYd2F4/Qc9mEmsu/m/VJLzoz5J8j9Y0m//H3qDTh6VLHtWSkVMhqQ19cMavWn7xrgoMD3LQBzVUnhrJxIwBZQgaYbgF2E99atHwb2sccYm4c/lLcXIFfUd9mUme+RDbuKrEb9CfQaLRw+t9y42HpA05SO4ZEJvpXRxk+5zj7FrcwrojHGoAEcwNXYjRh1Dpbb2ao2gqZayK/ytadbtdIlwboeQ0ezy+drwDCaKxPpscF/HV8EDbOTrJYzAo9hQn5eaX01DVflC9q/4P0YKL4WOOIPE3fF3QqFtw9s5rp+zc+Ar5nVWYMFoI0Ncv9MUZFes1hsoNBSycdlb/iYU2XgKvBDpZ4weqAUxvNsI9MF9A0NoUFsxqDFfcBcwaro37B9852tRd8Bc2Xxj5TFYcX2T/lAAUHHEbS9Mk0ikxbhOdFj359ZsUu2nRIDeGnSNn5VZV1xU4LQVFOcG+ecOcg9yJ/Dh9plHZyAgke3opYT/ZOqIfJAb/9sbrL7uVzwHVkjuw2kXmklUnXeECw2msbeKC1vM7NJ5zdekdXQ4GMj31/8/dLkeu6N2Ag+PVWsIKHIK3gQtXsE0ejGVkKBqOpXHDQoyO4GJ/xKV81QHsQ+s9FzXfk+IutwmewHeF87b2UKeb8yeX4Q4T51cjEbFsAPZi+eSg6+yan4ikImF5NkNunD6YWLoViq6AajegO4DTJ3FuX2bLzymAbjVCFAbK6Qbt8DS0Poq2xXePJyAJmtm2FjwrTSgEjWa1Hd4t9b0juA= 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:(13230040)(366016)(376014)(52116014)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: yMqhCJ8UHt6PAReeXkduKhda9xwbsy0qmu8NkfUwmdwixBCcouzsNb0UbUsChGrw5nKc1+7aZt3U1xjmEfLWXPTjaDFNEhnZnvX1N607yX4H0+MEUlvEsnxs8VkUxxNBeFkbQCHQVVkbYVGBmp6PwtiR/57WX6FGLuhoSoTUsi59XDw1PVgdTmNyUX7gioT1Qnv8vozDBgpOsw4cwc8ZP113HkCBnMOpyshGCbV7/xsAdeH5akD1OCwz6rSLfAtRgZoHx5RCtEVBkCxSgfMuy8ga5foYicvSfzY5gJR6gxuIE5M7GIFkBrsa554bnb9jygHSfoDn0oO2XrxzvtfwiEcx8VoHG0N3srEqwizMihtIKg/4RLm8fsjIr241eHbs9ReiqpPmjGPvq3lEOd6RoqfXGog/SL1KQpYcqjtYiQJPeIbU/KjHJKn/saiVRpUJwN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6/QtNqEhf7W4nu2YXOuzZHWXij3mZUA6FkT3MNjnm4O7a0w5TWR/5rbineMJnqb4ZyERlMyuQtVc/6OwgQVoJFn8RY3krQ== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0a7962a0-0362-4ad0-f306-08dcfa4fa087 X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 08:31:48.3659 (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: Hg6rRuZFzkqp7Xm7vIpA5jOxqcXM2HsVsqwbGY95eCw6wnpmbGAFPxST0wXj+5ol/DI71/02ssIfhHU+PPnj+g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA2PR04MB10215 This fixes memory leaks that appear in iso_accept_cb because a new io channel is allocated but never unreferenced at the end of the test. ================================================================= ==20460==ERROR: LeakSanitizer: detected memory leaks Direct leak of 120 byte(s) in 1 object(s) allocated from: #0 0x7dcddc8fbb37 in malloc ../../../../src/libsanitizer/asan/ asan_malloc_linux.cpp:69 #1 0x7dcddc719af9 in g_malloc (/lib/x86_64-linux-gnu/ libglib-2.0.so.0+0x62af9) #2 0x7dcddc7722bd in g_io_channel_unix_new (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0xbb2bd #3 0x5d3fdfe28262 in iso_accept_cb tools/iso-tester.c:3004 Indirect leak of 6 byte(s) in 1 object(s) allocated from: #0 0x7dcddc8fbb37 in malloc ../../../../src/libsanitizer/asan/ asan_malloc_linux.cpp:69 #1 0x7dcddc719af9 in g_malloc (/lib/x86_64-linux-gnu/ libglib-2.0.so.0+0x62af9) #2 0x7dcddc70016f in g_io_channel_init (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0x4916f) #3 0x7dcddc7722c8 in g_io_channel_unix_new (/lib/x86_64-linux-gnu/libglib-2.0.so.0+0xbb2c8) #4 0x5d3fdfe28262 in iso_accept_cb tools/iso-tester.c:3004 SUMMARY: AddressSanitizer: 126 byte(s) leaked in 2 allocation(s). --- tools/iso-tester.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tools/iso-tester.c b/tools/iso-tester.c index e80c2159c..41d46f554 100644 --- a/tools/iso-tester.c +++ b/tools/iso-tester.c @@ -2987,6 +2987,7 @@ static gboolean iso_accept_cb(GIOChannel *io, GIOCondition cond, struct test_data *data = tester_get_data(); const struct iso_client_data *isodata = data->test_data; int sk, new_sk; + gboolean ret; iso_defer_accept_t iso_accept = isodata->bcast ? iso_defer_accept_bcast : iso_defer_accept_ucast; @@ -3014,8 +3015,10 @@ static gboolean iso_accept_cb(GIOChannel *io, GIOCondition cond, if (isodata->bcast) { iso_connect(io, cond, user_data); - if (!data->step) + if (!data->step) { + g_io_channel_unref(io); return false; + } } if (!iso_accept(data, io)) { @@ -3037,7 +3040,10 @@ static gboolean iso_accept_cb(GIOChannel *io, GIOCondition cond, } } - return iso_connect(io, cond, user_data); + ret = iso_connect(io, cond, user_data); + + g_io_channel_unref(io); + return ret; } static void test_listen(const void *test_data) From patchwork Fri Nov 1 08:31:18 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 840441 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2044.outbound.protection.outlook.com [40.107.105.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A513E14AD2B for ; Fri, 1 Nov 2024 08:31:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.105.44 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449920; cv=fail; b=sugG213ILokso0T8yFLW7a0MPOvMpwigNbvtzDtjAGz0aV4xmwuupv9lNFmyirYefYx5RYidQ4qEH7JKpon6AkNlP1EMl4EQXs9dNwMADoG8brkyRoVP7KISdcDSCuj3xbql8fxQm0qXlwbPVhUpdgfbaY/FCbwznIOidgg0MbQ= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449920; c=relaxed/simple; bh=Mivx3tE/T6A9yMetkRWxn4wNhG+d1M2d14zNXjJbin4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=pWMHrV8VmUTL6Z3m5hIxt7tZ+lxgTlYcbR9tPM1mCBSWcbeZP3Gx7EYA6IWTvITmaFfxZrN2CIZrCAYnzTtkc5Yl4Q4pLjVOIONaVZRsVVNLQrRr105UPVXhG2idDv+tQHzQfXK2ydlPP8XD94qqBhvNe9ccfnw0Shfg8cCT8yM= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=VZXKs/xr; arc=fail smtp.client-ip=40.107.105.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="VZXKs/xr" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=AwuhhlLLgOeojJ7epA0wcUijHGXQvuO1SJBBazOA9QCPgUk3Rvuwa9pEq3X98tsI9mFc1BQfAS+5QdJqbUhMNpO3IzpRbSdlkXX7Vge7aqf5h53mlJyWSU6TuwT4OAzkJNgUai4PRgpmex1ioG+RNr3an1W2+HisblBGvaqa5mxxGCL1bUuNp1sCXVvdFxKqoha5Gb8F73JtVP9sqUZPR19SWNg3yQaNNbKyw5t/iyIrXhMNL3KWwQ5zJso54Xkccg5HeJkyUuAgwCU/2NjikwdYrCj0HcfpfQ3mqsHFbgKKJ/FPhNjwopsg//RxZ7w1IGcnRSMp6tWBDFOkQHtFGg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=+vxT3KMTxmxuODIbDPnn4ZshYittW77Ud6qZrCdfZQ4=; b=zD2DgJVGyYWu6Z0WmqZYCy6xxXfhH3RfKYDhI5nXqK5qubAHMohKW1fspkf2QYe90zN3sB8hO4yXCXrhXAXo7EXQ7tSiQmQjRIexoWg3D3WwESySDQJyr3gAhNdBPjBGBGHbJFzOuRxvVnednHEATmjMApEDaLY9uB1IpeLWnbLUzOFQoVXgzwdh4DQ62yzK/eyncnq6LATPTmL6md/WGg8il4YQ5CN2h9ce4g0AT+ih+sh0slkAfpwivTNIXvS+XE5CrivBEkEh5QUK9KHyUn8xpXXe8RJ36gKbV1duoK2qO+bge3OmoTyGWPQoG65LmPV+rW3vVj7wot6CFNp7Jw== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=+vxT3KMTxmxuODIbDPnn4ZshYittW77Ud6qZrCdfZQ4=; b=VZXKs/xrxywOSIjJHnRZKhqpbfrWdPJw08GL/IPAU7VlzdoTvoOHjDDN6sPkAxGPisWINmoQqJP454KubmkVO+ocwOY7+SJhtJsqM63NrIxaoxn6EipIBy8YjWsOfaG3KJBq2bl8hNgwjwPraJa6p9cWAn/ko6Sa4B6fBFlUkFnr5h4//FlONTJXPxrCWYn/Mp4989XG6+DfHXuPu2banZ36XeQR/XaoZdr06lsRmzm2D4gKCESlnXDDG8679ECZ4BxkdjEQiQSmk0ynv3PAVZhvwbRlCvnNFFopTpvwKXfPnwPN3EtTXEX7eZhetpmjYcq49fVSkXat7C5TurOBLw== 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 PA2PR04MB10215.eurprd04.prod.outlook.com (2603:10a6:102:409::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Fri, 1 Nov 2024 08:31:49 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::5e22:869c:33c:9654]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::5e22:869c:33c:9654%4]) with mapi id 15.20.8093.027; Fri, 1 Nov 2024 08:31:49 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Iulia Tanasescu Subject: [PATCH BlueZ 4/5] iso-tester: Add test for Broadcast Receiver sync to 2 BIGs Date: Fri, 1 Nov 2024 10:31:18 +0200 Message-ID: <20241101083119.4510-5-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241101083119.4510-1-iulia.tanasescu@nxp.com> References: <20241101083119.4510-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AM4PR07CA0033.eurprd07.prod.outlook.com (2603:10a6:205:1::46) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|PA2PR04MB10215:EE_ X-MS-Office365-Filtering-Correlation-Id: 691f8477-67cd-42a3-45fd-08dcfa4fa15f X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|376014|52116014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: Q95t1+rFxNh1+aFRj7Bxc90YfDhBAW2+n1uHn5wGJNhyhYu3Jzt/H+1lW+BWuTJIbWRhphK1FuwV7nK/rK+A2zXueDI+StVQDYi56lOxfrNB+e7uI9OKPVRCPX7ih3xuGtG9KYCSqdl6L1tbOWx3RNkAgB0oyZ2bQwgLqvPmfMeXiETVsSIo2zGNuyV5BeYnkzDKr6nD2x98cddFOwH/H4goKHjWYudmpPM0M2hI2lW7F/+Z5GnnbKnfUvpYxSX5/n8ferKBdtnx1yQVC55naKzXPF8h44BYx6bfUkIzOsqR2Y0i5Jcb432fFkWpQ07OojFasNvTqL6uen8pOWih0Nsx5VcfNqvHHz3HVdpxADGWgXnCaqDugE+GqYVrv0uh1j3DorLjM5XwopwAxsPMsEalpl94d0JzI7R4IK7zFASbX5aWE4+UEC96OzVlbHb9jceQh5WDAqkMr4VdlF41R/rKlVsAVS/NsGoSe3M/tkoC05OGbNe1K5zAosOtD+sBz1fVKqabFHdYFeFTEMWxrDpRks/4VgVLcFOdM3XxyJJf3oRP659a+t/ISNOw9t27Xh+/cOELgkrY7Pjdqp5GxkJnTXUqIW3onZ+HsPNlxav4GKqIwpQPZsZIkOP8jygeEbEyNj3gmY6PlV+qRSyLGtsXHG3hZyJMcyf+RNiqAwNSE/hNnTp+hDes0F9NOtRxAhZbNh71Lo01rIA8EE7AczBrX6yh7bDmoHBWWm4eomIIVup6txG9aTLxNYanlkU2iNwhT+qtNUUQ06XY7gsjtjgnKotpsESkaKapop5x+el9sWZiPMy5zcihdxO2LhZV4Pifavnnp+BnSSAUqr2dl6g6RiKlYDtPwEpat7OWDKYuDm2Md+bXAFJHmmPs8SFi6PN2b7iz1K8/OX8NnFuQYbNy2LRGAtrIWcoIo5akQJbhaOLWMPKhnlMMRnJme8s5jkW6U5CT0FXtcusrSn83n+7wmOU+UGsX9TzZyjBHsgFytt938500vZoKDsg3KzTXg/xteWoms5OFYBWmmDxkCBDShhbXvNu+lcN7DaZkSwlbIaXMxaZr/IfQw/6ZOzHC/hCVSVxOa67CiOPHJkuhJdGzCiy0bmWObQeaoPe4YlW9yVS3aVEysW3MB1eRAIb9XGGW7pB4VC68ckMurisC0hYy05Y+LNUjkB/Di1uGNnlz7dB+bdiER07EkCPeVGmDmCkLDa2Ylk2CjvR/QLVGnGOdqtpjDaMxCwNdj5OQktuVK8FFp9LDKXn+x5fklIxxsQ+3LAdxVTcalZkmTB63lZDEIeNiNNakkruTi2FOGfbu8QIIQt1mnTcCFKGdAXV+PB6jXR6b6j0pEAOIMrQVSz2tvTDYdiS71D9vkUjQvw8= 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:(13230040)(366016)(376014)(52116014)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: StqvZKxdJP8cQCx/upzZ1Xell2n6tZL66SDTWyP2WHdFg3kLwvmRAfgRBUXnkkQ9CuMI1qNcCLOy0E5LW6+6lJX1psNdd+PR4UJOQQUkGBG5RxWimrsv752q8ERgkdjJuiFAu0Svjt95ptk4EQi6pVz0sjpWuzn5qvjn80da2qFdXRhAFwM6ytCdmRU8qZybHYp9MRYdCJ+aKLIPVnIs3g5BWE+8EGiBXQVL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ZcXwPoE0prFmq7jOnPWoRxGfV0uvVAMF4PUv43DKmHOzu2FSFThk728ECPTIbjbmgveHLEcyeQzkW54CX7d9LVB127t5zMUhO8/9iLwJRgvGLHIa2k8Y5DyIA/8D8DsOvDmOKBw7/daV/oLIY2/AMxbPtFEJKlpV3x6VyEbBvTKmBrHFWVwRT3wMc4RWCCF45vtJ2dkStijw0zN3KEhufogF+ULFcSidERY4PO04N7n+nyuSULrxfeBU9kYxPSVpkxxlxE/f9Gi9ZdASYUAXmkXoGRGhCdxpUInNocJbcYuaiB8qSPpVawKpZvw== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 691f8477-67cd-42a3-45fd-08dcfa4fa15f X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 08:31:49.7945 (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: OgVeH7JfKSUACU3U/1TbN3yAPY07FtZOFpBKd/51gRUSU0wf1ldZTSdwhOYxnvNta0aCZIcqqrPG1HdRW10yIA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA2PR04MB10215 This adds a new Broadcast Receiver test, for a Broadcast Sink synchronizing to 2 Broadcasters. ISO Broadcaster Receiver2 - Success --- tools/iso-tester.c | 101 ++++++++++++++++++++++++++++++++++----------- 1 file changed, 77 insertions(+), 24 deletions(-) diff --git a/tools/iso-tester.c b/tools/iso-tester.c index 41d46f554..6215fd456 100644 --- a/tools/iso-tester.c +++ b/tools/iso-tester.c @@ -1418,6 +1418,14 @@ static const struct iso_client_data bcast_16_2_1_recv = { .big = true, }; +static const struct iso_client_data bcast_16_2_1_recv2 = { + .qos = QOS_IN_16_2_1, + .expect_err = 0, + .bcast = true, + .server = true, + .big = true, +}; + static const struct iso_client_data bcast_enc_16_2_1_recv = { .qos = QOS_IN_ENC_16_2_1, .expect_err = 0, @@ -2763,7 +2771,7 @@ static void test_defer(const void *test_data) tester_test_failed(); } -static int listen_iso_sock(struct test_data *data) +static int listen_iso_sock(struct test_data *data, uint8_t num) { const struct iso_client_data *isodata = data->test_data; const uint8_t *src, *dst; @@ -2793,8 +2801,12 @@ static int listen_iso_sock(struct test_data *data) addr->iso_bdaddr_type = BDADDR_LE_PUBLIC; if (isodata->bcast) { + struct hciemu_client *client; + + client = hciemu_get_client(data->hciemu, num); + /* Bind to destination address in case of broadcast */ - dst = hciemu_get_client_bdaddr(data->hciemu); + dst = hciemu_client_bdaddr(client); if (!dst) { tester_warn("No source bdaddr"); err = -ENODEV; @@ -2857,31 +2869,36 @@ fail: return err; } -static void setup_listen(struct test_data *data, uint8_t num, GIOFunc func) +static void setup_listen_many(struct test_data *data, uint8_t n, uint8_t *num, + GIOFunc *func) { const struct iso_client_data *isodata = data->test_data; + int sk[256]; GIOChannel *io; - int sk; + unsigned int i; - sk = listen_iso_sock(data); - if (sk < 0) { - if (sk == -EPROTONOSUPPORT) - tester_test_abort(); - else - tester_test_failed(); - return; - } + for (i = 0; i < n; ++i) { + sk[i] = listen_iso_sock(data, num[i]); + if (sk[i] < 0) { + if (sk[i] == -EPROTONOSUPPORT) + tester_test_abort(); + else + tester_test_failed(); + return; + } - io = g_io_channel_unix_new(sk); - g_io_channel_set_close_on_unref(io, TRUE); + io = g_io_channel_unix_new(sk[i]); + g_io_channel_set_close_on_unref(io, TRUE); - data->io_id[num] = g_io_add_watch(io, G_IO_IN, func, NULL); + data->io_id[num[i]] = g_io_add_watch(io, G_IO_IN, + func[i], NULL); - g_io_channel_unref(io); + g_io_channel_unref(io); - tester_print("Listen in progress"); + tester_print("Listen %d in progress", num[i]); - data->step++; + data->step++; + } if (!isodata->bcast) { struct hciemu_client *client; @@ -2901,6 +2918,11 @@ static void setup_listen(struct test_data *data, uint8_t num, GIOFunc func) } } +static void setup_listen(struct test_data *data, uint8_t num, GIOFunc func) +{ + return setup_listen_many(data, 1, &num, &func); +} + static bool iso_defer_accept_bcast(struct test_data *data, GIOChannel *io) { int sk; @@ -2981,19 +3003,17 @@ static bool iso_defer_accept_ucast(struct test_data *data, GIOChannel *io) return true; } -static gboolean iso_accept_cb(GIOChannel *io, GIOCondition cond, - gpointer user_data) +static gboolean iso_accept(GIOChannel *io, GIOCondition cond, + gpointer user_data) { struct test_data *data = tester_get_data(); const struct iso_client_data *isodata = data->test_data; int sk, new_sk; gboolean ret; - iso_defer_accept_t iso_accept = isodata->bcast ? + iso_defer_accept_t iso_defer_accept = isodata->bcast ? iso_defer_accept_bcast : iso_defer_accept_ucast; - data->io_id[0] = 0; - sk = g_io_channel_unix_get_fd(io); new_sk = accept(sk, NULL, NULL); @@ -3021,7 +3041,7 @@ static gboolean iso_accept_cb(GIOChannel *io, GIOCondition cond, } } - if (!iso_accept(data, io)) { + if (!iso_defer_accept(data, io)) { tester_warn("Unable to accept deferred setup"); tester_test_failed(); } @@ -3046,6 +3066,26 @@ static gboolean iso_accept_cb(GIOChannel *io, GIOCondition cond, return ret; } +static gboolean iso_accept_cb(GIOChannel *io, GIOCondition cond, + gpointer user_data) +{ + struct test_data *data = tester_get_data(); + + data->io_id[0] = 0; + + return iso_accept(io, cond, user_data); +} + +static gboolean iso_accept2_cb(GIOChannel *io, GIOCondition cond, + gpointer user_data) +{ + struct test_data *data = tester_get_data(); + + data->io_id[1] = 0; + + return iso_accept(io, cond, user_data); +} + static void test_listen(const void *test_data) { struct test_data *data = tester_get_data(); @@ -3321,6 +3361,15 @@ static void test_bcast_recv(const void *test_data) setup_listen(data, 0, iso_accept_cb); } +static void test_bcast_recv2(const void *test_data) +{ + struct test_data *data = tester_get_data(); + uint8_t num[2] = {0, 1}; + GIOFunc funcs[2] = {iso_accept_cb, iso_accept2_cb}; + + setup_listen_many(data, 2, num, funcs); +} + static void test_bcast_recv_defer(const void *test_data) { struct test_data *data = tester_get_data(); @@ -3709,6 +3758,10 @@ int main(int argc, char *argv[]) test_iso("ISO Broadcaster Receiver - Success", &bcast_16_2_1_recv, setup_powered, test_bcast_recv); + test_iso2("ISO Broadcaster Receiver2 - Success", &bcast_16_2_1_recv2, + setup_powered, + test_bcast_recv2); + test_iso("ISO Broadcaster Receiver Encrypted - Success", &bcast_enc_16_2_1_recv, setup_powered, From patchwork Fri Nov 1 08:31:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Iulia Tanasescu X-Patchwork-Id: 840168 Received: from EUR03-AM7-obe.outbound.protection.outlook.com (mail-am7eur03on2044.outbound.protection.outlook.com [40.107.105.44]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 83AAD156F55 for ; Fri, 1 Nov 2024 08:32:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=fail smtp.client-ip=40.107.105.44 ARC-Seal: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449923; cv=fail; b=YlytKgG4FrnnvBh5WR7VsVhmjGHX0yF4mHp1O1P2BrLcw9/beAEmFfiBM2WzlTm6L4mxu5solHPCGXuNzRVRxB1eBGsgadDvvGYVLBwIfGXhYKMbowHR2GuJIrE6jh0dtbffGrCLG7vglPgRnDhVsUxgS7hssNrxQD2FYN5Zgdg= ARC-Message-Signature: i=2; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730449923; c=relaxed/simple; bh=YVy5MLuLVhUzKTXU36Bp+w106pOsgzGfjnGsUxRCq08=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: Content-Type:MIME-Version; b=GV3Byt4tHo0LHnjKbaielzLPEtC2mP4qlgrU6jJ93n2Aj6YFomDod+aR4LteRfqXjncz+IKep77oHT7ha19gtjVe7NCj7xm9GUEcKRnRb7BBpTmZTuMKq6EieBjjfMR2lzKJ+cA2GYGqX62a13skBzBBWlU+tesbITpU6/ZhU84= ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com; spf=pass smtp.mailfrom=nxp.com; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b=nDyCmnX/; arc=fail smtp.client-ip=40.107.105.44 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=nxp.com header.i=@nxp.com header.b="nDyCmnX/" ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=X++whTqS7ibh4M3BC8GNn558/anXCL3RnhbmZWCF5TTL8l5jffLR7HTehgPo/kiazSTTJBjbMOjnQyoKM/und3jQYtd5rJ+/yR7Cna/PLY7aaHgBpzvzNbLyRvXGJjdVEwGifDn6516lkeuWJuC9R14GeVBfz2ovMcVN8VBjtvuuQqD5NGQgSpGNIEVRqqoeNgH/liX+mIulMUHKAZVrLprulT1997efy3D5kidwT9NCaVY3AH4870hx/RJBr74VGcRod+0Lx9dWwCiK+9BFU1WKCSUsSO9D4Tg8GjRRCnYA3RQVb7OJ5gBeYXHEkgNKPlUK84P/zcbchTfD9Vk3kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; 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=OaXdf2MK3De/CLGuNA+GLdZV47xQG9oFCIuWa9HQhJA=; b=AgFgtfv2nWYuVt8etw8KQVIWdj6/I6r2CwZgQD+KwzlEbnvbR8ZzEnVQaqFmH8yoEllMcihXIiKk1TiJwKRsRa0oYLaPl9GjBwPk3N2C5SVKuDHESdug1Ik0VU1VHWweVclfkqBP8WASitV0ZkM995ZoWrCbZPuBZHBvb54/CJCzZ8kH6sWnnvsguDsUl7WRUF+SNx7s8TM/jBHJ8eqNKbYhjVpm8cISgZnOYr+IgUIXH+lksZeqsl2Tb5hmwOMNSYPQ2pKZDBBsW4UfZbv96KhzH1MM8sp941YmET24Xk3TlETaiXYP31vcM9n15neE/wtYUY3BRZ6xF4v4niWdEw== 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=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=OaXdf2MK3De/CLGuNA+GLdZV47xQG9oFCIuWa9HQhJA=; b=nDyCmnX/E/cX2oy/4T45cWbbqaVPUYmlYaBV4YstiGLSlwAVIMyv2jw03UlAbbl8iJ4pRLCgUyLFR7rupiK9pnGOaREQTxqEed4q/N8Wey7Ek8HMauwng4E7Qe/YjGMSYns+Vooc/8PMUfF9NmQyIG0jctssz+fl3GNdsKrbTLbUov3SCCowo8p5fh8GSnb11SSHQWra73oo4oQgXEQzAVZ6VmjwQN/QJH1d2PS/t7AxHlvIqXtNQq4FXlfGe4AkkCWnUB7fwm62+UnAeIEn1QtuhFYM9R3TND3cFMq2cfwQbuS0KuNbJICHXtY39TZ2kDzMn3vpICbue9ktysetYg== 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 PA2PR04MB10215.eurprd04.prod.outlook.com (2603:10a6:102:409::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.8093.32; Fri, 1 Nov 2024 08:31:51 +0000 Received: from AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::5e22:869c:33c:9654]) by AS8PR04MB8898.eurprd04.prod.outlook.com ([fe80::5e22:869c:33c:9654%4]) with mapi id 15.20.8093.027; Fri, 1 Nov 2024 08:31:51 +0000 From: Iulia Tanasescu To: linux-bluetooth@vger.kernel.org Cc: claudia.rosu@nxp.com, mihai-octavian.urzica@nxp.com, andrei.istodorescu@nxp.com, luiz.dentz@gmail.com, Iulia Tanasescu Subject: [PATCH BlueZ 5/5] iso-tester: Add test for Broadcast Receiver Defer sync to 2 BIGs Date: Fri, 1 Nov 2024 10:31:19 +0200 Message-ID: <20241101083119.4510-6-iulia.tanasescu@nxp.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20241101083119.4510-1-iulia.tanasescu@nxp.com> References: <20241101083119.4510-1-iulia.tanasescu@nxp.com> X-ClientProxiedBy: AM4PR07CA0033.eurprd07.prod.outlook.com (2603:10a6:205:1::46) To AS8PR04MB8898.eurprd04.prod.outlook.com (2603:10a6:20b:42d::15) Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: AS8PR04MB8898:EE_|PA2PR04MB10215:EE_ X-MS-Office365-Filtering-Correlation-Id: 88d2f18d-c9f1-4dbe-f936-08dcfa4fa23d X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; ARA:13230040|366016|376014|52116014|1800799024|38350700014; X-Microsoft-Antispam-Message-Info: /c8Bf8lzJOaD5HPF/K1YGpqDTysM4A7v9uVh0zJ4MDHGLSanH7kGLYJB9amRThnmRSGN1zTUkdKSFjNB7qsJvrXR1x1VypdY6UH0anbga9TioOkYWVxqKhiExGHRLBlKW+XwsfdSUPMoFQPjQjt5hsHQ4JegX4ehk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/bfuUU7rvYze6cuXe/7udOEmXu+kgyvdQclRmQHEAkS6zWb43PS6zhNINHjpcoBOT37AaoiNCvV0QEIkb2WI1YVMmgyKhREfZRnOqRrrnZZ+hhqXFyC8N8zeSyRMI6j/BobmKdgUNbGc9I= 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:(13230040)(366016)(376014)(52116014)(1800799024)(38350700014); DIR:OUT; SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: ZPKqQ6ymV7OkY9CdkdZOhwd1rJj35/qfw+2gf1oTOEefq8qo4PaEY3n6//7Lccv+9ZzuEfQ4iyz0ixwsokXEDi/cXd9MhdQEtYZ1fFmRj0fXc4QqUl9erBQ2XRJMC+S+b3R0VDRNULUVED6YIxmecTxf3gT0ZDZwWxx7WVLxJl/YfVo6ZdZbj+PVh08kC4HR+2IvcYoEpB7FZ2dfh/mCrL+iQrutUwH7KtH3jQct+dGT2+tohmx9m2vN8nseu9lGmtPiZOjSZB9CJCXwoyjtqsa+y1N7EMoU0zWGn02zhfCWLzJyEfA8OxkXfnRUwCrWtb+N77R15oKqALki1LQC3Yxa5waI/otogNTm9Qj70hOA7GPLEJRuWuHurX95oYhoHuwEyNzpxiscCFsoNbDMkUUVlAqzLvK7FSUHXHM5m0ABhOhWGp+ZcMe3AYd+W5kQqAqBESypZZiMnlg+9ozWxJ8YqxFxhXSSsgfTMeWVJ8ECp2xPg02uktQnfmL7FTezaakF4V8qDFYOEh6i005OPfZiPsc3Fi5AuREqa0rhgYVey6RSqqcgc9pbCsR8pazp9kbyxOkrNewP9BqfAHcf5fJ36SoGzH7gWmonYW4D3NBzOFItqEYJYTWG3UINECM/H0LUip7uG6+RESUyVqArpeUQqTFkkkSRMWLm08G0cUtUiVqulEZwWMD9vi9RBrz14BAa5W03KoX11bNfdNIYP9/dgzjU8k3jqGzv7IAcqxERA5v90lB/bX0S44ZXYKk9eDusYWoWSp8lWNEMbd11iwE350q7A/jfInFr4RUKTVekVVyhT+/2fRTR6sv7E+Nlh1DC8aJb58HC/NPNaLSLYbRnjohLQv0rk6NrisdZjpYTu4sikG+hZauu4MgwxFShIymDj6i/ey/svzb+aXx8WVIQXvzrOiERGE6NA9T+KRLMFS5e+fnMCFB46joK58GNxUfshko2HOyEPCHY3NZrf96vDprlDZ+S9Rwe9SXYfI3BnBqZALYJpeZqZuWe+UxSNIyrC39TRADehuXB3gtLgtr+y9v/gyLvojRwKCAbb96lBi1G7B1n46UuB1IgORFEC8zjkkKHUE5+nYZsj0MCBSzjuqaNf+VKDD+QbTZp1kooRTuAd8JirzrFpQ2g49YOX9owsPAwJHas9XEzMDcZl+JkdD9tHE0GhsEm1JN+6GMP0blW4rcRuogsVW3+7iqqlPyShtT+bVeuwJ1s3VWWtLcams/JbpOkJ6HyqZlge6g1PvfiobD0j4UQA7Xy/SNPJ6pU4Yj8Um7/BL7lOh6M13cx44DFGQSGmsuu7PyH6AHLNmFpsjO+bba8C0TyOTHeqXIr4KCQKSE+IjPnXmK2g/cUBGGwtgNs7SHLNFwQPdRhm3zDPMS7Rz/ki0SQTpHGYiXAv/HbhV5tfVkjIjYwozlgLqbdYMWEG6cIztPXpJOQlVOv3jLvMAGUz3C0zhkLNnWuayvPxVpGs0qf812sfp7RzWxR93afdNWYbumKj0vHbPp/Yx3zEyTd5xuYVKoFsYFU9gWWnyD5tBBTJYeIqQ55rZ8A/1Xb2lG6z5A35tL49GTbhCJIOQmGmAt/Acx4J0rtMR5l7pEYX+dvW+ZG0w== X-OriginatorOrg: nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 88d2f18d-c9f1-4dbe-f936-08dcfa4fa23d X-MS-Exchange-CrossTenant-AuthSource: AS8PR04MB8898.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 01 Nov 2024 08:31:51.2412 (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: t07FcjMgDkWfphV3s4Q1MDonBj+VP7PY8HJLU5S+D2xfhbtb93OuIOp4LzGUTUFuklxoFOUioz4TCvCJ9isVRQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: PA2PR04MB10215 This adds a new Broadcast Receiver test, for a Broadcast Sink synchronizing to 2 Broadcasters, using defer setup. ISO Broadcaster Receiver2 Defer - Success --- tools/iso-tester.c | 80 +++++++++++++++++++++++++++++++++++----------- 1 file changed, 61 insertions(+), 19 deletions(-) diff --git a/tools/iso-tester.c b/tools/iso-tester.c index 6215fd456..5ec8634ac 100644 --- a/tools/iso-tester.c +++ b/tools/iso-tester.c @@ -518,7 +518,8 @@ struct iso_client_data { bool no_poll_errqueue; }; -typedef bool (*iso_defer_accept_t)(struct test_data *data, GIOChannel *io); +typedef bool (*iso_defer_accept_t)(struct test_data *data, GIOChannel *io, + uint8_t num, GIOFunc func); static void mgmt_debug(const char *str, void *user_data) { @@ -1446,6 +1447,16 @@ static const struct iso_client_data bcast_16_2_1_recv_defer = { .big = true, }; +static const struct iso_client_data bcast_16_2_1_recv2_defer = { + .qos = QOS_IN_16_2_1, + .expect_err = 0, + .defer = true, + .bcast = true, + .server = true, + .listen_bind = true, + .big = true, +}; + static const struct iso_client_data bcast_16_2_1_recv_defer_no_bis = { .qos = QOS_IN_16_2_1, .expect_err = 0, @@ -2923,7 +2934,8 @@ static void setup_listen(struct test_data *data, uint8_t num, GIOFunc func) return setup_listen_many(data, 1, &num, &func); } -static bool iso_defer_accept_bcast(struct test_data *data, GIOChannel *io) +static bool iso_defer_accept_bcast(struct test_data *data, GIOChannel *io, + uint8_t num, GIOFunc func) { int sk; char c; @@ -2957,17 +2969,20 @@ static bool iso_defer_accept_bcast(struct test_data *data, GIOChannel *io) tester_print("Accept deferred setup"); - data->io_queue = queue_new(); + if (!data->io_queue) + data->io_queue = queue_new(); + if (data->io_queue) queue_push_tail(data->io_queue, io); - data->io_id[0] = g_io_add_watch(io, G_IO_IN, - iso_accept_cb, NULL); + data->io_id[num] = g_io_add_watch(io, G_IO_IN, + func, NULL); return true; } -static bool iso_defer_accept_ucast(struct test_data *data, GIOChannel *io) +static bool iso_defer_accept_ucast(struct test_data *data, GIOChannel *io, + uint8_t num, GIOFunc func) { int sk; char c; @@ -2997,19 +3012,20 @@ static bool iso_defer_accept_ucast(struct test_data *data, GIOChannel *io) if (data->io_queue) queue_push_tail(data->io_queue, io); - data->io_id[0] = g_io_add_watch(io, G_IO_OUT, - iso_connect_cb, NULL); + data->io_id[num] = g_io_add_watch(io, G_IO_OUT, + func, NULL); return true; } static gboolean iso_accept(GIOChannel *io, GIOCondition cond, - gpointer user_data) + gpointer user_data, uint8_t num, GIOFunc func) { struct test_data *data = tester_get_data(); const struct iso_client_data *isodata = data->test_data; int sk, new_sk; gboolean ret; + GIOChannel *new_io; iso_defer_accept_t iso_defer_accept = isodata->bcast ? iso_defer_accept_bcast : iso_defer_accept_ucast; @@ -3022,26 +3038,32 @@ static gboolean iso_accept(GIOChannel *io, GIOCondition cond, return false; } - io = g_io_channel_unix_new(new_sk); - g_io_channel_set_close_on_unref(io, TRUE); + new_io = g_io_channel_unix_new(new_sk); + g_io_channel_set_close_on_unref(new_io, TRUE); if (isodata->defer) { if (isodata->expect_err < 0) { - g_io_channel_unref(io); + g_io_channel_unref(new_io); tester_test_passed(); return false; } if (isodata->bcast) { - iso_connect(io, cond, user_data); + iso_connect(new_io, cond, user_data); if (!data->step) { - g_io_channel_unref(io); + g_io_channel_unref(new_io); + return false; + } + + /* Return if connection has already been accepted */ + if (queue_find(data->io_queue, NULL, io)) { + g_io_channel_unref(new_io); return false; } } - if (!iso_defer_accept(data, io)) { + if (!iso_defer_accept(data, new_io, num, func)) { tester_warn("Unable to accept deferred setup"); tester_test_failed(); } @@ -3060,9 +3082,9 @@ static gboolean iso_accept(GIOChannel *io, GIOCondition cond, } } - ret = iso_connect(io, cond, user_data); + ret = iso_connect(new_io, cond, user_data); - g_io_channel_unref(io); + g_io_channel_unref(new_io); return ret; } @@ -3070,10 +3092,14 @@ static gboolean iso_accept_cb(GIOChannel *io, GIOCondition cond, gpointer user_data) { struct test_data *data = tester_get_data(); + const struct iso_client_data *isodata = data->test_data; data->io_id[0] = 0; - return iso_accept(io, cond, user_data); + if (isodata->bcast) + return iso_accept(io, cond, user_data, 0, iso_accept_cb); + else + return iso_accept(io, cond, user_data, 0, iso_connect_cb); } static gboolean iso_accept2_cb(GIOChannel *io, GIOCondition cond, @@ -3083,7 +3109,7 @@ static gboolean iso_accept2_cb(GIOChannel *io, GIOCondition cond, data->io_id[1] = 0; - return iso_accept(io, cond, user_data); + return iso_accept(io, cond, user_data, 1, iso_accept2_cb); } static void test_listen(const void *test_data) @@ -3379,6 +3405,17 @@ static void test_bcast_recv_defer(const void *test_data) setup_listen(data, 0, iso_accept_cb); } +static void test_bcast_recv2_defer(const void *test_data) +{ + struct test_data *data = tester_get_data(); + uint8_t num[2] = {0, 1}; + GIOFunc funcs[2] = {iso_accept_cb, iso_accept2_cb}; + + data->step = 2; + + setup_listen_many(data, 2, num, funcs); +} + static void test_connect2_suspend(const void *test_data) { test_connect2(test_data); @@ -3770,6 +3807,11 @@ int main(int argc, char *argv[]) &bcast_16_2_1_recv_defer, setup_powered, test_bcast_recv_defer); + test_iso2("ISO Broadcaster Receiver2 Defer - Success", + &bcast_16_2_1_recv2_defer, + setup_powered, + test_bcast_recv2_defer); + test_iso("ISO Broadcaster Receiver Defer No BIS - Success", &bcast_16_2_1_recv_defer_no_bis, setup_powered,