Received: by 2002:a05:6a10:17d3:0:0:0:0 with SMTP id hz19csp3009329pxb; Tue, 13 Apr 2021 16:18:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz313g+hBX5WBttzuqlaWSfMcZz+p8Lg5lNjzpax3oLmpCliN/PXtsm96KWFkcnbmPpALOB X-Received: by 2002:a17:906:3549:: with SMTP id s9mr11987127eja.327.1618355882580; Tue, 13 Apr 2021 16:18:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1618355882; cv=none; d=google.com; s=arc-20160816; b=gCiNzIycV4lBK6ic84z4C5IjZQiKfCBbda27NYafY/owEl+fEL6MUpx5tYPZyOuqXE q6pyob2eTysbnVlyhTix5SmgIsb/WBDfhHnz9wNToCzTvuhSeuht1sH6OAQcUKL2/jFj JUEvOfpF7MeEkvAnfjbKzYgQjp9eb4ERdb44nX8IbCb21DuBAcrSf7+qt7NHzMtilGgT 7rvxHR+7J0OqxwgIjRdBuT2+oL79WzRVlkfvSINDkN9WOTzC2L+1OfSJQoD7MgHCBoZc AEz30WpjztAOXq1ZDylB5iB0BOR34PKHJcjomkoWIEeVVLQMlS7wa/cdFFD2ZCz2ipG4 7wAQ== 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=L2qZAmrdT29U8jJweaiy88l5NReMGqYT0qOKGvMkZ80=; b=LHxKIxmgp7g7tMcX0DK+EMsNB9fLrLb4EI3QlNpmtibBBZHjzsOi5fvsY5lmj2CSBe yENng3DAgvVFgmucmzVRo7QezCiLpjCVCxRvde0Rahl8wCRlwpL1QLbG+VH6DDHXxYL/ E5jSHdbBoSnikLAQQRtbMP9IkeeWO2lqUh3/9tCDYAeDzoAVEd6Gc9IhNs3yh6clIaPI JXUp8fqZE8dwyj0Zfn64RX41Hc646IzpJmCQplX68FVPRMp6zyk/0Yd6IqmfMgjobiNS Hg/ARx5fXEuginybgSooTmNRurtnz598szHE8jCeis+J3zt2SXrNVeK68ycl49ijzRcQ aEjA== 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 f4si11350054eja.638.2021.04.13.16.17.39; Tue, 13 Apr 2021 16:18:02 -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 S232950AbhDMTO6 convert rfc822-to-8bit (ORCPT + 99 others); Tue, 13 Apr 2021 15:14:58 -0400 Received: from coyote.holtmann.net ([212.227.132.17]:49980 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231165AbhDMTO5 (ORCPT ); Tue, 13 Apr 2021 15:14:57 -0400 Received: from marcel-macbook.holtmann.net (p5b3d235a.dip0.t-ipconnect.de [91.61.35.90]) by mail.holtmann.org (Postfix) with ESMTPSA id 7E41ACECCD; Tue, 13 Apr 2021 21:22:18 +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 v2 1/3] Bluetooth: add support to enumerate codec capabilities From: Marcel Holtmann In-Reply-To: <20210412083538.18600-1-kiran.k@intel.com> Date: Tue, 13 Apr 2021 21:14:33 +0200 Cc: "open list:BLUETOOTH DRIVERS" , "Srivatsa, Ravishankar" , Chethan T N , Luiz Augusto von Dentz Content-Transfer-Encoding: 8BIT Message-Id: <3434AC21-8C36-435D-9D0F-3597FE434D54@holtmann.org> References: <20210412083538.18600-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 v2 > add skb->len check before accessing event data > > include/net/bluetooth/hci.h | 7 ++++ > net/bluetooth/hci_event.c | 68 +++++++++++++++++++++++++++++++++++++ > 2 files changed, 75 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 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); > + > + 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); > + } instead of sending hci_send_cmd here, I rather do this in a separate init stage. Since you want to cache the codec values anyway, start doing it now. Regards Marcel