From patchwork Sat Mar 5 01:22:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 548607 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 ABC5FC433F5 for ; Sat, 5 Mar 2022 01:22:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230372AbiCEBXY (ORCPT ); Fri, 4 Mar 2022 20:23:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230367AbiCEBXW (ORCPT ); Fri, 4 Mar 2022 20:23:22 -0500 Received: from mail-pl1-x630.google.com (mail-pl1-x630.google.com [IPv6:2607:f8b0:4864:20::630]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 80076656A for ; Fri, 4 Mar 2022 17:22:32 -0800 (PST) Received: by mail-pl1-x630.google.com with SMTP id bd1so9192382plb.13 for ; Fri, 04 Mar 2022 17:22:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=5+rBSTF3sbYgAZ1sTD//Ehy88r9kNGpqp/Y56gyqolU=; b=AIX0a+jvpvzzGM7soW3THUzWjg7hWBan8r30HiAEvkRtU6GUt/WykLFjFiSgthQqcO M59QxvsCFxVmgeJSnuFDylFVZ2tGBQJqj8YJNoIUPKRkdg6Fbq8Log0qvoyIQwOw9Zoy QNHJfQGYgvOKS2ygtwcgGgs1f8In1w1r+jUfZvJV4ZZO1Hm8Jf9HDOIWS99upZNymiEg qEQBG+GGhhVlXWNcKOi1uVR4zLPzudQVmazVKroPWlG719rHwQWd8Zec+Brq7F3aaUrp /beQrQbaAj6AokZAKQ5yaqaMaLdij/S2rWPdy9Pk5dVLkrxvY0IAq2Fj8b+FDYhlIayF ak1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5+rBSTF3sbYgAZ1sTD//Ehy88r9kNGpqp/Y56gyqolU=; b=efp+Act6b2E7/ta/6rmcISDS9Wyidsujq50wASLwTJck3g4cVSPChwlFkcMqzItgIo BqIbFteplXRa6oYx0Zxk8uNK2IYGyqG4hqiW+4GW5RReK9l8EF398c+4zMsWaGbH6PA3 gyJc7fhhhEPef7zsfeqJJVWPGU73qNyaZGDBroMa5/6JrF5OvBwi0Qeg7Yykqkj2e4g/ SQasU+doLF3himgtqMu1naf2rmhO1HrSZCUTeNoBKSVbbcixR3b4yaNMQHf/r/rOKzcX 0hUaXRo1xvJAvWFil7HtEpySBG0D6572vBn95VqvJsUitbNIRqOd6dQQtCcuBY7ssfHu IBbg== X-Gm-Message-State: AOAM532PPVFa5sFVSJmGlrpA/SxrucT6pLV8xesEn6Mv+1aXsuwdmuqb zjnTcLrQiu1Dhol2TKIs8a3vwqKmYeM= X-Google-Smtp-Source: ABdhPJx8ti6cWcjtgAu2smAsHE/B624/kMwXAD/hkRH2G0RiHHVhqb3RZzdp4jBeo32sBCBFedhn3Q== X-Received: by 2002:a17:902:cec8:b0:151:cac8:f0a2 with SMTP id d8-20020a170902cec800b00151cac8f0a2mr1189321plg.12.1646443351815; Fri, 04 Mar 2022 17:22:31 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id m16-20020a638c10000000b0037c4cf366c0sm5363932pgd.61.2022.03.04.17.22.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 17:22:31 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v2 01/12] monitor: Fix Create BIG PDU Date: Fri, 4 Mar 2022 17:22:18 -0800 Message-Id: <20220305012229.853784-2-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220305012229.853784-1-luiz.dentz@gmail.com> References: <20220305012229.853784-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz The PDU of Create BIG is actually fixed size as the num_bis is related to the number of indexes to be connected and not the BIS parameters. --- emulator/btdev.c | 2 +- monitor/bt.h | 2 +- monitor/packet.c | 9 ++------- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index 378674010..9189e8082 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -5692,10 +5692,10 @@ static int cmd_create_big_complete(struct btdev *dev, const void *data, uint8_t len) { const struct bt_hci_cmd_le_create_big *cmd = data; + const struct bt_hci_bis *bis = &cmd->bis; int i; for (i = 0; i < cmd->num_bis; i++) { - const struct bt_hci_bis *bis = &cmd->bis[i]; struct btdev_conn *conn; struct { struct bt_hci_evt_le_big_complete evt; diff --git a/monitor/bt.h b/monitor/bt.h index 66ed3ef5a..51b1833dc 100644 --- a/monitor/bt.h +++ b/monitor/bt.h @@ -2758,7 +2758,7 @@ struct bt_hci_cmd_le_create_big { uint8_t handle; uint8_t adv_handle; uint8_t num_bis; - struct bt_hci_bis bis[0]; + struct bt_hci_bis bis; } __attribute__ ((packed)); #define BT_HCI_CMD_LE_CREATE_BIG_TEST 0x2069 diff --git a/monitor/packet.c b/monitor/packet.c index ec779a9d5..a17c632a7 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -8200,10 +8200,8 @@ static void le_reject_cis_req_cmd(const void *data, uint8_t size) print_reason(cmd->reason); } -static void print_bis(const void *data, int i) +static void print_bis(const struct bt_hci_bis *bis) { - const struct bt_hci_bis *bis = data; - print_usec_interval("SDU Interval", bis->sdu_interval); print_field("Maximum SDU size: %u", le16_to_cpu(bis->sdu)); print_field("Maximum Latency: %u ms (0x%4.4x)", @@ -8223,10 +8221,7 @@ static void le_create_big_cmd(const void *data, uint8_t size) print_field("Handle: 0x%2.2x", cmd->handle); print_field("Advertising Handle: 0x%2.2x", cmd->adv_handle); print_field("Number of BIS: %u", cmd->num_bis); - - size -= sizeof(*cmd); - - print_list(cmd->bis, size, cmd->num_bis, sizeof(*cmd->bis), print_bis); + print_bis(&cmd->bis); } static void print_bis_test(const void *data, int i) From patchwork Sat Mar 5 01:22:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 548756 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 B1431C433FE for ; Sat, 5 Mar 2022 01:22:38 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230373AbiCEBXZ (ORCPT ); Fri, 4 Mar 2022 20:23:25 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230369AbiCEBXW (ORCPT ); Fri, 4 Mar 2022 20:23:22 -0500 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5F5AE1B783 for ; Fri, 4 Mar 2022 17:22:33 -0800 (PST) Received: by mail-pl1-x62c.google.com with SMTP id z11so9220180pla.7 for ; Fri, 04 Mar 2022 17:22:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=5GrbTgGybIX7VE+dUMBOi9DeNkU5nTUZSPVbLy7V1tY=; b=kKhLU9byVsSBR8dhMqfJZLMSw2ol10UbHYZOeBBL2X+Brd9Szbm+hDorp7fovOL95/ bn1wJr77U8twJIogjzbGdQj3D7p/2iZeIepMnuesn1SYLWfzjBSylVGbdqoG6rdA4LQF a6Ws/L1KAQjnPj1BwWejNh1c4C8pAGDNA8dcUj061kcowpeeEELsDYkcI5QbyNpAsx/V UP21Q1M+tOS7EX524bg6ZGVjML6ZoFg0+YqfI58cOsj7SbP8E3EqbOobZSOp85NyGqJI Xv9dvtCewzvNtO2KWLKLQeJ8uIZsYmbBRAf1cogthqXPrGurEg2GTlWPPlFIMughwP2Q tokg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=5GrbTgGybIX7VE+dUMBOi9DeNkU5nTUZSPVbLy7V1tY=; b=XAdc7CJAbo/bBaFau7VvBgoSgtSxvMni9Hd17ClBPNM3PQ5xNWajU7N+JS6qlao+1v 2NGBrwqF823fumFR5CzyhaIY0Oegwpdp43XBhJ1vDh7+GinuM+P8WF5bRgm7VgBk+oaq pNheYqhuNXbPbKCAzYIIItPLR9EL5t9cxItI/98ErvVs+ILPMGlLJYkEfHt4HKtvQoO8 V19jidq6rGi60yYbn0t9hdRsr8Xd/vjpE5xKMXdE3koKo3784VdXAYF1UVhGReJSgBfn FIk5e1cYtUrzDF1k4+q8oM255Cu73bNfnJRMTgT15AQ8cYwT/HupTjld2PS/94h8NrpY dkfQ== X-Gm-Message-State: AOAM532SQr9trcgkqW1KxhhXE+IdjU8gvjIOMZCkyMIFIrdE0BCudDRs cgAOHKZ0r9PMWpPhZoMPlsAtrclyFXE= X-Google-Smtp-Source: ABdhPJx6kEVIfNpiSGQjANMGd3kWTjgh/SwedojKUSac5T11WuyYoluaEG6Dids9UBZx6N04Wq/dFA== X-Received: by 2002:a17:90b:3ec9:b0:1bf:3158:9057 with SMTP id rm9-20020a17090b3ec900b001bf31589057mr3927130pjb.228.1646443352569; Fri, 04 Mar 2022 17:22:32 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id m16-20020a638c10000000b0037c4cf366c0sm5363932pgd.61.2022.03.04.17.22.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 17:22:32 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v2 02/12] btdev: Implement BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC Date: Fri, 4 Mar 2022 17:22:19 -0800 Message-Id: <20220305012229.853784-3-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220305012229.853784-1-luiz.dentz@gmail.com> References: <20220305012229.853784-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds implementation of BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC generating BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED and BT_HCI_EVT_LE_PER_ADV_REPORT. --- emulator/btdev.c | 99 ++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 96 insertions(+), 3 deletions(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index 9189e8082..34469d986 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -47,6 +47,7 @@ #define ACL_HANDLE 42 #define ISO_HANDLE 257 #define SCO_HANDLE 257 +#define SYC_HANDLE 1 struct hook { btdev_hook_func handler; @@ -195,6 +196,7 @@ struct btdev { uint16_t le_periodic_max_interval; uint8_t le_periodic_data_len; uint8_t le_periodic_data[31]; + uint16_t le_periodic_sync_handle; uint8_t le_ltk[16]; struct { struct bt_hci_cmd_le_set_cig_params params; @@ -5294,8 +5296,99 @@ static int cmd_ext_create_conn_complete(struct btdev *dev, const void *data, static int cmd_per_adv_create_sync(struct btdev *dev, const void *data, uint8_t len) { - /* TODO */ - return -ENOTSUP; + uint8_t status = BT_HCI_ERR_SUCCESS; + + if (dev->le_periodic_sync_handle) + status = BT_HCI_ERR_MEM_CAPACITY_EXCEEDED; + else + dev->le_periodic_sync_handle = SYC_HANDLE; + + cmd_status(dev, status, BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC); + + return 0; +} + +static void send_per_adv(struct btdev *dev, const struct btdev *remote, + uint8_t offset) +{ + struct __packed { + struct bt_hci_le_per_adv_report ev; + uint8_t data[31]; + } pdu; + + memset(&pdu.ev, 0, sizeof(pdu.ev)); + pdu.ev.handle = cpu_to_le16(dev->le_periodic_sync_handle); + pdu.ev.tx_power = 127; + pdu.ev.rssi = 127; + pdu.ev.cte_type = 0x0ff; + + if ((size_t) remote->le_periodic_data_len - offset > sizeof(pdu.data)) { + pdu.ev.data_status = 0x01; + pdu.ev.data_len = sizeof(pdu.data); + } else { + pdu.ev.data_status = 0x00; + pdu.ev.data_len = remote->le_periodic_data_len - offset; + } + + memcpy(pdu.data, remote->le_periodic_data + offset, pdu.ev.data_len); + + le_meta_event(dev, BT_HCI_EVT_LE_PER_ADV_REPORT, &pdu, + sizeof(pdu.ev) + pdu.ev.data_len); + + if (pdu.ev.data_status == 0x01) { + offset += pdu.ev.data_len; + send_per_adv(dev, remote, offset); + } +} + +static void le_per_adv_sync_estabilished(struct btdev *dev, + const struct bt_hci_cmd_le_periodic_adv_create_sync *cmd, + struct btdev *remote, uint8_t status) +{ + struct bt_hci_evt_le_per_sync_established ev; + + memset(&ev, 0, sizeof(ev)); + ev.status = status; + + if (status) { + le_meta_event(dev, BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED, &ev, + sizeof(ev)); + return; + } + + ev.handle = cpu_to_le16(dev->le_periodic_sync_handle); + ev.addr_type = cmd->addr_type; + memcpy(ev.addr, cmd->addr, sizeof(ev.addr)); + ev.phy = 0x01; + ev.interval = remote->le_periodic_min_interval; + ev.clock_accuracy = 0x07; + + le_meta_event(dev, BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED, &ev, sizeof(ev)); + send_per_adv(dev, remote, 0); +} + +static int cmd_per_adv_create_sync_complete(struct btdev *dev, const void *data, + uint8_t len) +{ + const struct bt_hci_cmd_le_periodic_adv_create_sync *cmd = data; + struct btdev *remote; + + /* This command may be issued whether or not scanning is enabled and + * scanning may be enabled and disabled (see the LE Set Extended Scan + * Enable command) while this command is pending. However, + * synchronization can only occur when scanning is enabled. While + * scanning is disabled, no attempt to synchronize will take place. + */ + if (!dev->scan_enable) + return 0; + + remote = find_btdev_by_bdaddr_type(cmd->addr, cmd->addr_type); + if (!remote || !remote->le_periodic_adv_enable) + return 0; + + le_per_adv_sync_estabilished(dev, cmd, remote, BT_HCI_ERR_SUCCESS); + + return 0; } static int cmd_per_adv_create_sync_cancel(struct btdev *dev, const void *data, @@ -5420,7 +5513,7 @@ done: CMD(BT_HCI_CMD_LE_EXT_CREATE_CONN, cmd_ext_create_conn, \ cmd_ext_create_conn_complete), \ CMD(BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC, cmd_per_adv_create_sync, \ - NULL), \ + cmd_per_adv_create_sync_complete), \ CMD(BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC_CANCEL, \ cmd_per_adv_create_sync_cancel, NULL), \ CMD(BT_HCI_CMD_LE_PERIODIC_ADV_TERM_SYNC, cmd_per_adv_term_sync, \ From patchwork Sat Mar 5 01:22:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 548606 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 B240BC433F5 for ; Sat, 5 Mar 2022 01:22:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230379AbiCEBX1 (ORCPT ); Fri, 4 Mar 2022 20:23:27 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58054 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230375AbiCEBXZ (ORCPT ); Fri, 4 Mar 2022 20:23:25 -0500 Received: from mail-pf1-x435.google.com (mail-pf1-x435.google.com [IPv6:2607:f8b0:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8004928E36 for ; Fri, 4 Mar 2022 17:22:34 -0800 (PST) Received: by mail-pf1-x435.google.com with SMTP id a5so9007982pfv.9 for ; Fri, 04 Mar 2022 17:22:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=gkECUbgP6SwJ+vdtBxsDCIGBwm8Bgzi3GVBj8I4iC20=; b=Ev9b6z8Hu3KGcnmv0g6FIGv2OvbcQsRdHwJzyeqzuJADKP76JUUucSfXgKWx0wYsoR F/fNfzrGWjg7mVDdYKNhM5d/cYJFcjJcEp129CiY3Q0rQevfU2vVWAaiwvMOkxrtD14p tTLHCckMDviQ0hk6lhc624qw+VMJNU6cKsJaApI7IxusjuA/zteJCc6zGzBIAjNS5VrC F7VuAJuklbLOhAgvMPyYwZeEaogMNefroZi1Yhlg+h6/b5aqVkQNQ08zoGFiB4bZWfOP X1OfXogBY/VM39ml/FYIjUXdTLp3y8iaKnBq9VJeHTL7xlN2pe5NbKkT5y708wBkx8ZF dc2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gkECUbgP6SwJ+vdtBxsDCIGBwm8Bgzi3GVBj8I4iC20=; b=QiqhlhsLcx3eeXM0IBFAE/vCPZkmFnxMekO3yKm2Oj3jHQ0RDOE8Q3765UUWFKH4W7 AW7EC3KSkN0TwRaMTEthKLoD0ak8IEHC+f+R/ij9t2nu8sRMxVmQXfsJoUpJCPt2thvm PNxpRGeK1ZSUcUzlaFblnX8w4Fi4Lg0dIIKNnOPfb7wYRhwm4lvGaJLylBTR5Dc2mpYv Njl4tV7bP08AZSx4msMzw/LBQBLPIFi9lBi0DSGdZMsjO8GGxqLgDv3sdgH3dti9vwbg 5i3fkkFyMb7st0JQGfmBXPUsBu9EOkPtUhYV0KdDzIc6BO2Fuq0XxOYMrfogEUKoC9Z0 dCrg== X-Gm-Message-State: AOAM530IyhfOc4CDqtDux1wiFEpvGhacfSiYtqArpN32N0kDQdNicJs3 VXhxAbH7FSiXh2uc7bycUJ4fiBd3fCM= X-Google-Smtp-Source: ABdhPJwnvIsHSaYHM/XmvfblFF6bm1xSnq5njryOujUnDFOdZNdrd1CMMCXgsBB9iKFc7Dh7RePmzA== X-Received: by 2002:aa7:8d47:0:b0:4f6:a7f9:1ead with SMTP id s7-20020aa78d47000000b004f6a7f91eadmr1338050pfe.42.1646443353320; Fri, 04 Mar 2022 17:22:33 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id m16-20020a638c10000000b0037c4cf366c0sm5363932pgd.61.2022.03.04.17.22.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 17:22:32 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v2 03/12] btdev: Implement BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC_CANCEL Date: Fri, 4 Mar 2022 17:22:20 -0800 Message-Id: <20220305012229.853784-4-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220305012229.853784-1-luiz.dentz@gmail.com> References: <20220305012229.853784-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds implementation of BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC_CANCEL generating BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED if necessary. --- emulator/btdev.c | 30 +++++++++++++++++++++++++++--- monitor/bt.h | 1 + 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index 34469d986..09101a5df 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -48,6 +48,7 @@ #define ISO_HANDLE 257 #define SCO_HANDLE 257 #define SYC_HANDLE 1 +#define INV_HANDLE 0xffff struct hook { btdev_hook_func handler; @@ -5301,7 +5302,7 @@ static int cmd_per_adv_create_sync(struct btdev *dev, const void *data, if (dev->le_periodic_sync_handle) status = BT_HCI_ERR_MEM_CAPACITY_EXCEEDED; else - dev->le_periodic_sync_handle = SYC_HANDLE; + dev->le_periodic_sync_handle = INV_HANDLE; cmd_status(dev, status, BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC); @@ -5351,11 +5352,14 @@ static void le_per_adv_sync_estabilished(struct btdev *dev, ev.status = status; if (status) { + dev->le_periodic_sync_handle = 0x0000; le_meta_event(dev, BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED, &ev, sizeof(ev)); return; } + dev->le_periodic_sync_handle = SYC_HANDLE; + ev.handle = cpu_to_le16(dev->le_periodic_sync_handle); ev.addr_type = cmd->addr_type; memcpy(ev.addr, cmd->addr, sizeof(ev.addr)); @@ -5394,8 +5398,28 @@ static int cmd_per_adv_create_sync_complete(struct btdev *dev, const void *data, static int cmd_per_adv_create_sync_cancel(struct btdev *dev, const void *data, uint8_t len) { - /* TODO */ - return -ENOTSUP; + uint8_t status = BT_HCI_ERR_SUCCESS; + + /* If the Host issues this command while no + * HCI_LE_Periodic_Advertising_Create_Sync command is pending, the + * Controller shall return the error code Command Disallowed (0x0C). + */ + if (dev->le_periodic_sync_handle != INV_HANDLE) + status = BT_HCI_ERR_COMMAND_DISALLOWED; + + cmd_complete(dev, BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC_CANCEL, + &status, sizeof(status)); + + /* After the HCI_Command_Complete is sent and if the cancellation was + * successful, the Controller sends an + * HCI_LE_Periodic_Advertising_Sync_Established event to the Host with + * the error code Operation Cancelled by Host (0x44). + */ + if (!status) + le_per_adv_sync_estabilished(dev, NULL, NULL, + BT_HCI_ERR_CANCELLED); + + return 0; } static int cmd_per_adv_term_sync(struct btdev *dev, const void *data, diff --git a/monitor/bt.h b/monitor/bt.h index 51b1833dc..b6b6c49e1 100644 --- a/monitor/bt.h +++ b/monitor/bt.h @@ -3660,6 +3660,7 @@ struct bt_hci_evt_le_req_peer_sca_complete { #define BT_HCI_ERR_ADV_TIMEOUT 0x3c #define BT_HCI_ERR_CONN_FAILED_TO_ESTABLISH 0x3e #define BT_HCI_ERR_UNKNOWN_ADVERTISING_ID 0x42 +#define BT_HCI_ERR_CANCELLED 0x44 struct bt_l2cap_hdr { uint16_t len; From patchwork Sat Mar 5 01:22:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 548605 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 9811DC433EF for ; Sat, 5 Mar 2022 01:22:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230384AbiCEBX3 (ORCPT ); Fri, 4 Mar 2022 20:23:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58056 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230376AbiCEBXZ (ORCPT ); Fri, 4 Mar 2022 20:23:25 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E5DF462F4 for ; Fri, 4 Mar 2022 17:22:34 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id ge19-20020a17090b0e1300b001bcca16e2e7so11938659pjb.3 for ; Fri, 04 Mar 2022 17:22:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=9Y5pgaVkXyazSAz0gklrbyoOTE7TwpdgHa0U0KeOhL0=; b=WC4uB+xcx94pbVKG3sJr0QpXg3azbv/9Phqws4rjY37LiJMYI23OxqwNkYAm9/l1lF hlQ0++qcWwRCDRrY+mimjgezy8Qq3jrv0g3n783So4UwC2jvb5kEw9Jhtd0P2aNW2Wo4 FtaOYl/PJfwUFhq0qLkUndS+rXR2Io/e/dhhay5ZAKZ8tCzSfiZ/49HmeIcJgFz4n/zJ zcZdjF96abumBht/+LGen2DjiDWAALwcABwYGLST/hMtsGmdaJPmCbdMTzPC2kN/li3H JZfwtk4EsxWIg8yUIT8jz0nLVvUwX68XNJ8lBwmlCFGoIIo3IieKxzSnQ9nIqbVOtNoK q0Yw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9Y5pgaVkXyazSAz0gklrbyoOTE7TwpdgHa0U0KeOhL0=; b=3tUQW0ZB3xTIkGrJu23YKGVNfpYLvPK7VN+uPyQMgMuYuaiKcL4ZK8n0C/1N0x9v3S hZQ2wcWNOumbYBALDFJgFOylx2OBu1f8fkCtO+iYf9837+Dfh7qpdnat7+CSE7W3gPOB mGKhC74D4SEtao9xqCPUt3tPfzHHI3ZJrw1rZ5VXdRN/ji2AASzgDJDbyoVZSdGr31Ny DW9GPX4OgMOLbard6pXw+xAcqyQ+RpsWJrJw96U2uT1XrUxnxL/2OvLtqe4WvIoNmHWg xg+wEx5ujeNDUnsFWuz6KwEYJSzETs9h4iabxlrDXUJ4sp+MVHfqDZFbgzWJ2JbAalh2 PMwA== X-Gm-Message-State: AOAM530LPRV5kevckQdVLzef4FcvYUy0X1bbaM5mpFzmcLAWpt0dqr/Z FV0qPyJ3WHNUvHEIZaSJ2myoqDcTU9A= X-Google-Smtp-Source: ABdhPJzqMwgfwrJzv2gWA3xOGhEjJJwA/+WsJj1lLmuztF2GjiZ5kF9d0+D3E7yEfkD9ZhzkyuY4Zw== X-Received: by 2002:a17:90b:17d1:b0:1bf:1e3:ded3 with SMTP id me17-20020a17090b17d100b001bf01e3ded3mr13531137pjb.144.1646443354194; Fri, 04 Mar 2022 17:22:34 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id m16-20020a638c10000000b0037c4cf366c0sm5363932pgd.61.2022.03.04.17.22.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 17:22:33 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v2 04/12] btdev: Implement BT_HCI_CMD_LE_PERIODIC_ADV_TERM_SYNC Date: Fri, 4 Mar 2022 17:22:21 -0800 Message-Id: <20220305012229.853784-5-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220305012229.853784-1-luiz.dentz@gmail.com> References: <20220305012229.853784-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds implementation of BT_HCI_CMD_LE_PERIODIC_ADV_TERM_SYNC. --- emulator/btdev.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index 09101a5df..15689137c 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -5425,8 +5425,21 @@ static int cmd_per_adv_create_sync_cancel(struct btdev *dev, const void *data, static int cmd_per_adv_term_sync(struct btdev *dev, const void *data, uint8_t len) { - /* TODO */ - return -ENOTSUP; + uint8_t status = BT_HCI_ERR_SUCCESS; + + /* 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_periodic_sync_handle != SYC_HANDLE) + status = BT_HCI_ERR_UNKNOWN_ADVERTISING_ID; + else + dev->le_periodic_sync_handle = 0x0000; + + cmd_complete(dev, BT_HCI_CMD_LE_PERIODIC_ADV_TERM_SYNC, + &status, sizeof(status)); + + return 0; } static int cmd_per_adv_add(struct btdev *dev, const void *data, uint8_t len) From patchwork Sat Mar 5 01:22:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 548755 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 85D83C433FE for ; Sat, 5 Mar 2022 01:22:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230383AbiCEBX2 (ORCPT ); Fri, 4 Mar 2022 20:23:28 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58058 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230374AbiCEBXZ (ORCPT ); Fri, 4 Mar 2022 20:23:25 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4227656A for ; Fri, 4 Mar 2022 17:22:35 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id c16-20020a17090aa61000b001befad2bfaaso8954026pjq.1 for ; Fri, 04 Mar 2022 17:22:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=CB84GU+65qC35bo/M0ozl8Z6qSqDAdXZpXKDOuBUTfg=; b=kr14BqESTdxZ43FFq/qYirg/s7flosm5xqG/R1cSVQhCE/stYxyMKBNrfogWVNsxBR vNxSFCxO+uEzgOqSQkA3kUJzo7edlnELd2eE18BN3ukvOCP670kYU1fVvvlcIvNgLevo uSADkLlnscChJdhQlMU6X3URjbloVPfcmYzOpCuc1mLopkcIx8kCIs19TSh70PELriTO 25uu3q7cGY+vK4HQYuchZZgIyH6iZxyNKudkHe9CdwnOHMYTikOwgjUS+IEjNs5x7VB3 XShRen55Z6+XTc3HraAIOjmb83/v7ZQa7Ap6D6eyDjKmbygAJptS/YVv7NCMatmfIh30 slzw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CB84GU+65qC35bo/M0ozl8Z6qSqDAdXZpXKDOuBUTfg=; b=S0MqDpnAzlrH94Z3tyHgI2ExMXjAagYLDpVJij2yynM/F23vSas04nFw/OkfyCK1jU RTo5QwtzemkCYJvW5Df9FWlyj7Cw/fMia74pkmJNaBWYhAMF/I3+c3+CRezylFSB7qqc ZBM+aVrEClcg8oxSvDDNfGE08P7uLtt07cuLhVv0jgqZe7vRvjoZGUQg5of5hGKlt8aW 2rPRWjN3fa7+y8YEsvyxc0ZBMnzkJLiJaw/2r3Sl0o5WMnZ+3zBEzrQWuZ5sINfIHwPk dUKaTCe1fM3gwkyEMPaj2jejfKMF+VJ5OHXamiWqz37oCUYtsxEYNxfvMOWp2f1tdmmB ifiw== X-Gm-Message-State: AOAM532/Cw7OHNqkoas9i5XRJh4iWytkJeSLO32iEgNlbEZkzHjdE7zl jbdwDV1YZKhST04vFbah2xqTY0a4Cxo= X-Google-Smtp-Source: ABdhPJyUU0PnHc8u+NJfdiv+o21Tbt2FeEcpfQ53qA+hD7BnzcQY9iZQaCGU8D4cb2fgwSJTcvr0sg== X-Received: by 2002:a17:90b:2486:b0:1bc:9d6a:f22 with SMTP id nt6-20020a17090b248600b001bc9d6a0f22mr13557401pjb.211.1646443354929; Fri, 04 Mar 2022 17:22:34 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id m16-20020a638c10000000b0037c4cf366c0sm5363932pgd.61.2022.03.04.17.22.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 17:22:34 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v2 05/12] btdev: Send BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED when scan is initiated Date: Fri, 4 Mar 2022 17:22:22 -0800 Message-Id: <20220305012229.853784-6-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220305012229.853784-1-luiz.dentz@gmail.com> References: <20220305012229.853784-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This sends BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED if scan is initiated while BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC is pending. --- emulator/btdev.c | 152 +++++++++++++++++++++++++++-------------------- 1 file changed, 86 insertions(+), 66 deletions(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index 15689137c..59014b535 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -197,6 +197,7 @@ struct btdev { uint16_t le_periodic_max_interval; uint8_t le_periodic_data_len; uint8_t le_periodic_data[31]; + struct bt_hci_cmd_le_periodic_adv_create_sync pa_sync_cmd; uint16_t le_periodic_sync_handle; uint8_t le_ltk[16]; struct { @@ -5160,6 +5161,85 @@ static void scan_ext_adv(struct btdev *dev, struct btdev *remote) } } +static void send_per_adv(struct btdev *dev, const struct btdev *remote, + uint8_t offset) +{ + struct __packed { + struct bt_hci_le_per_adv_report ev; + uint8_t data[31]; + } pdu; + + memset(&pdu.ev, 0, sizeof(pdu.ev)); + pdu.ev.handle = cpu_to_le16(dev->le_periodic_sync_handle); + pdu.ev.tx_power = 127; + pdu.ev.rssi = 127; + pdu.ev.cte_type = 0x0ff; + + if ((size_t) remote->le_periodic_data_len - offset > sizeof(pdu.data)) { + pdu.ev.data_status = 0x01; + pdu.ev.data_len = sizeof(pdu.data); + } else { + pdu.ev.data_status = 0x00; + pdu.ev.data_len = remote->le_periodic_data_len - offset; + } + + memcpy(pdu.data, remote->le_periodic_data + offset, pdu.ev.data_len); + + le_meta_event(dev, BT_HCI_EVT_LE_PER_ADV_REPORT, &pdu, + sizeof(pdu.ev) + pdu.ev.data_len); + + if (pdu.ev.data_status == 0x01) { + offset += pdu.ev.data_len; + send_per_adv(dev, remote, offset); + } +} + +static void le_per_adv_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_periodic_adv_create_sync *cmd = &dev->pa_sync_cmd; + + memset(&ev, 0, sizeof(ev)); + ev.status = status; + + if (status) { + memset(&dev->pa_sync_cmd, 0, sizeof(dev->pa_sync_cmd)); + dev->le_periodic_sync_handle = 0x0000; + le_meta_event(dev, BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED, &ev, + sizeof(ev)); + return; + } + + dev->le_periodic_sync_handle = SYC_HANDLE; + + ev.handle = cpu_to_le16(dev->le_periodic_sync_handle); + ev.addr_type = cmd->addr_type; + memcpy(ev.addr, cmd->addr, sizeof(ev.addr)); + ev.phy = 0x01; + ev.interval = remote->le_periodic_min_interval; + ev.clock_accuracy = 0x07; + + memset(&dev->pa_sync_cmd, 0, sizeof(dev->pa_sync_cmd)); + + le_meta_event(dev, BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED, &ev, sizeof(ev)); + send_per_adv(dev, remote, 0); +} + +static void scan_per_adv(struct btdev *dev, struct btdev *remote) +{ + if (dev->le_periodic_sync_handle != INV_HANDLE || + !remote->le_periodic_adv_enable) + return; + + + if (remote != find_btdev_by_bdaddr_type(dev->pa_sync_cmd.addr, + dev->pa_sync_cmd.addr_type)) + return; + + le_per_adv_sync_estabilished(dev, remote, BT_HCI_ERR_SUCCESS); +} + static int cmd_set_ext_scan_enable_complete(struct btdev *dev, const void *data, uint8_t len) { @@ -5174,6 +5254,7 @@ static int cmd_set_ext_scan_enable_complete(struct btdev *dev, const void *data, continue; scan_ext_adv(dev, btdev_list[i]); + scan_per_adv(dev, btdev_list[i]); } return 0; @@ -5301,76 +5382,16 @@ static int cmd_per_adv_create_sync(struct btdev *dev, const void *data, if (dev->le_periodic_sync_handle) status = BT_HCI_ERR_MEM_CAPACITY_EXCEEDED; - else + else { dev->le_periodic_sync_handle = INV_HANDLE; + memcpy(&dev->pa_sync_cmd, data, len); + } cmd_status(dev, status, BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC); return 0; } -static void send_per_adv(struct btdev *dev, const struct btdev *remote, - uint8_t offset) -{ - struct __packed { - struct bt_hci_le_per_adv_report ev; - uint8_t data[31]; - } pdu; - - memset(&pdu.ev, 0, sizeof(pdu.ev)); - pdu.ev.handle = cpu_to_le16(dev->le_periodic_sync_handle); - pdu.ev.tx_power = 127; - pdu.ev.rssi = 127; - pdu.ev.cte_type = 0x0ff; - - if ((size_t) remote->le_periodic_data_len - offset > sizeof(pdu.data)) { - pdu.ev.data_status = 0x01; - pdu.ev.data_len = sizeof(pdu.data); - } else { - pdu.ev.data_status = 0x00; - pdu.ev.data_len = remote->le_periodic_data_len - offset; - } - - memcpy(pdu.data, remote->le_periodic_data + offset, pdu.ev.data_len); - - le_meta_event(dev, BT_HCI_EVT_LE_PER_ADV_REPORT, &pdu, - sizeof(pdu.ev) + pdu.ev.data_len); - - if (pdu.ev.data_status == 0x01) { - offset += pdu.ev.data_len; - send_per_adv(dev, remote, offset); - } -} - -static void le_per_adv_sync_estabilished(struct btdev *dev, - const struct bt_hci_cmd_le_periodic_adv_create_sync *cmd, - struct btdev *remote, uint8_t status) -{ - struct bt_hci_evt_le_per_sync_established ev; - - memset(&ev, 0, sizeof(ev)); - ev.status = status; - - if (status) { - dev->le_periodic_sync_handle = 0x0000; - le_meta_event(dev, BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED, &ev, - sizeof(ev)); - return; - } - - dev->le_periodic_sync_handle = SYC_HANDLE; - - ev.handle = cpu_to_le16(dev->le_periodic_sync_handle); - ev.addr_type = cmd->addr_type; - memcpy(ev.addr, cmd->addr, sizeof(ev.addr)); - ev.phy = 0x01; - ev.interval = remote->le_periodic_min_interval; - ev.clock_accuracy = 0x07; - - le_meta_event(dev, BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED, &ev, sizeof(ev)); - send_per_adv(dev, remote, 0); -} - static int cmd_per_adv_create_sync_complete(struct btdev *dev, const void *data, uint8_t len) { @@ -5390,7 +5411,7 @@ static int cmd_per_adv_create_sync_complete(struct btdev *dev, const void *data, if (!remote || !remote->le_periodic_adv_enable) return 0; - le_per_adv_sync_estabilished(dev, cmd, remote, BT_HCI_ERR_SUCCESS); + le_per_adv_sync_estabilished(dev, remote, BT_HCI_ERR_SUCCESS); return 0; } @@ -5416,8 +5437,7 @@ static int cmd_per_adv_create_sync_cancel(struct btdev *dev, const void *data, * the error code Operation Cancelled by Host (0x44). */ if (!status) - le_per_adv_sync_estabilished(dev, NULL, NULL, - BT_HCI_ERR_CANCELLED); + le_per_adv_sync_estabilished(dev, NULL, BT_HCI_ERR_CANCELLED); return 0; } From patchwork Sat Mar 5 01:22:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 548754 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 28DE2C433F5 for ; Sat, 5 Mar 2022 01:22:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230394AbiCEBXb (ORCPT ); Fri, 4 Mar 2022 20:23:31 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58088 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230369AbiCEBXZ (ORCPT ); Fri, 4 Mar 2022 20:23:25 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C0D52A273 for ; Fri, 4 Mar 2022 17:22:36 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id v4so8687191pjh.2 for ; Fri, 04 Mar 2022 17:22:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=9UiSChX/MlhykLBJGD3Js3tynaUAJ9b+hYqI4IfTwkA=; b=AOTR/MBsuA96MJhVpb/pyOKZ2uVBH8KCtENrFIc7kw/AeUM3ekEB7xP77+1wyiS1Eo 0qYASJCiEmBMDqsIULkD/YJcp2BK/qjFT8UsDvBe8vQAw6N1OVg1Uylnjhnmi+7fPqFR LVtHMSnKPlIGmAOpFk47LEQaOpgpMRWG6TmY4J0XfEGlpC/lAe4F1YwwBQEAIc8aOjdN mMoSFWlickz830S4hPmJYNZArVmlZJvHvjBEnhlDeR+PlzDU1kFVAaTNtOgVdcWwwdiN /4fnftHBOS97PhgUAYqQEqoWvvs3SuP6oAjWXoKfQJrJ7eqFluHwwptRcpo7kv6dt+R7 9c4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9UiSChX/MlhykLBJGD3Js3tynaUAJ9b+hYqI4IfTwkA=; b=O60aDIiKscr01OXGIPJKXfR8C9EtHc9wwuZu6Sfzd94mb2WP/6gt/+9NSrEiUTkYtv dDBP1BMXKKTI0u3Yc1QqQQu6dNVgtLARAld4lYXrWsffFXpNKk/tzZCoHtXisswWcx4B 48r064+gPC6EcC65VMtt7H3Zi4GB9N+Sf/dEBxQYCRyo99HDE1kYxhe6J9CZkaA7xsQw yTIhUI5JCJU0aGJv7w0O6PsQD8q/tGevyIwcAkWB+KcdjhiKHvM4jh8Vc6kpfjJfhUZS TK/tfdBkeFYuWwYXRoRrZbv7FiGULCZWo2Rd0vFrVAu3iNJpd6fisQZ2rZOnmCQYxjzA YESA== X-Gm-Message-State: AOAM532IjoRjTkh9bNTFyYUvk1V+x/RVlz5NfQhCr99XZz3Ev2v1Du/m RyRZpRMyNY1ZxpwtZZ/7FWM4epleafs= X-Google-Smtp-Source: ABdhPJxNUOEboAy1mBNmpa0VHt4W+pry3pkzfEobFfAro4eJN9xJ0CFKTr0FenIHz4wjI4Pyk3ZH2w== X-Received: by 2002:a17:902:d2cd:b0:14f:c169:dc6f with SMTP id n13-20020a170902d2cd00b0014fc169dc6fmr1114099plc.170.1646443355779; Fri, 04 Mar 2022 17:22:35 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id m16-20020a638c10000000b0037c4cf366c0sm5363932pgd.61.2022.03.04.17.22.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 17:22:35 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v2 06/12] btdev: Send BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED if remote start pa Date: Fri, 4 Mar 2022 17:22:23 -0800 Message-Id: <20220305012229.853784-7-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220305012229.853784-1-luiz.dentz@gmail.com> References: <20220305012229.853784-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This sends BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED if remote device start to periodic advertise when BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC is pending. --- emulator/btdev.c | 144 +++++++++++++++++++++++++---------------------- 1 file changed, 78 insertions(+), 66 deletions(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index 59014b535..e79b0dc67 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -5044,11 +5044,77 @@ static int cmd_set_per_adv_data(struct btdev *dev, const void *data, return 0; } +static void send_per_adv(struct btdev *dev, const struct btdev *remote, + uint8_t offset) +{ + struct __packed { + struct bt_hci_le_per_adv_report ev; + uint8_t data[31]; + } pdu; + + memset(&pdu.ev, 0, sizeof(pdu.ev)); + pdu.ev.handle = cpu_to_le16(dev->le_periodic_sync_handle); + pdu.ev.tx_power = 127; + pdu.ev.rssi = 127; + pdu.ev.cte_type = 0x0ff; + + if ((size_t) remote->le_periodic_data_len - offset > sizeof(pdu.data)) { + pdu.ev.data_status = 0x01; + pdu.ev.data_len = sizeof(pdu.data); + } else { + pdu.ev.data_status = 0x00; + pdu.ev.data_len = remote->le_periodic_data_len - offset; + } + + memcpy(pdu.data, remote->le_periodic_data + offset, pdu.ev.data_len); + + le_meta_event(dev, BT_HCI_EVT_LE_PER_ADV_REPORT, &pdu, + sizeof(pdu.ev) + pdu.ev.data_len); + + if (pdu.ev.data_status == 0x01) { + offset += pdu.ev.data_len; + send_per_adv(dev, remote, offset); + } +} + +static void le_per_adv_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_periodic_adv_create_sync *cmd = &dev->pa_sync_cmd; + + memset(&ev, 0, sizeof(ev)); + ev.status = status; + + if (status) { + memset(&dev->pa_sync_cmd, 0, sizeof(dev->pa_sync_cmd)); + dev->le_periodic_sync_handle = 0x0000; + le_meta_event(dev, BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED, &ev, + sizeof(ev)); + return; + } + + dev->le_periodic_sync_handle = SYC_HANDLE; + + ev.handle = cpu_to_le16(dev->le_periodic_sync_handle); + ev.addr_type = cmd->addr_type; + memcpy(ev.addr, cmd->addr, sizeof(ev.addr)); + ev.phy = 0x01; + ev.interval = remote->le_periodic_min_interval; + ev.clock_accuracy = 0x07; + + memset(&dev->pa_sync_cmd, 0, sizeof(dev->pa_sync_cmd)); + + le_meta_event(dev, BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED, &ev, sizeof(ev)); + send_per_adv(dev, remote, 0); +} + static int cmd_set_per_adv_enable(struct btdev *dev, const void *data, uint8_t len) { const struct bt_hci_cmd_le_set_periodic_adv_enable *cmd = data; uint8_t status; + int i; if (dev->le_periodic_adv_enable == cmd->enable) { status = BT_HCI_ERR_COMMAND_DISALLOWED; @@ -5060,6 +5126,18 @@ static int cmd_set_per_adv_enable(struct btdev *dev, const void *data, cmd_complete(dev, BT_HCI_CMD_LE_SET_PERIODIC_ADV_ENABLE, &status, sizeof(status)); + for (i = 0; i < MAX_BTDEV_ENTRIES; i++) { + struct btdev *remote = btdev_list[i]; + + if (!remote || remote == dev) + continue; + + if (remote->le_scan_enable && + remote->le_periodic_sync_handle == INV_HANDLE) + le_per_adv_sync_estabilished(remote, dev, + BT_HCI_ERR_SUCCESS); + } + return 0; } @@ -5161,78 +5239,12 @@ static void scan_ext_adv(struct btdev *dev, struct btdev *remote) } } -static void send_per_adv(struct btdev *dev, const struct btdev *remote, - uint8_t offset) -{ - struct __packed { - struct bt_hci_le_per_adv_report ev; - uint8_t data[31]; - } pdu; - - memset(&pdu.ev, 0, sizeof(pdu.ev)); - pdu.ev.handle = cpu_to_le16(dev->le_periodic_sync_handle); - pdu.ev.tx_power = 127; - pdu.ev.rssi = 127; - pdu.ev.cte_type = 0x0ff; - - if ((size_t) remote->le_periodic_data_len - offset > sizeof(pdu.data)) { - pdu.ev.data_status = 0x01; - pdu.ev.data_len = sizeof(pdu.data); - } else { - pdu.ev.data_status = 0x00; - pdu.ev.data_len = remote->le_periodic_data_len - offset; - } - - memcpy(pdu.data, remote->le_periodic_data + offset, pdu.ev.data_len); - - le_meta_event(dev, BT_HCI_EVT_LE_PER_ADV_REPORT, &pdu, - sizeof(pdu.ev) + pdu.ev.data_len); - - if (pdu.ev.data_status == 0x01) { - offset += pdu.ev.data_len; - send_per_adv(dev, remote, offset); - } -} - -static void le_per_adv_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_periodic_adv_create_sync *cmd = &dev->pa_sync_cmd; - - memset(&ev, 0, sizeof(ev)); - ev.status = status; - - if (status) { - memset(&dev->pa_sync_cmd, 0, sizeof(dev->pa_sync_cmd)); - dev->le_periodic_sync_handle = 0x0000; - le_meta_event(dev, BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED, &ev, - sizeof(ev)); - return; - } - - dev->le_periodic_sync_handle = SYC_HANDLE; - - ev.handle = cpu_to_le16(dev->le_periodic_sync_handle); - ev.addr_type = cmd->addr_type; - memcpy(ev.addr, cmd->addr, sizeof(ev.addr)); - ev.phy = 0x01; - ev.interval = remote->le_periodic_min_interval; - ev.clock_accuracy = 0x07; - - memset(&dev->pa_sync_cmd, 0, sizeof(dev->pa_sync_cmd)); - - le_meta_event(dev, BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED, &ev, sizeof(ev)); - send_per_adv(dev, remote, 0); -} - static void scan_per_adv(struct btdev *dev, struct btdev *remote) { if (dev->le_periodic_sync_handle != INV_HANDLE || !remote->le_periodic_adv_enable) return; - if (remote != find_btdev_by_bdaddr_type(dev->pa_sync_cmd.addr, dev->pa_sync_cmd.addr_type)) return; From patchwork Sat Mar 5 01:22:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 548751 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 86D6FC433F5 for ; Sat, 5 Mar 2022 01:22:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230398AbiCEBXe (ORCPT ); Fri, 4 Mar 2022 20:23:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58210 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230380AbiCEBX2 (ORCPT ); Fri, 4 Mar 2022 20:23:28 -0500 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 5BD5C2F00F for ; Fri, 4 Mar 2022 17:22:38 -0800 (PST) Received: by mail-pj1-x102d.google.com with SMTP id z12-20020a17090ad78c00b001bf022b69d6so8290981pju.2 for ; Fri, 04 Mar 2022 17:22:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=00tpi3ubMc39x6VvlyEVIwLH2tXd1gkjhv4j61ryDfc=; b=ZqQWaeVPTnA6OX1/s6PtQKuoFb1YRhBp897tC6VNx4qwMIujbTuuHLpd5tTY2JEGPK YjtZjjDnsQGdNnyEoVrsibxJVAsthE/nlMmNWHUHGzs63p2IMzdbYrHUTtPsupQb0AC/ +ExQx81shfLjCpIRhCuv/9NE/F3FyAwHji0XFsTzDS618YOtSmLVnccJd533YIwBczTE sC1txCi49ddZFlKjpDRUugjyJmHRV1HhlQaiTixXRz80CbQtRgEYE6O+OZeEUl5jluVx hOfur2Zo5Y39jtJbN3rKNCp72shjulcmRVddFON/GwHVi8zwmYA+TaW9QkbCGRjR5VjS 8bjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=00tpi3ubMc39x6VvlyEVIwLH2tXd1gkjhv4j61ryDfc=; b=U3/UBqatZYtBfjNLgPKbMDXwjNjwjUr9x68eZiHf6ZFKaZdbIfn0beQ3HXX6z1o4Jm uwLEXoNBxbrk1x4Nwt5MNGr3+ZT6LuLy0iJospC1iRf8BkbTaaRCTQSgy7SOAcPj2wyx rckotvrWo0YJnxmN6sYl3NJANyiiNyECHs7gtVoEu1OfiMftxRllA4r0CuHOsmjo6yqQ N33a3QC4cSmeZQjTVQ2Tcq39l+NTwIn6wCcnl6h6a/glEFdAQuK3/eIyk1XBMSzOLfh4 JpkHIiII0DsOKfUvrkg9C1pjjCyqDr2rXODSRwsuAkwVqdLZeMdIxOV0Cr3Vf3k/pGTr LHEQ== X-Gm-Message-State: AOAM530G3KX5DcwNrD3FDMwl/0u3KyvtB5F59cLYGgjjBdxu9oZwR2+k oyfHtRbD59IR0Y3lREqUc3eNiuhM+Vw= X-Google-Smtp-Source: ABdhPJzfTHaxsqhnG1EWyelTtXpyLyn+Lz63oUfEdIUcFWS485o18daWqnCXqOhyQWjWkvbh7b2GMw== X-Received: by 2002:a17:903:41c7:b0:151:a52c:c63b with SMTP id u7-20020a17090341c700b00151a52cc63bmr1128614ple.32.1646443356909; Fri, 04 Mar 2022 17:22:36 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id m16-20020a638c10000000b0037c4cf366c0sm5363932pgd.61.2022.03.04.17.22.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 17:22:36 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v2 07/12] monitor: Rename Periodic Advertising terms to PA/pa Date: Fri, 4 Mar 2022 17:22:24 -0800 Message-Id: <20220305012229.853784-8-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220305012229.853784-1-luiz.dentz@gmail.com> References: <20220305012229.853784-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This renames the use of Periodic Advertising in the API to just PA. --- emulator/btdev.c | 168 ++++++++++++++++++++++------------------------- monitor/bt.h | 82 +++++++++++------------ monitor/packet.c | 104 ++++++++++++++--------------- 3 files changed, 173 insertions(+), 181 deletions(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index e79b0dc67..10fa046bc 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -191,14 +191,14 @@ struct btdev { uint8_t le_scan_filter_policy; uint8_t le_filter_dup; uint8_t le_adv_enable; - uint8_t le_periodic_adv_enable; - uint16_t le_periodic_adv_properties; - uint16_t le_periodic_min_interval; - uint16_t le_periodic_max_interval; - uint8_t le_periodic_data_len; - uint8_t le_periodic_data[31]; - struct bt_hci_cmd_le_periodic_adv_create_sync pa_sync_cmd; - uint16_t le_periodic_sync_handle; + uint8_t le_pa_enable; + uint16_t le_pa_properties; + uint16_t le_pa_min_interval; + uint16_t le_pa_max_interval; + uint8_t le_pa_data_len; + uint8_t le_pa_data[31]; + struct bt_hci_cmd_le_pa_create_sync pa_sync_cmd; + uint16_t le_pa_sync_handle; uint8_t le_ltk[16]; struct { struct bt_hci_cmd_le_set_cig_params params; @@ -5010,120 +5010,119 @@ static int cmd_clear_adv_sets(struct btdev *dev, const void *data, return 0; } -static int cmd_set_per_adv_params(struct btdev *dev, const void *data, +static int cmd_set_pa_params(struct btdev *dev, const void *data, uint8_t len) { - const struct bt_hci_cmd_le_set_periodic_adv_params *cmd = data; + const struct bt_hci_cmd_le_set_pa_params *cmd = data; uint8_t status; - if (dev->le_periodic_adv_enable) { + if (dev->le_pa_enable) { status = BT_HCI_ERR_COMMAND_DISALLOWED; } else { status = BT_HCI_ERR_SUCCESS; - dev->le_periodic_adv_properties = le16_to_cpu(cmd->properties); - dev->le_periodic_min_interval = cmd->min_interval; - dev->le_periodic_max_interval = cmd->max_interval; + dev->le_pa_properties = le16_to_cpu(cmd->properties); + dev->le_pa_min_interval = cmd->min_interval; + dev->le_pa_max_interval = cmd->max_interval; } - cmd_complete(dev, BT_HCI_CMD_LE_SET_PERIODIC_ADV_PARAMS, &status, + cmd_complete(dev, BT_HCI_CMD_LE_SET_PA_PARAMS, &status, sizeof(status)); return 0; } -static int cmd_set_per_adv_data(struct btdev *dev, const void *data, +static int cmd_set_pa_data(struct btdev *dev, const void *data, uint8_t len) { - const struct bt_hci_cmd_le_set_periodic_adv_data *cmd = data; + const struct bt_hci_cmd_le_set_pa_data *cmd = data; uint8_t status = BT_HCI_ERR_SUCCESS; - dev->le_periodic_data_len = cmd->data_len; - memcpy(dev->le_periodic_data, cmd->data, 31); - cmd_complete(dev, BT_HCI_CMD_LE_SET_PERIODIC_ADV_DATA, &status, + dev->le_pa_data_len = cmd->data_len; + memcpy(dev->le_pa_data, cmd->data, 31); + cmd_complete(dev, BT_HCI_CMD_LE_SET_PA_DATA, &status, sizeof(status)); return 0; } -static void send_per_adv(struct btdev *dev, const struct btdev *remote, +static void send_pa(struct btdev *dev, const struct btdev *remote, uint8_t offset) { struct __packed { - struct bt_hci_le_per_adv_report ev; + struct bt_hci_le_pa_report ev; uint8_t data[31]; } pdu; memset(&pdu.ev, 0, sizeof(pdu.ev)); - pdu.ev.handle = cpu_to_le16(dev->le_periodic_sync_handle); + pdu.ev.handle = cpu_to_le16(dev->le_pa_sync_handle); pdu.ev.tx_power = 127; pdu.ev.rssi = 127; pdu.ev.cte_type = 0x0ff; - if ((size_t) remote->le_periodic_data_len - offset > sizeof(pdu.data)) { + if ((size_t) remote->le_pa_data_len - offset > sizeof(pdu.data)) { pdu.ev.data_status = 0x01; pdu.ev.data_len = sizeof(pdu.data); } else { pdu.ev.data_status = 0x00; - pdu.ev.data_len = remote->le_periodic_data_len - offset; + pdu.ev.data_len = remote->le_pa_data_len - offset; } - memcpy(pdu.data, remote->le_periodic_data + offset, pdu.ev.data_len); + memcpy(pdu.data, remote->le_pa_data + offset, pdu.ev.data_len); - le_meta_event(dev, BT_HCI_EVT_LE_PER_ADV_REPORT, &pdu, + le_meta_event(dev, BT_HCI_EVT_LE_PA_REPORT, &pdu, sizeof(pdu.ev) + pdu.ev.data_len); if (pdu.ev.data_status == 0x01) { offset += pdu.ev.data_len; - send_per_adv(dev, remote, offset); + send_pa(dev, remote, offset); } } -static void le_per_adv_sync_estabilished(struct btdev *dev, - struct btdev *remote, uint8_t status) +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_periodic_adv_create_sync *cmd = &dev->pa_sync_cmd; + struct bt_hci_cmd_le_pa_create_sync *cmd = &dev->pa_sync_cmd; memset(&ev, 0, sizeof(ev)); ev.status = status; if (status) { memset(&dev->pa_sync_cmd, 0, sizeof(dev->pa_sync_cmd)); - dev->le_periodic_sync_handle = 0x0000; - le_meta_event(dev, BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED, &ev, + dev->le_pa_sync_handle = 0x0000; + le_meta_event(dev, BT_HCI_EVT_LE_PA_SYNC_ESTABLISHED, &ev, sizeof(ev)); return; } - dev->le_periodic_sync_handle = SYC_HANDLE; + dev->le_pa_sync_handle = SYC_HANDLE; - ev.handle = cpu_to_le16(dev->le_periodic_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.phy = 0x01; - ev.interval = remote->le_periodic_min_interval; + ev.interval = remote->le_pa_min_interval; ev.clock_accuracy = 0x07; memset(&dev->pa_sync_cmd, 0, sizeof(dev->pa_sync_cmd)); - le_meta_event(dev, BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED, &ev, sizeof(ev)); - send_per_adv(dev, remote, 0); + le_meta_event(dev, BT_HCI_EVT_LE_PA_SYNC_ESTABLISHED, &ev, sizeof(ev)); + send_pa(dev, remote, 0); } -static int cmd_set_per_adv_enable(struct btdev *dev, const void *data, - uint8_t len) +static int cmd_set_pa_enable(struct btdev *dev, const void *data, uint8_t len) { - const struct bt_hci_cmd_le_set_periodic_adv_enable *cmd = data; + const struct bt_hci_cmd_le_set_pa_enable *cmd = data; uint8_t status; int i; - if (dev->le_periodic_adv_enable == cmd->enable) { + if (dev->le_pa_enable == cmd->enable) { status = BT_HCI_ERR_COMMAND_DISALLOWED; } else { - dev->le_periodic_adv_enable = cmd->enable; + dev->le_pa_enable = cmd->enable; status = BT_HCI_ERR_SUCCESS; } - cmd_complete(dev, BT_HCI_CMD_LE_SET_PERIODIC_ADV_ENABLE, &status, + cmd_complete(dev, BT_HCI_CMD_LE_SET_PA_ENABLE, &status, sizeof(status)); for (i = 0; i < MAX_BTDEV_ENTRIES; i++) { @@ -5133,8 +5132,8 @@ static int cmd_set_per_adv_enable(struct btdev *dev, const void *data, continue; if (remote->le_scan_enable && - remote->le_periodic_sync_handle == INV_HANDLE) - le_per_adv_sync_estabilished(remote, dev, + remote->le_pa_sync_handle == INV_HANDLE) + le_pa_sync_estabilished(remote, dev, BT_HCI_ERR_SUCCESS); } @@ -5239,17 +5238,16 @@ static void scan_ext_adv(struct btdev *dev, struct btdev *remote) } } -static void scan_per_adv(struct btdev *dev, struct btdev *remote) +static void scan_pa(struct btdev *dev, struct btdev *remote) { - if (dev->le_periodic_sync_handle != INV_HANDLE || - !remote->le_periodic_adv_enable) + if (dev->le_pa_sync_handle != INV_HANDLE || !remote->le_pa_enable) return; if (remote != find_btdev_by_bdaddr_type(dev->pa_sync_cmd.addr, dev->pa_sync_cmd.addr_type)) return; - le_per_adv_sync_estabilished(dev, remote, BT_HCI_ERR_SUCCESS); + le_pa_sync_estabilished(dev, remote, BT_HCI_ERR_SUCCESS); } static int cmd_set_ext_scan_enable_complete(struct btdev *dev, const void *data, @@ -5266,7 +5264,7 @@ static int cmd_set_ext_scan_enable_complete(struct btdev *dev, const void *data, continue; scan_ext_adv(dev, btdev_list[i]); - scan_per_adv(dev, btdev_list[i]); + scan_pa(dev, btdev_list[i]); } return 0; @@ -5387,27 +5385,26 @@ static int cmd_ext_create_conn_complete(struct btdev *dev, const void *data, return 0; } -static int cmd_per_adv_create_sync(struct btdev *dev, const void *data, - uint8_t len) +static int cmd_pa_create_sync(struct btdev *dev, const void *data, uint8_t len) { uint8_t status = BT_HCI_ERR_SUCCESS; - if (dev->le_periodic_sync_handle) + if (dev->le_pa_sync_handle) status = BT_HCI_ERR_MEM_CAPACITY_EXCEEDED; else { - dev->le_periodic_sync_handle = INV_HANDLE; + dev->le_pa_sync_handle = INV_HANDLE; memcpy(&dev->pa_sync_cmd, data, len); } - cmd_status(dev, status, BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC); + cmd_status(dev, status, BT_HCI_CMD_LE_PA_CREATE_SYNC); return 0; } -static int cmd_per_adv_create_sync_complete(struct btdev *dev, const void *data, +static int cmd_pa_create_sync_complete(struct btdev *dev, const void *data, uint8_t len) { - const struct bt_hci_cmd_le_periodic_adv_create_sync *cmd = data; + const struct bt_hci_cmd_le_pa_create_sync *cmd = data; struct btdev *remote; /* This command may be issued whether or not scanning is enabled and @@ -5420,15 +5417,15 @@ static int cmd_per_adv_create_sync_complete(struct btdev *dev, const void *data, return 0; remote = find_btdev_by_bdaddr_type(cmd->addr, cmd->addr_type); - if (!remote || !remote->le_periodic_adv_enable) + if (!remote || !remote->le_pa_enable) return 0; - le_per_adv_sync_estabilished(dev, remote, BT_HCI_ERR_SUCCESS); + le_pa_sync_estabilished(dev, remote, BT_HCI_ERR_SUCCESS); return 0; } -static int cmd_per_adv_create_sync_cancel(struct btdev *dev, const void *data, +static int cmd_pa_create_sync_cancel(struct btdev *dev, const void *data, uint8_t len) { uint8_t status = BT_HCI_ERR_SUCCESS; @@ -5437,10 +5434,10 @@ static int cmd_per_adv_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_periodic_sync_handle != INV_HANDLE) + if (dev->le_pa_sync_handle != INV_HANDLE) status = BT_HCI_ERR_COMMAND_DISALLOWED; - cmd_complete(dev, BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC_CANCEL, + cmd_complete(dev, BT_HCI_CMD_LE_PA_CREATE_SYNC_CANCEL, &status, sizeof(status)); /* After the HCI_Command_Complete is sent and if the cancellation was @@ -5449,13 +5446,12 @@ static int cmd_per_adv_create_sync_cancel(struct btdev *dev, const void *data, * the error code Operation Cancelled by Host (0x44). */ if (!status) - le_per_adv_sync_estabilished(dev, NULL, BT_HCI_ERR_CANCELLED); + le_pa_sync_estabilished(dev, NULL, BT_HCI_ERR_CANCELLED); return 0; } -static int cmd_per_adv_term_sync(struct btdev *dev, const void *data, - uint8_t len) +static int cmd_pa_term_sync(struct btdev *dev, const void *data, uint8_t len) { uint8_t status = BT_HCI_ERR_SUCCESS; @@ -5463,36 +5459,36 @@ static int cmd_per_adv_term_sync(struct btdev *dev, const void *data, * parameter does not exist, then the Controller shall return the error * code Unknown Advertising Identifier (0x42). */ - if (dev->le_periodic_sync_handle != SYC_HANDLE) + if (dev->le_pa_sync_handle != SYC_HANDLE) status = BT_HCI_ERR_UNKNOWN_ADVERTISING_ID; else - dev->le_periodic_sync_handle = 0x0000; + dev->le_pa_sync_handle = 0x0000; - cmd_complete(dev, BT_HCI_CMD_LE_PERIODIC_ADV_TERM_SYNC, + cmd_complete(dev, BT_HCI_CMD_LE_PA_TERM_SYNC, &status, sizeof(status)); return 0; } -static int cmd_per_adv_add(struct btdev *dev, const void *data, uint8_t len) +static int cmd_pa_add(struct btdev *dev, const void *data, uint8_t len) { /* TODO */ return -ENOTSUP; } -static int cmd_per_adv_remove(struct btdev *dev, const void *data, uint8_t len) +static int cmd_pa_remove(struct btdev *dev, const void *data, uint8_t len) { /* TODO */ return -ENOTSUP; } -static int cmd_per_adv_clear(struct btdev *dev, const void *data, uint8_t len) +static int cmd_pa_clear(struct btdev *dev, const void *data, uint8_t len) { /* TODO */ return -ENOTSUP; } -static int cmd_read_per_adv_list_size(struct btdev *dev, const void *data, +static int cmd_read_pa_list_size(struct btdev *dev, const void *data, uint8_t len) { /* TODO */ @@ -5571,28 +5567,24 @@ done: NULL), \ CMD(BT_HCI_CMD_LE_REMOVE_ADV_SET, cmd_remove_adv_set, NULL), \ CMD(BT_HCI_CMD_LE_CLEAR_ADV_SETS, cmd_clear_adv_sets, NULL), \ - CMD(BT_HCI_CMD_LE_SET_PERIODIC_ADV_PARAMS, cmd_set_per_adv_params, \ - NULL), \ - CMD(BT_HCI_CMD_LE_SET_PERIODIC_ADV_DATA, cmd_set_per_adv_data, NULL), \ - CMD(BT_HCI_CMD_LE_SET_PERIODIC_ADV_ENABLE, cmd_set_per_adv_enable, \ + CMD(BT_HCI_CMD_LE_SET_PA_PARAMS, cmd_set_pa_params, \ NULL), \ + CMD(BT_HCI_CMD_LE_SET_PA_DATA, cmd_set_pa_data, NULL), \ + CMD(BT_HCI_CMD_LE_SET_PA_ENABLE, cmd_set_pa_enable, NULL), \ CMD(BT_HCI_CMD_LE_SET_EXT_SCAN_PARAMS, cmd_set_ext_scan_params, NULL), \ CMD(BT_HCI_CMD_LE_SET_EXT_SCAN_ENABLE, cmd_set_ext_scan_enable, \ cmd_set_ext_scan_enable_complete), \ CMD(BT_HCI_CMD_LE_EXT_CREATE_CONN, cmd_ext_create_conn, \ cmd_ext_create_conn_complete), \ - CMD(BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC, cmd_per_adv_create_sync, \ - cmd_per_adv_create_sync_complete), \ - CMD(BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC_CANCEL, \ - cmd_per_adv_create_sync_cancel, NULL), \ - CMD(BT_HCI_CMD_LE_PERIODIC_ADV_TERM_SYNC, cmd_per_adv_term_sync, \ - NULL), \ - CMD(BT_HCI_CMD_LE_ADD_DEV_PERIODIC_ADV_LIST, cmd_per_adv_add, NULL), \ - CMD(BT_HCI_CMD_LE_REMOVE_DEV_PERIODIC_ADV_LIST, cmd_per_adv_remove, \ + CMD(BT_HCI_CMD_LE_PA_CREATE_SYNC, cmd_pa_create_sync, \ + cmd_pa_create_sync_complete), \ + CMD(BT_HCI_CMD_LE_PA_CREATE_SYNC_CANCEL, cmd_pa_create_sync_cancel, \ NULL), \ - CMD(BT_HCI_CMD_LE_CLEAR_PERIODIC_ADV_LIST, cmd_per_adv_clear, NULL), \ - CMD(BT_HCI_CMD_LE_READ_PERIODIC_ADV_LIST_SIZE, \ - cmd_read_per_adv_list_size, NULL), \ + CMD(BT_HCI_CMD_LE_PA_TERM_SYNC, cmd_pa_term_sync, NULL), \ + CMD(BT_HCI_CMD_LE_ADD_DEV_PA_LIST, cmd_pa_add, NULL), \ + CMD(BT_HCI_CMD_LE_REMOVE_DEV_PA_LIST, cmd_pa_remove, NULL), \ + CMD(BT_HCI_CMD_LE_CLEAR_PA_LIST, cmd_pa_clear, NULL), \ + CMD(BT_HCI_CMD_LE_READ_PA_LIST_SIZE, cmd_read_pa_list_size, NULL), \ CMD(BT_HCI_CMD_LE_READ_TX_POWER, cmd_read_tx_power, NULL), \ CMD(BT_HCI_CMD_LE_SET_PRIV_MODE, cmd_set_privacy_mode, NULL) diff --git a/monitor/bt.h b/monitor/bt.h index b6b6c49e1..5c2acee67 100644 --- a/monitor/bt.h +++ b/monitor/bt.h @@ -2427,24 +2427,24 @@ struct bt_hci_cmd_le_remove_adv_set { #define BT_HCI_CMD_LE_CLEAR_ADV_SETS 0x203d -#define BT_HCI_CMD_LE_SET_PERIODIC_ADV_PARAMS 0x203e -struct bt_hci_cmd_le_set_periodic_adv_params { +#define BT_HCI_CMD_LE_SET_PA_PARAMS 0x203e +struct bt_hci_cmd_le_set_pa_params { uint8_t handle; uint16_t min_interval; uint16_t max_interval; uint16_t properties; } __attribute__ ((packed)); -#define BT_HCI_CMD_LE_SET_PERIODIC_ADV_DATA 0x203f -struct bt_hci_cmd_le_set_periodic_adv_data { +#define BT_HCI_CMD_LE_SET_PA_DATA 0x203f +struct bt_hci_cmd_le_set_pa_data { uint8_t handle; uint8_t operation; uint8_t data_len; uint8_t data[0]; } __attribute__ ((packed)); -#define BT_HCI_CMD_LE_SET_PERIODIC_ADV_ENABLE 0x2040 -struct bt_hci_cmd_le_set_periodic_adv_enable { +#define BT_HCI_CMD_LE_SET_PA_ENABLE 0x2040 +struct bt_hci_cmd_le_set_pa_enable { uint8_t enable; uint8_t handle; } __attribute__ ((packed)); @@ -2490,8 +2490,8 @@ struct bt_hci_le_ext_create_conn { uint16_t max_length; } __attribute__ ((packed)); -#define BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC 0x2044 -struct bt_hci_cmd_le_periodic_adv_create_sync { +#define BT_HCI_CMD_LE_PA_CREATE_SYNC 0x2044 +struct bt_hci_cmd_le_pa_create_sync { uint8_t options; uint8_t sid; uint8_t addr_type; @@ -2501,31 +2501,31 @@ struct bt_hci_cmd_le_periodic_adv_create_sync { uint8_t sync_cte_type; } __attribute__ ((packed)); -#define BT_HCI_CMD_LE_PERIODIC_ADV_CREATE_SYNC_CANCEL 0x2045 +#define BT_HCI_CMD_LE_PA_CREATE_SYNC_CANCEL 0x2045 -#define BT_HCI_CMD_LE_PERIODIC_ADV_TERM_SYNC 0x2046 -struct bt_hci_cmd_le_periodic_adv_term_sync { +#define BT_HCI_CMD_LE_PA_TERM_SYNC 0x2046 +struct bt_hci_cmd_le_pa_term_sync { uint16_t sync_handle; } __attribute__ ((packed)); -#define BT_HCI_CMD_LE_ADD_DEV_PERIODIC_ADV_LIST 0x2047 -struct bt_hci_cmd_le_add_dev_periodic_adv_list { +#define BT_HCI_CMD_LE_ADD_DEV_PA_LIST 0x2047 +struct bt_hci_cmd_le_add_dev_pa_list { uint8_t addr_type; uint8_t addr[6]; uint8_t sid; } __attribute__ ((packed)); -#define BT_HCI_CMD_LE_REMOVE_DEV_PERIODIC_ADV_LIST 0x2048 -struct bt_hci_cmd_le_remove_dev_periodic_adv_list { +#define BT_HCI_CMD_LE_REMOVE_DEV_PA_LIST 0x2048 +struct bt_hci_cmd_le_remove_dev_pa_list { uint8_t addr_type; uint8_t addr[6]; uint8_t sid; } __attribute__ ((packed)); -#define BT_HCI_CMD_LE_CLEAR_PERIODIC_ADV_LIST 0x2049 +#define BT_HCI_CMD_LE_CLEAR_PA_LIST 0x2049 -#define BT_HCI_CMD_LE_READ_PERIODIC_ADV_LIST_SIZE 0x204a -struct bt_hci_rsp_le_read_dev_periodic_adv_list_size { +#define BT_HCI_CMD_LE_READ_PA_LIST_SIZE 0x204a +struct bt_hci_rsp_le_read_dev_pa_list_size { uint8_t status; uint8_t list_size; } __attribute__ ((packed)); @@ -2582,28 +2582,28 @@ struct bt_hci_cmd_le_tx_test_v3 { uint8_t antenna_ids[0]; } __attribute__ ((packed)); -#define BT_HCI_CMD_SET_PERIODIC_ADV_REC_ENABLE 0x2059 -struct bt_hci_cmd_set_periodic_adv_rec_enable { +#define BT_HCI_CMD_SET_PA_REC_ENABLE 0x2059 +struct bt_hci_cmd_set_pa_rec_enable { uint16_t sync_handle; uint8_t enable; } __attribute__ ((packed)); -#define BT_HCI_CMD_PERIODIC_SYNC_TRANS 0x205a +#define BT_HCI_CMD_PERIODIC_SYNC_TRANS 0x205a struct bt_hci_cmd_periodic_sync_trans { uint16_t handle; uint16_t service_data; uint16_t sync_handle; } __attribute__ ((packed)); -#define BT_HCI_CMD_PERIODIC_ADV_SET_INFO_TRANS 0x205b -struct bt_hci_cmd_periodic_adv_set_info_trans { +#define BT_HCI_CMD_PA_SET_INFO_TRANS 0x205b +struct bt_hci_cmd_pa_set_info_trans { uint16_t handle; uint16_t service_data; uint16_t adv_handle; } __attribute__ ((packed)); -#define BT_HCI_CMD_PERIODIC_ADV_SYNC_TRANS_PARAMS 0x205c -struct bt_hci_cmd_periodic_adv_sync_trans_params { +#define BT_HCI_CMD_PA_SYNC_TRANS_PARAMS 0x205c +struct bt_hci_cmd_pa_sync_trans_params { uint16_t handle; uint8_t mode; uint16_t skip; @@ -2611,8 +2611,8 @@ struct bt_hci_cmd_periodic_adv_sync_trans_params { uint8_t cte_type; } __attribute__ ((packed)); -#define BT_HCI_CMD_DEFAULT_PERIODIC_ADV_SYNC_TRANS_PARAMS 0x205d -struct bt_hci_cmd_default_periodic_adv_sync_trans_params { +#define BT_HCI_CMD_DEFAULT_PA_SYNC_TRANS_PARAMS 0x205d +struct bt_hci_cmd_default_pa_sync_trans_params { uint8_t mode; uint16_t skip; uint16_t sync_timeout; @@ -3497,7 +3497,7 @@ struct bt_hci_le_ext_adv_report { uint8_t data[0]; } __attribute__ ((packed)); -#define BT_HCI_EVT_LE_PER_SYNC_ESTABLISHED 0x0e +#define BT_HCI_EVT_LE_PA_SYNC_ESTABLISHED 0x0e struct bt_hci_evt_le_per_sync_established { uint8_t status; uint16_t handle; @@ -3509,8 +3509,8 @@ struct bt_hci_evt_le_per_sync_established { uint8_t clock_accuracy; } __attribute__ ((packed)); -#define BT_HCI_EVT_LE_PER_ADV_REPORT 0x0f -struct bt_hci_le_per_adv_report { +#define BT_HCI_EVT_LE_PA_REPORT 0x0f +struct bt_hci_le_pa_report { uint16_t handle; uint8_t tx_power; int8_t rssi; @@ -3520,7 +3520,7 @@ struct bt_hci_le_per_adv_report { uint8_t data[0]; } __attribute__ ((packed)); -#define BT_HCI_EVT_LE_PER_SYNC_LOST 0x10 +#define BT_HCI_EVT_LE_PA_SYNC_LOST 0x10 struct bt_hci_evt_le_per_sync_lost { uint16_t handle; } __attribute__ ((packed)); @@ -3552,8 +3552,8 @@ struct bt_hci_evt_le_cte_request_failed { uint16_t handle; } __attribute__ ((packed)); -#define BT_HCI_EVT_LE_PER_ADV_SYNC_TRANS_REC 0x18 -struct bt_hci_evt_le_per_adv_sync_trans_rec { +#define BT_HCI_EVT_LE_PA_SYNC_TRANS_REC 0x18 +struct bt_hci_evt_le_pa_sync_trans_rec { uint8_t status; uint16_t handle; uint16_t service_data; @@ -3566,7 +3566,7 @@ struct bt_hci_evt_le_per_adv_sync_trans_rec { uint8_t clock_accuracy; } __attribute__ ((packed)); -#define BT_HCI_EVT_LE_CIS_ESTABLISHED 0x19 +#define BT_HCI_EVT_LE_CIS_ESTABLISHED 0x19 struct bt_hci_evt_le_cis_established { uint8_t status; uint16_t conn_handle; @@ -3586,7 +3586,7 @@ struct bt_hci_evt_le_cis_established { uint16_t interval; } __attribute__ ((packed)); -#define BT_HCI_EVT_LE_CIS_REQ 0x1a +#define BT_HCI_EVT_LE_CIS_REQ 0x1a struct bt_hci_evt_le_cis_req { uint16_t acl_handle; uint16_t cis_handle; @@ -3594,7 +3594,7 @@ struct bt_hci_evt_le_cis_req { uint8_t cis_id; } __attribute__ ((packed)); -#define BT_HCI_EVT_LE_BIG_COMPLETE 0x1b +#define BT_HCI_EVT_LE_BIG_COMPLETE 0x1b struct bt_hci_evt_le_big_complete { uint8_t status; uint8_t handle; @@ -3611,13 +3611,13 @@ struct bt_hci_evt_le_big_complete { uint16_t bis_handle[0]; } __attribute__ ((packed)); -#define BT_HCI_EVT_LE_BIG_TERMINATE 0x1c +#define BT_HCI_EVT_LE_BIG_TERMINATE 0x1c struct bt_hci_evt_le_big_terminate { uint8_t reason; uint8_t handle; } __attribute__ ((packed)); -#define BT_HCI_EVT_LE_BIG_SYNC_ESTABILISHED 0x1d +#define BT_HCI_EVT_LE_BIG_SYNC_ESTABILISHED 0x1d struct bt_hci_evt_le_big_sync_estabilished { uint8_t status; uint8_t handle; @@ -3632,13 +3632,13 @@ struct bt_hci_evt_le_big_sync_estabilished { uint16_t bis[0]; } __attribute__ ((packed)); -#define BT_HCI_EVT_LE_BIG_SYNC_LOST 0x1e +#define BT_HCI_EVT_LE_BIG_SYNC_LOST 0x1e struct bt_hci_evt_le_big_sync_lost { uint8_t big_id; uint8_t reason; } __attribute__ ((packed)); -#define BT_HCI_EVT_LE_REQ_PEER_SCA_COMPLETE 0x1f +#define BT_HCI_EVT_LE_REQ_PEER_SCA_COMPLETE 0x1f struct bt_hci_evt_le_req_peer_sca_complete { uint8_t status; uint16_t handle; @@ -3657,7 +3657,7 @@ struct bt_hci_evt_le_req_peer_sca_complete { #define BT_HCI_ERR_UNSUPPORTED_FEATURE 0x11 #define BT_HCI_ERR_INVALID_PARAMETERS 0x12 #define BT_HCI_ERR_UNSPECIFIED_ERROR 0x1f -#define BT_HCI_ERR_ADV_TIMEOUT 0x3c +#define BT_HCI_ERR_ADV_TIMEOUT 0x3c #define BT_HCI_ERR_CONN_FAILED_TO_ESTABLISH 0x3e #define BT_HCI_ERR_UNKNOWN_ADVERTISING_ID 0x42 #define BT_HCI_ERR_CANCELLED 0x44 diff --git a/monitor/packet.c b/monitor/packet.c index a17c632a7..b7431b57d 100644 --- a/monitor/packet.c +++ b/monitor/packet.c @@ -7400,37 +7400,37 @@ static void le_remove_adv_set_cmd(const void *data, uint8_t size) print_handle(cmd->handle); } -static const struct bitfield_data periodic_adv_properties_table[] = { +static const struct bitfield_data pa_properties_table[] = { { 6, "Include TxPower" }, { } }; -static void print_periodic_adv_properties(uint16_t flags) +static void print_pa_properties(uint16_t flags) { uint16_t mask; print_field("Properties: 0x%4.4x", flags); - mask = print_bitfield(2, flags, periodic_adv_properties_table); + mask = print_bitfield(2, flags, pa_properties_table); if (mask) print_text(COLOR_UNKNOWN_ADV_FLAG, " Unknown advertising properties (0x%4.4x)", mask); } -static void le_set_periodic_adv_params_cmd(const void *data, uint8_t size) +static void le_set_pa_params_cmd(const void *data, uint8_t size) { - const struct bt_hci_cmd_le_set_periodic_adv_params *cmd = data; + const struct bt_hci_cmd_le_set_pa_params *cmd = data; print_handle(cmd->handle); print_slot_125("Min interval", cmd->min_interval); print_slot_125("Max interval", cmd->max_interval); - print_periodic_adv_properties(cmd->properties); + print_pa_properties(cmd->properties); } -static void le_set_periodic_adv_data_cmd(const void *data, uint8_t size) +static void le_set_pa_data_cmd(const void *data, uint8_t size) { - const struct bt_hci_cmd_le_set_periodic_adv_data *cmd = data; + const struct bt_hci_cmd_le_set_pa_data *cmd = data; const char *str; print_handle(cmd->handle); @@ -7458,9 +7458,9 @@ static void le_set_periodic_adv_data_cmd(const void *data, uint8_t size) print_eir(cmd->data, cmd->data_len, true); } -static void le_set_periodic_adv_enable_cmd(const void *data, uint8_t size) +static void le_set_pa_enable_cmd(const void *data, uint8_t size) { - const struct bt_hci_cmd_le_set_periodic_adv_enable *cmd = data; + const struct bt_hci_cmd_le_set_pa_enable *cmd = data; print_enable("Periodic advertising", cmd->enable); print_handle(cmd->handle); @@ -7657,9 +7657,9 @@ static void print_create_sync_options(uint8_t flags) } } -static void le_periodic_adv_create_sync_cmd(const void *data, uint8_t size) +static void le_pa_create_sync_cmd(const void *data, uint8_t size) { - const struct bt_hci_cmd_le_periodic_adv_create_sync *cmd = data; + const struct bt_hci_cmd_le_pa_create_sync *cmd = data; print_create_sync_options(cmd->options); print_field("SID: 0x%2.2x", cmd->sid); @@ -7672,34 +7672,34 @@ static void le_periodic_adv_create_sync_cmd(const void *data, uint8_t size) print_create_sync_cte_type(cmd->sync_cte_type); } -static void le_periodic_adv_term_sync_cmd(const void *data, uint8_t size) +static void le_pa_term_sync_cmd(const void *data, uint8_t size) { - const struct bt_hci_cmd_le_periodic_adv_term_sync *cmd = data; + const struct bt_hci_cmd_le_pa_term_sync *cmd = data; print_field("Sync handle: 0x%4.4x", cmd->sync_handle); } -static void le_add_dev_periodic_adv_list_cmd(const void *data, uint8_t size) +static void le_add_dev_pa_list_cmd(const void *data, uint8_t size) { - const struct bt_hci_cmd_le_add_dev_periodic_adv_list *cmd = data; + const struct bt_hci_cmd_le_add_dev_pa_list *cmd = data; print_addr_type("Adv address type", cmd->addr_type); print_addr("Adv address", cmd->addr, cmd->addr_type); print_field("SID: 0x%2.2x", cmd->sid); } -static void le_remove_dev_periodic_adv_list_cmd(const void *data, uint8_t size) +static void le_remove_dev_pa_list_cmd(const void *data, uint8_t size) { - const struct bt_hci_cmd_le_remove_dev_periodic_adv_list *cmd = data; + const struct bt_hci_cmd_le_remove_dev_pa_list *cmd = data; print_addr_type("Adv address type", cmd->addr_type); print_addr("Adv address", cmd->addr, cmd->addr_type); print_field("SID: 0x%2.2x", cmd->sid); } -static void le_read_periodic_adv_list_size_rsp(const void *data, uint8_t size) +static void le_read_pa_list_size_rsp(const void *data, uint8_t size) { - const struct bt_hci_rsp_le_read_dev_periodic_adv_list_size *rsp = data; + const struct bt_hci_rsp_le_read_dev_pa_list_size *rsp = data; print_status(rsp->status); print_field("List size: 0x%2.2x", rsp->list_size); @@ -7861,15 +7861,15 @@ static void le_tx_test_cmd_v3(const void *data, uint8_t size) print_field(" Antenna ID: %u", cmd->antenna_ids[i]); } -static void le_periodic_adv_rec_enable(const void *data, uint8_t size) +static void le_pa_rec_enable(const void *data, uint8_t size) { - const struct bt_hci_cmd_le_set_periodic_adv_enable *cmd = data; + const struct bt_hci_cmd_le_set_pa_enable *cmd = data; print_field("Sync handle: %d", cmd->handle); print_enable("Reporting", cmd->enable); } -static void le_periodic_adv_sync_trans(const void *data, uint8_t size) +static void le_pa_sync_trans(const void *data, uint8_t size) { const struct bt_hci_cmd_periodic_sync_trans *cmd = data; @@ -7878,9 +7878,9 @@ static void le_periodic_adv_sync_trans(const void *data, uint8_t size) print_field("Sync handle: %d", cmd->sync_handle); } -static void le_periodic_adv_set_info_trans(const void *data, uint8_t size) +static void le_pa_set_info_trans(const void *data, uint8_t size) { - const struct bt_hci_cmd_periodic_adv_set_info_trans *cmd = data; + const struct bt_hci_cmd_pa_set_info_trans *cmd = data; print_field("Connection handle: %d", cmd->handle); print_field("Service data: 0x%4.4x", cmd->service_data); @@ -7909,9 +7909,9 @@ static void print_sync_mode(uint8_t mode) print_field("Mode: %s (0x%2.2x)", str, mode); } -static void le_periodic_adv_sync_trans_params(const void *data, uint8_t size) +static void le_pa_sync_trans_params(const void *data, uint8_t size) { - const struct bt_hci_cmd_periodic_adv_sync_trans_params *cmd = data; + const struct bt_hci_cmd_pa_sync_trans_params *cmd = data; print_field("Connection handle: %d", cmd->handle); print_sync_mode(cmd->mode); @@ -7922,10 +7922,10 @@ static void le_periodic_adv_sync_trans_params(const void *data, uint8_t size) print_create_sync_cte_type(cmd->cte_type); } -static void le_set_default_periodic_adv_sync_trans_params(const void *data, +static void le_set_default_pa_sync_trans_params(const void *data, uint8_t size) { - const struct bt_hci_cmd_default_periodic_adv_sync_trans_params *cmd = data; + const struct bt_hci_cmd_default_pa_sync_trans_params *cmd = data; print_sync_mode(cmd->mode); print_field("Skip: 0x%2.2x", cmd->skip); @@ -9141,13 +9141,13 @@ static const struct opcode_data opcode_table[] = { null_cmd, 0, true, status_rsp, 1, true }, { 0x203e, 298, "LE Set Periodic Advertising Parameters", - le_set_periodic_adv_params_cmd, 7, true, + le_set_pa_params_cmd, 7, true, status_rsp, 1, true }, { 0x203f, 299, "LE Set Periodic Advertising Data", - le_set_periodic_adv_data_cmd, 3, false, + le_set_pa_data_cmd, 3, false, status_rsp, 1, true }, { 0x2040, 300, "LE Set Periodic Advertising Enable", - le_set_periodic_adv_enable_cmd, 2, true, + le_set_pa_enable_cmd, 2, true, status_rsp, 1, true }, { 0x2041, 301, "LE Set Extended Scan Parameters", le_set_ext_scan_params_cmd, 3, false, @@ -9159,26 +9159,26 @@ static const struct opcode_data opcode_table[] = { le_ext_create_conn_cmd, 10, false, status_rsp, 1, true }, { 0x2044, 304, "LE Periodic Advertising Create Sync", - le_periodic_adv_create_sync_cmd, 14, true, + le_pa_create_sync_cmd, 14, true, status_rsp, 1, true }, { 0x2045, 305, "LE Periodic Advertising Create Sync Cancel", null_cmd, 0, true, status_rsp, 1, true }, { 0x2046, 306, "LE Periodic Advertising Terminate Sync", - le_periodic_adv_term_sync_cmd, 2, true, + le_pa_term_sync_cmd, 2, true, status_rsp, 1, true }, { 0x2047, 307, "LE Add Device To Periodic Advertiser List", - le_add_dev_periodic_adv_list_cmd, 8, true, + le_add_dev_pa_list_cmd, 8, true, status_rsp, 1, true }, { 0x2048, 308, "LE Remove Device From Periodic Advertiser List", - le_remove_dev_periodic_adv_list_cmd, 8, true, + le_remove_dev_pa_list_cmd, 8, true, status_rsp, 1, true }, { 0x2049, 309, "LE Clear Periodic Advertiser List", null_cmd, 0, true, status_rsp, 1, true }, { 0x204a, 310, "LE Read Periodic Advertiser List Size", null_cmd, 0, true, - le_read_periodic_adv_list_size_rsp, 2, true }, + le_read_pa_list_size_rsp, 2, true }, { 0x204b, 311, "LE Read Transmit Power", null_cmd, 0, true, le_read_tx_power_rsp, 3, true }, @@ -9198,20 +9198,20 @@ static const struct opcode_data opcode_table[] = { le_tx_test_cmd_v3, 9, false, status_rsp, 1, true }, { 0x2059, 325, "LE Periodic Advertising Receive Enable", - le_periodic_adv_rec_enable, 3, true, + le_pa_rec_enable, 3, true, status_rsp, 1, true }, { 0x205a, 326, "LE Periodic Advertising Sync Transfer", - le_periodic_adv_sync_trans, 6, true, + le_pa_sync_trans, 6, true, status_handle_rsp, 3, true }, { 0x205b, 327, "LE Periodic Advertising Set Info Transfer", - le_periodic_adv_set_info_trans, 5, true, + le_pa_set_info_trans, 5, true, status_handle_rsp, 3, true }, { 0x205c, 328, "LE Periodic Advertising Sync Transfer Parameters", - le_periodic_adv_sync_trans_params, 8, true, + le_pa_sync_trans_params, 8, true, status_handle_rsp, 3, true}, { 0x205d, 329, "LE Set Default Periodic Advertisng Sync Transfer " "Parameters", - le_set_default_periodic_adv_sync_trans_params, + le_set_default_pa_sync_trans_params, 6, true, status_rsp, 1, true}, { BT_HCI_CMD_LE_READ_BUFFER_SIZE_V2, BT_HCI_BIT_LE_READ_BUFFER_SIZE_V2, @@ -10631,7 +10631,7 @@ static void le_ext_adv_report_evt(const void *data, uint8_t size) } } -static void le_per_adv_sync(const void *data, uint8_t size) +static void le_pa_sync(const void *data, uint8_t size) { const struct bt_hci_evt_le_per_sync_established *evt = data; @@ -10649,9 +10649,9 @@ static void le_per_adv_sync(const void *data, uint8_t size) print_field("Advertiser clock accuracy: 0x%2.2x", evt->clock_accuracy); } -static void le_per_adv_report_evt(const void *data, uint8_t size) +static void le_pa_report_evt(const void *data, uint8_t size) { - const struct bt_hci_le_per_adv_report *evt = data; + const struct bt_hci_le_pa_report *evt = data; const char *color_on; const char *str; @@ -10710,7 +10710,7 @@ static void le_per_adv_report_evt(const void *data, uint8_t size) packet_hexdump(evt->data, evt->data_len); } -static void le_per_adv_sync_lost(const void *data, uint8_t size) +static void le_pa_sync_lost(const void *data, uint8_t size) { const struct bt_hci_evt_le_per_sync_lost *evt = data; @@ -10768,9 +10768,9 @@ static void le_cte_request_failed_evt(const void *data, uint8_t size) print_field("Connection handle: %d", evt->handle); } -static void le_per_adv_sync_trans_rec_evt(const void *data, uint8_t size) +static void le_pa_sync_trans_rec_evt(const void *data, uint8_t size) { - const struct bt_hci_evt_le_per_adv_sync_trans_rec *evt = data; + const struct bt_hci_evt_le_pa_sync_trans_rec *evt = data; print_status(evt->status); print_field("Handle: %d", evt->handle); @@ -10957,11 +10957,11 @@ static const struct subevent_data le_meta_event_table[] = { { 0x0d, "LE Extended Advertising Report", le_ext_adv_report_evt, 1, false}, { 0x0e, "LE Periodic Advertising Sync Established", - le_per_adv_sync, 15, true }, + le_pa_sync, 15, true }, { 0x0f, "LE Periodic Advertising Report", - le_per_adv_report_evt, 7, false}, + le_pa_report_evt, 7, false}, { 0x10, "LE Periodic Advertising Sync Lost", - le_per_adv_sync_lost, 2, true}, + le_pa_sync_lost, 2, true}, { 0x11, "LE Scan Timeout" }, { 0x12, "LE Advertising Set Terminated", le_adv_set_term_evt, 5, true}, @@ -10972,7 +10972,7 @@ static const struct subevent_data le_meta_event_table[] = { { 0x17, "LE CTE Request Failed", le_cte_request_failed_evt, 3, true}, { 0x18, "LE Periodic Advertising Sync Transfer Received", - le_per_adv_sync_trans_rec_evt, 19, + le_pa_sync_trans_rec_evt, 19, true}, { BT_HCI_EVT_LE_CIS_ESTABLISHED, "LE Connected Isochronous Stream Established", From patchwork Sat Mar 5 01:22:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 548604 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 595F4C433FE for ; Sat, 5 Mar 2022 01:22:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230397AbiCEBXc (ORCPT ); Fri, 4 Mar 2022 20:23:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58172 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230378AbiCEBX1 (ORCPT ); Fri, 4 Mar 2022 20:23:27 -0500 Received: from mail-pj1-x102f.google.com (mail-pj1-x102f.google.com [IPv6:2607:f8b0:4864:20::102f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 68F1731222 for ; Fri, 4 Mar 2022 17:22:38 -0800 (PST) Received: by mail-pj1-x102f.google.com with SMTP id gb21so8668777pjb.5 for ; Fri, 04 Mar 2022 17:22:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=S3XNC5obP+w/h0Z9WSaAkiva6CDaOCeNCUkMcPJpXoQ=; b=oplMO0EXDp24jyYFsLn7eLFYNI8MJXvrH+HZPbqwY8+eVunPcQgdCCfEsYkFBSgrfS XB5vPa3ZWkx9bpLxZrObukJJN72YDr16HSSa64ujsxeLougMvxeEakLRgYYUc9fGMg/h ex+KCYsWMwqCVuD/GErWdxqS6z/asNro0f6R+wkHGy/NrLFO1mRw3Up0mAVHjVsEhQHS a2A1XMrEmMNKpg7yDu92fdO4Q8A9JfVZ37I+a5HPGZQ/8QOVint5+0dNOhaqwlPB6Kas IlKmNb32ZXPS4hwxDhxuYAodGt8fYrdSUpPKf84WIbP9O9/92jWpnaghbmSw88/0zjja M3Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S3XNC5obP+w/h0Z9WSaAkiva6CDaOCeNCUkMcPJpXoQ=; b=5FbbxWtUFR0fvckhqHCnuUQUfwHVP4TnHc4RnWXv1zOX/A02gyojvmiOGdfrk6h+TB kpsa50Jj6BqHurGUHgEDVu2mn4KDjN30PRhhZHjcqLiMlPEyEdmKbfs4ieteWsNQ92fr 8LRbX7dyqGxok3b+mjeYB61eM1LvHDup1e36wZTytMaTvecB3W4FW+mtC2EjDuYkAhFO 8wPT9QLQ8UtRGYDEWVrwP+2M3Mrs1Thttp/o72xhY/jlLuZRsw0FEQ01/uTCmSESMiV9 Djrluruo/FZyu5Cyd1SEwvY0Zq/w4wHZ+RoBmSTUErw5P4l9d4My8P3ZPGs7w5W5Gbee 3yKQ== X-Gm-Message-State: AOAM532deaJFolZG40bjdn8MxWsaTSOPuDsXsOksEunqRbky+6MgVY4N 4yPozubiNOW8gk8/Xse7U5BP2z8hnv4= X-Google-Smtp-Source: ABdhPJyeZ67KA1QDR2rOblC0z49N1uRMS8qsbtKaOElPJGBxCzQFCzzGWN4xw/94PP0nKZN21iDOGg== X-Received: by 2002:a17:902:9a4c:b0:14d:b0c0:1f7a with SMTP id x12-20020a1709029a4c00b0014db0c01f7amr1161385plv.57.1646443357579; Fri, 04 Mar 2022 17:22:37 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id m16-20020a638c10000000b0037c4cf366c0sm5363932pgd.61.2022.03.04.17.22.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 17:22:37 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v2 08/12] btdev: Implements BT_HCI_CMD_LE_BIG_CREATE_SYNC Date: Fri, 4 Mar 2022 17:22:25 -0800 Message-Id: <20220305012229.853784-9-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220305012229.853784-1-luiz.dentz@gmail.com> References: <20220305012229.853784-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This sends BT_HCI_EVT_LE_BIG_SYNC_ESTABLISHED when handling BT_HCI_CMD_LE_BIG_CREATE_SYNC. --- emulator/btdev.c | 158 ++++++++++++++++++++++++++++++++++++++++++++--- monitor/bt.h | 1 + 2 files changed, 150 insertions(+), 9 deletions(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index 10fa046bc..567377caa 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -40,6 +40,7 @@ #define AL_SIZE 16 #define RL_SIZE 16 #define CIS_SIZE 3 +#define BIS_SIZE 3 #define has_bredr(btdev) (!((btdev)->features[4] & 0x20)) #define has_le(btdev) (!!((btdev)->features[4] & 0x40)) @@ -65,6 +66,7 @@ struct btdev_conn { uint8_t type; struct btdev *dev; struct btdev_conn *link; + void *data; }; struct btdev_al { @@ -199,6 +201,7 @@ struct btdev { uint8_t le_pa_data[31]; 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 { struct bt_hci_cmd_le_set_cig_params params; @@ -690,6 +693,7 @@ static void conn_remove(void *data) queue_remove(conn->dev->conns, conn); + free(conn->data); free(conn); } @@ -1121,9 +1125,65 @@ static struct btdev_conn *conn_add_cis(struct btdev_conn *acl, uint16_t handle) return conn_link(acl->dev, acl->link->dev, handle, HCI_ISODATA_PKT); } -static struct btdev_conn *conn_add_bis(struct btdev *dev, uint16_t handle) +static struct btdev_conn *conn_add_bis(struct btdev *dev, uint16_t handle, + const struct bt_hci_bis *bis) { - return conn_new(dev, handle, HCI_ISODATA_PKT); + struct btdev_conn *conn; + + conn = conn_new(dev, handle, HCI_ISODATA_PKT); + if (!conn) + return conn; + + conn->data = util_memdup(bis, sizeof(*bis)); + + return conn; +} + +static struct btdev_conn *find_bis_index(struct btdev *remote, uint8_t index) +{ + struct btdev_conn *conn; + const struct queue_entry *entry; + + for (entry = queue_get_entries(remote->conns); entry; + entry = entry->next) { + conn = entry->data; + + /* Skip if not a broadcast */ + if (conn->type != HCI_ISODATA_PKT || conn->link) + continue; + + if (!index) + return conn; + + index--; + } + + return NULL; +} + +static struct btdev_conn *conn_link_bis(struct btdev *dev, struct btdev *remote, + uint8_t index) +{ + struct btdev_conn *conn; + struct btdev_conn *bis; + + bis = find_bis_index(remote, index); + if (!bis) + return NULL; + + conn = conn_add_bis(dev, ISO_HANDLE, bis->data); + if (!conn) + return NULL; + + bis->link = conn; + conn->link = bis; + + util_debug(dev->debug_callback, dev->debug_data, + "bis %p handle 0x%04x", bis, bis->handle); + util_debug(dev->debug_callback, dev->debug_data, + "conn %p handle 0x%04x", conn, conn->handle); + + return conn; } static void conn_complete(struct btdev *btdev, @@ -5103,8 +5163,6 @@ static void le_pa_sync_estabilished(struct btdev *dev, struct btdev *remote, ev.interval = remote->le_pa_min_interval; ev.clock_accuracy = 0x07; - memset(&dev->pa_sync_cmd, 0, sizeof(dev->pa_sync_cmd)); - le_meta_event(dev, BT_HCI_EVT_LE_PA_SYNC_ESTABLISHED, &ev, sizeof(ev)); send_pa(dev, remote, 0); } @@ -5858,14 +5916,14 @@ static int cmd_create_big_complete(struct btdev *dev, const void *data, memset(&pdu, 0, sizeof(pdu)); - conn = conn_add_bis(dev, ISO_HANDLE); + conn = conn_add_bis(dev, ISO_HANDLE, bis); if (!conn) { pdu.evt.status = BT_HCI_ERR_MEM_CAPACITY_EXCEEDED; goto done; } pdu.evt.handle = cmd->handle; - pdu.evt.num_bis = 0x01; + pdu.evt.num_bis++; pdu.evt.phy = bis->phy; pdu.evt.max_pdu = bis->sdu; memcpy(pdu.evt.sync_delay, bis->sdu_interval, 3); @@ -5910,8 +5968,89 @@ static int cmd_term_big_complete(struct btdev *dev, const void *data, static int cmd_big_create_sync(struct btdev *dev, const void *data, uint8_t len) { - /* TODO */ - return -ENOTSUP; + const struct bt_hci_cmd_le_big_create_sync *cmd = data; + uint8_t status = BT_HCI_ERR_SUCCESS; + + /* 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)) + status = BT_HCI_ERR_UNKNOWN_ADVERTISING_ID; + + /* If the Host sends this command with a BIG_Handle that is already + * allocated, the Controller shall return the error code Command + * Disallowed (0x0C). + */ + if (dev->big_handle == cmd->handle) + status = BT_HCI_ERR_COMMAND_DISALLOWED; + + /* If the Num_BIS parameter is greater than the total number of BISes + * in the BIG, the Controller shall return the error code Unsupported + * Feature or Parameter Value (0x11). + */ + if (cmd->num_bis != len - sizeof(*cmd)) + status = BT_HCI_ERR_UNSUPPORTED_FEATURE; + + if (status) + return status; + + cmd_status(dev, status, BT_HCI_CMD_LE_BIG_CREATE_SYNC); + + return status; +} + +static int cmd_big_create_sync_complete(struct btdev *dev, const void *data, + uint8_t len) +{ + const struct bt_hci_cmd_le_big_create_sync *cmd = data; + struct __packed { + struct bt_hci_evt_le_big_sync_estabilished ev; + uint16_t bis[BIS_SIZE]; + } pdu; + struct btdev *remote; + struct btdev_conn *conn = NULL; + struct bt_hci_bis *bis; + int i; + + remote = find_btdev_by_bdaddr_type(dev->pa_sync_cmd.addr, + dev->pa_sync_cmd.addr_type); + if (!remote) + return 0; + + memset(&pdu.ev, 0, sizeof(pdu.ev)); + + for (i = 0; i < cmd->num_bis; i++) { + conn = conn_link_bis(dev, remote, i); + if (!conn) + break; + + pdu.bis[i] = cpu_to_le16(conn->handle); + } + + if (i != cmd->num_bis || !conn) { + 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; + } + + dev->big_handle = cmd->handle; + bis = conn->data; + + pdu.ev.handle = cmd->handle; + memcpy(pdu.ev.latency, bis->sdu_interval, sizeof(pdu.ev.interval)); + pdu.ev.nse = 0x01; + pdu.ev.bn = 0x01; + pdu.ev.pto = 0x00; + pdu.ev.irc = 0x01; + pdu.ev.max_pdu = bis->sdu; + pdu.ev.interval = bis->latency; + pdu.ev.num_bis = cmd->num_bis; + + le_meta_event(dev, BT_HCI_EVT_LE_BIG_SYNC_ESTABILISHED, &pdu, + sizeof(pdu.ev) + (cmd->num_bis * sizeof(uint16_t))); + + return 0; } static int cmd_big_term_sync(struct btdev *dev, const void *data, uint8_t len) @@ -6125,7 +6264,8 @@ static int cmd_config_data_path(struct btdev *dev, const void *data, cmd_create_big_complete), \ CMD(BT_HCI_CMD_LE_CREATE_BIG_TEST, cmd_create_big_test, NULL), \ CMD(BT_HCI_CMD_LE_TERM_BIG, cmd_term_big, cmd_term_big_complete), \ - CMD(BT_HCI_CMD_LE_BIG_CREATE_SYNC, cmd_big_create_sync, NULL), \ + CMD(BT_HCI_CMD_LE_BIG_CREATE_SYNC, cmd_big_create_sync, \ + cmd_big_create_sync_complete), \ CMD(BT_HCI_CMD_LE_BIG_TERM_SYNC, cmd_big_term_sync, NULL), \ CMD(BT_HCI_CMD_LE_REQ_PEER_SCA, cmd_req_peer_sca, NULL), \ CMD(BT_HCI_CMD_LE_SETUP_ISO_PATH, cmd_setup_iso_path, NULL), \ diff --git a/monitor/bt.h b/monitor/bt.h index 5c2acee67..3bee11868 100644 --- a/monitor/bt.h +++ b/monitor/bt.h @@ -2797,6 +2797,7 @@ struct bt_hci_cmd_le_term_big { #define BT_HCI_CMD_LE_BIG_CREATE_SYNC 0x206b #define BT_HCI_BIT_LE_BIG_CREATE_SYNC BT_HCI_CMD_BIT(43, 0) struct bt_hci_bis_sync { + uint8_t index; } __attribute__ ((packed)); struct bt_hci_cmd_le_big_create_sync { From patchwork Sat Mar 5 01:22:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 548753 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 C52BAC433EF for ; Sat, 5 Mar 2022 01:22:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230385AbiCEBXe (ORCPT ); Fri, 4 Mar 2022 20:23:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58212 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230382AbiCEBX2 (ORCPT ); Fri, 4 Mar 2022 20:23:28 -0500 Received: from mail-pf1-x430.google.com (mail-pf1-x430.google.com [IPv6:2607:f8b0:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 38003656A for ; Fri, 4 Mar 2022 17:22:39 -0800 (PST) Received: by mail-pf1-x430.google.com with SMTP id s11so8982212pfu.13 for ; Fri, 04 Mar 2022 17:22:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Hl0evxxrqp/Qfdb5sN8zGAfs6IrTTpCQEbp1CLx/B74=; b=KbZ4LOrERifi50YqDZOiZnPSeNVA8ZqKxDhspUkftd6i0RVsg8ZNlod/03BQPn+xHX 8HZsruhUUTq3LmRH0IpRmw8T0vpuy0Sj/JAFbWKkyPZKhiqghUn451L1dn/zg58ZveUp gK1LefIKxvgslhv2bZUHAI19TTHtHAkhHaeEK+QL4Nc2qMBu+WSWKX1G2WLgZFQGOGdN VYcqTX3W6vBZrkZPKy807SwZRSVHS+HF6n/tCGNlsJs7jbiQmIZdnZGl9uYSqxIr7Acj s3W3SCUCi3qbB6ffKDrAPcG9fvbDIAjK7jdYFILN+kbKmxw8mj6wnmoU7ZyexfziaTFS 4iJQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Hl0evxxrqp/Qfdb5sN8zGAfs6IrTTpCQEbp1CLx/B74=; b=YRiwyXUhCR+LtBVNzFbCcjhVcUJ2EtroXfVipm/tptBq8+fWXfdTUhGbXyGeX4CCmf AdvVUno5C3eldMOonHmTbmcMddk7CCJeqCFqtt5mTNZSv/nl5Nk1NCtlDCL+uuE43iqY o/tChhSWfLoPta6v1riLHXc0+sxdO77fU+tZ6uqL7wMmfqcccGVctH+xCQLwiHEjBR7T 9MTsZHUxJMRnxktTzHiZeOr88McW6+T/lSiR036h1z6qxmEGfMRw+9ZfGZJMxwpO4Nhb suZ1YXC07wzbDnzyEuJg+AfAr1SuLoJed6GxJI+qg5nWY8Ni8Tt849x2I1KzaGxiX0OJ Pgyg== X-Gm-Message-State: AOAM533zai877ElCvBx+AJAyhD92reTixrFibBz1s5DdOHo+7GnrenEW UhJ5UKrHRjIQ/40rKMZW5LajxqeNk6k= X-Google-Smtp-Source: ABdhPJxiVxlUwXP+uOwz1CF5JvdMCAg84b+EXR+Fp08GkGR3epOe6buXEb7vcEUXPKHEJOSY84JOXA== X-Received: by 2002:a63:2a96:0:b0:37c:46b0:add7 with SMTP id q144-20020a632a96000000b0037c46b0add7mr933904pgq.50.1646443358484; Fri, 04 Mar 2022 17:22:38 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id m16-20020a638c10000000b0037c4cf366c0sm5363932pgd.61.2022.03.04.17.22.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 17:22:38 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v2 09/12] btdev: Implements BT_HCI_CMD_LE_BIG_TERM_SYNC Date: Fri, 4 Mar 2022 17:22:26 -0800 Message-Id: <20220305012229.853784-10-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220305012229.853784-1-luiz.dentz@gmail.com> References: <20220305012229.853784-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This sends BT_HCI_EVT_DISCONNECT_COMPLETE when handling BT_HCI_CMD_LE_BIG_TERM_SYNC. --- emulator/btdev.c | 39 +++++++++++++++++++++++++++++++++++++-- monitor/bt.h | 5 +++++ 2 files changed, 42 insertions(+), 2 deletions(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index 567377caa..6834ec1c2 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -6055,8 +6055,43 @@ static int cmd_big_create_sync_complete(struct btdev *dev, const void *data, static int cmd_big_term_sync(struct btdev *dev, const void *data, uint8_t len) { - /* TODO */ - return -ENOTSUP; + 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; + + memset(&rsp, 0, sizeof(rsp)); + + /* If the Host issues this command with a BIG_Handle that does not + * exist, the Controller shall return the error code Unknown + * Advertising Identifier (0x42). + */ + if (dev->big_handle != cmd->handle) { + rsp.status = BT_HCI_ERR_UNKNOWN_ADVERTISING_ID; + goto done; + } + + rsp.status = BT_HCI_ERR_COMMAND_DISALLOWED; + 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; + + rsp.status = BT_HCI_ERR_SUCCESS; + disconnect_complete(dev, conn->handle, BT_HCI_ERR_SUCCESS, + 0x16); + + conn_remove(conn); + } + +done: + cmd_complete(dev, BT_HCI_CMD_LE_BIG_TERM_SYNC, &rsp, sizeof(rsp)); + + return 0; } static int cmd_req_peer_sca(struct btdev *dev, const void *data, uint8_t len) diff --git a/monitor/bt.h b/monitor/bt.h index 3bee11868..6ce6384a4 100644 --- a/monitor/bt.h +++ b/monitor/bt.h @@ -2817,6 +2817,11 @@ struct bt_hci_cmd_le_big_term_sync { uint8_t handle; } __attribute__ ((packed)); +struct bt_hci_rsp_le_big_term_sync { + uint8_t status; + uint8_t handle; +} __attribute__ ((packed)); + #define BT_HCI_CMD_LE_REQ_PEER_SCA 0x206d #define BT_HCI_BIT_LE_REQ_PEER_SCA BT_HCI_CMD_BIT(43, 2) struct bt_hci_cmd_le_req_peer_sca { From patchwork Sat Mar 5 01:22:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 548603 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 DE51FC4332F for ; Sat, 5 Mar 2022 01:22:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230389AbiCEBXf (ORCPT ); Fri, 4 Mar 2022 20:23:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230387AbiCEBXa (ORCPT ); Fri, 4 Mar 2022 20:23:30 -0500 Received: from mail-pj1-x1029.google.com (mail-pj1-x1029.google.com [IPv6:2607:f8b0:4864:20::1029]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A806628E36 for ; Fri, 4 Mar 2022 17:22:40 -0800 (PST) Received: by mail-pj1-x1029.google.com with SMTP id kx1-20020a17090b228100b001bf2dd26729so2199514pjb.1 for ; Fri, 04 Mar 2022 17:22:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=kLgLzYVc8A/ZbeNHx7AVn2c3UDsNrYm1LuYu8aNKta4=; b=jbP7x3qkbkWW31V1p1Lj+k4UuIVH7XZEJyP0WaBc3LLj2PDWtLo5nSlO2n4DITy8Hu raKsy+Qper8+owjxWmszXxtPcr7nzQiP4HX9QKgAi6YYOzXmZpLWsvcsKzMGBY3abfgC M7ZeMOeXWEkDkLKhoJ1y15XUmLw6I+RWZ/pXZWHWsL7XfJHIQVfJU1N1Xh/n8n9soyqj 265gw7MJhPYLD+20jGNtjRx6efyWxN9K7Tyw/ywGTsfTgMBKInRiHKR9u1Rccq3ikccg x5rtEwO3Wb6jFdHefP5w4xI+iiAJzUA5cHhTYB+CDqIGIQMur4S8wgN4hJHvHeKcQU2C OySA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kLgLzYVc8A/ZbeNHx7AVn2c3UDsNrYm1LuYu8aNKta4=; b=Ox3PYm2v/UTeJmb4SfEjshJ+DxV1z4UeHlf+PRMbFfjJfXDpJjC1CYCsDDlOnE5WN1 DcmLvyTGUrhblMhM7H2eV4tc2jr65L+UWsC/E+3wXCkF641MQtaPgrVQ3jCeLC/vJF+/ zZT1ixQ3UKV5xyprkHazM/XwWzLDO3kkZEEIqrdPZVZpen4No6FxEwU91yakvnpjUnFV XmnFBfojf6pDj74lcy/QtJ/6OWjg++krUirh1qfH71PwJuBALHWVvXWoxroAMa8Bd+Qq KnDXLVcERX8t1ATERPZz3tTYaN40M7MgLRrRa6gAOjX6Eg7aLrOg/2cOgdDgkY0bN0Er XqJQ== X-Gm-Message-State: AOAM530avIsaN+/xl0Eci3MoC9dYWPSoB2RSb1YSUSUbcQTBRIJvnSAR 4pTFht6L3VEfJfAGwTtoN53Nq2Q7N5U= X-Google-Smtp-Source: ABdhPJwrpGO991Z/hyqhc//cE83Ha0ryltjuZbSC+2k9oi5XV/nlGzfChZ4lH9ak7dCFu+boyVBsBw== X-Received: by 2002:a17:902:690c:b0:151:b8ec:2048 with SMTP id j12-20020a170902690c00b00151b8ec2048mr1079763plk.163.1646443359296; Fri, 04 Mar 2022 17:22:39 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id m16-20020a638c10000000b0037c4cf366c0sm5363932pgd.61.2022.03.04.17.22.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 17:22:38 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v2 10/12] bthost: Add support for BT_H4_ISO_PKT Date: Fri, 4 Mar 2022 17:22:27 -0800 Message-Id: <20220305012229.853784-11-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220305012229.853784-1-luiz.dentz@gmail.com> References: <20220305012229.853784-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds sending and receiving BT_H4_ISO_PKT packets. --- emulator/bthost.c | 356 ++++++++++++++++++++++++++++++++++++++++------ emulator/bthost.h | 11 ++ emulator/hciemu.c | 1 + monitor/bt.h | 2 + 4 files changed, 328 insertions(+), 42 deletions(-) diff --git a/emulator/bthost.c b/emulator/bthost.c index d751e7dd4..54a2728e0 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -37,6 +37,9 @@ #define acl_handle(h) (h & 0x0fff) #define acl_flags(h) (h >> 12) +#define iso_flags_pb(f) (f & 0x0003) +#define iso_data_len_pack(h, f) ((uint16_t) ((h) | ((f) << 14))) + #define L2CAP_FEAT_FIXED_CHAN 0x00000080 #define L2CAP_FC_SIG_BREDR 0x02 #define L2CAP_FC_SMP_BREDR 0x80 @@ -131,6 +134,11 @@ struct rfcomm_chan_hook { struct rfcomm_chan_hook *next; }; +struct iso_hook { + bthost_cid_hook_func_t func; + void *user_data; +}; + struct btconn { uint16_t handle; uint8_t bdaddr[6]; @@ -142,8 +150,12 @@ struct btconn { struct rcconn *rcconns; struct cid_hook *cid_hooks; struct rfcomm_chan_hook *rfcomm_chan_hooks; + struct iso_hook *iso_hook; struct btconn *next; void *smp_data; + uint16_t recv_len; + uint16_t data_len; + void *recv_data; }; struct l2conn { @@ -203,9 +215,6 @@ struct bthost { uint8_t bdaddr[6]; uint8_t features[8]; bthost_send_func send_handler; - uint16_t acl_len; - uint16_t l2_len; - void *acl_data; void *send_data; struct cmd_queue cmd_q; uint8_t ncmd; @@ -214,6 +223,8 @@ struct bthost { void *cmd_complete_data; bthost_new_conn_cb new_conn_cb; void *new_conn_data; + bthost_new_conn_cb new_iso_cb; + void *new_iso_data; struct rfcomm_connection_data *rfcomm_conn_data; struct l2cap_conn_cb_data *new_l2cap_conn_data; struct rfcomm_conn_cb_data *new_rfcomm_conn_data; @@ -295,6 +306,8 @@ static void btconn_free(struct btconn *conn) free(hook); } + free(conn->iso_hook); + free(conn->recv_data); free(conn); } @@ -494,7 +507,6 @@ void bthost_destroy(struct bthost *bthost) queue_destroy(bthost->le_ext_adv, le_ext_adv_free); - free(bthost->acl_data); free(bthost); } @@ -663,6 +675,28 @@ void bthost_add_cid_hook(struct bthost *bthost, uint16_t handle, uint16_t cid, conn->cid_hooks = hook; } +void bthost_add_iso_hook(struct bthost *bthost, uint16_t handle, + bthost_cid_hook_func_t func, void *user_data) +{ + struct iso_hook *hook; + struct btconn *conn; + + conn = bthost_find_conn(bthost, handle); + if (!conn || conn->iso_hook) + return; + + hook = malloc(sizeof(*hook)); + if (!hook) + return; + + memset(hook, 0, sizeof(*hook)); + + hook->func = func; + hook->user_data = user_data; + + conn->iso_hook = hook; +} + void bthost_send_cid(struct bthost *bthost, uint16_t handle, uint16_t cid, const void *data, uint16_t len) { @@ -687,6 +721,52 @@ void bthost_send_cid_v(struct bthost *bthost, uint16_t handle, uint16_t cid, send_iov(bthost, handle, cid, iov, iovcnt); } +static void send_iso(struct bthost *bthost, uint16_t handle, + const struct iovec *iov, int iovcnt) +{ + struct bt_hci_iso_hdr iso_hdr; + struct bt_hci_iso_data_start data_hdr; + uint8_t pkt = BT_H4_ISO_PKT; + struct iovec pdu[3 + iovcnt]; + int i, len = 0; + static uint16_t sn; + + for (i = 0; i < iovcnt; i++) { + pdu[3 + i].iov_base = iov[i].iov_base; + pdu[3 + i].iov_len = iov[i].iov_len; + len += iov[i].iov_len; + } + + pdu[0].iov_base = &pkt; + pdu[0].iov_len = sizeof(pkt); + + iso_hdr.handle = acl_handle_pack(handle, 0x02); + iso_hdr.dlen = cpu_to_le16(len + sizeof(data_hdr)); + + pdu[1].iov_base = &iso_hdr; + pdu[1].iov_len = sizeof(iso_hdr); + + data_hdr.sn = cpu_to_le16(sn++); + data_hdr.slen = cpu_to_le16(iso_data_len_pack(len, 0)); + + pdu[2].iov_base = &data_hdr; + pdu[2].iov_len = sizeof(data_hdr); + + send_packet(bthost, pdu, 3 + iovcnt); +} + +void bthost_send_iso(struct bthost *bthost, uint16_t handle, + const struct iovec *iov, int iovcnt) +{ + struct btconn *conn; + + conn = bthost_find_conn(bthost, handle); + if (!conn) + return; + + send_iso(bthost, handle, iov, iovcnt); +} + bool bthost_l2cap_req(struct bthost *bthost, uint16_t handle, uint8_t code, const void *data, uint16_t len, bthost_l2cap_rsp_cb cb, void *user_data) @@ -1337,6 +1417,40 @@ static void evt_le_ltk_request(struct bthost *bthost, const void *data, sizeof(cp)); } +static void init_iso(struct bthost *bthost, uint16_t handle, + const uint8_t *bdaddr, uint8_t addr_type) +{ + struct btconn *conn; + + bthost_debug(bthost, "ISO handle 0x%4.4x", handle); + + conn = malloc(sizeof(*conn)); + if (!conn) + return; + + memset(conn, 0, sizeof(*conn)); + conn->handle = handle; + memcpy(conn->bdaddr, bdaddr, 6); + conn->addr_type = addr_type; + + conn->next = bthost->conns; + bthost->conns = conn; + + if (bthost->new_iso_cb) + bthost->new_iso_cb(handle, bthost->new_iso_data); +} + +static void evt_le_cis_established(struct bthost *bthost, const void *data, + uint8_t size) +{ + const struct bt_hci_evt_le_cis_established *ev = data; + + if (ev->status) + return; + + init_iso(bthost, ev->conn_handle, BDADDR_ANY->b, BDADDR_LE_PUBLIC); +} + static void evt_le_cis_req(struct bthost *bthost, const void *data, uint8_t len) { const struct bt_hci_evt_le_cis_req *ev = data; @@ -1384,6 +1498,38 @@ static void evt_le_ext_adv_report(struct bthost *bthost, const void *data, } } +static void evt_le_big_complete(struct bthost *bthost, const void *data, + uint8_t size) +{ + const struct bt_hci_evt_le_big_complete *ev = data; + int i; + + if (ev->status) + return; + + for (i = 0; i < ev->num_bis; i++) { + uint16_t handle = le16_to_cpu(ev->bis_handle[i]); + + init_iso(bthost, handle, BDADDR_ANY->b, BDADDR_LE_PUBLIC); + } +} + +static void evt_le_big_sync_established(struct bthost *bthost, + const void *data, uint8_t size) +{ + const struct bt_hci_evt_le_big_sync_estabilished *ev = data; + int i; + + if (ev->status) + return; + + for (i = 0; i < ev->num_bis; i++) { + uint16_t handle = le16_to_cpu(ev->bis[i]); + + init_iso(bthost, handle, BDADDR_ANY->b, BDADDR_LE_PUBLIC); + } +} + static void evt_le_meta_event(struct bthost *bthost, const void *data, uint8_t len) { @@ -1393,7 +1539,7 @@ static void evt_le_meta_event(struct bthost *bthost, const void *data, if (len < 1) return; - bthost_debug(bthost, "event 0x%02x", *event); + bthost_debug(bthost, "meta event 0x%02x", *event); switch (*event) { case BT_HCI_EVT_LE_CONN_COMPLETE: @@ -1414,9 +1560,18 @@ static void evt_le_meta_event(struct bthost *bthost, const void *data, case BT_HCI_EVT_LE_EXT_ADV_REPORT: evt_le_ext_adv_report(bthost, evt_data, len - 1); break; + case BT_HCI_EVT_LE_CIS_ESTABLISHED: + evt_le_cis_established(bthost, evt_data, len - 1); + break; case BT_HCI_EVT_LE_CIS_REQ: evt_le_cis_req(bthost, evt_data, len - 1); break; + case BT_HCI_EVT_LE_BIG_COMPLETE: + evt_le_big_complete(bthost, evt_data, len - 1); + break; + case BT_HCI_EVT_LE_BIG_SYNC_ESTABILISHED: + evt_le_big_sync_established(bthost, evt_data, len - 1); + break; default: bthost_debug(bthost, "Unsupported LE Meta event 0x%2.2x", *event); @@ -2437,22 +2592,14 @@ static void process_rfcomm(struct bthost *bthost, struct btconn *conn, } } -static void process_l2cap(struct bthost *bthost, uint16_t handle, +static void process_l2cap(struct bthost *bthost, struct btconn *conn, const void *data, uint16_t len) { const struct bt_l2cap_hdr *l2_hdr = data; struct cid_hook *hook; - struct btconn *conn; struct l2conn *l2conn; uint16_t cid, l2_len; - conn = bthost_find_conn(bthost, handle); - if (!conn) { - bthost_debug(bthost, "ACL data for unknown handle 0x%04x", - handle); - return; - } - l2_len = le16_to_cpu(l2_hdr->len); if (len != sizeof(*l2_hdr) + l2_len) { bthost_debug(bthost, "L2CAP invalid length: %u != %zu", @@ -2496,36 +2643,55 @@ static void process_l2cap(struct bthost *bthost, uint16_t handle, } } -static void append_acl_data(struct bthost *bthost, uint16_t handle, - uint8_t flags, const void *data, uint16_t len) +static void append_recv_data(struct bthost *bthost, struct btconn *conn, + const char *type, uint8_t flags, + const void *data, uint16_t len) { - if (!bthost->acl_data) { - bthost_debug(bthost, "Unexpected ACL frame: handle 0x%4.4x " - "flags 0x%2.2x", handle, flags); + if (!conn->recv_data) { + bthost_debug(bthost, "Unexpected %s frame: handle 0x%4.4x " + "flags 0x%2.2x", type, conn->handle, flags); return; } - if (bthost->acl_len + len > bthost->l2_len) { - bthost_debug(bthost, "Unexpected ACL frame: handle 0x%4.4x " - "flags 0x%2.2x", handle, flags); + if (conn->recv_len + len > conn->data_len) { + bthost_debug(bthost, "Unexpected %s frame: handle 0x%4.4x " + "flags 0x%2.2x", type, conn->handle, flags); return; } - memcpy(bthost->acl_data + bthost->acl_len, data, len); - bthost->acl_len += len; + memcpy(conn->recv_data + conn->recv_len, data, len); + conn->recv_len += len; - bthost_debug(bthost, "ACL data: %u/%u bytes", bthost->acl_len, - bthost->l2_len); + bthost_debug(bthost, "%s data: %u/%u bytes", type, conn->recv_len, + conn->data_len); +} - if (bthost->acl_len < bthost->l2_len) +static void free_recv_data(struct btconn *conn) +{ + free(conn->recv_data); + conn->recv_data = NULL; + conn->recv_len = 0; + conn->data_len = 0; +} + +static void append_acl_data(struct bthost *bthost, struct btconn *conn, + uint8_t flags, const void *data, uint16_t len) +{ + append_recv_data(bthost, conn, "ACL", flags, data, len); + + if (conn->recv_len < conn->data_len) return; - process_l2cap(bthost, handle, bthost->acl_data, bthost->acl_len); + process_l2cap(bthost, conn, conn->recv_data, conn->recv_len); - free(bthost->acl_data); - bthost->acl_data = NULL; - bthost->acl_len = 0; - bthost->l2_len = 0; + free_recv_data(conn); +} + +static void new_recv_data(struct btconn *conn, uint16_t len) +{ + conn->recv_data = malloc(len); + conn->recv_len = 0; + conn->data_len = len; } static void process_acl(struct bthost *bthost, const void *data, uint16_t len) @@ -2534,6 +2700,7 @@ static void process_acl(struct bthost *bthost, const void *data, uint16_t len) const struct bt_l2cap_hdr *l2_hdr = (void *) acl_hdr->data; uint16_t handle, acl_len, l2_len; uint8_t flags; + struct btconn *conn; acl_len = le16_to_cpu(acl_hdr->dlen); if (len != sizeof(*acl_hdr) + acl_len) @@ -2542,14 +2709,18 @@ static void process_acl(struct bthost *bthost, const void *data, uint16_t len) handle = acl_handle(acl_hdr->handle); flags = acl_flags(acl_hdr->handle); + conn = bthost_find_conn(bthost, handle); + if (!conn) { + bthost_debug(bthost, "Unknown handle: 0x%4.4x", handle); + return; + } + switch (flags) { case 0x00: /* start of a non-automatically-flushable PDU */ case 0x02: /* start of an automatically-flushable PDU */ - if (bthost->acl_data) { + if (conn->recv_data) { bthost_debug(bthost, "Unexpected ACL start frame"); - free(bthost->acl_data); - bthost->acl_data = NULL; - bthost->acl_len = 0; + free_recv_data(conn); } l2_len = le16_to_cpu(l2_hdr->len) + sizeof(*l2_hdr); @@ -2557,25 +2728,116 @@ static void process_acl(struct bthost *bthost, const void *data, uint16_t len) bthost_debug(bthost, "acl_len %u l2_len %u", acl_len, l2_len); if (acl_len == l2_len) { - process_l2cap(bthost, handle, acl_hdr->data, acl_len); + process_l2cap(bthost, conn, acl_hdr->data, acl_len); break; } - bthost->acl_data = malloc(l2_len); - bthost->acl_len = 0; - bthost->l2_len = l2_len; + new_recv_data(conn, l2_len); /* fall through */ case 0x01: /* continuing fragment */ - append_acl_data(bthost, handle, flags, acl_hdr->data, acl_len); + append_acl_data(bthost, conn, flags, acl_hdr->data, acl_len); break; case 0x03: /* complete automatically-flushable PDU */ - process_l2cap(bthost, handle, acl_hdr->data, acl_len); + process_l2cap(bthost, conn, acl_hdr->data, acl_len); break; default: bthost_debug(bthost, "Invalid ACL frame flags 0x%2.2x", flags); } } +static void process_iso_data(struct bthost *bthost, struct btconn *conn, + const void *data, uint16_t len) +{ + const struct bt_hci_iso_data_start *data_hdr = data; + uint16_t data_len; + struct iso_hook *hook; + + data_len = le16_to_cpu(data_hdr->slen); + if (len != sizeof(*data_hdr) + data_len) { + bthost_debug(bthost, "ISO invalid length: %u != %zu", + len, sizeof(*data_hdr) + data_len); + return; + } + + bthost_debug(bthost, "ISO data: %u bytes (%u)", data_len, data_hdr->sn); + + hook = conn->iso_hook; + if (!hook) + return; + + hook->func(data_hdr->data, data_len, hook->user_data); +} + +static void append_iso_data(struct bthost *bthost, struct btconn *conn, + uint8_t flags, const void *data, uint16_t len) +{ + append_recv_data(bthost, conn, "ISO", flags, data, len); + + if (conn->recv_len < conn->data_len) { + if (flags == 0x03) { + bthost_debug(bthost, "Unexpected ISO end frame"); + free_recv_data(conn); + } + return; + } + + process_iso_data(bthost, conn, conn->recv_data, conn->recv_len); + + free_recv_data(conn); +} + +static void process_iso(struct bthost *bthost, const void *data, uint16_t len) +{ + const struct bt_hci_iso_hdr *iso_hdr = data; + const struct bt_hci_iso_data_start *data_hdr; + uint16_t handle, iso_len, data_len; + uint8_t flags; + struct btconn *conn; + + iso_len = le16_to_cpu(iso_hdr->dlen); + if (len != sizeof(*iso_hdr) + iso_len) + return; + + handle = acl_handle(iso_hdr->handle); + flags = iso_flags_pb(acl_flags(iso_hdr->handle)); + + conn = bthost_find_conn(bthost, handle); + if (!conn) { + bthost_debug(bthost, "Unknown handle: 0x%4.4x", handle); + return; + } + + data_hdr = (void *) data + sizeof(*iso_hdr); + + switch (flags) { + case 0x00: + case 0x02: + if (conn->recv_data) { + bthost_debug(bthost, "Unexpected ISO start frame"); + free_recv_data(conn); + } + + data_len = le16_to_cpu(data_hdr->slen) + sizeof(*data_hdr); + + bthost_debug(bthost, "iso_len %u data_len %u", iso_len, + data_len); + + if (iso_len == data_len) { + process_iso_data(bthost, conn, iso_hdr->data, iso_len); + break; + } + + new_recv_data(conn, data_len); + /* fall through */ + case 0x01: + case 0x03: + append_iso_data(bthost, conn, flags, iso_hdr->data, iso_len); + break; + default: + bthost_debug(bthost, "Invalid ISO frame flags 0x%2.2x", flags); + } +} + void bthost_receive_h4(struct bthost *bthost, const void *data, uint16_t len) { uint8_t pkt_type; @@ -2598,6 +2860,9 @@ void bthost_receive_h4(struct bthost *bthost, const void *data, uint16_t len) case BT_H4_ACL_PKT: process_acl(bthost, data + 1, len - 1); break; + case BT_H4_ISO_PKT: + process_iso(bthost, data + 1, len - 1); + break; default: bthost_debug(bthost, "Unsupported packet 0x%2.2x", pkt_type); break; @@ -2618,6 +2883,13 @@ void bthost_set_connect_cb(struct bthost *bthost, bthost_new_conn_cb cb, bthost->new_conn_data = user_data; } +void bthost_set_iso_cb(struct bthost *bthost, bthost_new_conn_cb cb, + void *user_data) +{ + bthost->new_iso_cb = cb; + bthost->new_iso_data = user_data; +} + void bthost_hci_connect(struct bthost *bthost, const uint8_t *bdaddr, uint8_t addr_type) { diff --git a/emulator/bthost.h b/emulator/bthost.h index 868af5469..f597d7596 100644 --- a/emulator/bthost.h +++ b/emulator/bthost.h @@ -47,6 +47,9 @@ typedef void (*bthost_new_conn_cb) (uint16_t handle, void *user_data); void bthost_set_connect_cb(struct bthost *bthost, bthost_new_conn_cb cb, void *user_data); +void bthost_set_iso_cb(struct bthost *bthost, bthost_new_conn_cb cb, + void *user_data); + void bthost_hci_connect(struct bthost *bthost, const uint8_t *bdaddr, uint8_t addr_type); @@ -62,10 +65,18 @@ typedef void (*bthost_cid_hook_func_t)(const void *data, uint16_t len, void bthost_add_cid_hook(struct bthost *bthost, uint16_t handle, uint16_t cid, bthost_cid_hook_func_t func, void *user_data); +typedef void (*bthost_iso_hook_func_t)(const void *data, uint16_t len, + void *user_data); + +void bthost_add_iso_hook(struct bthost *bthost, uint16_t handle, + bthost_iso_hook_func_t func, void *user_data); + void bthost_send_cid(struct bthost *bthost, uint16_t handle, uint16_t cid, const void *data, uint16_t len); void bthost_send_cid_v(struct bthost *bthost, uint16_t handle, uint16_t cid, const struct iovec *iov, int iovcnt); +void bthost_send_iso(struct bthost *bthost, uint16_t handle, + const struct iovec *iov, int iovcnt); typedef void (*bthost_l2cap_rsp_cb) (uint8_t code, const void *data, uint16_t len, void *user_data); diff --git a/emulator/hciemu.c b/emulator/hciemu.c index 057f76ff3..dcfed9be7 100644 --- a/emulator/hciemu.c +++ b/emulator/hciemu.c @@ -190,6 +190,7 @@ static gboolean receive_btdev(GIOChannel *channel, GIOCondition condition, case BT_H4_CMD_PKT: case BT_H4_ACL_PKT: case BT_H4_SCO_PKT: + case BT_H4_ISO_PKT: btdev_receive_h4(btdev, buf, len); break; } diff --git a/monitor/bt.h b/monitor/bt.h index 6ce6384a4..704c70fba 100644 --- a/monitor/bt.h +++ b/monitor/bt.h @@ -499,11 +499,13 @@ struct bt_hci_sco_hdr { struct bt_hci_iso_hdr { uint16_t handle; uint16_t dlen; + uint8_t data[]; } __attribute__ ((packed)); struct bt_hci_iso_data_start { uint16_t sn; uint16_t slen; + uint8_t data[]; } __attribute__ ((packed)); struct bt_hci_evt_hdr { From patchwork Sat Mar 5 01:22:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 548602 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 E3610C433FE for ; Sat, 5 Mar 2022 01:22:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230393AbiCEBXg (ORCPT ); Fri, 4 Mar 2022 20:23:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58310 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230390AbiCEBXa (ORCPT ); Fri, 4 Mar 2022 20:23:30 -0500 Received: from mail-pj1-x1031.google.com (mail-pj1-x1031.google.com [IPv6:2607:f8b0:4864:20::1031]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A823231222 for ; Fri, 4 Mar 2022 17:22:40 -0800 (PST) Received: by mail-pj1-x1031.google.com with SMTP id mg21-20020a17090b371500b001bef9e4657cso8574461pjb.0 for ; Fri, 04 Mar 2022 17:22:40 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=TAMJA6rc8NyQ5zesNMZHUQ52CnaUl7RkrULN9uEBqkE=; b=dwdQ7sX8n60C6WTUFnrHRNSjA5nUW3O/R4yWqjB37SWmGaCC1ha0sMuJT5f0fxLe9z OKQ5FgWO/3/Sg1K09ZHhjWFmWJFhfI+SYcvbmBw/uE4V3V1nrJ2lu6D+13/wXMnM82aC OVi81p7lx3r+HtyzMKDQF/93btQd5mVZaHOPTF4MkfgMShBeWEHe59+egkvLiT4Ijm7S hCSn5GQtrTGijE3oenOn7a1J2KRvxuKLohdHBJniPEM+0EXim360uKT2OqgASR3mJOs2 FkyG8snj8DiXB7K0p/MQPVHca6a0i+x/1M57VK/aoqe49IOrHvsiBLtyAeZK2/YAo3kU JH9Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TAMJA6rc8NyQ5zesNMZHUQ52CnaUl7RkrULN9uEBqkE=; b=JXQs+mV+c/euTtybgQ7XqRXgfMFLhQoAX8afq87PKhREk+Il5mlyAAVjl5DSk2hbRK x2qIDy1CFiwj1cgvECbrXQyNXK+qj2K+QuAoNaTuMxGSfo7XFXO37w1pGqjS98Qs56qx 0u8QebZzbJM1qEIr2pgJtz//s8Ty+acM+Rk14kko+AagGr5AS7Z0GtDsYYr6GZcCteTx BGkjhVTQQLrJR4oKOuvzKgrpAdRhZRHf2Q3BI/78rvUI4P28fDd4Ra6hSw0IIe3UavbQ iBexi/CSohX7MRCBvJn337ToVUxM32qPcv8VbiCSHNkDZYtm4l1jsPLy9USXmTMuc3AD LCVA== X-Gm-Message-State: AOAM532/YpP7vOWtbeNbSNb0Ra1yobbeToPROmUobcCh9lmJ4w0JYA6U d7Mtq+g+CRTyakFZpIW9ytNd0lIlKNk= X-Google-Smtp-Source: ABdhPJy138CFBD0c6w5DGy0C+BmOV+3Azq3WBbC198h1duECaCsXNCVuQqR/Id/IHqOvPt3r8dBmdA== X-Received: by 2002:a17:902:7b94:b0:151:bfdc:823b with SMTP id w20-20020a1709027b9400b00151bfdc823bmr1298860pll.171.1646443359944; Fri, 04 Mar 2022 17:22:39 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id m16-20020a638c10000000b0037c4cf366c0sm5363932pgd.61.2022.03.04.17.22.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 17:22:39 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v2 11/12] bthost: Add support for Periodic Advertising Date: Fri, 4 Mar 2022 17:22:28 -0800 Message-Id: <20220305012229.853784-12-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220305012229.853784-1-luiz.dentz@gmail.com> References: <20220305012229.853784-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds bthost_set_pa_params and bthost_set_pa_enable. --- emulator/bthost.c | 23 +++++++++++++++++++++++ emulator/bthost.h | 2 ++ 2 files changed, 25 insertions(+) diff --git a/emulator/bthost.c b/emulator/bthost.c index 54a2728e0..a45a67d14 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -1006,6 +1006,10 @@ static void evt_cmd_complete(struct bthost *bthost, const void *data, break; case BT_HCI_CMD_LE_SET_EXT_ADV_ENABLE: break; + case BT_HCI_CMD_LE_SET_PA_PARAMS: + break; + case BT_HCI_CMD_LE_SET_PA_ENABLE: + break; default: bthost_debug(bthost, "Unhandled cmd_complete opcode 0x%04x", opcode); @@ -3073,6 +3077,25 @@ void bthost_set_ext_adv_enable(struct bthost *bthost, uint8_t enable) send_command(bthost, BT_HCI_CMD_LE_SET_EXT_ADV_ENABLE, cp, 6); } +void bthost_set_pa_params(struct bthost *bthost) +{ + struct bt_hci_cmd_le_set_pa_params cp; + + memset(&cp, 0, sizeof(cp)); + cp.handle = 0x01; + send_command(bthost, BT_HCI_CMD_LE_SET_PA_PARAMS, &cp, sizeof(cp)); +} + +void bthost_set_pa_enable(struct bthost *bthost, uint8_t enable) +{ + struct bt_hci_cmd_le_set_pa_enable cp; + + memset(&cp, 0, sizeof(cp)); + cp.enable = enable; + cp.handle = 0x01; + send_command(bthost, BT_HCI_CMD_LE_SET_PA_ENABLE, &cp, sizeof(cp)); +} + bool bthost_search_ext_adv_addr(struct bthost *bthost, const uint8_t *addr) { const struct queue_entry *entry; diff --git a/emulator/bthost.h b/emulator/bthost.h index f597d7596..fb7b1431e 100644 --- a/emulator/bthost.h +++ b/emulator/bthost.h @@ -95,6 +95,8 @@ void bthost_set_ext_adv_data(struct bthost *bthost, const uint8_t *data, uint8_t len); void bthost_set_ext_adv_params(struct bthost *bthost); void bthost_set_ext_adv_enable(struct bthost *bthost, uint8_t enable); +void bthost_set_pa_params(struct bthost *bthost); +void bthost_set_pa_enable(struct bthost *bthost, uint8_t enable); bool bthost_search_ext_adv_addr(struct bthost *bthost, const uint8_t *addr); void bthost_set_scan_params(struct bthost *bthost, uint8_t scan_type, From patchwork Sat Mar 5 01:22:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Augusto von Dentz X-Patchwork-Id: 548752 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 D19BFC433EF for ; Sat, 5 Mar 2022 01:22:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230387AbiCEBXf (ORCPT ); Fri, 4 Mar 2022 20:23:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58314 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230392AbiCEBXa (ORCPT ); Fri, 4 Mar 2022 20:23:30 -0500 Received: from mail-pg1-x52f.google.com (mail-pg1-x52f.google.com [IPv6:2607:f8b0:4864:20::52f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 954F83151D for ; Fri, 4 Mar 2022 17:22:41 -0800 (PST) Received: by mail-pg1-x52f.google.com with SMTP id w37so8874045pga.7 for ; Fri, 04 Mar 2022 17:22:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Zpoj1dZTGEsaE4MFshJmiX0Xk6PBd6Tolyq7wU9OsX4=; b=Z8d8tqNNBYi5OJ17HudHPTqWYYqZTf+7a8BcC9zHXcpEviEO0iMfp7FKoAwRso8gri wm1OKGveaBimS9mj5K1ew3z5nab2SLTrwaHAXyrSnpfKWBVExgFB2JVK9qOWL4Ir18Ju lVJjI9FMmhfL8kjOTlYF7aWl9yMkR4MAQhSeVkze8B67zjyPzyWqPThvbmS2aBnaJSpv DZYK3SNgHZMiDcCFiIipX9Nxjcj069LLbWetD3RrDSHhk6JVGw1i73QNzZexNLA/eSPH ywWYZTBJeMCUyGXzO4ozubMHMLUFApRBqUpHnOEW708H//nyvPTxdwQwN+fr5p+a+JJ4 asdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Zpoj1dZTGEsaE4MFshJmiX0Xk6PBd6Tolyq7wU9OsX4=; b=3ZAidV42mKJAGxvNdiF7jg11m5kD4fs7L04vhOCMcKO9O6OnsHkXzNI03C33pYcX+L Mo1uYJI4ggdhFX7Ti5iX5zPxBoTY08zjb3MvfBGHoKg7XnQ9Ez4R+sOf2zFZxXUGscj8 VzEx8uiwoOyOaTmHG4A8llZpmo4/+tMds2B87AAwiK/WjSo7CBLbHtERaBeMhUH8RWSv eZ81uAelNfYg7IW3sF9Lgmw0ddRj8ChwfcCRJ3hMMU36n3oRG9hkooOP9WMvQv5d8huz PLm8JmNadfpHYQttGqeZTq4JuSgNlbI06OAOUuGT3QQzB9VFgdH658YZ9JdmqcOGMKQv l0kw== X-Gm-Message-State: AOAM531uO+jxTblRWxZYs+4V7frV8gCkm1ir0q9m6PtYor5dMG7IdcRv bSpGRBJyy+0RffHFEkwRIjECIffwnfk= X-Google-Smtp-Source: ABdhPJwKIWZIen83G8x29e4viUhpwsLfQaURtYgt46Fmw+2yvJ3indxVgPk/19szqx5jO826Irxe2w== X-Received: by 2002:a63:8ac8:0:b0:37c:ed36:8e45 with SMTP id y191-20020a638ac8000000b0037ced368e45mr941125pgd.48.1646443360793; Fri, 04 Mar 2022 17:22:40 -0800 (PST) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id m16-20020a638c10000000b0037c4cf366c0sm5363932pgd.61.2022.03.04.17.22.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 04 Mar 2022 17:22:40 -0800 (PST) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH v2 12/12] bthost: Add support for Create BIG Date: Fri, 4 Mar 2022 17:22:29 -0800 Message-Id: <20220305012229.853784-13-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220305012229.853784-1-luiz.dentz@gmail.com> References: <20220305012229.853784-1-luiz.dentz@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This adds bthost_create_big --- emulator/bthost.c | 13 +++++++++++++ emulator/bthost.h | 1 + 2 files changed, 14 insertions(+) diff --git a/emulator/bthost.c b/emulator/bthost.c index a45a67d14..f629f2e6e 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -3096,6 +3096,19 @@ void bthost_set_pa_enable(struct bthost *bthost, uint8_t enable) send_command(bthost, BT_HCI_CMD_LE_SET_PA_ENABLE, &cp, sizeof(cp)); } +void bthost_create_big(struct bthost *bthost, uint8_t num_bis) +{ + struct bt_hci_cmd_le_create_big cp; + + memset(&cp, 0, sizeof(cp)); + cp.handle = 0x01; + cp.adv_handle = 0x01; + cp.num_bis = num_bis; + cp.bis.sdu = 40; + cp.bis.phy = 0x01; + send_command(bthost, BT_HCI_CMD_LE_CREATE_BIG, &cp, sizeof(cp)); +} + bool bthost_search_ext_adv_addr(struct bthost *bthost, const uint8_t *addr) { const struct queue_entry *entry; diff --git a/emulator/bthost.h b/emulator/bthost.h index fb7b1431e..ae5678009 100644 --- a/emulator/bthost.h +++ b/emulator/bthost.h @@ -97,6 +97,7 @@ void bthost_set_ext_adv_params(struct bthost *bthost); void bthost_set_ext_adv_enable(struct bthost *bthost, uint8_t enable); void bthost_set_pa_params(struct bthost *bthost); void bthost_set_pa_enable(struct bthost *bthost, uint8_t enable); +void bthost_create_big(struct bthost *bthost, uint8_t num_bis); bool bthost_search_ext_adv_addr(struct bthost *bthost, const uint8_t *addr); void bthost_set_scan_params(struct bthost *bthost, uint8_t scan_type,