linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kiran K <kiran.k@intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: ravishankar.srivatsa@intel.com, chethan.tumkur.narayan@intel.com,
	luiz.von.dentz@intel.com, Kiran K <kiran.k@intel.com>
Subject: [PATCH v4 14/14] Bluetooth: Add MSFT a2dp offload codec under experimental flag
Date: Fri, 19 Nov 2021 13:50:27 +0530	[thread overview]
Message-ID: <20211119082027.12809-14-kiran.k@intel.com> (raw)
In-Reply-To: <20211119082027.12809-1-kiran.k@intel.com>

Keep MSFT a2dp offload codecs feature under experimental flag.

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>
---
 net/bluetooth/mgmt.c | 94 +++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 93 insertions(+), 1 deletion(-)

diff --git a/net/bluetooth/mgmt.c b/net/bluetooth/mgmt.c
index f8f74d344297..913e2c66cdf6 100644
--- a/net/bluetooth/mgmt.c
+++ b/net/bluetooth/mgmt.c
@@ -3887,10 +3887,16 @@ static const u8 rpa_resolution_uuid[16] = {
 	0xea, 0x11, 0x73, 0xc2, 0x48, 0xa1, 0xc0, 0x15,
 };
 
+/* 0cc2131f-96f0-4cd1-b313-b97e7cbc8335 */
+static const u8 msft_a2dp_offload_codecs_uuid[16] = {
+	0x35, 0x83, 0xbc, 0x7c, 0x7e, 0xb9, 0x13, 0xb3,
+	0xd1, 0x4c, 0xf0, 0x96, 0x1f, 0x13, 0xc2, 0x0c,
+};
+
 static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev,
 				  void *data, u16 data_len)
 {
-	char buf[102];   /* Enough space for 5 features: 2 + 20 * 5 */
+	char buf[122];   /* Enough space for 6 features: 2 + 20 * 6 */
 	struct mgmt_rp_read_exp_features_info *rp = (void *)buf;
 	u16 idx = 0;
 	u32 flags;
@@ -3957,6 +3963,17 @@ static int read_exp_features_info(struct sock *sk, struct hci_dev *hdev,
 		idx++;
 	}
 
+	if (hdev && hdev->get_data_path_id) {
+		if (hci_dev_test_flag(hdev, HCI_MSFT_A2DP_OFFLOAD_CODECS_ENABLED))
+			flags = BIT(0);
+		else
+			flags = 0;
+
+		memcpy(rp->features[idx].uuid, msft_a2dp_offload_codecs_uuid, 16);
+		rp->features[idx].flags = cpu_to_le32(flags);
+		idx++;
+	}
+
 	rp->feature_count = cpu_to_le16(idx);
 
 	/* After reading the experimental features information, enable
@@ -4256,6 +4273,20 @@ static int exp_offload_codec_feature_changed(bool enabled, struct hci_dev *hdev,
 				  HCI_MGMT_EXP_FEATURE_EVENTS, skip);
 }
 
+static int exp_msft_a2dp_offload_codec_feature_changed(bool enabled,
+						       struct sock *skip)
+{
+	struct mgmt_ev_exp_feature_changed ev;
+
+	memset(&ev, 0, sizeof(ev));
+	memcpy(ev.uuid, msft_a2dp_offload_codecs_uuid, 16);
+	ev.flags = cpu_to_le32(enabled ? BIT(0) : 0);
+
+	return mgmt_limited_event(MGMT_EV_EXP_FEATURE_CHANGED, NULL,
+				  &ev, sizeof(ev),
+				  HCI_MGMT_EXP_FEATURE_EVENTS, skip);
+}
+
 static int set_offload_codec_func(struct sock *sk, struct hci_dev *hdev,
 				  struct mgmt_cp_set_exp_feature *cp,
 				  u16 data_len)
@@ -4314,6 +4345,66 @@ static int set_offload_codec_func(struct sock *sk, struct hci_dev *hdev,
 	return err;
 }
 
+static int set_msft_a2dp_offload_codec_func(struct sock *sk, struct hci_dev *hdev,
+					    struct mgmt_cp_set_exp_feature *cp,
+					    u16 data_len)
+{
+	bool val, changed;
+	int err;
+	struct mgmt_rp_set_exp_feature rp;
+
+	/* Command requires to use a valid controller index */
+	if (!hdev)
+		return mgmt_cmd_status(sk, MGMT_INDEX_NONE,
+				       MGMT_OP_SET_EXP_FEATURE,
+				       MGMT_STATUS_INVALID_INDEX);
+
+	/* Parameters are limited to a single octet */
+	if (data_len != MGMT_SET_EXP_FEATURE_SIZE + 1)
+		return mgmt_cmd_status(sk, hdev->id,
+				       MGMT_OP_SET_EXP_FEATURE,
+				       MGMT_STATUS_INVALID_PARAMS);
+
+	/* Only boolean on/off is supported */
+	if (cp->param[0] != 0x00 && cp->param[0] != 0x01)
+		return mgmt_cmd_status(sk, hdev->id,
+				       MGMT_OP_SET_EXP_FEATURE,
+				       MGMT_STATUS_INVALID_PARAMS);
+
+	val = !!cp->param[0];
+	changed = (val != hci_dev_test_flag(hdev,
+					    HCI_MSFT_A2DP_OFFLOAD_CODECS_ENABLED));
+
+	if (!hdev->get_data_path_id) {
+		return mgmt_cmd_status(sk, hdev->id,
+				       MGMT_OP_SET_EXP_FEATURE,
+				       MGMT_STATUS_NOT_SUPPORTED);
+	}
+
+	if (changed) {
+		if (val)
+			hci_dev_set_flag(hdev,
+					 HCI_MSFT_A2DP_OFFLOAD_CODECS_ENABLED);
+		else
+			hci_dev_clear_flag(hdev,
+					   HCI_MSFT_A2DP_OFFLOAD_CODECS_ENABLED);
+	}
+
+	bt_dev_info(hdev, "msft offload codecs enable %d changed %d",
+		    val, changed);
+
+	memcpy(rp.uuid, msft_a2dp_offload_codecs_uuid, 16);
+	rp.flags = cpu_to_le32(val ? BIT(0) : 0);
+	hci_sock_set_flag(sk, HCI_MGMT_EXP_FEATURE_EVENTS);
+	err = mgmt_cmd_complete(sk, hdev->id,
+				MGMT_OP_SET_EXP_FEATURE, 0,
+				&rp, sizeof(rp));
+
+	if (changed)
+		exp_msft_a2dp_offload_codec_feature_changed(val, sk);
+
+	return err;
+}
 static const struct mgmt_exp_feature {
 	const u8 *uuid;
 	int (*set_func)(struct sock *sk, struct hci_dev *hdev,
@@ -4326,6 +4417,7 @@ static const struct mgmt_exp_feature {
 	EXP_FEAT(rpa_resolution_uuid, set_rpa_resolution_func),
 	EXP_FEAT(quality_report_uuid, set_quality_report_func),
 	EXP_FEAT(offload_codecs_uuid, set_offload_codec_func),
+	EXP_FEAT(msft_a2dp_offload_codecs_uuid, set_msft_a2dp_offload_codec_func),
 
 	/* end with a null feature */
 	EXP_FEAT(NULL, NULL)
-- 
2.17.1


      parent reply	other threads:[~2021-11-19  8:15 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-19  8:20 [PATCH v4 01/14] Bluetooth: Refactor code to read supported codecs in getsockopt Kiran K
2021-11-19  8:20 ` [PATCH v4 02/14] Bluetooth: Support reading of codecs supported over l2cap socket Kiran K
2021-11-19  8:20 ` [PATCH v4 03/14] Bluetooth: btintel: cache offload use case data Kiran K
2021-11-19  8:20 ` [PATCH v4 04/14] Bluetooth: Pass transport type in get_data_path_id Kiran K
2021-11-23 23:43   ` Luiz Augusto von Dentz
2021-11-19  8:20 ` [PATCH v4 05/14] Bluetooth: btintel: Add support to fetch data path id for a2dp offload Kiran K
2021-11-23 23:49   ` Luiz Augusto von Dentz
2021-11-19  8:20 ` [PATCH v4 06/14] Bluetooth: Remove unused member in struct hci_vnd_codec_v2 Kiran K
2021-11-23 23:52   ` Luiz Augusto von Dentz
2021-11-19  8:20 ` [PATCH v4 07/14] Bluetooth: Read Output codec capabilities Kiran K
2021-11-19  8:20 ` [PATCH v4 08/14] Bluetooth: Implement MSFT avdtp open command Kiran K
2021-11-24  1:26   ` Luiz Augusto von Dentz
2021-11-19  8:20 ` [PATCH v4 09/14] Bluetooth: Handle MSFT avdtp open event Kiran K
2021-11-19  8:20 ` [PATCH v4 10/14] " Kiran K
2021-11-19  8:20 ` [PATCH v4 11/14] Bluetooth: Implment MSFT avdtp start command Kiran K
2021-11-19  8:20 ` [PATCH v4 12/14] Bluetooth: Implment MSFT avdtp suspend command Kiran K
2021-11-19  8:20 ` [PATCH v4 13/14] Bluetooth: Implment MSFT avdtp close command Kiran K
2021-11-19  8:20 ` Kiran K [this message]

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=20211119082027.12809-14-kiran.k@intel.com \
    --to=kiran.k@intel.com \
    --cc=chethan.tumkur.narayan@intel.com \
    --cc=linux-bluetooth@vger.kernel.org \
    --cc=luiz.von.dentz@intel.com \
    --cc=ravishankar.srivatsa@intel.com \
    /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).