diff mbox series

[v8,6/9] Bluetooth: btintel: Add a callback function to configure data path

Message ID 20210518104232.5431-6-kiran.k@intel.com
State New
Headers show
Series [v8,1/9] Bluetooth: enumerate local supported codec and cache details | expand

Commit Message

K, Kiran May 18, 2021, 10:42 a.m. UTC
In HFP offload usecase, Intel controllers require offload use
case id (NBS or WBS) to be set before opening SCO connection. Define
a new callback which gets called on setsockopt SCO socket. User space
audio module is expected to set codec via setsockopt(sk, BT_CODEC, ....)
before opening SCO connection.

Signed-off-by: Kiran K <kiran.k@intel.com>
Reviewed-by: Chethan T N <chethan.tumkur.narayan@intel.com>
Reviewed-by: Srivatsa Ravishankar <ravishankar.srivatsa@intel.com>
---

This callback gets called when audio module does setsockopt(sk, BT_CODEC,...)
on SCO socket and data_path is 1 (non-HCI transport). For non-HCI transport,
Intel controller expects presets to be set before opening SCO connection.
Presets are pre-defined, 0 - NBS, 1 - WBS. Likewise additional presets will
be defined for A2DP, LE Audio offload use cases.

 drivers/bluetooth/btintel.c      | 50 ++++++++++++++++++++++++++++++++
 drivers/bluetooth/btintel.h      |  8 +++++
 drivers/bluetooth/btusb.c        |  1 +
 include/net/bluetooth/hci.h      |  8 +++++
 include/net/bluetooth/hci_core.h |  2 ++
 5 files changed, 69 insertions(+)

Comments

Marcel Holtmann June 3, 2021, 2:30 p.m. UTC | #1
Hi Kiran,

> In HFP offload usecase, Intel controllers require offload use

> case id (NBS or WBS) to be set before opening SCO connection. Define

> a new callback which gets called on setsockopt SCO socket. User space

> audio module is expected to set codec via setsockopt(sk, BT_CODEC, ....)

> before opening SCO connection.

> 

> Signed-off-by: Kiran K <kiran.k@intel.com>

> Reviewed-by: Chethan T N <chethan.tumkur.narayan@intel.com>

> Reviewed-by: Srivatsa Ravishankar <ravishankar.srivatsa@intel.com>

> ---

> 

> This callback gets called when audio module does setsockopt(sk, BT_CODEC,...)

> on SCO socket and data_path is 1 (non-HCI transport). For non-HCI transport,

> Intel controller expects presets to be set before opening SCO connection.

> Presets are pre-defined, 0 - NBS, 1 - WBS. Likewise additional presets will

> be defined for A2DP, LE Audio offload use cases.

> 

> drivers/bluetooth/btintel.c      | 50 ++++++++++++++++++++++++++++++++

> drivers/bluetooth/btintel.h      |  8 +++++

> drivers/bluetooth/btusb.c        |  1 +

> include/net/bluetooth/hci.h      |  8 +++++

> include/net/bluetooth/hci_core.h |  2 ++

> 5 files changed, 69 insertions(+)


same thing here. Please introduce the callbacks as one patch and then in a separate patch, you start using them in a driver.

Regards

Marcel
diff mbox series

Patch

diff --git a/drivers/bluetooth/btintel.c b/drivers/bluetooth/btintel.c
index 8407e9736c62..8efb15504973 100644
--- a/drivers/bluetooth/btintel.c
+++ b/drivers/bluetooth/btintel.c
@@ -1308,6 +1308,56 @@  int btintel_get_data_path_id(struct hci_dev *hdev)
 }
 EXPORT_SYMBOL_GPL(btintel_get_data_path_id);
 
+int btintel_configure_data_path(struct hci_dev *hdev, __u8 type,
+				struct bt_codec *codec)
+{
+	__u8 preset;
+	struct hci_op_configure_data_path *cmd;
+	__u8 buffer[255];
+	struct sk_buff *skb;
+
+	if (type != SCO_LINK && type != ESCO_LINK)
+		return -EINVAL;
+
+	switch (codec->id) {
+	case 0x02:
+		preset = 0x00;
+	break;
+	case 0x05:
+		preset = 0x01;
+	break;
+	default:
+		return -EINVAL;
+	}
+
+	cmd = (void *)buffer;
+	cmd->data_path_id = 0x01;
+	cmd->len = 1;
+	cmd->data[0] = preset;
+
+	cmd->direction = 0x00;
+	skb = __hci_cmd_sync(hdev, HCI_CONFIGURE_DATA_PATH, sizeof(*cmd) + 1,
+			     cmd, HCI_INIT_TIMEOUT);
+	if (IS_ERR(skb)) {
+		bt_dev_err(hdev, "configure input data path failed (%ld)",
+			   PTR_ERR(skb));
+		return PTR_ERR(skb);
+	}
+	kfree_skb(skb);
+
+	cmd->direction = 0x01;
+	skb = __hci_cmd_sync(hdev, HCI_CONFIGURE_DATA_PATH, sizeof(*cmd) + 1,
+			     cmd, HCI_INIT_TIMEOUT);
+	if (IS_ERR(skb)) {
+		bt_dev_err(hdev, "configure output data path failed (%ld)",
+			   PTR_ERR(skb));
+		return PTR_ERR(skb);
+	}
+	kfree_skb(skb);
+	return 0;
+}
+EXPORT_SYMBOL_GPL(btintel_configure_data_path);
+
 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
 MODULE_DESCRIPTION("Bluetooth support for Intel devices ver " VERSION);
 MODULE_VERSION(VERSION);
diff --git a/drivers/bluetooth/btintel.h b/drivers/bluetooth/btintel.h
index 6d4edfd16d44..f4af22ecdc0d 100644
--- a/drivers/bluetooth/btintel.h
+++ b/drivers/bluetooth/btintel.h
@@ -177,6 +177,8 @@  int btintel_set_debug_features(struct hci_dev *hdev,
 			       const struct intel_debug_features *features);
 int btintel_read_offload_usecases(struct hci_dev *hdev);
 int btintel_get_data_path_id(struct hci_dev *hdev);
+int btintel_configure_data_path(struct hci_dev *hdev, __u8 type,
+				struct bt_codec *codec);
 #else
 
 static inline int btintel_check_bdaddr(struct hci_dev *hdev)
@@ -318,4 +320,10 @@  static int btintel_get_data_path_id(struct hci_dev *hdev)
 {
 	return -EOPNOTSUPP;
 }
+
+static int btintel_configure_data_path(struct hci_dev *hdev, __u8 type,
+				       struct bt_codec *codec)
+{
+	return -EOPNOTSUPP;
+}
 #endif
diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c
index f7b349db392a..220e7c85db10 100644
--- a/drivers/bluetooth/btusb.c
+++ b/drivers/bluetooth/btusb.c
@@ -4632,6 +4632,7 @@  static int btusb_probe(struct usb_interface *intf,
 		hdev->set_bdaddr = btintel_set_bdaddr;
 		hdev->cmd_timeout = btusb_intel_cmd_timeout;
 		hdev->get_data_path_id = btintel_get_data_path_id;
+		hdev->configure_data_path = btintel_configure_data_path;
 		set_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks);
 		set_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks);
 		set_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks);
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index 9658600ae5de..bd666b114aea 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -1257,6 +1257,14 @@  struct hci_rp_read_local_oob_ext_data {
 	__u8     rand256[16];
 } __packed;
 
+#define HCI_CONFIGURE_DATA_PATH	0x0c83
+struct hci_op_configure_data_path {
+	__u8	direction;
+	__u8	data_path_id;
+	__u8	len;
+	__u8	data[];
+} __packed;
+
 #define HCI_OP_READ_LOCAL_VERSION	0x1001
 struct hci_rp_read_local_version {
 	__u8     status;
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 78d1ebab58f6..959585bafa8d 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -618,6 +618,8 @@  struct hci_dev {
 	void (*cmd_timeout)(struct hci_dev *hdev);
 	bool (*prevent_wake)(struct hci_dev *hdev);
 	int (*get_data_path_id)(struct hci_dev *hdev);
+	int (*configure_data_path)(struct hci_dev *hdev, __u8 type,
+				   struct bt_codec *codec);
 };
 
 #define HCI_PHY_HANDLE(handle)	(handle & 0xff)