All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 1/4] Bluetooth: Only allow setting msft_opcode at setup stage
@ 2021-10-13  0:30 Luiz Augusto von Dentz
  2021-10-13  0:30 ` [PATCH v2 2/4] Bluetooth: Only allow setting AOSP capable " Luiz Augusto von Dentz
                   ` (4 more replies)
  0 siblings, 5 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2021-10-13  0:30 UTC (permalink / raw)
  To: linux-bluetooth

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

The msft_opcode shall only be changed while at the setup stage otherwise
it can possible cause problems where different opcodes are used while
running.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
v2: Fix typos: s/extention/extension/g

 include/net/bluetooth/hci_core.h | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index dd8840e70e25..eb5d4ea88c3a 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1272,11 +1272,15 @@ int hci_recv_diag(struct hci_dev *hdev, struct sk_buff *skb);
 __printf(2, 3) void hci_set_hw_info(struct hci_dev *hdev, const char *fmt, ...);
 __printf(2, 3) void hci_set_fw_info(struct hci_dev *hdev, const char *fmt, ...);
 
-static inline void hci_set_msft_opcode(struct hci_dev *hdev, __u16 opcode)
+static inline int hci_set_msft_opcode(struct hci_dev *hdev, __u16 opcode)
 {
+	if (!hci_dev_test_flag(hdev, HCI_SETUP))
+		return -EPERM;
+
 #if IS_ENABLED(CONFIG_BT_MSFTEXT)
 	hdev->msft_opcode = opcode;
 #endif
+	return 0;
 }
 
 static inline void hci_set_aosp_capable(struct hci_dev *hdev)
-- 
2.31.1


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

* [PATCH v2 2/4] Bluetooth: Only allow setting AOSP capable at setup stage
  2021-10-13  0:30 [PATCH v2 1/4] Bluetooth: Only allow setting msft_opcode at setup stage Luiz Augusto von Dentz
@ 2021-10-13  0:30 ` Luiz Augusto von Dentz
  2021-10-13  0:30 ` [PATCH v2 3/4] Bluetooth: vhci: Add support for setting msft_opcode Luiz Augusto von Dentz
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2021-10-13  0:30 UTC (permalink / raw)
  To: linux-bluetooth

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

The aosp_capable flag shall only be changed while at the setup stage
otherwise it can possible take no effect.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
 include/net/bluetooth/hci_core.h | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index eb5d4ea88c3a..ac81745d2ac4 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1283,11 +1283,16 @@ static inline int hci_set_msft_opcode(struct hci_dev *hdev, __u16 opcode)
 	return 0;
 }
 
-static inline void hci_set_aosp_capable(struct hci_dev *hdev)
+static inline int hci_set_aosp_capable(struct hci_dev *hdev)
 {
+	if (!hci_dev_test_flag(hdev, HCI_SETUP))
+		return -EPERM;
+
 #if IS_ENABLED(CONFIG_BT_AOSPEXT)
 	hdev->aosp_capable = true;
 #endif
+
+	return 0;
 }
 
 int hci_dev_open(__u16 dev);
-- 
2.31.1


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

* [PATCH v2 3/4] Bluetooth: vhci: Add support for setting msft_opcode
  2021-10-13  0:30 [PATCH v2 1/4] Bluetooth: Only allow setting msft_opcode at setup stage Luiz Augusto von Dentz
  2021-10-13  0:30 ` [PATCH v2 2/4] Bluetooth: Only allow setting AOSP capable " Luiz Augusto von Dentz
@ 2021-10-13  0:30 ` Luiz Augusto von Dentz
  2021-10-13  0:30 ` [PATCH v2 4/4] Bluetooth: vhci: Add support for setting aosp_capable Luiz Augusto von Dentz
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2021-10-13  0:30 UTC (permalink / raw)
  To: linux-bluetooth

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

This adds a debugfs entry to set msft_opcode enabling vhci to emulate
controllers with MSFT extension support.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
 drivers/bluetooth/hci_vhci.c | 52 ++++++++++++++++++++++++++++++++++++
 1 file changed, 52 insertions(+)

diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index 56c6b22be10b..68a970db8db1 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -42,6 +42,9 @@ struct vhci_data {
 
 	bool suspended;
 	bool wakeup;
+#if IS_ENABLED(CONFIG_BT_MSFTEXT)
+	__u16 msft_opcode;
+#endif
 };
 
 static int vhci_open_dev(struct hci_dev *hdev)
@@ -194,6 +197,44 @@ static const struct file_operations force_wakeup_fops = {
 	.llseek		= default_llseek,
 };
 
+#if IS_ENABLED(CONFIG_BT_MSFTEXT)
+
+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 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);
+
+	return 0;
+}
+
+#endif /* CONFIG_BT_MSFTEXT */
+
 static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
 {
 	struct hci_dev *hdev;
@@ -237,6 +278,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 is selected */
+#if IS_ENABLED(CONFIG_BT_MSFTEXT)
+	hdev->setup = vhci_setup;
+	set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks);
+#endif
+
 	/* bit 6 is for external configuration */
 	if (opcode & 0x40)
 		set_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks);
@@ -259,6 +306,11 @@ 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);
+#endif
+
 	hci_skb_pkt_type(skb) = HCI_VENDOR_PKT;
 
 	skb_put_u8(skb, 0xff);
-- 
2.31.1


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

* [PATCH v2 4/4] Bluetooth: vhci: Add support for setting aosp_capable
  2021-10-13  0:30 [PATCH v2 1/4] Bluetooth: Only allow setting msft_opcode at setup stage Luiz Augusto von Dentz
  2021-10-13  0:30 ` [PATCH v2 2/4] Bluetooth: Only allow setting AOSP capable " Luiz Augusto von Dentz
  2021-10-13  0:30 ` [PATCH v2 3/4] Bluetooth: vhci: Add support for setting msft_opcode Luiz Augusto von Dentz
@ 2021-10-13  0:30 ` Luiz Augusto von Dentz
  2021-10-13  6:45   ` Marcel Holtmann
  2021-10-13  2:11 ` [v2,1/4] Bluetooth: Only allow setting msft_opcode at setup stage bluez.test.bot
  2021-10-13  6:35 ` [PATCH v2 1/4] " Marcel Holtmann
  4 siblings, 1 reply; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2021-10-13  0:30 UTC (permalink / raw)
  To: linux-bluetooth

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

This adds a debugfs entry to set aosp_capable enabling vhci to emulate
controllers with AOSP extension support.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
---
 drivers/bluetooth/hci_vhci.c | 68 +++++++++++++++++++++++++++++++++---
 1 file changed, 64 insertions(+), 4 deletions(-)

diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
index 68a970db8db1..f9aa3fe14995 100644
--- a/drivers/bluetooth/hci_vhci.c
+++ b/drivers/bluetooth/hci_vhci.c
@@ -45,6 +45,9 @@ struct vhci_data {
 #if IS_ENABLED(CONFIG_BT_MSFTEXT)
 	__u16 msft_opcode;
 #endif
+#if IS_ENABLED(CONFIG_BT_AOSPEXT)
+	__u16 aosp_capable;
+#endif
 };
 
 static int vhci_open_dev(struct hci_dev *hdev)
@@ -223,18 +226,68 @@ static int msft_opcode_get(void *data, u64 *val)
 DEFINE_DEBUGFS_ATTRIBUTE(msft_opcode_fops, msft_opcode_get, msft_opcode_set,
 			 "%llu\n");
 
+#endif /* CONFIG_BT_MSFTEXT */
+
+#if IS_ENABLED(CONFIG_BT_AOSPEXT)
+
+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,
+};
+
+#endif /* CONFIG_BT_AOSEXT */
+
 static int vhci_setup(struct hci_dev *hdev)
 {
 	struct vhci_data *vhci = hci_get_drvdata(hdev);
 
+#if IS_ENABLED(CONFIG_BT_MSFTEXT)
 	if (vhci->msft_opcode)
 		hci_set_msft_opcode(hdev, vhci->msft_opcode);
+#endif
+
+#if IS_ENABLED(CONFIG_BT_AOSPEXT)
+	if (vhci->aosp_capable)
+		hci_set_aosp_capable(hdev);
+#endif
 
 	return 0;
 }
 
-#endif /* CONFIG_BT_MSFTEXT */
-
 static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
 {
 	struct hci_dev *hdev;
@@ -278,8 +331,10 @@ 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 is selected */
-#if IS_ENABLED(CONFIG_BT_MSFTEXT)
+	/* Enable custom setup if CONFIG_BT_MSFTEXT or CONFIG_BT_AOSPEXT is
+	 * selected.
+	 */
+#if IS_ENABLED(CONFIG_BT_MSFTEXT) || IS_ENABLED(CONFIG_BT_AOSPEXT)
 	hdev->setup = vhci_setup;
 	set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks);
 #endif
@@ -311,6 +366,11 @@ static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
 			    &msft_opcode_fops);
 #endif
 
+#if IS_ENABLED(CONFIG_BT_AOSPEXT)
+	debugfs_create_file("aosp_capable", 0644, hdev->debugfs, data,
+			    &aosp_capable_fops);
+#endif
+
 	hci_skb_pkt_type(skb) = HCI_VENDOR_PKT;
 
 	skb_put_u8(skb, 0xff);
-- 
2.31.1


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

* RE: [v2,1/4] Bluetooth: Only allow setting msft_opcode at setup stage
  2021-10-13  0:30 [PATCH v2 1/4] Bluetooth: Only allow setting msft_opcode at setup stage Luiz Augusto von Dentz
                   ` (2 preceding siblings ...)
  2021-10-13  0:30 ` [PATCH v2 4/4] Bluetooth: vhci: Add support for setting aosp_capable Luiz Augusto von Dentz
@ 2021-10-13  2:11 ` bluez.test.bot
  2021-10-13  6:35 ` [PATCH v2 1/4] " Marcel Holtmann
  4 siblings, 0 replies; 9+ messages in thread
From: bluez.test.bot @ 2021-10-13  2:11 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=562233

---Test result---

Test Summary:
CheckPatch                    PASS      6.63 seconds
GitLint                       PASS      3.63 seconds
BuildKernel                   PASS      613.81 seconds
TestRunner: Setup             PASS      449.45 seconds
TestRunner: l2cap-tester      PASS      10.26 seconds
TestRunner: bnep-tester       PASS      5.53 seconds
TestRunner: mgmt-tester       PASS      92.99 seconds
TestRunner: rfcomm-tester     PASS      6.82 seconds
TestRunner: sco-tester        PASS      7.06 seconds
TestRunner: smp-tester        PASS      6.84 seconds
TestRunner: userchan-tester   PASS      5.79 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: 11830 bytes --]

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

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

* Re: [PATCH v2 1/4] Bluetooth: Only allow setting msft_opcode at setup stage
  2021-10-13  0:30 [PATCH v2 1/4] Bluetooth: Only allow setting msft_opcode at setup stage Luiz Augusto von Dentz
                   ` (3 preceding siblings ...)
  2021-10-13  2:11 ` [v2,1/4] Bluetooth: Only allow setting msft_opcode at setup stage bluez.test.bot
@ 2021-10-13  6:35 ` Marcel Holtmann
  2021-10-13 21:10   ` Luiz Augusto von Dentz
  4 siblings, 1 reply; 9+ messages in thread
From: Marcel Holtmann @ 2021-10-13  6:35 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hi Luiz,

> The msft_opcode shall only be changed while at the setup stage otherwise
> it can possible cause problems where different opcodes are used while
> running.
> 
> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> ---
> v2: Fix typos: s/extention/extension/g
> 
> include/net/bluetooth/hci_core.h | 6 +++++-
> 1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> index dd8840e70e25..eb5d4ea88c3a 100644
> --- a/include/net/bluetooth/hci_core.h
> +++ b/include/net/bluetooth/hci_core.h
> @@ -1272,11 +1272,15 @@ int hci_recv_diag(struct hci_dev *hdev, struct sk_buff *skb);
> __printf(2, 3) void hci_set_hw_info(struct hci_dev *hdev, const char *fmt, ...);
> __printf(2, 3) void hci_set_fw_info(struct hci_dev *hdev, const char *fmt, ...);
> 
> -static inline void hci_set_msft_opcode(struct hci_dev *hdev, __u16 opcode)
> +static inline int hci_set_msft_opcode(struct hci_dev *hdev, __u16 opcode)
> {
> +	if (!hci_dev_test_flag(hdev, HCI_SETUP))
> +		return -EPERM;
> +
> #if IS_ENABLED(CONFIG_BT_MSFTEXT)
> 	hdev->msft_opcode = opcode;
> #endif
> +	return 0;
> }

this is also not going to work since some driver might set it in their probe() routine before calling hci_register_dev.

Regards

Marcel


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

* Re: [PATCH v2 4/4] Bluetooth: vhci: Add support for setting aosp_capable
  2021-10-13  0:30 ` [PATCH v2 4/4] Bluetooth: vhci: Add support for setting aosp_capable Luiz Augusto von Dentz
@ 2021-10-13  6:45   ` Marcel Holtmann
  2021-10-13 21:29     ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 9+ messages in thread
From: Marcel Holtmann @ 2021-10-13  6:45 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hi Luiz,

> This adds a debugfs entry to set aosp_capable enabling vhci to emulate
> controllers with AOSP extension support.
> 
> Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> ---
> drivers/bluetooth/hci_vhci.c | 68 +++++++++++++++++++++++++++++++++---
> 1 file changed, 64 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
> index 68a970db8db1..f9aa3fe14995 100644
> --- a/drivers/bluetooth/hci_vhci.c
> +++ b/drivers/bluetooth/hci_vhci.c
> @@ -45,6 +45,9 @@ struct vhci_data {
> #if IS_ENABLED(CONFIG_BT_MSFTEXT)
> 	__u16 msft_opcode;
> #endif
> +#if IS_ENABLED(CONFIG_BT_AOSPEXT)
> +	__u16 aosp_capable;
> +#endif
> };
> 
> static int vhci_open_dev(struct hci_dev *hdev)
> @@ -223,18 +226,68 @@ static int msft_opcode_get(void *data, u64 *val)
> DEFINE_DEBUGFS_ATTRIBUTE(msft_opcode_fops, msft_opcode_get, msft_opcode_set,
> 			 "%llu\n");
> 
> +#endif /* CONFIG_BT_MSFTEXT */
> +
> +#if IS_ENABLED(CONFIG_BT_AOSPEXT)
> +
> +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,
> +};
> +
> +#endif /* CONFIG_BT_AOSEXT */
> +
> static int vhci_setup(struct hci_dev *hdev)
> {
> 	struct vhci_data *vhci = hci_get_drvdata(hdev);
> 
> +#if IS_ENABLED(CONFIG_BT_MSFTEXT)
> 	if (vhci->msft_opcode)
> 		hci_set_msft_opcode(hdev, vhci->msft_opcode);
> +#endif
> +
> +#if IS_ENABLED(CONFIG_BT_AOSPEXT)
> +	if (vhci->aosp_capable)
> +		hci_set_aosp_capable(hdev);
> +#endif

this is too much ifdef for me. And you are not really saving anything here since this is a test driver and who cares if we waste an additional 3 bytes memory for vhci_data struct.

So really just do this unconditionally

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

And frankly, do both vendor extensions in one patch.

> 
> 	return 0;
> }
> 
> -#endif /* CONFIG_BT_MSFTEXT */
> -
> static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
> {
> 	struct hci_dev *hdev;
> @@ -278,8 +331,10 @@ 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 is selected */
> -#if IS_ENABLED(CONFIG_BT_MSFTEXT)
> +	/* Enable custom setup if CONFIG_BT_MSFTEXT or CONFIG_BT_AOSPEXT is
> +	 * selected.
> +	 */
> +#if IS_ENABLED(CONFIG_BT_MSFTEXT) || IS_ENABLED(CONFIG_BT_AOSPEXT)
> 	hdev->setup = vhci_setup;
> 	set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks);
> #endif

Even this one is not worth it, just have it run through hdev->setup all the time. If nothing is run, then there is no harm.

> @@ -311,6 +366,11 @@ static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
> 			    &msft_opcode_fops);
> #endif
> 
> +#if IS_ENABLED(CONFIG_BT_AOSPEXT)
> +	debugfs_create_file("aosp_capable", 0644, hdev->debugfs, data,
> +			    &aosp_capable_fops);
> +#endif
> +

This is the ifdef check we should keep. If not enabled, then we should not expose the debugfs setting. Just wrap it in an if-clause from C so that the compiler doesn’t warn us for unused functions.

Regards

Marcel


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

* Re: [PATCH v2 1/4] Bluetooth: Only allow setting msft_opcode at setup stage
  2021-10-13  6:35 ` [PATCH v2 1/4] " Marcel Holtmann
@ 2021-10-13 21:10   ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2021-10-13 21:10 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth

Hi Marcel,

On Tue, Oct 12, 2021 at 11:35 PM Marcel Holtmann <marcel@holtmann.org> wrote:
>
> Hi Luiz,
>
> > The msft_opcode shall only be changed while at the setup stage otherwise
> > it can possible cause problems where different opcodes are used while
> > running.
> >
> > Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> > ---
> > v2: Fix typos: s/extention/extension/g
> >
> > include/net/bluetooth/hci_core.h | 6 +++++-
> > 1 file changed, 5 insertions(+), 1 deletion(-)
> >
> > diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
> > index dd8840e70e25..eb5d4ea88c3a 100644
> > --- a/include/net/bluetooth/hci_core.h
> > +++ b/include/net/bluetooth/hci_core.h
> > @@ -1272,11 +1272,15 @@ int hci_recv_diag(struct hci_dev *hdev, struct sk_buff *skb);
> > __printf(2, 3) void hci_set_hw_info(struct hci_dev *hdev, const char *fmt, ...);
> > __printf(2, 3) void hci_set_fw_info(struct hci_dev *hdev, const char *fmt, ...);
> >
> > -static inline void hci_set_msft_opcode(struct hci_dev *hdev, __u16 opcode)
> > +static inline int hci_set_msft_opcode(struct hci_dev *hdev, __u16 opcode)
> > {
> > +     if (!hci_dev_test_flag(hdev, HCI_SETUP))
> > +             return -EPERM;
> > +
> > #if IS_ENABLED(CONFIG_BT_MSFTEXT)
> >       hdev->msft_opcode = opcode;
> > #endif
> > +     return 0;
> > }
>
> this is also not going to work since some driver might set it in their probe() routine before calling hci_register_dev.

Shall we allow that though? Perhaps we should be checking for HCI_RUNNING then?

-- 
Luiz Augusto von Dentz

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

* Re: [PATCH v2 4/4] Bluetooth: vhci: Add support for setting aosp_capable
  2021-10-13  6:45   ` Marcel Holtmann
@ 2021-10-13 21:29     ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 9+ messages in thread
From: Luiz Augusto von Dentz @ 2021-10-13 21:29 UTC (permalink / raw)
  To: Marcel Holtmann; +Cc: linux-bluetooth

Hi Marcel,

On Tue, Oct 12, 2021 at 11:46 PM Marcel Holtmann <marcel@holtmann.org> wrote:
>
> Hi Luiz,
>
> > This adds a debugfs entry to set aosp_capable enabling vhci to emulate
> > controllers with AOSP extension support.
> >
> > Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> > ---
> > drivers/bluetooth/hci_vhci.c | 68 +++++++++++++++++++++++++++++++++---
> > 1 file changed, 64 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/bluetooth/hci_vhci.c b/drivers/bluetooth/hci_vhci.c
> > index 68a970db8db1..f9aa3fe14995 100644
> > --- a/drivers/bluetooth/hci_vhci.c
> > +++ b/drivers/bluetooth/hci_vhci.c
> > @@ -45,6 +45,9 @@ struct vhci_data {
> > #if IS_ENABLED(CONFIG_BT_MSFTEXT)
> >       __u16 msft_opcode;
> > #endif
> > +#if IS_ENABLED(CONFIG_BT_AOSPEXT)
> > +     __u16 aosp_capable;
> > +#endif
> > };
> >
> > static int vhci_open_dev(struct hci_dev *hdev)
> > @@ -223,18 +226,68 @@ static int msft_opcode_get(void *data, u64 *val)
> > DEFINE_DEBUGFS_ATTRIBUTE(msft_opcode_fops, msft_opcode_get, msft_opcode_set,
> >                        "%llu\n");
> >
> > +#endif /* CONFIG_BT_MSFTEXT */
> > +
> > +#if IS_ENABLED(CONFIG_BT_AOSPEXT)
> > +
> > +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,
> > +};
> > +
> > +#endif /* CONFIG_BT_AOSEXT */
> > +
> > static int vhci_setup(struct hci_dev *hdev)
> > {
> >       struct vhci_data *vhci = hci_get_drvdata(hdev);
> >
> > +#if IS_ENABLED(CONFIG_BT_MSFTEXT)
> >       if (vhci->msft_opcode)
> >               hci_set_msft_opcode(hdev, vhci->msft_opcode);
> > +#endif
> > +
> > +#if IS_ENABLED(CONFIG_BT_AOSPEXT)
> > +     if (vhci->aosp_capable)
> > +             hci_set_aosp_capable(hdev);
> > +#endif
>
> this is too much ifdef for me. And you are not really saving anything here since this is a test driver and who cares if we waste an additional 3 bytes memory for vhci_data struct.
>
> So really just do this unconditionally
>
>         hci_set_msft_opcode(hdev, vhci->msft_opcode);
>         hci_set_aosp_capable(hdev);
>
> And frankly, do both vendor extensions in one patch.

Ack.

> >
> >       return 0;
> > }
> >
> > -#endif /* CONFIG_BT_MSFTEXT */
> > -
> > static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
> > {
> >       struct hci_dev *hdev;
> > @@ -278,8 +331,10 @@ 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 is selected */
> > -#if IS_ENABLED(CONFIG_BT_MSFTEXT)
> > +     /* Enable custom setup if CONFIG_BT_MSFTEXT or CONFIG_BT_AOSPEXT is
> > +      * selected.
> > +      */
> > +#if IS_ENABLED(CONFIG_BT_MSFTEXT) || IS_ENABLED(CONFIG_BT_AOSPEXT)
> >       hdev->setup = vhci_setup;
> >       set_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks);
> > #endif
>
> Even this one is not worth it, just have it run through hdev->setup all the time. If nothing is run, then there is no harm.

Ack

> > @@ -311,6 +366,11 @@ static int __vhci_create_device(struct vhci_data *data, __u8 opcode)
> >                           &msft_opcode_fops);
> > #endif
> >
> > +#if IS_ENABLED(CONFIG_BT_AOSPEXT)
> > +     debugfs_create_file("aosp_capable", 0644, hdev->debugfs, data,
> > +                         &aosp_capable_fops);
> > +#endif
> > +
>
> This is the ifdef check we should keep. If not enabled, then we should not expose the debugfs setting. Just wrap it in an if-clause from C so that the compiler doesn’t warn us for unused functions.

Got it.

> Regards
>
> Marcel
>


-- 
Luiz Augusto von Dentz

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

end of thread, other threads:[~2021-10-13 21:29 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-10-13  0:30 [PATCH v2 1/4] Bluetooth: Only allow setting msft_opcode at setup stage Luiz Augusto von Dentz
2021-10-13  0:30 ` [PATCH v2 2/4] Bluetooth: Only allow setting AOSP capable " Luiz Augusto von Dentz
2021-10-13  0:30 ` [PATCH v2 3/4] Bluetooth: vhci: Add support for setting msft_opcode Luiz Augusto von Dentz
2021-10-13  0:30 ` [PATCH v2 4/4] Bluetooth: vhci: Add support for setting aosp_capable Luiz Augusto von Dentz
2021-10-13  6:45   ` Marcel Holtmann
2021-10-13 21:29     ` Luiz Augusto von Dentz
2021-10-13  2:11 ` [v2,1/4] Bluetooth: Only allow setting msft_opcode at setup stage bluez.test.bot
2021-10-13  6:35 ` [PATCH v2 1/4] " Marcel Holtmann
2021-10-13 21:10   ` Luiz Augusto von Dentz

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.