Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp1144434pxy; Fri, 23 Apr 2021 00:59:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxgXHoHXPaFVAe8x5+NCI1qXbNFxJjNU39kDVd0CraAZDrDh0g49U4gGvuhsVLqXREoZ7Ww X-Received: by 2002:a17:902:8693:b029:eb:53f:1336 with SMTP id g19-20020a1709028693b02900eb053f1336mr2540972plo.52.1619164788498; Fri, 23 Apr 2021 00:59:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619164788; cv=none; d=google.com; s=arc-20160816; b=Rr4gAqvosIZ3FV6K+JAvSGr7FhCuO7PZfgMI+L0xPbuWIQ4/gNHxuaqV+nnZ5wkT3+ 0eqFz+1wqTiABMWiJle0hYHh1le59TyyUvL+Q3Y/UU/xuEuZKGzkwZJ6XVKWhn+2kZ46 oerZ0NF2jOKM8uGyaOKcUMG58UhZPLMAh3o9tpRBgX6qeQfJEFCTyRTsX/5ofXVZNawC 7kgBS+0lwoF8Hv3ktWzhRTBe0IJ7SGLnNkICHm57a9TveAvkp2/4ojWdNJf3PuP8bhZs zr85VjDIxgjVK+haGl+7HqfNkN5F4kggfT+AEW4Sp2hSeE5MCEMG2ZetqabbpTNjkp8f WWkA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:references:message-id :content-transfer-encoding:cc:date:in-reply-to:from:subject :mime-version; bh=srgA04Tx+avV9A8ZbhKdeknQSXrkaohPdxYQmwvRML8=; b=nYzCOt+ay2NvvVpEsiuxtvumrUWo0FQXWyQp6j5eTEhxJe4HK5WKDKfkR8UAC2FbDT /xsojDymDuRP4vdrQb0Gw2AKERPBm7v4U2mY7w3lOZ1YgVaRyVdcMU0+6Z1JDxkhv1Ht QmpuNfgmpfw/w5BuJMvwpucW128CG8ZpD/V7ZGpt8kZWfvRJRaj6d1gtnrM0hSFBW9Gc NGf7Mlx4Y2huuH54m0Qq32gRU23Tej4iLqnmvRAzD/0zBVX+PjZdA3W1opY8lScinsUK SIffxno4Zx7tEIBfRIaEQfj6B/bpQOhr1Gk/W1e6JCbn56gjWYauB+SD7w4DWxoQR2A7 3XJQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id x1si6556998pll.94.2021.04.23.00.59.21; Fri, 23 Apr 2021 00:59:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229917AbhDWH6y convert rfc822-to-8bit (ORCPT + 99 others); Fri, 23 Apr 2021 03:58:54 -0400 Received: from coyote.holtmann.net ([212.227.132.17]:59564 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229456AbhDWH6y (ORCPT ); Fri, 23 Apr 2021 03:58:54 -0400 Received: from marcel-macbook.holtmann.net (p4fefc624.dip0.t-ipconnect.de [79.239.198.36]) by mail.holtmann.org (Postfix) with ESMTPSA id DAF04CECFB; Fri, 23 Apr 2021 10:06:03 +0200 (CEST) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.60.0.2.21\)) Subject: Re: [PATCH v3 1/3] Bluetooth: add support to enumerate codec capabilities From: Marcel Holtmann In-Reply-To: <20210422141449.25155-1-kiran.k@intel.com> Date: Fri, 23 Apr 2021 09:58:16 +0200 Cc: Bluetooth Kernel Mailing List , Chethan T N , Srivatsa Ravishankar Content-Transfer-Encoding: 8BIT Message-Id: <96E58F60-51DE-4D47-B0BC-3D988D16C401@holtmann.org> References: <20210422141449.25155-1-kiran.k@intel.com> To: Kiran K X-Mailer: Apple Mail (2.3654.60.0.2.21) Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Kiran, > 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 > Signed-off-by: Chethan T N > Signed-off-by: Srivatsa Ravishankar > --- > * changes in v3 > move codec enumeration into a new init function > * changes in v2 > add skb length check before accessing data > > include/net/bluetooth/hci.h | 7 ++++ > net/bluetooth/hci_core.c | 16 ++++++--- > net/bluetooth/hci_event.c | 68 +++++++++++++++++++++++++++++++++++++ > 3 files changed, 87 insertions(+), 4 deletions(-) > > 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_core.c b/net/bluetooth/hci_core.c > index fd12f1652bdf..9419bbf55d90 100644 > --- a/net/bluetooth/hci_core.c > +++ b/net/bluetooth/hci_core.c > @@ -838,10 +838,6 @@ static int hci_init4_req(struct hci_request *req, unsigned long opt) > if (hdev->commands[22] & 0x04) > hci_set_event_mask_page_2(req); > > - /* Read local codec list if the HCI command is supported */ > - if (hdev->commands[29] & 0x20) > - hci_req_add(req, HCI_OP_READ_LOCAL_CODECS, 0, NULL); > - that is not what I actually meant. The initial command to read the codec list can clearly stay in this init phase. Just the subsequent calls to read further details require an extra phase. > /* Read local pairing options if the HCI command is supported */ > if (hdev->commands[41] & 0x08) > hci_req_add(req, HCI_OP_READ_LOCAL_PAIRING_OPTS, 0, NULL); > @@ -907,6 +903,15 @@ static int hci_init4_req(struct hci_request *req, unsigned long opt) > return 0; > } > > +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) > + hci_req_add(req, HCI_OP_READ_LOCAL_CODECS, 0, NULL); So here instead you go through your list of codec ids and read its capabilities. > + return 0; > +} > static int __hci_init(struct hci_dev *hdev) > { > int err; > @@ -937,6 +942,9 @@ static int __hci_init(struct hci_dev *hdev) > if (err < 0) > return err; > > + err = __hci_req_sync(hdev, hci_init5_req, 0, HCI_INIT_TIMEOUT, NULL); > + if (err < 0) > + return err; > /* This function is only called when the controller is actually in > * configured state. When the controller is marked as unconfigured, > * this initialization procedure is not run. > diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c > index 5e99968939ce..a4b905a76c1b 100644 > --- a/net/bluetooth/hci_event.c > +++ b/net/bluetooth/hci_event.c > @@ -887,6 +887,70 @@ 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; > + 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_dbg(hdev, "Number of standard codecs: %u", num_codecs); > + > + skb_pull(skb, 1); > + > + if (skb->len < num_codecs) > + return; > + > + while (num_codecs--) { > + caps.codec_id[0] = skb->data[0]; > + caps.transport = 0x00; > + caps.direction = 0x00; > + > + hci_send_cmd(hdev, HCI_OP_READ_LOCAL_CODEC_CAPS, sizeof(caps), > + &caps); > + Here you just store the codec ids. > + skb_pull(skb, 1); > + } > + > + /* enumerate vendor specific codecs */ > + if (skb->len < 1) > + return; > + > + num_codecs = skb->data[0]; > + skb_pull(skb, 1); > + > + bt_dev_dbg(hdev, "Number of vendor specific codecs: %u", num_codecs); > + > + if (skb->len < (num_codecs * 4)) > + return; > + > + while (num_codecs--) { > + caps.codec_id[0] = 0xFF; > + memcpy(&caps.codec_id[1], skb->data, 4); > + caps.transport = 0x00; > + caps.direction = 0x00; > + > + hci_send_cmd(hdev, HCI_OP_READ_LOCAL_CODEC_CAPS, sizeof(caps), > + &caps); > + skb_pull(skb, 4); > + } > +} > + > 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 +3501,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; Regards Marcel