diff mbox series

[v1,1/3] Bluetooth: add support to enumerate codec capabilities

Message ID 20210409122405.29850-2-kiran.k@intel.com
State New
Headers show
Series [v1,1/3] Bluetooth: add support to enumerate codec capabilities | expand

Commit Message

Kiran K April 9, 2021, 12:24 p.m. UTC
add support to enumerate local supported codec capabilities

< 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>
---
 include/net/bluetooth/hci.h |  7 +++++
 net/bluetooth/hci_event.c   | 56 +++++++++++++++++++++++++++++++++++++
 2 files changed, 63 insertions(+)

Comments

bluez.test.bot@gmail.com April 9, 2021, 1:24 p.m. UTC | #1
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=464373

---Test result---

##############################
Test: CheckPatch - PASS


##############################
Test: CheckGitLint - PASS


##############################
Test: CheckBuildK - PASS


##############################
Test: CheckTestRunner: Setup - PASS


##############################
Test: CheckTestRunner: l2cap-tester - PASS
Total: 40, Passed: 34 (85.0%), Failed: 0, Not Run: 6

##############################
Test: CheckTestRunner: bnep-tester - PASS
Total: 1, Passed: 1 (100.0%), Failed: 0, Not Run: 0

##############################
Test: CheckTestRunner: mgmt-tester - FAIL
Total: 416, Passed: 396 (95.2%), Failed: 6, Not Run: 14

Failed Test Cases
Set connectable off (LE) - Success 2                 Failed       0.021 seconds
Set connectable off (LE) - Success 3                 Failed       0.020 seconds
Set connectable off (LE) - Success 4                 Failed       0.020 seconds
Add Advertising - Success 13 (ADV_SCAN_IND)          Failed       0.013 seconds
Add Advertising - Success 14 (ADV_NONCONN_IND)       Failed       0.013 seconds
Add Advertising - Success 17 (Connectable -> off)    Failed       0.014 seconds

##############################
Test: CheckTestRunner: rfcomm-tester - PASS
Total: 9, Passed: 9 (100.0%), Failed: 0, Not Run: 0

##############################
Test: CheckTestRunner: sco-tester - PASS
Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0

##############################
Test: CheckTestRunner: smp-tester - PASS
Total: 8, Passed: 8 (100.0%), Failed: 0, Not Run: 0

##############################
Test: CheckTestRunner: userchan-tester - PASS
Total: 3, Passed: 3 (100.0%), Failed: 0, Not Run: 0



---
Regards,
Linux Bluetooth
Kiran K April 12, 2021, 8:31 a.m. UTC | #2
Hi Luiz,

Thanks for the comments.  I will fix and send out an updated version.

Regards,
Kiran

> -----Original Message-----

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

> Sent: Friday, April 9, 2021 10:32 PM

> To: K, Kiran <kiran.k@intel.com>

> Cc: linux-bluetooth@vger.kernel.org; Srivatsa, Ravishankar

> <ravishankar.srivatsa@intel.com>; Tumkur Narayan, Chethan

> <chethan.tumkur.narayan@intel.com>; Von Dentz, Luiz

> <luiz.von.dentz@intel.com>

> Subject: Re: [PATCH v1 1/3] Bluetooth: add support to enumerate codec

> capabilities

> 

> Hi Kiran,

> 

> On Fri, Apr 9, 2021 at 5:21 AM Kiran K <kiran.k@intel.com> wrote:

> >

> > add support to enumerate local supported codec capabilities

> >

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

> > ---

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

> >  net/bluetooth/hci_event.c   | 56

> +++++++++++++++++++++++++++++++++++++

> >  2 files changed, 63 insertions(+)

> >

> > diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h

> > index ea4ae551c426..e3f7771fe84f 100644

> > --- a/include/net/bluetooth/hci.h

> > +++ b/include/net/bluetooth/hci.h

> > @@ -1314,6 +1314,13 @@ struct hci_rp_read_local_pairing_opts {

> >         __u8     max_key_size;

> >  } __packed;

> >

> > +#define HCI_OP_READ_LOCAL_CODEC_CAPS   0x100e

> > +struct hci_op_read_local_codec_caps {

> > +       __u8    codec_id[5];

> > +       __u8    transport;

> > +       __u8    direction;

> > +} __packed;

> > +

> >  #define HCI_OP_READ_PAGE_SCAN_ACTIVITY 0x0c1b  struct

> > hci_rp_read_page_scan_activity {

> >         __u8     status;

> > diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c

> > index 016b2999f219..ceed5a5d332b 100644

> > --- a/net/bluetooth/hci_event.c

> > +++ b/net/bluetooth/hci_event.c

> > @@ -887,6 +887,58 @@ static void hci_cc_read_data_block_size(struct

> hci_dev *hdev,

> >                hdev->block_cnt, hdev->block_len);  }

> >

> > +static void hci_cc_read_local_codecs(struct hci_dev *hdev,

> > +                                    struct sk_buff *skb) {

> > +       __u8 num_codecs;

> > +       __u8 *ptr;

> > +       struct hci_op_read_local_codec_caps caps;

> > +

> > +       bt_dev_dbg(hdev, "status 0x%2.2x", skb->data[0]);

> > +

> > +       if (skb->data[0])

> > +               return;

> > +

> > +       /* enumerate standard codecs */

> > +       skb_pull(skb, 1);

> 

> After each skb_pull check the expected length against skb->len.

> 

> > +       num_codecs = skb->data[0];

> > +

> > +       bt_dev_dbg(hdev, "Number of standard codecs: %u", num_codecs);

> > +

> > +       skb_pull(skb, 1);

> 

> Ditto.

> 

> > +       ptr = (__u8 *)skb->data;

> > +

> > +       skb_pull(skb, num_codecs);

> > +

> > +       while (num_codecs--) {

> > +               caps.codec_id[0] = *ptr++;

> 

> Lets just use skb_pull to advance on the codecs ids, that way we can properly

> check the remaining length with use of skb->len.

> 

> > +               caps.transport = 0x00;

> > +               caps.direction = 0x00;

> > +

> > +               hci_send_cmd(hdev, HCI_OP_READ_LOCAL_CODEC_CAPS,

> sizeof(caps),

> > +                            &caps);

> > +       }

> > +

> > +       /* enumerate vendor specific codecs */

> > +       num_codecs = skb->data[0];

> > +       skb_pull(skb, 1);

> > +

> > +       bt_dev_dbg(hdev, "Number of vendor specific codecs: %u",

> > + num_codecs);

> > +

> > +       ptr = (__u8 *)skb->data;

> > +

> > +       while (num_codecs--) {

> > +               caps.codec_id[0] = 0xFF;

> > +               memcpy(&caps.codec_id[1], ptr, 4);

> > +               ptr += 4;

> > +               caps.transport = 0x00;

> > +               caps.direction = 0x00;

> > +

> > +               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; @@ -3437,6

> > +3489,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev,

> struct sk_buff *skb,

> >                 hci_cc_read_data_block_size(hdev, skb);

> >                 break;

> >

> > +       case HCI_OP_READ_LOCAL_CODECS:

> > +               hci_cc_read_local_codecs(hdev, skb);

> > +               break;

> > +

> >         case HCI_OP_READ_FLOW_CONTROL_MODE:

> >                 hci_cc_read_flow_control_mode(hdev, skb);

> >                 break;

> > --

> > 2.17.1

> >

> 

> 

> --

> Luiz Augusto von Dentz
diff mbox series

Patch

diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h
index ea4ae551c426..e3f7771fe84f 100644
--- a/include/net/bluetooth/hci.h
+++ b/include/net/bluetooth/hci.h
@@ -1314,6 +1314,13 @@  struct hci_rp_read_local_pairing_opts {
 	__u8     max_key_size;
 } __packed;
 
+#define HCI_OP_READ_LOCAL_CODEC_CAPS	0x100e
+struct hci_op_read_local_codec_caps {
+	__u8	codec_id[5];
+	__u8	transport;
+	__u8	direction;
+} __packed;
+
 #define HCI_OP_READ_PAGE_SCAN_ACTIVITY	0x0c1b
 struct hci_rp_read_page_scan_activity {
 	__u8     status;
diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c
index 016b2999f219..ceed5a5d332b 100644
--- a/net/bluetooth/hci_event.c
+++ b/net/bluetooth/hci_event.c
@@ -887,6 +887,58 @@  static void hci_cc_read_data_block_size(struct hci_dev *hdev,
 	       hdev->block_cnt, hdev->block_len);
 }
 
+static void hci_cc_read_local_codecs(struct hci_dev *hdev,
+				     struct sk_buff *skb)
+{
+	__u8 num_codecs;
+	__u8 *ptr;
+	struct hci_op_read_local_codec_caps caps;
+
+	bt_dev_dbg(hdev, "status 0x%2.2x", skb->data[0]);
+
+	if (skb->data[0])
+		return;
+
+	/* enumerate standard codecs */
+	skb_pull(skb, 1);
+	num_codecs = skb->data[0];
+
+	bt_dev_dbg(hdev, "Number of standard codecs: %u", num_codecs);
+
+	skb_pull(skb, 1);
+	ptr = (__u8 *)skb->data;
+
+	skb_pull(skb, num_codecs);
+
+	while (num_codecs--) {
+		caps.codec_id[0] = *ptr++;
+		caps.transport = 0x00;
+		caps.direction = 0x00;
+
+		hci_send_cmd(hdev, HCI_OP_READ_LOCAL_CODEC_CAPS, sizeof(caps),
+			     &caps);
+	}
+
+	/* enumerate vendor specific codecs */
+	num_codecs = skb->data[0];
+	skb_pull(skb, 1);
+
+	bt_dev_dbg(hdev, "Number of vendor specific codecs: %u", num_codecs);
+
+	ptr = (__u8 *)skb->data;
+
+	while (num_codecs--) {
+		caps.codec_id[0] = 0xFF;
+		memcpy(&caps.codec_id[1], ptr, 4);
+		ptr += 4;
+		caps.transport = 0x00;
+		caps.direction = 0x00;
+
+		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;
@@ -3437,6 +3489,10 @@  static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb,
 		hci_cc_read_data_block_size(hdev, skb);
 		break;
 
+	case HCI_OP_READ_LOCAL_CODECS:
+		hci_cc_read_local_codecs(hdev, skb);
+		break;
+
 	case HCI_OP_READ_FLOW_CONTROL_MODE:
 		hci_cc_read_flow_control_mode(hdev, skb);
 		break;