From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: Marcel Holtmann <marcel@holtmann.org>
Cc: "linux-bluetooth@vger.kernel.org" <linux-bluetooth@vger.kernel.org>
Subject: Re: [PATCH v2 1/2] Bluetooth: Introduce HCI_CONN_FLAG_DEVICE_PRIVACY device flag
Date: Thu, 18 Nov 2021 14:02:11 -0800 [thread overview]
Message-ID: <CABBYNZ+VaBM+FM9GAAAd5Kb4LJnfPs6LrZaU-KpVOwK7kPawpQ@mail.gmail.com> (raw)
In-Reply-To: <B47FBB15-3593-43AB-BA21-E08B34DE3C1F@holtmann.org>
Hi Marcel,
On Thu, Nov 18, 2021 at 9:19 AM Marcel Holtmann <marcel@holtmann.org> wrote:
>
> Hi Luiz,
>
> >>> This introduces HCI_CONN_FLAG_DEVICE_PRIVACY which can be used by
> >>> userspace to indicate to the controller to use Device Privacy Mode to a
> >>> specific device.
> >>>
> >>> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> >>> ---
> >>> v2: Fix marking Device Privacy Flag even when adapter is not capable of
> >>> handling Set Privacy Mode.
> >>>
> >>> include/net/bluetooth/hci_core.h | 4 ++++
> >>> net/bluetooth/mgmt.c | 24 ++++++++++++++++++++----
> >>> 2 files changed, 24 insertions(+), 4 deletions(-)
> >>>
> >>> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> >>> index b5f061882c10..07d2d099dc2a 100644
> >>> --- a/include/net/bluetooth/hci_core.h
> >>> +++ b/include/net/bluetooth/hci_core.h
> >>> @@ -160,6 +160,7 @@ struct bdaddr_list_with_flags {
> >>>
> >>> enum hci_conn_flags {
> >>> HCI_CONN_FLAG_REMOTE_WAKEUP,
> >>> + HCI_CONN_FLAG_DEVICE_PRIVACY,
> >>> HCI_CONN_FLAG_MAX
> >>> };
> >>>
> >>> @@ -1468,6 +1469,9 @@ void hci_conn_del_sysfs(struct hci_conn *conn);
> >>> #define use_ll_privacy(dev) (ll_privacy_capable(dev) && \
> >>> hci_dev_test_flag(dev, HCI_ENABLE_LL_PRIVACY))
> >>>
> >>> +#define privacy_mode_capable(dev) (use_ll_privacy(dev) && \
> >>> + (hdev->commands[39] & 0x04))
> >>> +
> >>> /* Use enhanced synchronous connection if command is supported */
> >>> #define enhanced_sco_capable(dev) ((dev)->commands[29] & 0x08)
> >>>
> >>> diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
> >>> index 06384d761928..8a8376d32be3 100644
> >>> --- a/net/bluetooth/mgmt.c
> >>> +++ b/net/bluetooth/mgmt.c
> >>> @@ -4350,7 +4350,16 @@ static int set_exp_feature(struct sock *sk, struct hci_dev *hdev,
> >>> MGMT_STATUS_NOT_SUPPORTED);
> >>> }
> >>>
> >>> -#define SUPPORTED_DEVICE_FLAGS() ((1U << HCI_CONN_FLAG_MAX) - 1)
> >>> +static u32 supported_device_flags(struct hci_dev *hdev)
> >>> +{
> >>> + u32 flags = BIT(HCI_CONN_FLAG_MAX) - 1;
> >>> +
> >>> + /* Check if Privacy Mode can be set */
> >>> + if (!privacy_mode_capable(hdev))
> >>> + flags &= ~BIT(HCI_CONN_FLAG_DEVICE_PRIVACY);
> >>> +
> >>> + return flags;
> >>> +}
> >>
> >> I am lost on what we are doing, I know that SUPPORTED_DEVICE_FLAGS was introduced by 4c54bf2b093bb from Abhishek, but I fail to reason now why it is correct.
> >
> > But we don't set the HCI_CONN_FLAG_DEVICE_PRIVACY is hdev is not
> > capable of setting it, anyway the general idea of the supported_flags
> > is to indicate to userspace what flags the kernel is capable of
> > settings, so yeah I would expected it to be capable of setting every
> > flag except for those the controller don't have proper support for.
> > Maybe you got confused by the logic of first enabling everything and
> > then toggle back the bits that are not supported by the hdev.
>
> and I think that is wrong. We should only set the bits that the hardware and/or kernel supports. I have no idea on how I missed this in the review back then. I am trying to figure it out, but I am failing to follow this logic.
There is only 1 flag currently though, HCI_CONN_FLAG_REMOTE_WAKEUP, so
I wonder if that really requires a check? Or perhaps you want to
change the way we supported_device_flags works to:
index fe52b7eefb56..3ad09ce6eaeb 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -4351,11 +4351,15 @@ static int set_exp_feature(struct sock *sk,
struct hci_dev *hdev,
static u32 supported_device_flags(struct hci_dev *hdev)
{
- u32 flags = BIT(HCI_CONN_FLAG_MAX) - 1;
+ u32 flags = 0;
+
+ /* Check if adapter can wakeup the system */
+ if (hdev->wakeup && hdev->wakeup(hdev))
+ flags |= HCI_CONN_FLAG_REMOTE_WAKEUP;
/* Check if Privacy Mode can be set */
- if (!privacy_mode_capable(hdev))
- flags &= ~BIT(HCI_CONN_FLAG_DEVICE_PRIVACY);
+ if (privacy_mode_capable(hdev))
+ flags |= HCI_CONN_FLAG_DEVICE_PRIVACY;
return flags;
}
We will need to adjust some of the tests though to reflect this change
in behavior:
et Device Flags - Success Failed 0.016 seconds
Set Device Flags - Success Not Run
next prev parent reply other threads:[~2021-11-18 22:02 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-05 22:27 [PATCH v2 1/2] Bluetooth: Introduce HCI_CONN_FLAG_DEVICE_PRIVACY device flag Luiz Augusto von Dentz
2021-11-05 22:27 ` [PATCH v2 2/2] Bluetooth: hci_sync: Set Privacy Mode when updating the resolving list Luiz Augusto von Dentz
2021-11-18 4:46 ` Marcel Holtmann
2021-11-18 16:12 ` Luiz Augusto von Dentz
2021-11-18 4:45 ` [PATCH v2 1/2] Bluetooth: Introduce HCI_CONN_FLAG_DEVICE_PRIVACY device flag Marcel Holtmann
2021-11-18 16:09 ` Luiz Augusto von Dentz
2021-11-18 17:19 ` Marcel Holtmann
2021-11-18 22:02 ` Luiz Augusto von Dentz [this message]
2021-11-18 22:09 ` Marcel Holtmann
2021-11-18 23:13 Luiz Augusto von Dentz
2021-11-19 10:01 ` Marcel Holtmann
2021-11-19 19:39 ` Luiz Augusto von Dentz
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=CABBYNZ+VaBM+FM9GAAAd5Kb4LJnfPs6LrZaU-KpVOwK7kPawpQ@mail.gmail.com \
--to=luiz.dentz@gmail.com \
--cc=linux-bluetooth@vger.kernel.org \
--cc=marcel@holtmann.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).