Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp3811253imw; Mon, 11 Jul 2022 16:46:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uCtGb+vxdhfo5QuRcFwi9sa2ZQd0xFrFHNSJrb4/LtN/qPpiSrA8DxkjmboxNvfR6gQJ4A X-Received: by 2002:a17:906:dc8c:b0:726:e51b:d5c3 with SMTP id cs12-20020a170906dc8c00b00726e51bd5c3mr20373909ejc.369.1657583206126; Mon, 11 Jul 2022 16:46:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657583206; cv=none; d=google.com; s=arc-20160816; b=wKFhlFllIDSyJruT0CPcOfqPkeSriFWTdXExZGiVRWvP9O1R9sQVTLj1mUxrtIUwKa 8s0yXxWUJT2xvR1SSJdyN3manqnaZ1ViesrcyUwxat6oFc/KX/dfOZTUyf3slgHiPjIT wbJm9f2LUx+Q8ewijPba75nAjAOGmbC4G8bEUWrbqQjOIeLzylsAkMhoAks42Dc7cxJj 1PLBQHRVHJj72baE/GoHO+f6JHYf35H9U+IZNE9tsOHny5ueVdHKt60LYyKLVZ5PD1mD LvdGK6LfxO2IKQnUdIj1UxIfOs6e1KL0ABtGNXO02BRdmfpyJ8afNA3onQ2CRn87bBFr bNiA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:to:from:dkim-signature; bh=9oZJUV3RpGzSZCa65z3Ze1dKnt/BilmUQkfi4nYEz/8=; b=PNfI18Tb5Vclinj9wZHHparXaYqvviX8GP12lhEHa7vAjOsaLXULh2wp9MNajCZmT9 ksm11caLMV24ot+cW9Vy+Lri062Vzwk3w8y5ezllOn357AtxBFr0sS/k3MtaGqRx7qZW PARBDhr6w31MhKYPYAi1923QFzHTntz3Q59Z1Mt+r72nYV5w4gGV2TwnPHWpBm9C9uV1 ybeqa07AsQUvP9L4L0YR2++PAsNq/mvliAJKLTBM1Ic63rDoXmlOHrIm6m0wgDd8awjA PESucanxVSqjIcQsGt2pL3i6g7oKzgTh+UVg4iu+9U0GkW3OcqUzhn1hsb6SVHi/r85r kV3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=b4EKrUDK; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 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 out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e15-20020a50ec8f000000b0043770f4e810si10631291edr.217.2022.07.11.16.46.06; Mon, 11 Jul 2022 16:46:46 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=b4EKrUDK; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 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 S229839AbiGKXfl (ORCPT + 99 others); Mon, 11 Jul 2022 19:35:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52908 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229743AbiGKXfj (ORCPT ); Mon, 11 Jul 2022 19:35:39 -0400 Received: from mail-pf1-x433.google.com (mail-pf1-x433.google.com [IPv6:2607:f8b0:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ED25F2B18A for ; Mon, 11 Jul 2022 16:35:38 -0700 (PDT) Received: by mail-pf1-x433.google.com with SMTP id b9so6032572pfp.10 for ; Mon, 11 Jul 2022 16:35:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=9oZJUV3RpGzSZCa65z3Ze1dKnt/BilmUQkfi4nYEz/8=; b=b4EKrUDKTXFF82hn5jD70J/0jQHmsTaWU9AzqWKD/po53+oPnj/pWPfOoAcdPR+BwC d/EbxjMyaddggmCFEZFo3BYkoNXSphrep2m4K96ETRiytYpz7FRlgXZlf22H08w1R+n/ nYpDcDgaPtdlQ0kx75U/soL3kqTCCUfsQTlEbYdcaO2sylfln2zajEJV+ChmoPciejvA T96Q4po8kOAk8m/NK68hMD2jypPYJjkIKQYsnZgvNxub7aBZanDpZFsTpxIv4O4apvop wi+mucc/R0+4uLG0798EhN1ot13NoTErnndmOFL5xBsVzzsHyNSMDEoM1V6rZbw9viHq PRvQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=9oZJUV3RpGzSZCa65z3Ze1dKnt/BilmUQkfi4nYEz/8=; b=O7bzKyriedwJJhhyk0kRuFl+8H4ZOY/YNPWKRu/W9pCBq4gAjaoV01uUGskTKe85KG z8yIE2TbluxTW/7Fiin/l04e0xMbnKRtNJTw1IivlR9clTgAxKKkWCbVnFQCUF2P7d+n BWq37M4uGzCzbOvyav2GiCmN7AwnWYGpm2NZNwX8jCrgq0HlSj+mCIMoc2FPSJbblMvz r6Pszkw0VemLX3EZlNp10DHkesTcywiPHsVWyeUcBXpTGUqjYWGLNNvmAOTbqQVQrnjN nOLRv4ZPKEYC4GWnQ/rh4QCDzcGfF76O9h3zsfEjKdi66jrkZ21zpfj8NmxZnD16y2Xl 1leQ== X-Gm-Message-State: AJIora9fkh76CgUKiM6ObWvyYTydeAT8ULffXPETxPj/Nsr/ozeV0TTm Onazqvujz8fTRAommRYhednkXRBYlaM= X-Received: by 2002:a65:6907:0:b0:415:c9c1:eb4f with SMTP id s7-20020a656907000000b00415c9c1eb4fmr14502988pgq.193.1657582537907; Mon, 11 Jul 2022 16:35:37 -0700 (PDT) Received: from lvondent-mobl4.. (c-71-56-157-77.hsd1.or.comcast.net. [71.56.157.77]) by smtp.gmail.com with ESMTPSA id q93-20020a17090a17e600b001e33e264fd6sm5446281pja.40.2022.07.11.16.35.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 11 Jul 2022 16:35:37 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH v7 1/7] Bluetooth: hci_core: Introduce hci_recv_event_data Date: Mon, 11 Jul 2022 16:35:29 -0700 Message-Id: <20220711233535.3134546-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.35.3 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org From: Luiz Augusto von Dentz This introduces hci_recv_event_data to make it simpler to access the contents of last received event rather than having to pass its contents to the likes of *_ind/*_cfm callbacks. Signed-off-by: Luiz Augusto von Dentz --- v2: Fixes CI/kernel test robot findings v3: Fix crash when disabling ISO Socket experimental UUID. v4: Fix crashes when running iso-tester Defer and Defer Send tests which just binds the CIS using DEFER_SETUP without attempting to connect it at first. v5: Fix kbuild findings v6: Fix checkpatch findings v7: Fix setting timeout on connect when DEFER_SETUP is used include/net/bluetooth/hci_core.h | 2 ++ net/bluetooth/hci_core.c | 32 ++++++++++++++++++++++++++++++++ net/bluetooth/hci_event.c | 3 +++ 3 files changed, 37 insertions(+) diff --git a/include/net/bluetooth/hci_core.h b/include/net/bluetooth/hci_core.h index 15237ee5f761..0ce57e1856e5 100644 --- a/include/net/bluetooth/hci_core.h +++ b/include/net/bluetooth/hci_core.h @@ -530,6 +530,7 @@ struct hci_dev { struct sk_buff_head cmd_q; struct sk_buff *sent_cmd; + struct sk_buff *recv_event; struct mutex req_lock; wait_queue_head_t req_wait_q; @@ -1755,6 +1756,7 @@ void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags); void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb); void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode); +void *hci_recv_event_data(struct hci_dev *hdev, __u8 event); u32 hci_conn_get_phy(struct hci_conn *conn); diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index 27e90eb4bf4c..baaf2fb969c3 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -2742,6 +2742,7 @@ void hci_release_dev(struct hci_dev *hdev) ida_simple_remove(&hci_index_ida, hdev->id); kfree_skb(hdev->sent_cmd); + kfree_skb(hdev->recv_event); kfree(hdev); } EXPORT_SYMBOL(hci_release_dev); @@ -3048,6 +3049,37 @@ void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode) return hdev->sent_cmd->data + HCI_COMMAND_HDR_SIZE; } +/* Get data from last received event */ +void *hci_recv_event_data(struct hci_dev *hdev, __u8 event) +{ + struct hci_event_hdr *hdr; + int offset; + + if (!hdev->recv_event) + return NULL; + + hdr = (void *)hdev->recv_event->data; + offset = sizeof(*hdr); + + if (hdr->evt != event) { + /* In case of LE metaevent check the subevent match */ + if (hdr->evt == HCI_EV_LE_META) { + struct hci_ev_le_meta *ev; + + ev = (void *)hdev->recv_event->data + offset; + offset += sizeof(*ev); + if (ev->subevent == event) + goto found; + } + return NULL; + } + +found: + bt_dev_dbg(hdev, "event 0x%2.2x", event); + + return hdev->recv_event->data + offset; +} + /* Send ACL data */ static void hci_add_acl_hdr(struct sk_buff *skb, __u16 handle, __u16 flags) { diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 34bec7446d00..2440275a143c 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -6936,6 +6936,9 @@ void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb) goto done; } + kfree_skb(hdev->recv_event); + hdev->recv_event = skb_clone(skb, GFP_KERNEL); + event = hdr->evt; if (!event) { bt_dev_warn(hdev, "Received unexpected HCI Event 0x%2.2x", -- 2.35.3