diff mbox series

[3/4] Bluetooth: vhci: Add support for setting msft_opcode

Message ID 20211012213158.2635219-3-luiz.dentz@gmail.com (mailing list archive)
State Superseded
Headers show
Series [1/4] Bluetooth: Only allow setting msft_opcode at setup stage | expand

Checks

Context Check Description
tedd_an/checkpatch fail [3/4] Bluetooth: vhci: Add support for setting msft_opcode\WARNING:TYPO_SPELLING: 'extention' may be misspelled - perhaps 'extension'? #87: controllers with MSFT extention support. ^^^^^^^^^ total: 0 errors, 1 warnings, 76 lines checked NOTE: For some of the reported defects, checkpatch may be able to mechanically convert to the typical style using --fix or --fix-inplace. /github/workspace/src/12553715.patch has style problems, please review. NOTE: Ignored message types: UNKNOWN_COMMIT_ID NOTE: If any of the errors are false positives, please report them to the maintainer, see CHECKPATCH in MAINTAINERS.
tedd_an/gitlint success Gitlint PASS

Commit Message

Luiz Augusto von Dentz Oct. 12, 2021, 9:31 p.m. UTC
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 extention 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 mbox series

Patch

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