Received: by 2002:a05:6358:5282:b0:b5:90e7:25cb with SMTP id g2csp2856581rwa; Mon, 22 Aug 2022 15:29:25 -0700 (PDT) X-Google-Smtp-Source: AA6agR71GzdyaxcYXcJPbb5elHNUz2GBlJHKa3UZV/0ZpiWoimc1Bnsswx8tr2O026nFRDpoXq+H X-Received: by 2002:a17:907:2bec:b0:73d:7353:d1cd with SMTP id gv44-20020a1709072bec00b0073d7353d1cdmr5860384ejc.424.1661207365561; Mon, 22 Aug 2022 15:29:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1661207365; cv=none; d=google.com; s=arc-20160816; b=CoTHG2BnuOgUuv+1kCcGXuxDoFUs9WeFMsRvF7x7Q9Rr3gxsFKzf4z5IFLcMpxrFfR Jw6sFh1coF6AW66QFkx1kQ7Got+mo4Kx6/sutg3trGu7jsMTVqqT0SLw1tARZ1GRB3xD SqqYZXM8TO5IDDoM20eI0qV+5uaDbGoaos+A6dVjHlJeUotc9/jkXQJ4UY2/e2Psey/0 POdsyTT9dXPjX1Rise8/uDYW8DymC7Qz+6v4nrSxT4+2pVIJCLsvAaut/jfPyzLjAUSB mcBUuqCkj5y9Dc+n0RqBliR4mz2wpxVnc3dTq3pwKEP/+TXYHENGyQw6ziVgL9NnJ03c 7o5g== 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=c6c2W9lldeIbv0uRG289EkdmoZZc6VFBSAXh9hrQiKk=; b=sSuLuQd/tvskhV8HThw5s3vzqRDxrdBwfDhAblblQTN60L2hmnByevYxesewEj2l8M AQWCUhApgIbSW1drh0Z2/BDFcU+2x9C9A/p/iNMHrBP4tBN4pSJy9iSSkydlPG64p2tB CMZRxfkOvR2wHm2/tkxmhTOsEeos3sjgdMmXnjBz8POrPZ0+exWpoHEO4CT/Ld8NEmxT TQj6aIyAwiYVwwX1AovHswQMl/Rwl9DiaYLu9FeIUarFJcvX9NeA0Xu4xkhMCdN/LwaD s6GiWRO2UIb66qahqfwrqWpGtP1UZf5nUq3hr20d6WJ0Xwg2iQepvLrxarFqSf38jcFs f4vw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=PRCEOOy3; 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 d22-20020a50f696000000b004466839e30fsi524081edn.337.2022.08.22.15.28.59; Mon, 22 Aug 2022 15:29:25 -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=PRCEOOy3; 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 S231774AbiHVWAr (ORCPT + 99 others); Mon, 22 Aug 2022 18:00:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54268 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238304AbiHVWA2 (ORCPT ); Mon, 22 Aug 2022 18:00:28 -0400 Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 53D573DF02 for ; Mon, 22 Aug 2022 15:00:28 -0700 (PDT) Received: by mail-pl1-x62b.google.com with SMTP id v23so5863249plo.9 for ; Mon, 22 Aug 2022 15:00:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:from:to:cc; bh=c6c2W9lldeIbv0uRG289EkdmoZZc6VFBSAXh9hrQiKk=; b=PRCEOOy3nKaD2iju9zXRdy/CPByIrX7JLSNun69vpd7NfQN9KxsUjfCOE47fNfc5K3 F4OjQYF2qhN/T17tITMoTBBiqm8N+FBUM69SVjt1QxuPpsRv/O3+aM12A2+MD1affSYv 39zrVXAvDqGMbeI9RFTVHY0mUsAxhYiD9AuKRna6Dvn2rIzryPLm3ma46UVmOC3Yaal7 zGwHMMbRUgH8zjEWQ8IzbSJxB9zaSbNxoAhuJKEXJgwLjd5xylxMWtljnE5mpaa4ssC1 WPnJidjXsDb5B/PboEUHPFlUUBdf+cEdB6gW5a56JHcbwcvP5hnIw/Zu8eGdN5EEuQLv YmBQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc; bh=c6c2W9lldeIbv0uRG289EkdmoZZc6VFBSAXh9hrQiKk=; b=rEjDGjxfDzgk/zPlkinGUJSwtuvKDXd3xGdAwBF/bcRWC877Ed1riWYGpMGnoMH1Mz 8PU/LFOAWpsNZ8B3CqJlteGRy5U9J56CXxvQLAoMfyxJE07d5wgFhCszD/aElke5OENk EVnh69aInstqmtxyNbyotucPmoqgd3J1srmy6+zZW70EZ9x7iUtroVtwzdqk8KOtKPqu XhHk3hA0l1YQG9Ldk0XceRCULh37iyTFyGMVSlj76iAEtyaxNPR7Onhj5yTvTmDHS9Bk JMriQz7sMFUJhE/Cw5OQgcC/+owd86saRFPgRbNdjuja7fDtXzdZhmN9+VUpD1BdlyAM 1P/g== X-Gm-Message-State: ACgBeo2ITlViLIMMKT9y1tBlxUHZG81vtx1WpVYWHxfDOsb5C/RDTUbu k7fgDmHBo2N3PfYe/C58X14N5yuRU+k= X-Received: by 2002:a17:902:be02:b0:172:d409:e057 with SMTP id r2-20020a170902be0200b00172d409e057mr12201255pls.90.1661205627151; Mon, 22 Aug 2022 15:00:27 -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 z12-20020aa79e4c000000b00535e950aa28sm8364751pfq.131.2022.08.22.15.00.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 22 Aug 2022 15:00:26 -0700 (PDT) From: Luiz Augusto von Dentz To: linux-bluetooth@vger.kernel.org Subject: [PATCH BlueZ 1/2] bthost: Add destroy callback to bthost_add_iso_hook Date: Mon, 22 Aug 2022 15:00:24 -0700 Message-Id: <20220822220025.541691-1-luiz.dentz@gmail.com> X-Mailer: git-send-email 2.37.2 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 adds a destroy callback to bthost_add_iso_hook so its user can detect when the hook is freed when the connection is disconnected. --- emulator/bthost.c | 8 +++++++- emulator/bthost.h | 3 ++- tools/iso-tester.c | 2 +- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/emulator/bthost.c b/emulator/bthost.c index f067d39a0262..b05198953506 100644 --- a/emulator/bthost.c +++ b/emulator/bthost.c @@ -137,6 +137,7 @@ struct rfcomm_chan_hook { struct iso_hook { bthost_cid_hook_func_t func; void *user_data; + bthost_destroy_func_t destroy; }; struct btconn { @@ -306,6 +307,9 @@ static void btconn_free(struct btconn *conn) free(hook); } + if (conn->iso_hook && conn->iso_hook->destroy) + conn->iso_hook->destroy(conn->iso_hook->user_data); + free(conn->iso_hook); free(conn->recv_data); free(conn); @@ -676,7 +680,8 @@ void bthost_add_cid_hook(struct bthost *bthost, uint16_t handle, uint16_t cid, } void bthost_add_iso_hook(struct bthost *bthost, uint16_t handle, - bthost_cid_hook_func_t func, void *user_data) + bthost_iso_hook_func_t func, void *user_data, + bthost_destroy_func_t destroy) { struct iso_hook *hook; struct btconn *conn; @@ -693,6 +698,7 @@ void bthost_add_iso_hook(struct bthost *bthost, uint16_t handle, hook->func = func; hook->user_data = user_data; + hook->destroy = destroy; conn->iso_hook = hook; } diff --git a/emulator/bthost.h b/emulator/bthost.h index 3d7a124f08ad..2cfdef766e4d 100644 --- a/emulator/bthost.h +++ b/emulator/bthost.h @@ -71,7 +71,8 @@ typedef void (*bthost_iso_hook_func_t)(const void *data, uint16_t len, void *user_data); void bthost_add_iso_hook(struct bthost *bthost, uint16_t handle, - bthost_iso_hook_func_t func, void *user_data); + bthost_iso_hook_func_t func, void *user_data, + bthost_destroy_func_t destroy); void bthost_send_cid(struct bthost *bthost, uint16_t handle, uint16_t cid, const void *data, uint16_t len); diff --git a/tools/iso-tester.c b/tools/iso-tester.c index 5727f3055222..8c935b9220dd 100644 --- a/tools/iso-tester.c +++ b/tools/iso-tester.c @@ -1137,7 +1137,7 @@ static void iso_send(struct test_data *data, GIOChannel *io) tester_print("Writing %zu bytes of data", isodata->send->iov_len); host = hciemu_client_get_host(data->hciemu); - bthost_add_iso_hook(host, data->handle, bthost_recv_data, data); + bthost_add_iso_hook(host, data->handle, bthost_recv_data, data, NULL); ret = writev(sk, isodata->send, 1); if (ret < 0 || isodata->send->iov_len != (size_t) ret) { -- 2.37.2