From patchwork Mon Oct 25 04:47:22 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 12580701 X-Patchwork-Delegate: luiz.dentz@gmail.com 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C92D8C433EF for ; Mon, 25 Oct 2021 04:47:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A3C6A60FBF for ; Mon, 25 Oct 2021 04:47:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231831AbhJYEtu (ORCPT ); Mon, 25 Oct 2021 00:49:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48228 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229678AbhJYEtt (ORCPT ); Mon, 25 Oct 2021 00:49:49 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 309F3C061745 for ; Sun, 24 Oct 2021 21:47:28 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id r2so9678481pgl.10 for ; Sun, 24 Oct 2021 21:47:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=GN64q4nuu6zkiuwohx69Zu7UQYLWgsXgndnImWCPccA=; b=kUJy2KoQbWBBlw3dSaqeCHZjREFkGq/akTqxmvcriEwLkjg+IHhZXKL5o6HwXfIyJg Kagka173v9T7uiJHYWsbiDX/RdOoqGaExUdbWlrjLxka9xlH8uk5QRN/0lTZUSHwuoSM Zr6q83B+qIFqVYfbxOTcd53ttjrX7jedPxhURmjZNY0j53/8fLtI/Pti4jRcyCECZKlU LAWhPnEKSWkCwsG3X3M+nWvI3bVovyGm6QiT0QMIB1RoYiLRmHKcEPbJzRKfpyVCZzEV TPd+uIalGNWKYy+ErkYjoR0a5+peeireV3SOXyXw35T8q9kv77qwO19AviLucf4jsBxX g7BA== 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:mime-version :content-transfer-encoding; bh=GN64q4nuu6zkiuwohx69Zu7UQYLWgsXgndnImWCPccA=; b=tSXtRHlOv8Iyjanu/WBjacXlUlvFbOF9LW+Z02P9Ij7E0ps0A/S4MomgOtoeM7OiIt g6SFBQ37F1DXHAgC8YJejiudF2uhhtbuGJvVC1dSo6W9lkiemVOavft9owAFtwnLjQkn t4e0smF4/gLT4QUJhkr9SpN+4lSx/2xtfhmW0OjUlM3cZRGqsMYL1XlrOzuLTz0brVi3 k3f3ve/Qj89e8RuR++bl35UAUkrVJS+KOmbM6VsHBidM3gYe7e+gdONsi8YkKloSFtKW 1RFN7G7HN1WVBHkHlykVM1bJiMwkyAH0LEs6n1D3/g9WUlMPyddEix0fuMBa4JH1eSvl JDUg== X-Gm-Message-State: AOAM533vx/OTX6Pob6gexygb/4P7dFrS/E7yMPrOJqGUMbWdgKoyaZys HBnaLglXkW5P/FfxUrvU++p+31WYyk4ozA== X-Google-Smtp-Source: ABdhPJwr/clZcO5XZHfbYu4WqkVs6yB0sYyGLnbqk15jQGMcS7L0JYsGJfF6/UHCvHIstZN9fwZKQA== X-Received: by 2002:a05:6a00:24c1:b0:44d:3047:4229 with SMTP id d1-20020a056a0024c100b0044d30474229mr15690312pfv.70.1635137247322; Sun, 24 Oct 2021 21:47:27 -0700 (PDT) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830:d228:1bef:af2a:db8e]) by smtp.gmail.com with ESMTPSA id a17sm13926204pfv.64.2021.10.24.21.47.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Oct 2021 21:47:26 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 1/4] emulator: Add support to config the accept and resolve list Date: Sun, 24 Oct 2021 21:47:22 -0700 Message-Id: <20211025044725.482641-1-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch adds interfaces to config the accept list and resolve list in the btdev. --- emulator/btdev.c | 37 +++++++++++++++++++++++++++++-------- emulator/btdev.h | 4 ++++ emulator/hciemu.c | 28 ++++++++++++++++++++++++++++ emulator/hciemu.h | 4 ++++ 4 files changed, 65 insertions(+), 8 deletions(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index 03003d949..1ae71765d 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -198,6 +198,10 @@ struct btdev { } __attribute__ ((packed)) le_cig; uint8_t le_iso_path[2]; + /* Real time length of AL array */ + uint8_t le_al_len; + /* Real time length of RL array */ + uint8_t le_rl_len; struct btdev_al le_al[AL_SIZE]; struct btdev_rl le_rl[RL_SIZE]; uint8_t le_rl_enable; @@ -482,6 +486,18 @@ static void rl_clear(struct btdev *dev) rl_reset(&dev->le_rl[i]); } +/* Set the real time length of AL array */ +void btdev_set_al_len(struct btdev *btdev, uint8_t len) +{ + btdev->le_al_len = len; +} + +/* Set the real time length of RL array */ +void btdev_set_rl_len(struct btdev *btdev, uint8_t len) +{ + btdev->le_rl_len = len; +} + static void btdev_reset(struct btdev *btdev) { /* FIXME: include here clearing of all states that should be @@ -493,6 +509,9 @@ static void btdev_reset(struct btdev *btdev) al_clear(btdev); rl_clear(btdev); + + btdev->le_al_len = AL_SIZE; + btdev->le_rl_len = RL_SIZE; } static int cmd_reset(struct btdev *dev, const void *data, uint8_t len) @@ -3578,7 +3597,7 @@ static int cmd_read_al_size(struct btdev *dev, const void *data, uint8_t len) struct bt_hci_rsp_le_read_accept_list_size rsp; rsp.status = BT_HCI_ERR_SUCCESS; - rsp.size = AL_SIZE; + rsp.size = dev->le_al_len; cmd_complete(dev, BT_HCI_CMD_LE_READ_ACCEPT_LIST_SIZE, &rsp, sizeof(rsp)); @@ -3665,7 +3684,7 @@ static int cmd_add_al(struct btdev *dev, const void *data, uint8_t len) if (cmd->addr_type > 0x01) return -EINVAL; - for (i = 0; i < AL_SIZE; i++) { + for (i = 0; i < dev->le_al_len; i++) { struct btdev_al *al = &dev->le_al[i]; if (AL_ADDR_EQUAL(al, cmd->addr_type, &cmd->addr)) { @@ -3716,7 +3735,7 @@ static int cmd_remove_al(struct btdev *dev, const void *data, uint8_t len) if (cmd->addr_type > 0x01) return -EINVAL; - for (i = 0; i < AL_SIZE; i++) { + for (i = 0; i < dev->le_al_len; i++) { struct btdev_al *al = &dev->le_al[i]; ba2str(&al->addr, addr); @@ -3731,7 +3750,7 @@ static int cmd_remove_al(struct btdev *dev, const void *data, uint8_t len) } } - if (i == AL_SIZE) + if (i == dev->le_al_len) return -EINVAL; status = BT_HCI_ERR_SUCCESS; @@ -3762,7 +3781,7 @@ static int cmd_add_rl(struct btdev *dev, const void *data, uint8_t len) if (cmd->addr_type > 0x01) return -EINVAL; - for (i = 0; i < RL_SIZE; i++) { + for (i = 0; i < dev->le_rl_len; i++) { struct btdev_rl *rl = &dev->le_rl[i]; if (RL_ADDR_EQUAL(rl, cmd->addr_type, &cmd->addr)) { @@ -3813,7 +3832,7 @@ static int cmd_remove_rl(struct btdev *dev, const void *data, uint8_t len) if (cmd->addr_type > 0x01) return -EINVAL; - for (i = 0; i < RL_SIZE; i++) { + for (i = 0; i < dev->le_rl_len; i++) { struct btdev_rl *rl = &dev->le_rl[i]; if (RL_ADDR_EQUAL(rl, cmd->addr_type, &cmd->addr)) { @@ -3822,7 +3841,7 @@ static int cmd_remove_rl(struct btdev *dev, const void *data, uint8_t len) } } - if (i == RL_SIZE) + if (i == dev->le_rl_len) return -EINVAL; status = BT_HCI_ERR_SUCCESS; @@ -3860,7 +3879,7 @@ static int cmd_read_rl_size(struct btdev *dev, const void *data, uint8_t len) struct bt_hci_rsp_le_read_resolv_list_size rsp; rsp.status = BT_HCI_ERR_SUCCESS; - rsp.size = RL_SIZE; + rsp.size = dev->le_rl_len; cmd_complete(dev, BT_HCI_CMD_LE_READ_RESOLV_LIST_SIZE, &rsp, sizeof(rsp)); @@ -6310,6 +6329,8 @@ struct btdev *btdev_create(enum btdev_type type, uint16_t id) btdev->conns = queue_new(); btdev->le_ext_adv = queue_new(); + btdev->le_al_len = AL_SIZE; + btdev->le_rl_len = RL_SIZE; return btdev; } diff --git a/emulator/btdev.h b/emulator/btdev.h index 412bfd158..b5f9979a8 100644 --- a/emulator/btdev.h +++ b/emulator/btdev.h @@ -80,6 +80,10 @@ uint8_t btdev_get_le_scan_enable(struct btdev *btdev); void btdev_set_le_states(struct btdev *btdev, const uint8_t *le_states); +void btdev_set_al_len(struct btdev *btdev, uint8_t len); + +void btdev_set_rl_len(struct btdev *btdev, uint8_t len); + void btdev_set_command_handler(struct btdev *btdev, btdev_command_func handler, void *user_data); diff --git a/emulator/hciemu.c b/emulator/hciemu.c index 4752c8a4d..1f7af3b93 100644 --- a/emulator/hciemu.c +++ b/emulator/hciemu.c @@ -601,6 +601,34 @@ void hciemu_set_central_le_states(struct hciemu *hciemu, btdev_set_le_states(dev, le_states); } +void hciemu_set_central_le_al_len(struct hciemu *hciemu, uint8_t len) +{ + struct btdev *dev; + + if (!hciemu || !hciemu->vhci) + return; + + dev = vhci_get_btdev(hciemu->vhci); + if (!dev) + return; + + btdev_set_al_len(dev, len); +} + +void hciemu_set_central_le_rl_len(struct hciemu *hciemu, uint8_t len) +{ + struct btdev *dev; + + if (!hciemu || !hciemu->vhci) + return; + + dev = vhci_get_btdev(hciemu->vhci); + if (!dev) + return; + + btdev_set_rl_len(dev, len); +} + bool hciemu_add_central_post_command_hook(struct hciemu *hciemu, hciemu_command_func_t function, void *user_data) { diff --git a/emulator/hciemu.h b/emulator/hciemu.h index 338fa844d..2a49d8bad 100644 --- a/emulator/hciemu.h +++ b/emulator/hciemu.h @@ -61,6 +61,10 @@ uint8_t hciemu_get_central_le_scan_enable(struct hciemu *hciemu); void hciemu_set_central_le_states(struct hciemu *hciemu, const uint8_t *le_states); +void hciemu_set_central_le_al_len(struct hciemu *hciemu, uint8_t len); + +void hciemu_set_central_le_rl_len(struct hciemu *hciemu, uint8_t len); + typedef void (*hciemu_command_func_t)(uint16_t opcode, const void *data, uint8_t len, void *user_data); From patchwork Mon Oct 25 04:47:23 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 12580703 X-Patchwork-Delegate: luiz.dentz@gmail.com 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CAF18C433EF for ; Mon, 25 Oct 2021 04:47:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF5B560FBF for ; Mon, 25 Oct 2021 04:47:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232073AbhJYEtv (ORCPT ); Mon, 25 Oct 2021 00:49:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231613AbhJYEtu (ORCPT ); Mon, 25 Oct 2021 00:49:50 -0400 Received: from mail-pl1-x631.google.com (mail-pl1-x631.google.com [IPv6:2607:f8b0:4864:20::631]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E7A74C061745 for ; Sun, 24 Oct 2021 21:47:28 -0700 (PDT) Received: by mail-pl1-x631.google.com with SMTP id c4so3164694plg.13 for ; Sun, 24 Oct 2021 21:47:28 -0700 (PDT) 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=a92ewmJCIhCXFTeCxJwy0bcIgrcxBRq6irNBLVf+kLY=; b=LRRE5JScnNOJBKhSA4SadiOMHAn/vF/BgE9ty8CJvxOJn2SwS/OMEnjEXh9CJVZDKl c+Ejv91DHo8nSyltMCzaarDyWcMjvOt8mRguCZHnq7PmLZbbMYX/7OHjZtLW13qwdX+q F2qmcY+QVPJ6tAapwr+0iKf7kU5QqFQNdXy055Rsg4vf8ylNi/cGJDAEMjlAsIXXbsE2 shTvxnRZ6+DCftdvh9d7OqbwZAG4zZ1JcJPnYSL40Ll/T6Y6D+runBRXac59NJ9VpPiN GnZif+ZBwMTfW+qtAVC++6ZZsCkO/saUv4HxZNhOQGb0B7hZX10mAUhHNURmo7vNZXgk nI3g== 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=a92ewmJCIhCXFTeCxJwy0bcIgrcxBRq6irNBLVf+kLY=; b=d5gJNPYF0xPdGFZnJ0T/XAutPzsRd1cet3qbmf/ZuIqxZe3UHbmEjKh0nCje15fNnj TPmP+IjSRF1Tg7S9EgnJAyYFgkBSlGFztakumiZatgoxtwKQ70+keyH6aet3LWZczPiE 63CTSzsK5BkpWVJIbzkWuN2as5gwLlm2ZMQAGvN6q8kd5lair29KnGRxcS98O2lZlYOg qbJS8gMMzbf0gIaJMLKd2W9N+iLA1cQcyGDzDu5savDBlITn43DMG0MBH8Yxe85cYPob UyrkAKaWI1T9I8HaXdPMDVpDgHBWvQ8G3xhTvzPJaJG4Kyqi1aL/EM8JfppM2Ol0eaod jfyQ== X-Gm-Message-State: AOAM530eC2LpOqKY8p8Apx/T+RMBREkrq0zcYjnwry1HW7juVl/qxpOt buaq1h+feTFtdT8Lay+m0G2nDrpl/58leA== X-Google-Smtp-Source: ABdhPJyTsEh3MwwtejlBDpZVP6PNyCeFZcQ34UkH+MKhm/xUzJqtv9I3jqjUYiu3qS4NmNgz6aJpTQ== X-Received: by 2002:a17:90a:530f:: with SMTP id x15mr17992339pjh.156.1635137248193; Sun, 24 Oct 2021 21:47:28 -0700 (PDT) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830:d228:1bef:af2a:db8e]) by smtp.gmail.com with ESMTPSA id a17sm13926204pfv.64.2021.10.24.21.47.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Oct 2021 21:47:27 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 2/4] emulator: bthost: Add support LE Ext Adv Report Date: Sun, 24 Oct 2021 21:47:23 -0700 Message-Id: <20211025044725.482641-2-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211025044725.482641-1-hj.tedd.an@gmail.com> References: <20211025044725.482641-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch adds support LE_Extended_Advertising_Report Eevnt in bthost. --- emulator/bthost.c | 118 ++++++++++++++++++++++++++++++++++++++++++++++ emulator/bthost.h | 5 ++ 2 files changed, 123 insertions(+) diff --git a/emulator/bthost.c b/emulator/bthost.c index 4f1598f0d..61f1cd361 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -25,6 +25,7 @@ #include "src/shared/util.h" #include "src/shared/tester.h" +#include "src/shared/queue.h" #include "monitor/bt.h" #include "monitor/rfcomm.h" #include "bthost.h" @@ -187,6 +188,15 @@ struct rfcomm_connection_data { void *user_data; }; +struct le_ext_adv { + struct bthost *bthost; + uint16_t event_type; + uint8_t addr_type; + uint8_t addr[6]; + uint8_t direct_addr_type; + uint8_t direct_addr[6]; +}; + struct bthost { bool ready; bthost_ready_cb ready_cb; @@ -215,6 +225,8 @@ struct bthost { bool le; bool sc; + struct queue *le_ext_adv; + bthost_debug_func_t debug_callback; bthost_destroy_func_t debug_destroy; void *debug_data; @@ -234,6 +246,8 @@ struct bthost *bthost_create(void) return NULL; } + bthost->le_ext_adv = queue_new(); + /* Set defaults */ bthost->io_capability = 0x03; @@ -403,6 +417,32 @@ static struct rfcomm_conn_cb_data *bthost_find_rfcomm_cb_by_channel( return NULL; } +static struct le_ext_adv *le_ext_adv_new(struct bthost *bthost) +{ + struct le_ext_adv *ext_adv; + + ext_adv = new0(struct le_ext_adv, 1); + ext_adv->bthost = bthost; + + /* Add to queue */ + if (!queue_push_tail(bthost->le_ext_adv, ext_adv)) { + free(ext_adv); + return NULL; + } + + return ext_adv; +} + +static void le_ext_adv_free(void *data) +{ + struct le_ext_adv *ext_adv = data; + + /* Remove from queue */ + queue_remove(ext_adv->bthost->le_ext_adv, ext_adv); + + free(ext_adv); +} + void bthost_destroy(struct bthost *bthost) { if (!bthost) @@ -449,6 +489,8 @@ void bthost_destroy(struct bthost *bthost) smp_stop(bthost->smp_data); + queue_destroy(bthost->le_ext_adv, le_ext_adv_free); + free(bthost); } @@ -1306,6 +1348,38 @@ static void evt_le_cis_req(struct bthost *bthost, const void *data, uint8_t len) send_command(bthost, BT_HCI_CMD_LE_ACCEPT_CIS, &cmd, sizeof(cmd)); } +static void evt_le_ext_adv_report(struct bthost *bthost, const void *data, + uint8_t len) +{ + const struct bt_hci_evt_le_ext_adv_report *ev = data; + const struct bt_hci_le_ext_adv_report *report; + struct le_ext_adv *le_ext_adv; + int i; + + data += sizeof(ev->num_reports); + + for (i = 0; i < ev->num_reports; i++) { + char addr_str[18]; + + report = data; + ba2str((bdaddr_t *) report->addr, addr_str); + + bthost_debug(bthost, "le ext adv report: %s (0x%02x)", + addr_str, report->addr_type); + + /* Add ext event to the queue */ + le_ext_adv = le_ext_adv_new(bthost); + if (le_ext_adv) { + le_ext_adv->addr_type = report->addr_type; + memcpy(le_ext_adv->addr, report->addr, 6); + le_ext_adv->direct_addr_type = report->direct_addr_type; + memcpy(le_ext_adv->direct_addr, report->direct_addr, 6); + } + + data += (sizeof(*report) + report->data_len); + } +} + static void evt_le_meta_event(struct bthost *bthost, const void *data, uint8_t len) { @@ -1333,6 +1407,9 @@ static void evt_le_meta_event(struct bthost *bthost, const void *data, case BT_HCI_EVT_LE_ENHANCED_CONN_COMPLETE: evt_le_ext_conn_complete(bthost, evt_data, len - 1); break; + 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_REQ: evt_le_cis_req(bthost, evt_data, len - 1); break; @@ -2583,6 +2660,29 @@ void bthost_set_adv_enable(struct bthost *bthost, uint8_t enable) send_command(bthost, BT_HCI_CMD_LE_SET_ADV_ENABLE, &enable, 1); } +void bthost_set_scan_params(struct bthost *bthost, uint8_t scan_type, + uint8_t addr_type, uint8_t filter_policy) +{ + struct bt_hci_cmd_le_set_scan_parameters cp; + + memset(&cp, 0, sizeof(cp)); + cp.type = scan_type; + cp.own_addr_type = addr_type; + cp.filter_policy = filter_policy; + send_command(bthost, BT_HCI_CMD_LE_SET_SCAN_PARAMETERS, + &cp, sizeof(cp)); +} + +void bthost_set_scan_enable(struct bthost *bthost, uint8_t enable) +{ + struct bt_hci_cmd_le_set_scan_enable cp; + + memset(&cp, 0, sizeof(cp)); + cp.enable = enable; + send_command(bthost, BT_HCI_CMD_LE_SET_SCAN_ENABLE, + &cp, sizeof(cp)); +} + void bthost_set_ext_adv_params(struct bthost *bthost) { struct bt_hci_cmd_le_set_ext_adv_params cp; @@ -2612,6 +2712,24 @@ 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); } +bool bthost_search_ext_adv_addr(struct bthost *bthost, const uint8_t *addr) +{ + const struct queue_entry *entry; + + if (queue_isempty(bthost->le_ext_adv)) + return false; + + for (entry = queue_get_entries(bthost->le_ext_adv); entry; + entry = entry->next) { + struct le_ext_adv *le_ext_adv = entry->data; + + if (!memcmp(le_ext_adv->addr, addr, 6)) + return true; + } + + return false; +} + void bthost_write_ssp_mode(struct bthost *bthost, uint8_t mode) { send_command(bthost, BT_HCI_CMD_WRITE_SIMPLE_PAIRING_MODE, &mode, 1); diff --git a/emulator/bthost.h b/emulator/bthost.h index 3dec44514..868af5469 100644 --- a/emulator/bthost.h +++ b/emulator/bthost.h @@ -84,6 +84,11 @@ 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); +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, + uint8_t addr_type, uint8_t filter_policy); +void bthost_set_scan_enable(struct bthost *bthost, uint8_t enable); void bthost_write_ssp_mode(struct bthost *bthost, uint8_t mode); From patchwork Mon Oct 25 04:47:24 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 12580705 X-Patchwork-Delegate: luiz.dentz@gmail.com 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id F10F7C433F5 for ; Mon, 25 Oct 2021 04:47:32 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D691E60FBF for ; Mon, 25 Oct 2021 04:47:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232185AbhJYEtx (ORCPT ); Mon, 25 Oct 2021 00:49:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48240 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232090AbhJYEtv (ORCPT ); Mon, 25 Oct 2021 00:49:51 -0400 Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA4C5C061745 for ; Sun, 24 Oct 2021 21:47:29 -0700 (PDT) Received: by mail-pg1-x52c.google.com with SMTP id l186so3267609pge.7 for ; Sun, 24 Oct 2021 21:47:29 -0700 (PDT) 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=QzNUEGLXUNt3vd3D+yISGLe6W/66aRI7qYr//lJTxqg=; b=hTPCIienQ/+IZx23iGf8G8VPIDMS39KHcjkQ8YNXJBxu5j2ei1ghL6H/i19b2lqkjw fWFyI3CIJA/MTemTDYZLBOCQGJtZS75LLu4h8pmNRwogFJOALTCATwN1u8mshdjv8RLt yGZ+GNcIq8AfsYdJPzsXR5hz73f6gX+oHUNMW4hgTrEaqUCQ+CgkGi5ksuCx2ppYbM+G fGzVpqbx/n7KyRNy0RqE48V5G/nAaVeAVOJwa9qki71nUtrghjzkB6/aZhJVvVLrSidS PKYPfbXyYQwF8FaEi8CNzHrKErpX3ck2BqfQiBZol07jpWfNQxEfU+4zHA1FgG27YIoz Z1AA== 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=QzNUEGLXUNt3vd3D+yISGLe6W/66aRI7qYr//lJTxqg=; b=I+QXKqjn4EsttjfSOluEtqHtA9ranIq0XvHinq1bA5WjJjR+lfBsyrn3H29srKdPGg pxKgvhLyn/iJZRGyo/yR/VpuPxEr0vj3mYbSnw2bdZqhfckwhlwnlzQi03TaiqbE5K7b Uk6oZSEI39iFHCw3JnQYnx4+9vQZ3uQCf7yURbvXW89qDMYWVHKUJSCNoooHO0iwR59F MP60kGCN5jx2PfMFRmVqMjO0YHK0AInUVVdyMizr5R/hfmjg5Cc9kUBwJ2AvliDwF+fd 7R9JR9NPnH1zhBVCRSZ6UM3UmkWHs2s1yUk8lm5JOSmCVaRYlZJo3y7wcpPppUcIPXOT qGLA== X-Gm-Message-State: AOAM5317xt4CnT9uhfuZyRFvcTNnQBaYFIxaYfWYC3QDoFKxMYYyzdMx DsDWHE7GkqSg9/NJ93J9UhK3cT3xao2huQ== X-Google-Smtp-Source: ABdhPJwpgiur9nAlGdz1HBFg4aOWnq/v21MQfGB5D1od8UGaopqDt+vy9vfJcWBkB7l1wcRPdJ2q5Q== X-Received: by 2002:a05:6a00:1503:b0:472:df2c:d821 with SMTP id q3-20020a056a00150300b00472df2cd821mr15830487pfu.60.1635137249113; Sun, 24 Oct 2021 21:47:29 -0700 (PDT) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830:d228:1bef:af2a:db8e]) by smtp.gmail.com with ESMTPSA id a17sm13926204pfv.64.2021.10.24.21.47.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Oct 2021 21:47:28 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 3/4] emulator: Add support to get the advertising address Date: Sun, 24 Oct 2021 21:47:24 -0700 Message-Id: <20211025044725.482641-3-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211025044725.482641-1-hj.tedd.an@gmail.com> References: <20211025044725.482641-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch add supprt emulator to get the advertising address of the central device. --- emulator/btdev.c | 23 +++++++++++++++++++++-- emulator/btdev.h | 2 ++ emulator/hciemu.c | 15 +++++++++++++++ emulator/hciemu.h | 3 +++ 4 files changed, 41 insertions(+), 2 deletions(-) diff --git a/emulator/btdev.c b/emulator/btdev.c index 1ae71765d..e129b5cda 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -4655,6 +4655,7 @@ static void send_ext_adv(struct btdev *btdev, const struct btdev *remote, struct le_ext_adv *ext_adv, uint16_t type, bool is_scan_rsp) { + struct __packed { uint8_t num_reports; union { @@ -4770,6 +4771,9 @@ static int cmd_set_ext_adv_enable(struct btdev *dev, const void *data, /* Disable all advertising sets */ queue_foreach(dev->le_ext_adv, ext_adv_disable, NULL); + + dev->le_adv_enable = 0x00; + goto exit_complete; } @@ -4824,6 +4828,8 @@ static int cmd_set_ext_adv_enable(struct btdev *dev, const void *data, ext_adv->enable = cmd->enable; + dev->le_adv_enable = 0x01; + if (!cmd->enable) ext_adv_disable(ext_adv, NULL); else if (eas->duration) @@ -4888,7 +4894,7 @@ static int cmd_remove_adv_set(struct btdev *dev, const void *data, UINT_TO_PTR(cmd->handle)); if (!ext_adv) { status = BT_HCI_ERR_UNKNOWN_ADVERTISING_ID; - cmd_complete(dev, BT_HCI_CMD_LE_SET_EXT_ADV_DATA, &status, + cmd_complete(dev, BT_HCI_CMD_LE_REMOVE_ADV_SET, &status, sizeof(status)); return 0; } @@ -5158,7 +5164,7 @@ static void le_ext_conn_complete(struct btdev *btdev, /* Set Local RPA if an RPA was generated for the advertising */ if (ext_adv->rpa) memcpy(ev.local_rpa, ext_adv->random_addr, - sizeof(ev.local_rpa)); + sizeof(ev.local_rpa)); le_meta_event(conn->link->dev, BT_HCI_EVT_LE_ENHANCED_CONN_COMPLETE, &ev, @@ -6387,6 +6393,19 @@ uint8_t btdev_get_le_scan_enable(struct btdev *btdev) return btdev->le_scan_enable; } +const uint8_t *btdev_get_adv_addr(struct btdev *btdev, uint8_t handle) +{ + struct le_ext_adv *ext_adv; + + /* Check if Ext Adv is already existed */ + ext_adv = queue_find(btdev->le_ext_adv, match_ext_adv_handle, + UINT_TO_PTR(handle)); + if (!ext_adv) + return NULL; + + return ext_adv_addr(btdev, ext_adv); +} + void btdev_set_le_states(struct btdev *btdev, const uint8_t *le_states) { memcpy(btdev->le_states, le_states, sizeof(btdev->le_states)); diff --git a/emulator/btdev.h b/emulator/btdev.h index b5f9979a8..9493938c6 100644 --- a/emulator/btdev.h +++ b/emulator/btdev.h @@ -78,6 +78,8 @@ uint8_t btdev_get_scan_enable(struct btdev *btdev); uint8_t btdev_get_le_scan_enable(struct btdev *btdev); +const uint8_t *btdev_get_adv_addr(struct btdev *btdev, uint8_t handle); + void btdev_set_le_states(struct btdev *btdev, const uint8_t *le_states); void btdev_set_al_len(struct btdev *btdev, uint8_t len); diff --git a/emulator/hciemu.c b/emulator/hciemu.c index 1f7af3b93..057f76ff3 100644 --- a/emulator/hciemu.c +++ b/emulator/hciemu.c @@ -629,6 +629,21 @@ void hciemu_set_central_le_rl_len(struct hciemu *hciemu, uint8_t len) btdev_set_rl_len(dev, len); } +const uint8_t *hciemu_get_central_adv_addr(struct hciemu *hciemu, + uint8_t handle) +{ + struct btdev *dev; + + if (!hciemu || !hciemu->vhci) + return NULL; + + dev = vhci_get_btdev(hciemu->vhci); + if (!dev) + return NULL; + + return btdev_get_adv_addr(dev, handle); +} + bool hciemu_add_central_post_command_hook(struct hciemu *hciemu, hciemu_command_func_t function, void *user_data) { diff --git a/emulator/hciemu.h b/emulator/hciemu.h index 2a49d8bad..3a06ca578 100644 --- a/emulator/hciemu.h +++ b/emulator/hciemu.h @@ -65,6 +65,9 @@ void hciemu_set_central_le_al_len(struct hciemu *hciemu, uint8_t len); void hciemu_set_central_le_rl_len(struct hciemu *hciemu, uint8_t len); +const uint8_t *hciemu_get_central_adv_addr(struct hciemu *hciemu, + uint8_t handle); + typedef void (*hciemu_command_func_t)(uint16_t opcode, const void *data, uint8_t len, void *user_data); From patchwork Mon Oct 25 04:47:25 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tedd Ho-Jeong An X-Patchwork-Id: 12580707 X-Patchwork-Delegate: luiz.dentz@gmail.com 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A082DC433EF for ; Mon, 25 Oct 2021 04:47:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7C68460F4F for ; Mon, 25 Oct 2021 04:47:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232193AbhJYEty (ORCPT ); Mon, 25 Oct 2021 00:49:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48244 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232110AbhJYEtw (ORCPT ); Mon, 25 Oct 2021 00:49:52 -0400 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 83197C061764 for ; Sun, 24 Oct 2021 21:47:30 -0700 (PDT) Received: by mail-pf1-x430.google.com with SMTP id m26so9560746pff.3 for ; Sun, 24 Oct 2021 21:47:30 -0700 (PDT) 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=uRci+wXRHEpx0vPCJHP4/3h6ULOKax09k+gEH+0a86A=; b=QOFOy0IjA9Sq3eD8YgLGL3mXYluje0Tkpd6U/6sQHdkkiTKxwPbnLcP2ChzUQE/KKP RwyofBxlX5vNrbPJlRFcNuvWLzoql3DAMNfqxZoLKyg1sOfm+LGPpoT0hvMsPDGFCrc7 kwlxrqSX8megxFDlG+E2S8dkLFnvGCGUaWo/jvMC1D3ELC5NlZbcUY539JkHjWQBEhrn aVCKUstirXExyQxqgqXfJBpVWLRZ7Kc7UXuVRqP4vDXtG8Eq0+RM0KEwaOMgQx7M+2YR sw+i1OK8wl5rcdHcHNHjJU7JxhchSV4K3eJK1azouaWS7+ILzQaHrXFLBrjuQOCqJBpo tbbQ== 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=uRci+wXRHEpx0vPCJHP4/3h6ULOKax09k+gEH+0a86A=; b=CdvhLgaXKwAvh74SlmGVdqRqESkHNcBPR9yYCBipYACgY8PdrTVhpJwQC+uop5k31O vA8xME3jumvLtNG4cUqm+t4+0pxi2vM0TBmjNWMDh1iNVBkVthY1aIGGyxS0FhgnFUDW T4ikKUsxWU7CanveWyROFZimhymX2mCAdr1mZ/+qtGyAKIwznEXa14S7N6rWluNJu5Vu AnRzxva9zP86L+si2SttvTHpa+cpj4En/ScHnIj9v0xMvBMROtWMCyYWZwW9c+h6QdQT 4LjYBTFblfuEpf8R69mseaJAyaZOvd47SWjym/WOBp/gLfDwY5ANHWPRHGA7d9DwvkyO s83g== X-Gm-Message-State: AOAM530z6YfPjc249DOH/ioz8eQDZdF6Eg3RR+5OVnPGOAtUWW6xmY5+ 9F4rDz7vMAZxUX+FnnWQes4YQSLI9TaHAA== X-Google-Smtp-Source: ABdhPJzj745ANWVlwB5eJxV605gkSwsYsDIxj5wxVLhGvMOTZWL4yvjCbZ2XlJEh7IOn3rSD9kxDtg== X-Received: by 2002:aa7:99c3:0:b0:47b:e21d:7315 with SMTP id v3-20020aa799c3000000b0047be21d7315mr8567950pfi.35.1635137249817; Sun, 24 Oct 2021 21:47:29 -0700 (PDT) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830:d228:1bef:af2a:db8e]) by smtp.gmail.com with ESMTPSA id a17sm13926204pfv.64.2021.10.24.21.47.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 24 Oct 2021 21:47:29 -0700 (PDT) From: Tedd Ho-Jeong An To: linux-bluetooth@vger.kernel.org Subject: [BlueZ PATCH 4/4] tools/mgmt-tester: Add support for experimental feature in setup Date: Sun, 24 Oct 2021 21:47:25 -0700 Message-Id: <20211025044725.482641-4-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211025044725.482641-1-hj.tedd.an@gmail.com> References: <20211025044725.482641-1-hj.tedd.an@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Tedd Ho-Jeong An This patch adds support for experimental feature in setup_settings options. --- tools/mgmt-tester.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/tools/mgmt-tester.c b/tools/mgmt-tester.c index f490dc261..1ccce0ad6 100644 --- a/tools/mgmt-tester.c +++ b/tools/mgmt-tester.c @@ -260,6 +260,7 @@ struct generic_data { const uint16_t *setup_settings; bool setup_nobredr; bool setup_limited_discov; + const void *setup_exp_feat_param; uint16_t setup_expect_hci_command; const void *setup_expect_hci_param; uint8_t setup_expect_hci_len; @@ -7222,6 +7223,7 @@ proceed: unsigned char privacy_param[] = { 0x01, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 }; + unsigned char set_exp_feat_param[17] = { 0x00 }; unsigned char *param = simple_param; size_t param_size = sizeof(simple_param); mgmt_request_func_t func = NULL; @@ -7250,14 +7252,30 @@ proceed: memcpy(param, test->setup_discovery_param, 1); } + if (*cmd == MGMT_OP_SET_EXP_FEATURE) { + if (test->setup_exp_feat_param) { + memcpy(set_exp_feat_param, + test->setup_exp_feat_param, 17); + param_size = sizeof(set_exp_feat_param); + param = set_exp_feat_param; + } + } + if (*cmd == MGMT_OP_SET_LE && test->setup_nobredr) { unsigned char off[] = { 0x00 }; + tester_print("Setup sending %s (0x%04x)", + mgmt_opstr(*cmd), *cmd); mgmt_send(data->mgmt, *cmd, data->mgmt_index, param_size, param, NULL, NULL, NULL); + tester_print("Setup sending %s (0x%04x)", + mgmt_opstr(MGMT_OP_SET_BREDR), + MGMT_OP_SET_BREDR); mgmt_send(data->mgmt, MGMT_OP_SET_BREDR, data->mgmt_index, sizeof(off), off, func, data, NULL); } else { + tester_print("Setup sending %s (0x%04x)", + mgmt_opstr(*cmd), *cmd); mgmt_send(data->mgmt, *cmd, data->mgmt_index, param_size, param, func, data, NULL); }