From: Kiran K <kiran.k@intel.com>
To: linux-bluetooth@vger.kernel.org
Cc: Kiran K <kiran.k@intel.com>,
Chethan T N <chethan.tumkur.narayan@intel.com>,
Srivatsa Ravishankar <ravishankar.srivatsa@intel.com>
Subject: [PATCH v3 2/3] Bluetooth: add support to enumerate local supports codecs v2
Date: Thu, 22 Apr 2021 19:44:48 +0530 [thread overview]
Message-ID: <20210422141449.25155-2-kiran.k@intel.com> (raw)
In-Reply-To: <20210422141449.25155-1-kiran.k@intel.com>
Add support for HCI_Read_Local_Supported_Codecs_V2 and query codec
capabilities
snoop:
> HCI Event: Command Complete (0x0e) plen 20
Read Local Supported Codecs V2 (0x04|0x000d) ncmd 1
Status: Success (0x00)
Number of supported codecs: 7
Codec: u-law log (0x00)
Logical Transport Type: 0x02
Codec supported over BR/EDR SCO and eSCO
Codec: A-law log (0x01)
Logical Transport Type: 0x02
Codec supported over BR/EDR SCO and eSCO
Codec: CVSD (0x02)
Logical Transport Type: 0x02
Codec supported over BR/EDR SCO and eSCO
Codec: Transparent (0x03)
Logical Transport Type: 0x02
Codec supported over BR/EDR SCO and eSCO
Codec: Linear PCM (0x04)
Logical Transport Type: 0x02
Codec supported over BR/EDR SCO and eSCO
Codec: Reserved (0x08)
Logical Transport Type: 0x03
Codec supported over BR/EDR ACL
Codec supported over BR/EDR SCO and eSCO
Codec: mSBC (0x05)
Logical Transport Type: 0x03
Codec supported over BR/EDR ACL
Codec supported over BR/EDR SCO and eSCO
Number of vendor codecs: 0
......
< HCI Command: Read Local Suppor.. (0x04|0x000e) plen 7
Codec: mSBC (0x05)
Logical Transport Type: 0x00
Direction: Input (Host to Controller) (0x00)
> HCI Event: Command Complete (0x0e) plen 12
Read Local Supported Codec Capabilities (0x04|0x000e) ncmd 1
Status: Success (0x00)
Number of codec capabilities: 1
Capabilities #0:
00 00 11 15 02 33
Signed-off-by: Kiran K <kiran.k@intel.com>
Signed-off-by: Chethan T N <chethan.tumkur.narayan@intel.com>
Signed-off-by: Srivatsa Ravishankar <ravishankar.srivatsa@intel.com>
---
* changes in v3:
No changes
* changes in v2:
add length check for event data before accessing
include/net/bluetooth/hci.h | 2 +
include/net/bluetooth/hci_core.h | 10 +++
net/bluetooth/hci_core.c | 4 +-
net/bluetooth/hci_event.c | 110 +++++++++++++++++++++++++++++++
4 files changed, 125 insertions(+), 1 deletion(-)
diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index e3f7771fe84f..34eb9f4b027f 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -1314,6 +1314,8 @@ struct hci_rp_read_local_pairing_opts {
__u8 max_key_size;
} __packed;
+#define HCI_OP_READ_LOCAL_CODECS_V2 0x100d
+
#define HCI_OP_READ_LOCAL_CODEC_CAPS 0x100e
struct hci_op_read_local_codec_caps {
__u8 codec_id[5];
diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h
index 8f5f390363f5..2c19b02a805d 100644
--- a/include/net/bluetooth/hci_core.h
+++ b/include/net/bluetooth/hci_core.h
@@ -1848,4 +1848,14 @@ void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
#define SCO_AIRMODE_CVSD 0x0000
#define SCO_AIRMODE_TRANSP 0x0003
+#define LOCAL_CODEC_ACL_MASK BIT(0)
+#define LOCAL_CODEC_SCO_MASK BIT(1)
+#define LOCAL_CODEC_CIS_MASK BIT(2)
+#define LOCAL_CODEC_BIS_MASK BIT(3)
+
+#define LOCAL_CODEC_ACL 0x00
+#define LOCAL_CODEC_SCO 0x01
+#define LOCAL_CODEC_CIS 0x02
+#define LOCAL_CODEC_BIS 0x03
+
#endif /* __HCI_CORE_H */
diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c
index 9419bbf55d90..fda7077d0d47 100644
--- a/net/bluetooth/hci_core.c
+++ b/net/bluetooth/hci_core.c
@@ -908,7 +908,9 @@ static int hci_init5_req(struct hci_request *req, unsigned long opt)
struct hci_dev *hdev = req->hdev;
/* Read local codec list if the HCI command is supported */
- if (hdev->commands[29] & 0x20)
+ if (hdev->commands[45] & 0x04)
+ hci_req_add(req, HCI_OP_READ_LOCAL_CODECS_V2, 0, NULL);
+ else if (hdev->commands[29] & 0x20)
hci_req_add(req, HCI_OP_READ_LOCAL_CODECS, 0, NULL);
return 0;
}
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index a4b905a76c1b..7ca3535f30de 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -951,6 +951,112 @@ static void hci_cc_read_local_codecs(struct hci_dev *hdev,
}
}
+static void hci_cc_read_local_codecs_v2(struct hci_dev *hdev,
+ struct sk_buff *skb)
+{
+ __u8 num_codecs, transport;
+ struct hci_op_read_local_codec_caps caps;
+
+ if (skb->len < sizeof(caps))
+ return;
+
+ bt_dev_dbg(hdev, "status 0x%2.2x", skb->data[0]);
+
+ if (skb->data[0])
+ return;
+
+ /* enumerate standard codecs */
+ skb_pull(skb, 1);
+
+ if (skb->len < 1)
+ return;
+
+ num_codecs = skb->data[0];
+
+ bt_dev_info(hdev, "Number of standard codecs: %u", num_codecs);
+
+ skb_pull(skb, 1);
+
+ if (skb->len < (num_codecs * 2))
+ return;
+
+ while (num_codecs--) {
+ caps.codec_id[0] = skb->data[0];
+ transport = skb->data[1];
+ caps.direction = 0x00;
+
+ if (transport & LOCAL_CODEC_ACL_MASK) {
+ caps.transport = LOCAL_CODEC_ACL;
+ hci_send_cmd(hdev, HCI_OP_READ_LOCAL_CODEC_CAPS, sizeof(caps),
+ &caps);
+ }
+
+ if (transport & LOCAL_CODEC_SCO_MASK) {
+ caps.transport = LOCAL_CODEC_SCO;
+ hci_send_cmd(hdev, HCI_OP_READ_LOCAL_CODEC_CAPS, sizeof(caps),
+ &caps);
+ }
+
+ if (transport & LOCAL_CODEC_BIS_MASK) {
+ caps.transport = LOCAL_CODEC_BIS;
+ hci_send_cmd(hdev, HCI_OP_READ_LOCAL_CODEC_CAPS, sizeof(caps),
+ &caps);
+ }
+
+ if (transport & LOCAL_CODEC_CIS_MASK) {
+ caps.transport = LOCAL_CODEC_CIS;
+ hci_send_cmd(hdev, HCI_OP_READ_LOCAL_CODEC_CAPS, sizeof(caps),
+ &caps);
+ }
+
+ skb_pull(skb, 2);
+ }
+
+ /* enumerate vendor specific codecs */
+ if (skb->len < 1)
+ return;
+
+ num_codecs = skb->data[0];
+
+ skb_pull(skb, 1);
+
+ if (skb->len < (num_codecs * 5))
+ return;
+
+ bt_dev_info(hdev, "Number of vendor specific codecs: %u", num_codecs);
+
+ while (num_codecs--) {
+ caps.codec_id[0] = 0xFF;
+ memcpy(&caps.codec_id[1], skb->data, 4);
+ transport = skb->data[4];
+ caps.direction = 0x00;
+
+ if (transport & LOCAL_CODEC_ACL_MASK) {
+ caps.transport = LOCAL_CODEC_ACL;
+ hci_send_cmd(hdev, HCI_OP_READ_LOCAL_CODEC_CAPS, sizeof(caps),
+ &caps);
+ }
+
+ if (transport & LOCAL_CODEC_SCO_MASK) {
+ caps.transport = LOCAL_CODEC_SCO;
+ hci_send_cmd(hdev, HCI_OP_READ_LOCAL_CODEC_CAPS, sizeof(caps),
+ &caps);
+ }
+
+ if (transport & LOCAL_CODEC_BIS) {
+ caps.transport = LOCAL_CODEC_BIS;
+ hci_send_cmd(hdev, HCI_OP_READ_LOCAL_CODEC_CAPS, sizeof(caps),
+ &caps);
+ }
+
+ if (transport & LOCAL_CODEC_CIS_MASK) {
+ caps.transport = LOCAL_CODEC_CIS;
+ hci_send_cmd(hdev, HCI_OP_READ_LOCAL_CODEC_CAPS, sizeof(caps),
+ &caps);
+ }
+ }
+}
+
static void hci_cc_read_clock(struct hci_dev *hdev, struct sk_buff *skb)
{
struct hci_rp_read_clock *rp = (void *) skb->data;
@@ -3505,6 +3611,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,
hci_cc_read_local_codecs(hdev, skb);
break;
+ case HCI_OP_READ_LOCAL_CODECS_V2:
+ hci_cc_read_local_codecs_v2(hdev, skb);
+ break;
+
case HCI_OP_READ_FLOW_CONTROL_MODE:
hci_cc_read_flow_control_mode(hdev, skb);
break;
--
2.17.1
next prev parent reply other threads:[~2021-04-22 14:11 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-04-22 14:14 [PATCH v3 1/3] Bluetooth: add support to enumerate codec capabilities Kiran K
2021-04-22 14:14 ` Kiran K [this message]
2021-04-23 8:00 ` [PATCH v3 2/3] Bluetooth: add support to enumerate local supports codecs v2 Marcel Holtmann
2021-04-22 14:14 ` [PATCH v3 3/3] Bluetooth: cache local supported codec capabilities Kiran K
2021-04-23 8:04 ` Marcel Holtmann
2021-04-28 13:53 ` K, Kiran
2021-04-28 14:49 ` Marcel Holtmann
2021-04-28 15:11 ` K, Kiran
2021-04-22 15:08 ` [v3,1/3] Bluetooth: add support to enumerate " bluez.test.bot
2021-04-23 7:58 ` [PATCH v3 1/3] " Marcel Holtmann
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=20210422141449.25155-2-kiran.k@intel.com \
--to=kiran.k@intel.com \
--cc=chethan.tumkur.narayan@intel.com \
--cc=linux-bluetooth@vger.kernel.org \
--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 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.