Received: by 2002:a05:6a10:a841:0:0:0:0 with SMTP id d1csp474593pxy; Wed, 28 Apr 2021 07:57:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwqkDLYi71qniYn/+mag2TrQBlVXNfesdaNmkvr4ZJ5JGzyruubAWDUfiz8dQ0wLL/H3Io1 X-Received: by 2002:a05:6402:154:: with SMTP id s20mr12217966edu.90.1619621825591; Wed, 28 Apr 2021 07:57:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1619621825; cv=none; d=google.com; s=arc-20160816; b=PQWpdNaACP9/ZK3c6v+iP5BJcCoT2O8B99v7qYhxHhKGPWJnAmxc5Hc5ujAQRSxdrS P7Z0nd6hpcXKwgywzeBdHl0x1P4qbSG38rmXKRSoV3IUBq6ct+dzxq1dRjJ0MXpTJVpS VfMG5rMgIW+ksHf0vkr7BkKwbs/z/Bl3LB8yW46XyGNuQ24MG2jvL/pF2c8ug5gMtUSD u8OohiUgmaa/x/zHpwDgYqvnnumv4xHEHtq6++rM828Ojpzb09kGXUq/a2poPPLUpoTe rzYI7gkdLaMQ+cZbWtrKtHqjs0QJ+d0SQxFG4m1krHv1U9Vhg+hhd0sjhcZsqLPO82yw rUXw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from:ironport-sdr:ironport-sdr; bh=S6DAwlOVfWsl36MleYT2RGDn59Ttn8bebaq75D4AF1I=; b=j9rTlNN3o2AUz4wh2Z4E2a7OhgcdYjVxNu5fRaMMhA4fUstSTk03vyjxam1+PwPl5v 3dNcREspUig4ARlvpKoFSXYKQyB7glVfc8VO4ym62nhDlsCKsB0NLyuIo6MUIU7i2Yfu KinWPBo/IiUG+Df7D4o8Y4Et2fzfamngfMtR6AssPYXw5AlLP3cOy5HsoxCre17g/Bk6 a5PXXwynqfaMt+9RWZKzWgbfNraf65cDaRIEbLvdctRPQI8vILQmWhvM0ZsUL4TutDFi El9Q3UQrqJCVypD7bM6syEmEtHxt4rwhWkKJnsQKR46X1AZ/Jue+PO2Fq4UD1oJYd+uG KcuQ== 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id r1si5694487edp.303.2021.04.28.07.56.26; Wed, 28 Apr 2021 07:57:05 -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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239091AbhD1N6a (ORCPT + 99 others); Wed, 28 Apr 2021 09:58:30 -0400 Received: from mga01.intel.com ([192.55.52.88]:27560 "EHLO mga01.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S239283AbhD1N6V (ORCPT ); Wed, 28 Apr 2021 09:58:21 -0400 IronPort-SDR: 0wGM5KkgY7pL3PxiHG+oH/P7bweWcbDz8cOqmFrvEQYrzKv0k2B+DnOpnJdBifJfIchNtsuxTb obDdG1RtwGcw== X-IronPort-AV: E=McAfee;i="6200,9189,9968"; a="217462967" X-IronPort-AV: E=Sophos;i="5.82,258,1613462400"; d="scan'208";a="217462967" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga101.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Apr 2021 06:57:35 -0700 IronPort-SDR: Lt88wcvrDQn8s/izBWh+jf3JHArSQbT08eooYHLHMZnS8kKzDOd2UUrFW2s7ZR7FfC6Kd3hu/W e1ab9K4zbFuQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.82,258,1613462400"; d="scan'208";a="423549405" Received: from intel-lenovo-legion-y540-15irh-pg0.iind.intel.com ([10.224.186.95]) by fmsmga008.fm.intel.com with ESMTP; 28 Apr 2021 06:57:33 -0700 From: Kiran K To: linux-bluetooth@vger.kernel.org Cc: Kiran K , Chethan T N , Srivatsa Ravishankar Subject: [PATCH v4 2/2] Bluetooth: Add support for Read Local Supported Codecs V2 Date: Wed, 28 Apr 2021 19:31:32 +0530 Message-Id: <20210428140132.30316-2-kiran.k@intel.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210428140132.30316-1-kiran.k@intel.com> References: <20210428140132.30316-1-kiran.k@intel.com> Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Use V2 version of read local supported command is controller supports 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 Signed-off-by: Chethan T N Signed-off-by: Srivatsa Ravishankar --- * changes in v4: converts codec read capabilities calls from async to sync * changes in v3: No changes * changes in v2: add length check for event data before accessing include/net/bluetooth/hci.h | 2 + net/bluetooth/hci_core.c | 97 ++++++++++++++++++++++++++++++++++++- 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index 2f7f8c6f7d63..38a6eeb5e03a 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/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 7201967b6e9c..039747b5617a 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1003,10 +1003,105 @@ static void hci_read_supported_codecs(struct hci_dev *hdev) kfree_skb(skb); } +static void hci_read_supported_codecs_v2(struct hci_dev *hdev) +{ + struct sk_buff *skb; + __u8 num_codecs; + + skb = __hci_cmd_sync(hdev, HCI_OP_READ_LOCAL_CODECS_V2, 0, NULL, + HCI_CMD_TIMEOUT); + + if (IS_ERR(skb)) { + bt_dev_err(hdev, "Failed to read local supported codecs v2 (%ld)", + PTR_ERR(skb)); + return; + } + + if (skb->len < 1 || skb->data[0]) + goto error; + + skb_pull(skb, 1); + + if (skb->len < 1) + goto error; + + /* enumerate standard codecs */ + num_codecs = skb->data[0]; + + skb_pull(skb, 1); + + if (num_codecs && skb->len < (num_codecs * 2)) + goto error; + + while (num_codecs--) { + __u8 transport; + + transport = skb->data[1]; + + if (transport & LOCAL_CODEC_ACL_MASK) + hci_read_codec_capabilities(hdev, skb->data, + LOCAL_CODEC_ACL, false); + + if (transport & LOCAL_CODEC_SCO_MASK) + hci_read_codec_capabilities(hdev, skb->data, + LOCAL_CODEC_SCO, false); + + if (transport & LOCAL_CODEC_BIS_MASK) + hci_read_codec_capabilities(hdev, skb->data, + LOCAL_CODEC_BIS, false); + + if (transport & LOCAL_CODEC_CIS_MASK) + hci_read_codec_capabilities(hdev, skb->data, + LOCAL_CODEC_CIS, false); + + skb_pull(skb, 2); + } + + /* enumerate vendor specific codecs */ + if (skb->len < 1) + goto error; + + num_codecs = skb->data[0]; + + skb_pull(skb, 1); + + if (num_codecs && skb->len < (num_codecs * 5)) + goto error; + + while (num_codecs--) { + __u8 transport; + + transport = skb->data[4]; + + if (transport & LOCAL_CODEC_ACL_MASK) + hci_read_codec_capabilities(hdev, skb->data, + LOCAL_CODEC_ACL, true); + + if (transport & LOCAL_CODEC_SCO_MASK) + hci_read_codec_capabilities(hdev, skb->data, + LOCAL_CODEC_SCO, true); + + if (transport & LOCAL_CODEC_BIS_MASK) + hci_read_codec_capabilities(hdev, skb->data, + LOCAL_CODEC_BIS, true); + + if (transport & LOCAL_CODEC_CIS_MASK) + hci_read_codec_capabilities(hdev, skb->data, + LOCAL_CODEC_CIS, true); + + skb_pull(skb, 5); + } + +error: + kfree_skb(skb); +} + static void hci_init5_req(struct hci_dev *hdev) { /* Read local codec list if the HCI command is supported */ - if (hdev->commands[29] & 0x20) + if (hdev->commands[45] & 0x04) + hci_read_supported_codecs_v2(hdev); + else if (hdev->commands[29] & 0x20) hci_read_supported_codecs(hdev); } -- 2.17.1