linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] Bluetooth: vhci: Add support for setting msft_opcode and aosp_capable
@ 2021-10-13 22:17 Luiz Augusto von Dentz
  2021-10-13 23:10 ` [v3] " bluez.test.bot
  2021-10-14 12:39 ` [PATCH v3] " Marcel Holtmann
  0 siblings, 2 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2021-10-13 22:17 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This adds a debugfs entries to set msft_opcode and aosp_capable enabling
vhci to emulate controllers with MSFT/AOSP extension support.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
v2: Fix typos: s/extention/extension/g
v3: Remove checks for HCI_SETUP, merge changes to introduce MSFT/AOSP support
at the same time.

 drivers/bluetooth/hci_vhci.c | 92 ++++++++++++++++++++++++++++++++++++
 1 file changed, 92 insertions(+)

diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index 56c6b22be10b..dc05729104a1 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -42,6 +42,8 @@ struct vhci_data {
 
 	bool suspended;
 	bool wakeup;
+	__u16 msft_opcode;
+	bool aosp_capable;
 };
 
 static int vhci_open_dev(struct hci_dev *hdev)
@@ -194,6 +196,82 @@ static const struct file_operations force_wakeup_fops = {
 	.llseek		= default_llseek,
 };
 
+static int msft_opcode_set(void *data, u64 val)
+{
+	struct vhci_data *vhci = data;
+
+	if (val > 0xffff || (val & 0xffff >> 10) != 0x3f)
+		return -EINVAL;
+
+	vhci->msft_opcode = val;
+
+	return 0;
+}
+
+static int msft_opcode_get(void *data, u64 *val)
+{
+	struct vhci_data *vhci = data;
+
+	*val = vhci->msft_opcode;
+
+	return 0;
+}
+
+DEFINE_DEBUGFS_ATTRIBUTE(msft_opcode_fops, msft_opcode_get, msft_opcode_set,
+			 "%llu\n");
+
+static ssize_t aosp_capable_read(struct file *file, char __user *user_buf,
+				 size_t count, loff_t *ppos)
+{
+	struct vhci_data *vhci = file->private_data;
+	char buf[3];
+
+	buf[0] = vhci->aosp_capable ? 'Y' : 'N';
+	buf[1] = '\n';
+	buf[2] = '\0';
+	return simple_read_from_buffer(user_buf, count, ppos, buf, 2);
+}
+
+static ssize_t aosp_capable_write(struct file *file,
+				  const char __user *user_buf, size_t count,
+				  loff_t *ppos)
+{
+	struct vhci_data *vhci = file->private_data;
+	bool enable;
+	int err;
+
+	err = kstrtobool_from_user(user_buf, count, &enable);
+	if (err)
+		return err;
+
+	if (vhci->aosp_capable == enable)
+		return -EALREADY;
+
+	vhci->aosp_capable = enable;
+
+	return count;
+}
+
+static const struct file_operations aosp_capable_fops = {
+	.open		= simple_open,
+	.read		= aosp_capable_read,
+	.write		= aosp_capable_write,
+	.llseek		= default_llseek,
+};
+
+static int vhci_setup(struct hci_dev *hdev)
+{
+	struct vhci_data *vhci = hci_get_drvdata(hdev);
+
+	if (vhci->msft_opcode)
+		hci_set_msft_opcode(hdev, vhci->msft_opcode);
+
+	if (vhci->aosp_capable)
+		hci_set_aosp_capable(hdev);
+
+	return 0;
+}
+
 static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
 {
 	struct hci_dev *hdev;
@@ -237,6 +315,12 @@ static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
 	hdev->get_codec_config_data = vhci_get_codec_config_data;
 	hdev->wakeup = vhci_wakeup;
 
+	/* Enable custom setup if CONFIG_BT_MSFTEXT or CONFIG_BT_AOSPEXT is
+	 * selected.
+	 */
+	hdev->setup = vhci_setup;
+	set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks);
+
 	/* bit 6 is for external configuration */
 	if (opcode & 0x40)
 		set_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks);
@@ -259,6 +343,14 @@ static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
 	debugfs_create_file("force_wakeup", 0644, hdev->debugfs, data,
 			    &force_wakeup_fops);
 
+	if (IS_ENABLED(CONFIG_BT_MSFTEXT))
+		debugfs_create_file("msft_opcode", 0644, hdev->debugfs, data,
+				    &msft_opcode_fops);
+
+	if (IS_ENABLED(CONFIG_BT_AOSPEXT))
+		debugfs_create_file("aosp_capable", 0644, hdev->debugfs, data,
+				    &aosp_capable_fops);
+
 	hci_skb_pkt_type(skb) = HCI_VENDOR_PKT;
 
 	skb_put_u8(skb, 0xff);
-- 
2.31.1


^ permalink raw reply	[flat|nested] 5+ messages in thread

* RE: [v3] Bluetooth: vhci: Add support for setting msft_opcode and aosp_capable
  2021-10-13 22:17 [PATCH v3] Bluetooth: vhci: Add support for setting msft_opcode and aosp_capable Luiz Augusto von Dentz
@ 2021-10-13 23:10 ` bluez.test.bot
  2021-10-14 12:39 ` [PATCH v3] " Marcel Holtmann
  1 sibling, 0 replies; 5+ messages in thread
From: bluez.test.bot @ 2021-10-13 23:10 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

[-- Attachment #1: Type: text/plain, Size: 936 bytes --]

This is automated email and please do not reply to this email!

Dear submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
This is a CI test results with your patch series:
PW Link:https://patchwork.kernel.org/project/bluetooth/list/?series=563071

---Test result---

Test Summary:
CheckPatch                    PASS      1.59 seconds
GitLint                       PASS      0.93 seconds
BuildKernel                   PASS      615.15 seconds
TestRunner: Setup             PASS      453.00 seconds
TestRunner: l2cap-tester      PASS      10.03 seconds
TestRunner: bnep-tester       PASS      5.38 seconds
TestRunner: mgmt-tester       PASS      95.52 seconds
TestRunner: rfcomm-tester     PASS      6.63 seconds
TestRunner: sco-tester        PASS      7.10 seconds
TestRunner: smp-tester        PASS      6.76 seconds
TestRunner: userchan-tester   PASS      5.59 seconds



---
Regards,
Linux Bluetooth


[-- Attachment #2: l2cap-tester.log --]
[-- Type: application/octet-stream, Size: 44357 bytes --]

[-- Attachment #3: bnep-tester.log --]
[-- Type: application/octet-stream, Size: 3564 bytes --]

[-- Attachment #4: mgmt-tester.log --]
[-- Type: application/octet-stream, Size: 646011 bytes --]

[-- Attachment #5: rfcomm-tester.log --]
[-- Type: application/octet-stream, Size: 11684 bytes --]

[-- Attachment #6: sco-tester.log --]
[-- Type: application/octet-stream, Size: 13924 bytes --]

[-- Attachment #7: smp-tester.log --]
[-- Type: application/octet-stream, Size: 11829 bytes --]

[-- Attachment #8: userchan-tester.log --]
[-- Type: application/octet-stream, Size: 6372 bytes --]

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] Bluetooth: vhci: Add support for setting msft_opcode and aosp_capable
  2021-10-13 22:17 [PATCH v3] Bluetooth: vhci: Add support for setting msft_opcode and aosp_capable Luiz Augusto von Dentz
  2021-10-13 23:10 ` [v3] " bluez.test.bot
@ 2021-10-14 12:39 ` Marcel Holtmann
  2021-10-14 17:23   ` Luiz Augusto von Dentz
  1 sibling, 1 reply; 5+ messages in thread
From: Marcel Holtmann @ 2021-10-14 12:39 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hi Luiz,

> This adds a debugfs entries to set msft_opcode and aosp_capable enabling
> vhci to emulate controllers with MSFT/AOSP extension support.
> 
> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> ---
> v2: Fix typos: s/extention/extension/g
> v3: Remove checks for HCI_SETUP, merge changes to introduce MSFT/AOSP support
> at the same time.
> 
> drivers/bluetooth/hci_vhci.c | 92 ++++++++++++++++++++++++++++++++++++
> 1 file changed, 92 insertions(+)

patch has been applied to bluetooth-next tree (with slight modifications).

Regards

Marcel


^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] Bluetooth: vhci: Add support for setting msft_opcode and aosp_capable
  2021-10-14 12:39 ` [PATCH v3] " Marcel Holtmann
@ 2021-10-14 17:23   ` Luiz Augusto von Dentz
  2021-10-14 17:47     ` Marcel Holtmann
  0 siblings, 1 reply; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2021-10-14 17:23 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth

Hi Marcel,

On Thu, Oct 14, 2021 at 5:39 AM Marcel Holtmann <marcel@holtmann.org> wrote:
>
> Hi Luiz,
>
> > This adds a debugfs entries to set msft_opcode and aosp_capable enabling
> > vhci to emulate controllers with MSFT/AOSP extension support.
> >
> > Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> > ---
> > v2: Fix typos: s/extention/extension/g
> > v3: Remove checks for HCI_SETUP, merge changes to introduce MSFT/AOSP support
> > at the same time.
> >
> > drivers/bluetooth/hci_vhci.c | 92 ++++++++++++++++++++++++++++++++++++
> > 1 file changed, 92 insertions(+)
>
> patch has been applied to bluetooth-next tree (with slight modifications).

++<<<<<<< HEAD
 +      hci_set_msft_opcode(hdev, vhci->msft_opcode);
 +      hci_set_aosp_capable(hdev);
++=======
+       if (vhci->msft_opcode)
+               hci_set_msft_opcode(hdev, vhci->msft_opcode);
+
+       if (vhci->aosp_capable)
+               hci_set_aosp_capable(hdev);
++>>>>>>> 9bbbb6a7ad09 (Bluetooth: vhci: Add support for setting
msft_opcode and aosp_capable)

I suspect the above changes won't work if we don't init the fields in
the vhci_data, msft_opcode would be set to 0x0000 so it won't be
enabled anyway but aosp_capable would be enabled which would be out of
sync with vhci->aosp_capable, so perhaps we want to change
hci_set_aosp_capable to take a parameter:

diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index 74c0eb28c422..9e67517b6cef 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -264,7 +264,7 @@ static int vhci_setup(struct hci_dev *hdev)
        struct vhci_data *vhci = hci_get_drvdata(hdev);

        hci_set_msft_opcode(hdev, vhci->msft_opcode);
-       hci_set_aosp_capable(hdev);
+       hci_set_aosp_capable(hdev, vhci->aosp_capable);

        return 0;
 }

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index dd8840e70e25..d007b487d4c1 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1279,10 +1279,10 @@ static inline void hci_set_msft_opcode(struct
hci_dev *hdev, __u16 opcode)
 #endif
 }

-static inline void hci_set_aosp_capable(struct hci_dev *hdev)
+static inline void hci_set_aosp_capable(struct hci_dev *hdev, bool enable)
 {
 #if IS_ENABLED(CONFIG_BT_AOSPEXT)
-       hdev->aosp_capable = true;
+       hdev->aosp_capable = enable;
 #endif
 }


> Regards
>
> Marcel
>


-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* Re: [PATCH v3] Bluetooth: vhci: Add support for setting msft_opcode and aosp_capable
  2021-10-14 17:23   ` Luiz Augusto von Dentz
@ 2021-10-14 17:47     ` Marcel Holtmann
  0 siblings, 0 replies; 5+ messages in thread
From: Marcel Holtmann @ 2021-10-14 17:47 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hi Luiz,

>>> This adds a debugfs entries to set msft_opcode and aosp_capable enabling
>>> vhci to emulate controllers with MSFT/AOSP extension support.
>>> 
>>> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
>>> ---
>>> v2: Fix typos: s/extention/extension/g
>>> v3: Remove checks for HCI_SETUP, merge changes to introduce MSFT/AOSP support
>>> at the same time.
>>> 
>>> drivers/bluetooth/hci_vhci.c | 92 ++++++++++++++++++++++++++++++++++++
>>> 1 file changed, 92 insertions(+)
>> 
>> patch has been applied to bluetooth-next tree (with slight modifications).
> 
> ++<<<<<<< HEAD
> +      hci_set_msft_opcode(hdev, vhci->msft_opcode);
> +      hci_set_aosp_capable(hdev);
> ++=======
> +       if (vhci->msft_opcode)
> +               hci_set_msft_opcode(hdev, vhci->msft_opcode);
> +
> +       if (vhci->aosp_capable)
> +               hci_set_aosp_capable(hdev);
> ++>>>>>>> 9bbbb6a7ad09 (Bluetooth: vhci: Add support for setting
> msft_opcode and aosp_capable)
> 
> I suspect the above changes won't work if we don't init the fields in
> the vhci_data, msft_opcode would be set to 0x0000 so it won't be
> enabled anyway but aosp_capable would be enabled which would be out of
> sync with vhci->aosp_capable, so perhaps we want to change
> hci_set_aosp_capable to take a parameter:

I went to bed yesterday and today, I realized that I have done something stupid. I fixed this upstream and also made sure that you can only ever set this once per debugfs. 

Regards

Marcel


^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-10-14 17:48 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-13 22:17 [PATCH v3] Bluetooth: vhci: Add support for setting msft_opcode and aosp_capable Luiz Augusto von Dentz
2021-10-13 23:10 ` [v3] " bluez.test.bot
2021-10-14 12:39 ` [PATCH v3] " Marcel Holtmann
2021-10-14 17:23   ` Luiz Augusto von Dentz
2021-10-14 17:47     ` Marcel Holtmann

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).