From patchwork Mon Oct 25 20:31:17 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: 12582883 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 5F8C7C433EF for ; Mon, 25 Oct 2021 20:31:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3B5AF60E52 for ; Mon, 25 Oct 2021 20:31:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233736AbhJYUds (ORCPT ); Mon, 25 Oct 2021 16:33:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233439AbhJYUdp (ORCPT ); Mon, 25 Oct 2021 16:33:45 -0400 Received: from mail-pf1-x42c.google.com (mail-pf1-x42c.google.com [IPv6:2607:f8b0:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99D29C061348 for ; Mon, 25 Oct 2021 13:31:22 -0700 (PDT) Received: by mail-pf1-x42c.google.com with SMTP id d9so11996005pfl.6 for ; Mon, 25 Oct 2021 13:31:22 -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=ibBibPNypXY+D2ENNoPS+wPVpW1eD6IA597WrTdc+zw=; b=DDQCtyltt2YQ1bpPKEnHELBngvsEv+0SSBujSHWhpc+G/X+IoZ+afGn/xuq6Z78VlZ bf+6OzhAb9kEqy5dVhNjD3UDpl7KJO8j58hl/g6UNqMxAUlvBiHJrY4CH3y3FamCwhJJ gXRVe1+IhzWeHihVrsKmH7vwjWw98I0ZmeaK7fNnhwAUj2KveLVLlb6BCFcDmmB0mX22 a+gDwfcGpfscIBskJCY90Ddvwp3plsT1ebVdQSJBhGi0kgemQS/mOD0W7WV5It2oU8Fa Xvu9zzGHBD6SO67gV4M7LMVFSjhiRd3EXBDclBnEkMRhFMsFDh+TCt/snNSpYQGvCNjs i6cA== 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=ibBibPNypXY+D2ENNoPS+wPVpW1eD6IA597WrTdc+zw=; b=LMoS7bIbEJXuMgcyePMREzJI6T4VfsYf501ud3HIejwZYVx3303Fz4ah91jzklxySe MAuKiBSJ8R2opHoF2sbVDQIf15kfY4gymxuDo3WXv04c1uzvuryFhTHuNN4evzz9eb60 bdJJo2cDshI/+1FyLbg4yevKdtHhaITFyUWPuJX59/pZe9T0vI7Y3+Dg3bxPG9OjWKAd tKzsDwKZHb5kcskzf1+q8ofQpfrjKLbn8bTv2vCC5tXnYrthK7XEeLAzTAynnL5SAbKR h602IY07Gwf28pPOBpr4Oxd81MUzdYdZ3AeflDBj/EJZf+PZrJbDgxm+ORz757hnbahA wCVw== X-Gm-Message-State: AOAM53322nBIWI/7njcI69PE1rNTKNO0/2IYA1ASAZRGt75szvZaCwKR ak9RuDjB332xTJ+FkdVYHvSMtMXxjXyYRw== X-Google-Smtp-Source: ABdhPJzJZIHRM+h8fvey2xlEoMoCnMk4gu9oODKbRTIfjCPIc0O0jqc5OfctBTV1S2jZde9kAoZbLg== X-Received: by 2002:a65:6a15:: with SMTP id m21mr15446332pgu.415.1635193881588; Mon, 25 Oct 2021 13:31:21 -0700 (PDT) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830:78ab:b967:528:d348]) by smtp.gmail.com with ESMTPSA id l12sm21504899pfu.100.2021.10.25.13.31.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 13:31:21 -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: Mon, 25 Oct 2021 13:31:17 -0700 Message-Id: <20211025203120.513189-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 177633b9c..2cbe24edc 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)); @@ -3669,7 +3688,7 @@ static int cmd_add_al(struct btdev *dev, const void *data, uint8_t len) goto done; } - 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)) { @@ -3731,7 +3750,7 @@ static int cmd_remove_al(struct btdev *dev, const void *data, uint8_t len) goto done; } - 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); @@ -3746,7 +3765,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) { status = BT_HCI_ERR_INVALID_PARAMETERS; goto done; } @@ -3785,7 +3804,7 @@ static int cmd_add_rl(struct btdev *dev, const void *data, uint8_t len) goto done; } - 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)) { @@ -3847,7 +3866,7 @@ static int cmd_remove_rl(struct btdev *dev, const void *data, uint8_t len) goto done; } - 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)) { @@ -3856,7 +3875,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) { status = BT_HCI_ERR_INVALID_PARAMETERS; goto done; } @@ -3902,7 +3921,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)); @@ -6358,6 +6377,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 20:31:18 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: 12582881 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 DB518C433FE for ; Mon, 25 Oct 2021 20:31:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C04B860E0B for ; Mon, 25 Oct 2021 20:31:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233439AbhJYUds (ORCPT ); Mon, 25 Oct 2021 16:33:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233524AbhJYUdp (ORCPT ); Mon, 25 Oct 2021 16:33:45 -0400 Received: from mail-pf1-x431.google.com (mail-pf1-x431.google.com [IPv6:2607:f8b0:4864:20::431]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3DD78C061243 for ; Mon, 25 Oct 2021 13:31:23 -0700 (PDT) Received: by mail-pf1-x431.google.com with SMTP id t184so12022109pfd.0 for ; Mon, 25 Oct 2021 13:31:23 -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=b14IGr1Hdl1OsI4vZLjvq4xtsgkICiQm5PicvGQM0fjJd0VKWXM9EHlkUnHQ42v1sd qZ1KPQOvVoU4mkD1YoxOtTyFZ+6PnpBXaFxec8XgTfYW+HfN0k/9vs8ACNoNhdBNDnaw eymygWzunFpItVFvhgfaM7+IaXwqS4LILodYvHBJfi1mnW6UCNsRGAf/hJPfEIueAw3Z 8T0s9vlnfDJs+rFLrNLEuef9wRbbTDWFwofc0IokQK5Ybl7iUEa35Es4cpyMDtmQgnUD O7GpPyOihX98dlSp9ztxdsLJ5yoAJ8JaKlDR+IgJjwWZYZYmZk1X/GLvbrZGdGEbDZ1G RsXA== 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=1NgOzl98IpEv2PN61f/rekctq+Hwrw7UfiYL1YLWPhEGu3rtBVHfm23I8et3tSy33X bdzkh7tmIQ1giAMbZc0I8WXHegYVP7sd8z+k7OIHjYNzzKgjbLd0a9sIdw0A5nwv+dpU E5piQyShUG00Kf7zJFsrcLJJSxw0s2hE3FKUHcC5YY2Yx3UufzcyJkwMvgKlcc2On9Lp UKkvtg9iQXwX0IozlkTc5/PMEn9GyZmc3Au4RHhk8DFtyigPRpMy7/k+1WHh8Zld9ynm jF0pIJN/DpBTRzcISnRI7xkdK7gxE0K+t+Pp5yio2O7KRUKtCyflrrJrsqHIlmWsAadB OS2w== X-Gm-Message-State: AOAM530fHFWWKVfYHe34DPqFzRpIE0EteJ4Ks06OeF8ePnqBZX+I38+g 81QoARt1RtwQHpxr5DU3oI0boQdsFHxFMw== X-Google-Smtp-Source: ABdhPJxLLLkY883GR8tGfhQN5B0GV6brxGXbhti6TXs0wpIrifOu3ZJ3TMw5QTTcrzPfpe6P4mepvg== X-Received: by 2002:a05:6a00:15d4:b0:47b:af23:6888 with SMTP id o20-20020a056a0015d400b0047baf236888mr20570898pfu.14.1635193882244; Mon, 25 Oct 2021 13:31:22 -0700 (PDT) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830:78ab:b967:528:d348]) by smtp.gmail.com with ESMTPSA id l12sm21504899pfu.100.2021.10.25.13.31.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 13:31:21 -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: Mon, 25 Oct 2021 13:31:18 -0700 Message-Id: <20211025203120.513189-2-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211025203120.513189-1-hj.tedd.an@gmail.com> References: <20211025203120.513189-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 20:31:19 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: 12582885 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 C4FAFC433F5 for ; Mon, 25 Oct 2021 20:31:29 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A181960E0B for ; Mon, 25 Oct 2021 20:31:29 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233561AbhJYUdt (ORCPT ); Mon, 25 Oct 2021 16:33:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38834 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233343AbhJYUdq (ORCPT ); Mon, 25 Oct 2021 16:33:46 -0400 Received: from mail-pf1-x434.google.com (mail-pf1-x434.google.com [IPv6:2607:f8b0:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A5C3BC061745 for ; Mon, 25 Oct 2021 13:31:23 -0700 (PDT) Received: by mail-pf1-x434.google.com with SMTP id t184so12022141pfd.0 for ; Mon, 25 Oct 2021 13:31:23 -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=YtgMF/aE7f3R8Ln9dfMopZcvYwb0dG6lRLohzMGKZHY=; b=XuRySU/6PmCX5B1YQJ2OxwCsw7XqXMmTp/Eh1CI21Nn8NRTd1FhJylATBYKolLDGep VbT3GSrY2XVqzn8gWzjgaxr6BIpsxzpQ8nEcWR+GKETlrORiojDRHDoIJTKovvxDfu5d dSVbcHXm9eh4/P5JqVndu1f06wlXWep3wsyDYx43ITwl0xTARCdFmVbOrAY1DEXolcjC nTPZ/U65Lc64zop4cZtr9kKPbpSyqUf3sxtknmirSDuWwUPVwM/MyWvFGFV1pyIAi75y tNWNNS/MV21ZTrQwDfX4e3fLWEFPrbWZbZARe06srm4bwyVntph1isX4WkEmJNow1EIP I+Tw== 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=YtgMF/aE7f3R8Ln9dfMopZcvYwb0dG6lRLohzMGKZHY=; b=Y7ChTstPL40DK6YfmrpP0UxA/avzNg2Gva0Oonc0lpYlhm4WJAuJJ9gLslpA58+nBc 6/pAd6NbZUMWnraBpDBAaIHHsyeCkVFobma2FU4b8CpC+PzNdug1d3IAeSsbSNe/wtWP dZibZEcb9H7vE5jWO3R8pINchByOmHwYC6b+iq3ATsnQKzIvPhKBcz9b+YdLhXFNt1AJ jGjeR8B/VglS4TMBdtUNcN97gChh+GKARoHXM4MoLHYu5Q6y3xJGvo9G1pCRnl1xwK3V DdNrzc8NArnNIE9HWqYg0w3aDFr9GqCuuMnT7dT3v4QjdIJppD81v95aDfMRjv4MXS0J rKKA== X-Gm-Message-State: AOAM530uuuaTPiFXsEQURSzTaR49K0O4xAGXo3kABVtJd/K8+3fI/X33 TXMBtx+8Y2Ycgp/B/7APq40xLak5AyX6aA== X-Google-Smtp-Source: ABdhPJzLOn8rqD6BctOq8wtVvyqoC6VFpFoIgp+jnhSqH/1Y0k0UHIoNB6vyGH2jthyCrkkgzYUKZg== X-Received: by 2002:aa7:9727:0:b0:47b:e175:2320 with SMTP id k7-20020aa79727000000b0047be1752320mr14562931pfg.77.1635193882892; Mon, 25 Oct 2021 13:31:22 -0700 (PDT) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830:78ab:b967:528:d348]) by smtp.gmail.com with ESMTPSA id l12sm21504899pfu.100.2021.10.25.13.31.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 13:31:22 -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: Mon, 25 Oct 2021 13:31:19 -0700 Message-Id: <20211025203120.513189-3-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211025203120.513189-1-hj.tedd.an@gmail.com> References: <20211025203120.513189-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 2cbe24edc..7b311f347 100644 --- a/emulator/btdev.c +++ b/emulator/btdev.c @@ -4703,6 +4703,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 { @@ -4818,6 +4819,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; } @@ -4872,6 +4876,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) @@ -4936,7 +4942,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; } @@ -5206,7 +5212,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, @@ -6435,6 +6441,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 20:31:20 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: 12582887 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 208F0C433FE for ; Mon, 25 Oct 2021 20:31:31 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0328960E8B for ; Mon, 25 Oct 2021 20:31:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233827AbhJYUdv (ORCPT ); Mon, 25 Oct 2021 16:33:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233694AbhJYUdr (ORCPT ); Mon, 25 Oct 2021 16:33:47 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8B5ECC061767 for ; Mon, 25 Oct 2021 13:31:24 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id v1-20020a17090a088100b001a21156830bso363899pjc.1 for ; Mon, 25 Oct 2021 13:31:24 -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=i2WbMFErQMbUljbsAR6hgwtPwzo6aPnP7/GLCuInIBEIwp4ABZBDwwi0mw8S2r/SZq NZaTjoSSFAJ6ofkn1FV0xfFk86LaXXs3e5PCaamVCwKUeW+HO2XrOrghdu677zWBL1t2 XYLa9Q3TnW37FQ+g0R0/VVkiomZIJ1P4THEHvn/qIHuZWVfQ4r+SRyv3PAMwZ7I3llv5 Ltp59xaF13H66JHsuirA/AgkhkSVKeYtNfmhqiiYPzp2UufqTiXYYyj0nARCzTFBNkOl 1euetpJ0692ub4unf9X9QSo3hPf1CQgnt5e6LDnJdvllJs4qW2gC9tabGbc2+lrZvP7i 9hRg== 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=ZTcUN72HNCDC+lX1wZGfB/zvFJ4Suq1F+MSUB9W6APCWtHQf3LE5r7H0mM/ByhnC64 y/GQ+5v/5N5y0aXIpTM9HV7ok+ZopW/h9za/8U/gNof9i17fjEWyKUI42FKuFUqhHY4Z UcZ9vclG7QZdLOwlXrB8RMq7tWzfqw+sffj/c2QyZhz2o7884/1VHlL2W1exNk6AFiJL pgdtL5gbX887S3GEm16qLEpdGIb35H9xrqUDQxVwQtfI7z7EVHmAvtR895IjJvgz1VHf nx+NWDH0qObch6JfDLo6kPfBlf5xVRCyXLCGKIoRKAYnhTmoqhPbfGsEwHGibGuRoyUO VELQ== X-Gm-Message-State: AOAM533UfUTjUwrnunHc7fFIBU8QRkr+X3D217iMeqcJtqIW5JO+CdXe pWgEg02YG7EmnvWwDJ8E/961U7b3UX6cyg== X-Google-Smtp-Source: ABdhPJwXdoohTeGwk4XPvNUXEbncOej9b/dG5EOIlEvjqIacdvIxp9YGP4WPnLLLS+0J9qn9oUzgBw== X-Received: by 2002:a17:902:f550:b0:140:54d5:78bb with SMTP id h16-20020a170902f55000b0014054d578bbmr8109683plf.76.1635193883709; Mon, 25 Oct 2021 13:31:23 -0700 (PDT) Received: from han1-NUC8i7BEH.hsd1.or.comcast.net ([2601:1c0:6a01:d830:78ab:b967:528:d348]) by smtp.gmail.com with ESMTPSA id l12sm21504899pfu.100.2021.10.25.13.31.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 25 Oct 2021 13:31:23 -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: Mon, 25 Oct 2021 13:31:20 -0700 Message-Id: <20211025203120.513189-4-hj.tedd.an@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211025203120.513189-1-hj.tedd.an@gmail.com> References: <20211025203120.513189-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); }