Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp1533954pxf; Fri, 9 Apr 2021 10:42:02 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKhDYwEv0HVm9jPhoc7Cvs+Wt4rOUKNcMxbHL54SU15K80pY3O57zrddv/SfqrOqp+mgpG X-Received: by 2002:a17:90a:cb10:: with SMTP id z16mr2346620pjt.106.1617990122651; Fri, 09 Apr 2021 10:42:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1617990122; cv=none; d=google.com; s=arc-20160816; b=l3w/jVwTDh1LkWXaley99dDPsn/KQLifu/9lJYT2i4pwtM89HjJiZ0LTe2GjI0+gBz 4lAKHXanibWXoduFlMnyAIOCadFwX29NQyFvTLqfDdTU1ui6P+7BfhWLq3ZAjcr766IN FlIDWDgU70RM5UVpto8/RuqU20VPE832MsUFHvJD2bhYs/5otQWHmXfHoHLZv6yt688q dI3F8NK+8+L97/cAls8YVqt9uN/oBt9TluAzMjjxG/11ChX+zPPnjh83zMYg2MRjKlEJ XfOE7WT4mkSAByGf3oTl+9niDeENbs8g/ICc1cYARxWPTw5BHkBkVRhkxNoussLCH6t1 p4pg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=ThZUPnON2QavqY+ACh0OHXoH/B18LX5W4PgoLlXpIKw=; b=x2wVy+CltC7a1Xydx4gSttbZIxykS4xnk33OMt2DwBK0T120bTs1PcZEWQh30PYVD+ 1kmCECgs/+kLb/+Q/aNjwds/rZ0yoxhle95g1VKV2zLNwl8IhDSTKcdmDeVLk3lkWgaP s0T1pAhagqHtkNK8tKknj87FRo+nyzKEVSku4R+YdvwMnJzgCtktwqlL6/p8jEEe6KlS n5DddWbZHyAnI5XgOh6+MnOuzCLz5/uXbFwymSrXnPy3A75e4x0Ilv7vVkS8aLqMe6tQ ud6s2G+jMS/1trIei4L1uVx7cpe1SBAyYCOaQ5S+dGOzEhOjfK4+He9BqsgaNSzLWJpp nyNQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=f6Oh6qpP; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id n4si3499393plk.422.2021.04.09.10.41.47; Fri, 09 Apr 2021 10:42: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; dkim=pass header.i=@gmail.com header.s=20161025 header.b=f6Oh6qpP; 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=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234316AbhDIRkm (ORCPT + 99 others); Fri, 9 Apr 2021 13:40:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42156 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234049AbhDIRkm (ORCPT ); Fri, 9 Apr 2021 13:40:42 -0400 Received: from mail-ot1-x330.google.com (mail-ot1-x330.google.com [IPv6:2607:f8b0:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2BC9AC061761 for ; Fri, 9 Apr 2021 10:40:29 -0700 (PDT) Received: by mail-ot1-x330.google.com with SMTP id l12-20020a9d6a8c0000b0290238e0f9f0d8so6424796otq.8 for ; Fri, 09 Apr 2021 10:40:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=ThZUPnON2QavqY+ACh0OHXoH/B18LX5W4PgoLlXpIKw=; b=f6Oh6qpPAxl0TRVBYAo/UYespgUDSjlWxXKV9ZDhVR4CYYI3ZSsQBO6iwGJhW6dgTL Z85BqSAbGCLtpJINV0V2PLU8uEZnXm1hkn6fSmljZF08wC3WDvg+vf7LAciMlJUQc/nd vTYfNRVOi5VEy33BWyvgs4bdp4HiinJyC6uypYGKVSrY3nSnfCDB0qLSoctw/2LuiCcX o+rGaSbmsiyyFjtUYP7v8JVdTtD3RwM1BXnF7dnSEy65Jeeu8c5TusDemYxj3hylYuYL P0k2aQ0sTIqpvDlioW6vdnoEZGKW1nKb9rEZ3FICCDNUQwENXyoOJB1Ej1rMNZ5bzAUr 8EEQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=ThZUPnON2QavqY+ACh0OHXoH/B18LX5W4PgoLlXpIKw=; b=STexdgd42PbTAxz9Y5BEPOJ+MI6fk0pe9OH+jbmuJBMEqRIUckiMlLVqEkZTdRZ9BI PwnnbF+/MjkbvzLa9N3yx0/+ebaRmAuoI1CH9rR1o3XC8AoWaWYGnmzWy05wZLG8ChaZ u7ekswEyPncxcp6OKddqsRnABevR4K9VzJgQYGKz2OAxryHwzi/oxP7+cy+tbzlRm1KN ypXS8l46ackHIvv5eYE/Wn+wapTWZUKDYiA3egKeQIUknddtT0Ao/aiscR4Nq+qZvBve c2+8QZbWVWM2e09032OoPBan1rB8he2JhrQuM73xprnH86XmJWAa/hg8lvwayJSGe8BB AlBQ== X-Gm-Message-State: AOAM531livZMqJ1WTOILGQhTGD9X+rnHi1lSDyf6azVfmgdfRePoa3F/ tmiliIHyFJncj0NevbYjF2WSfjDut2JzyB/vAhFUuICmKLdJNQ== X-Received: by 2002:a05:6830:619:: with SMTP id w25mr13183516oti.371.1617990028259; Fri, 09 Apr 2021 10:40:28 -0700 (PDT) MIME-Version: 1.0 References: <20210409122405.29850-1-kiran.k@intel.com> <20210409122405.29850-4-kiran.k@intel.com> In-Reply-To: <20210409122405.29850-4-kiran.k@intel.com> From: Luiz Augusto von Dentz Date: Fri, 9 Apr 2021 10:40:17 -0700 Message-ID: Subject: Re: [PATCH v1 3/3] Bluetooth: cache local supported codec capabilities To: Kiran K Cc: "linux-bluetooth@vger.kernel.org" , "Srivatsa, Ravishankar" , Chethan T N , Luiz Augusto Von Dentz Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Hi Kiran, On Fri, Apr 9, 2021 at 5:21 AM Kiran K wrote: > > Cache the codec information in the driver and this data can > be exposed to user space audio modules via getsockopt > > Signed-off-by: Kiran K > Signed-off-by: Chethan T N > Signed-off-by: Srivatsa Ravishankar > --- > include/net/bluetooth/hci.h | 11 +++++++++++ > include/net/bluetooth/hci_core.h | 13 +++++++++++++ > net/bluetooth/hci_core.c | 31 +++++++++++++++++++++++++++++++ > net/bluetooth/hci_event.c | 31 +++++++++++++++++++++++++++++++ > 4 files changed, 86 insertions(+) > > diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h > index 34eb9f4b027f..6b4344639ff7 100644 > --- a/include/net/bluetooth/hci.h > +++ b/include/net/bluetooth/hci.h > @@ -1323,6 +1323,17 @@ struct hci_op_read_local_codec_caps { > __u8 direction; > } __packed; > > +struct hci_codec_caps { > + __u8 len; > + __u8 caps[]; > +} __packed; > + > +struct hci_rp_read_local_codec_caps { > + __u8 status; > + __u8 num_caps; > + struct hci_codec_caps caps[]; > +} __packed; > + > #define HCI_OP_READ_PAGE_SCAN_ACTIVITY 0x0c1b > struct hci_rp_read_page_scan_activity { > __u8 status; > diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h > index fa0c68fd3306..974372644990 100644 > --- a/include/net/bluetooth/hci_core.h > +++ b/include/net/bluetooth/hci_core.h > @@ -131,6 +131,14 @@ struct bdaddr_list { > u8 bdaddr_type; > }; > > +struct codec_list { > + struct list_head list; > + u8 transport; > + u8 codec_id[5]; > + u8 num_caps; > + struct hci_codec_caps caps[]; > +}; > + > struct bdaddr_list_with_irk { > struct list_head list; > bdaddr_t bdaddr; > @@ -534,6 +542,7 @@ struct hci_dev { > struct list_head pend_le_conns; > struct list_head pend_le_reports; > struct list_head blocked_keys; > + struct list_head local_codecs; > > struct hci_dev_stats stat; > > @@ -1843,6 +1852,10 @@ void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand, > > void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr, > u8 *bdaddr_type); > +int hci_codec_list_add(struct list_head *list, struct hci_rp_read_local_codec_caps *rp, > + __u32 len, > + struct hci_op_read_local_codec_caps *sent); > +void hci_codec_list_clear(struct list_head *codec_list); > > #define SCO_AIRMODE_MASK 0x0003 > #define SCO_AIRMODE_CVSD 0x0000 > diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c > index 230aeedd6d00..578f417d1904 100644 > --- a/net/bluetooth/hci_core.c > +++ b/net/bluetooth/hci_core.c > @@ -3561,6 +3561,35 @@ void hci_conn_params_clear_disabled(struct hci_dev *hdev) > BT_DBG("All LE disabled connection parameters were removed"); > } > > +int hci_codec_list_add(struct list_head *list, struct hci_rp_read_local_codec_caps *rp, > + __u32 len, > + struct hci_op_read_local_codec_caps *sent) > +{ > + struct codec_list *entry; > + > + entry = kzalloc(sizeof(*entry) + len, GFP_KERNEL); > + if (!entry) > + return -ENOMEM; > + > + memcpy(entry->codec_id, sent->codec_id, 5); > + entry->transport = sent->transport; > + entry->num_caps = rp->num_caps; > + if (rp->num_caps) > + memcpy(entry->caps, rp->caps, len); > + list_add(&entry->list, list); > + > + return 0; > +} > + > +void hci_codec_list_clear(struct list_head *codec_list) > +{ > + struct codec_list *c, *n; > + > + list_for_each_entry_safe(c, n, codec_list, list) { > + list_del(&c->list); > + kfree(c); > + } > +} > /* This function requires the caller holds hdev->lock */ > static void hci_conn_params_clear_all(struct hci_dev *hdev) > { > @@ -3820,6 +3849,7 @@ struct hci_dev *hci_alloc_dev(void) > INIT_LIST_HEAD(&hdev->conn_hash.list); > INIT_LIST_HEAD(&hdev->adv_instances); > INIT_LIST_HEAD(&hdev->blocked_keys); > + INIT_LIST_HEAD(&hdev->local_codecs); > > INIT_WORK(&hdev->rx_work, hci_rx_work); > INIT_WORK(&hdev->cmd_work, hci_cmd_work); > @@ -4038,6 +4068,7 @@ void hci_unregister_dev(struct hci_dev *hdev) > hci_conn_params_clear_all(hdev); > hci_discovery_filter_clear(hdev); > hci_blocked_keys_clear(hdev); > + hci_codec_list_clear(&hdev->local_codecs); > hci_dev_unlock(hdev); > > hci_dev_put(hdev); > diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c > index a16723c89dc6..f57ee199f0f3 100644 > --- a/net/bluetooth/hci_event.c > +++ b/net/bluetooth/hci_event.c > @@ -1033,6 +1033,33 @@ static void hci_cc_read_local_codecs_v2(struct hci_dev *hdev, > } > } > > +static void hci_cc_read_local_codec_caps(struct hci_dev *hdev, > + struct sk_buff *skb) > +{ > + struct hci_op_read_local_codec_caps *sent; > + struct hci_rp_read_local_codec_caps *rp; > + > + rp = (void *)skb->data; We should attempt to always use construct like the following when checking the remaining/received bytes of packet: if (skb->len < sizeof(*rp)) bt_dev_err skb_pull(skb, sizeof(*rp)); Or perhaps introduce something like: void *bt_skb_pull_mem(skb, len) { void *data = skb->data; if (skb->len < len) { return NULL; } skb_pull(skb, len); return data; } That way we can use it like: rp = bt_skb_pull_mem(skb, sizeof(*rp)); if (!rp) bt_dev_err > + > + bt_dev_dbg(hdev, "status 0x%2.2x", rp->status); > + > + if (rp->status) > + return; > + > + sent = hci_sent_cmd_data(hdev, HCI_OP_READ_LOCAL_CODEC_CAPS); > + > + if (!sent) > + return; > + > + hci_dev_lock(hdev); > + > + bt_dev_info(hdev, "Adding Codec. No of caps: %u", rp->num_caps); > + hci_codec_list_add(&hdev->local_codecs, rp, skb->len - 2, sent); > + > + hci_dev_unlock(hdev); > +} > + > static void hci_cc_read_clock(struct hci_dev *hdev, struct sk_buff *skb) > { > struct hci_rp_read_clock *rp = (void *) skb->data; > @@ -3591,6 +3618,10 @@ static void hci_cmd_complete_evt(struct hci_dev *hdev, struct sk_buff *skb, > hci_cc_read_local_codecs_v2(hdev, skb); > break; > > + case HCI_OP_READ_LOCAL_CODEC_CAPS: > + hci_cc_read_local_codec_caps(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