All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH BlueZ 1/2] bthost: Add destroy callback to bthost_add_iso_hook
@ 2022-08-22 22:00 Luiz Augusto von Dentz
  2022-08-22 22:00 ` [PATCH BlueZ 2/2] iso-tester: Make use of bthost_add_iso_hook destroy callback Luiz Augusto von Dentz
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2022-08-22 22:00 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

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


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH BlueZ 2/2] iso-tester: Make use of bthost_add_iso_hook destroy callback
  2022-08-22 22:00 [PATCH BlueZ 1/2] bthost: Add destroy callback to bthost_add_iso_hook Luiz Augusto von Dentz
@ 2022-08-22 22:00 ` Luiz Augusto von Dentz
  2022-08-22 22:27 ` [BlueZ,1/2] bthost: Add destroy callback to bthost_add_iso_hook bluez.test.bot
  2022-08-22 22:40 ` [PATCH BlueZ 1/2] " patchwork-bot+bluetooth
  2 siblings, 0 replies; 4+ messages in thread
From: Luiz Augusto von Dentz @ 2022-08-22 22:00 UTC (permalink / raw)
  To: linux-bluetooth

From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

This makes use of bthost_add_iso_hook to track when an ISO connection
has been disconnected and then set its handle to 0x0000 which is then
checked when the socket HUP to confirm the remote has properly
disconnected (e.g. received Disconnected Complete).
---
 tools/iso-tester.c | 52 +++++++++++++++++++++++++++-------------------
 1 file changed, 31 insertions(+), 21 deletions(-)

diff --git a/tools/iso-tester.c b/tools/iso-tester.c
index 8c935b9220dd..269fbe2d6c62 100644
--- a/tools/iso-tester.c
+++ b/tools/iso-tester.c
@@ -676,13 +676,42 @@ static void client_connectable_complete(uint16_t opcode, uint8_t status,
 	}
 }
 
+static void bthost_recv_data(const void *buf, uint16_t len, void *user_data)
+{
+	struct test_data *data = user_data;
+	const struct iso_client_data *isodata = data->test_data;
+
+	tester_print("Client received %u bytes of data", len);
+
+	if (isodata->send && (isodata->send->iov_len != len ||
+			memcmp(isodata->send->iov_base, buf, len))) {
+		if (!isodata->recv->iov_base)
+			tester_test_failed();
+	} else
+		tester_test_passed();
+}
+
+static void bthost_iso_disconnected(void *user_data)
+{
+	struct test_data *data = user_data;
+
+	tester_print("ISO handle 0x%04x disconnected", data->handle);
+
+	data->handle = 0x0000;
+}
+
 static void iso_new_conn(uint16_t handle, void *user_data)
 {
 	struct test_data *data = user_data;
+	struct bthost *host;
 
 	tester_print("New client connection with handle 0x%04x", handle);
 
 	data->handle = handle;
+
+	host = hciemu_client_get_host(data->hciemu);
+	bthost_add_iso_hook(host, data->handle, bthost_recv_data, data,
+				bthost_iso_disconnected);
 }
 
 static void acl_new_conn(uint16_t handle, void *user_data)
@@ -722,7 +751,7 @@ static void setup_powered_callback(uint8_t status, uint16_t length,
 		if (!isodata)
 			continue;
 
-		if (isodata->send || isodata->recv)
+		if (isodata->send || isodata->recv || isodata->disconnect)
 			bthost_set_iso_cb(host, iso_new_conn, data);
 
 		if (isodata->bcast) {
@@ -1110,25 +1139,9 @@ static void iso_recv(struct test_data *data, GIOChannel *io)
 	data->io_id[0] = g_io_add_watch(io, G_IO_IN, iso_recv_data, data);
 }
 
-static void bthost_recv_data(const void *buf, uint16_t len, void *user_data)
-{
-	struct test_data *data = user_data;
-	const struct iso_client_data *isodata = data->test_data;
-
-	tester_print("Client received %u bytes of data", len);
-
-	if (isodata->send && (isodata->send->iov_len != len ||
-			memcmp(isodata->send->iov_base, buf, len))) {
-		if (!isodata->recv->iov_base)
-			tester_test_failed();
-	} else
-		tester_test_passed();
-}
-
 static void iso_send(struct test_data *data, GIOChannel *io)
 {
 	const struct iso_client_data *isodata = data->test_data;
-	struct bthost *host;
 	ssize_t ret;
 	int sk;
 
@@ -1136,9 +1149,6 @@ 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, NULL);
-
 	ret = writev(sk, isodata->send, 1);
 	if (ret < 0 || isodata->send->iov_len != (size_t) ret) {
 		tester_warn("Failed to write %zu bytes: %s (%d)",
@@ -1167,7 +1177,7 @@ static gboolean iso_disconnected(GIOChannel *io, GIOCondition cond,
 
 	data->io_id[0] = 0;
 
-	if (cond & G_IO_HUP) {
+	if ((cond & G_IO_HUP) && !data->handle) {
 		tester_print("Successfully disconnected");
 
 		if (data->reconnect) {
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* RE: [BlueZ,1/2] bthost: Add destroy callback to bthost_add_iso_hook
  2022-08-22 22:00 [PATCH BlueZ 1/2] bthost: Add destroy callback to bthost_add_iso_hook Luiz Augusto von Dentz
  2022-08-22 22:00 ` [PATCH BlueZ 2/2] iso-tester: Make use of bthost_add_iso_hook destroy callback Luiz Augusto von Dentz
@ 2022-08-22 22:27 ` bluez.test.bot
  2022-08-22 22:40 ` [PATCH BlueZ 1/2] " patchwork-bot+bluetooth
  2 siblings, 0 replies; 4+ messages in thread
From: bluez.test.bot @ 2022-08-22 22:27 UTC (permalink / raw)
  To: linux-bluetooth, luiz.dentz

[-- Attachment #1: Type: text/plain, Size: 539 bytes --]

This is an automated email and please do not reply to this email.

Dear Submitter,

Thank you for submitting the patches to the linux bluetooth mailing list.
While preparing the CI tests, the patches you submitted couldn't be applied to the current HEAD of the repository.

----- Output -----
error: patch failed: tools/iso-tester.c:1167
error: tools/iso-tester.c: patch does not apply
hint: Use 'git am --show-current-patch' to see the failed patch


Please resolve the issue and submit the patches again.


---
Regards,
Linux Bluetooth


^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH BlueZ 1/2] bthost: Add destroy callback to bthost_add_iso_hook
  2022-08-22 22:00 [PATCH BlueZ 1/2] bthost: Add destroy callback to bthost_add_iso_hook Luiz Augusto von Dentz
  2022-08-22 22:00 ` [PATCH BlueZ 2/2] iso-tester: Make use of bthost_add_iso_hook destroy callback Luiz Augusto von Dentz
  2022-08-22 22:27 ` [BlueZ,1/2] bthost: Add destroy callback to bthost_add_iso_hook bluez.test.bot
@ 2022-08-22 22:40 ` patchwork-bot+bluetooth
  2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+bluetooth @ 2022-08-22 22:40 UTC (permalink / raw)
  To: Luiz Augusto von Dentz; +Cc: linux-bluetooth

Hello:

This series was applied to bluetooth/bluez.git (master)
by Luiz Augusto von Dentz <luiz.von.dentz@intel.com>:

On Mon, 22 Aug 2022 15:00:24 -0700 you wrote:
> From: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
> 
> 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(-)

Here is the summary with links:
  - [BlueZ,1/2] bthost: Add destroy callback to bthost_add_iso_hook
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=5bf220eb3b86
  - [BlueZ,2/2] iso-tester: Make use of bthost_add_iso_hook destroy callback
    https://git.kernel.org/pub/scm/bluetooth/bluez.git/?id=081897da74f0

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-08-22 22:40 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-08-22 22:00 [PATCH BlueZ 1/2] bthost: Add destroy callback to bthost_add_iso_hook Luiz Augusto von Dentz
2022-08-22 22:00 ` [PATCH BlueZ 2/2] iso-tester: Make use of bthost_add_iso_hook destroy callback Luiz Augusto von Dentz
2022-08-22 22:27 ` [BlueZ,1/2] bthost: Add destroy callback to bthost_add_iso_hook bluez.test.bot
2022-08-22 22:40 ` [PATCH BlueZ 1/2] " patchwork-bot+bluetooth

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.