Linux bluetooth development
 help / color / mirror / Atom feed
From: Luiz Augusto von Dentz <luiz.dentz@gmail.com>
To: linux-bluetooth@vger.kernel.org
Subject: [PATCH BlueZ v1 1/4] emulator/vhci: Add debug messages to error paths
Date: Tue,  5 May 2026 16:47:16 -0400	[thread overview]
Message-ID: <20260505204719.1348473-1-luiz.dentz@gmail.com> (raw)

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

Add debug_callback, debug_destroy and debug_data fields to struct vhci
so vhci_set_debug stores the callback locally in addition to passing it
to btdev. Introduce a variadic vhci_debug() helper using util_debug_va
and add debug messages to the following error paths:

 - vhci_write_callback: failed io_send
 - vhci_read_callback: failed read
 - vhci_debugfs_write: failed open and failed write
---
 emulator/vhci.c | 40 ++++++++++++++++++++++++++++++++++++----
 1 file changed, 36 insertions(+), 4 deletions(-)

diff --git a/emulator/vhci.c b/emulator/vhci.c
index 22ca15796872..05fcfd0b77cb 100644
--- a/emulator/vhci.c
+++ b/emulator/vhci.c
@@ -19,6 +19,7 @@
 #include <unistd.h>
 #include <stdlib.h>
 #include <string.h>
+#include <stdarg.h>
 #include <sys/uio.h>
 #include <fcntl.h>
 #include <unistd.h>
@@ -29,6 +30,7 @@
 #include "bluetooth/hci.h"
 
 #include "src/shared/io.h"
+#include "src/shared/util.h"
 #include "monitor/bt.h"
 #include "btdev.h"
 #include "vhci.h"
@@ -41,8 +43,23 @@ struct vhci {
 	uint16_t index;
 	struct io *io;
 	struct btdev *btdev;
+	vhci_debug_func_t debug_callback;
+	vhci_destroy_func_t debug_destroy;
+	void *debug_data;
 };
 
+static void vhci_debug(struct vhci *vhci, const char *format, ...)
+{
+	va_list ap;
+
+	if (!vhci || !format || !vhci->debug_callback)
+		return;
+
+	va_start(ap, format);
+	util_debug_va(vhci->debug_callback, vhci->debug_data, format, ap);
+	va_end(ap);
+}
+
 static void vhci_destroy(void *user_data)
 {
 	struct vhci *vhci = user_data;
@@ -61,7 +78,7 @@ static void vhci_write_callback(const struct iovec *iov, int iovlen,
 
 	written = io_send(vhci->io, iov, iovlen);
 	if (written < 0)
-		return;
+		vhci_debug(vhci, "Failed to write: %s", strerror(-written));
 }
 
 static bool vhci_read_callback(struct io *io, void *user_data)
@@ -72,8 +89,10 @@ static bool vhci_read_callback(struct io *io, void *user_data)
 	ssize_t len;
 
 	len = read(fd, buf, sizeof(buf));
-	if (len < 1)
+	if (len < 1) {
+		vhci_debug(vhci, "Failed to read: %s", strerror(errno));
 		return false;
+	}
 
 	btdev_receive_h4(vhci->btdev, buf, len);
 
@@ -86,6 +105,13 @@ bool vhci_set_debug(struct vhci *vhci, vhci_debug_func_t callback,
 	if (!vhci)
 		return false;
 
+	if (vhci->debug_destroy)
+		vhci->debug_destroy(vhci->debug_data);
+
+	vhci->debug_callback = callback;
+	vhci->debug_destroy = destroy;
+	vhci->debug_data = user_data;
+
 	return btdev_set_debug(vhci->btdev, callback, user_data, destroy);
 }
 
@@ -205,14 +231,20 @@ static int vhci_debugfs_write(struct vhci *vhci, char *option, const void *data,
 	sprintf(path, DEBUGFS_PATH "/hci%d/%s", vhci->index, option);
 
 	fd = open(path, O_RDWR);
-	if (fd < 0)
+	if (fd < 0) {
+		vhci_debug(vhci, "Failed to open %s: %s", path,
+							strerror(errno));
 		return -errno;
+	}
 
 	n = write(fd, data, len);
 	if (n == len)
 		err = 0;
-	else
+	else {
 		err = -errno;
+		vhci_debug(vhci, "Failed to write %s: %s", option,
+							strerror(-err));
+	}
 
 	close(fd);
 
-- 
2.53.0


             reply	other threads:[~2026-05-05 20:47 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-05 20:47 Luiz Augusto von Dentz [this message]
2026-05-05 20:47 ` [PATCH BlueZ v1 2/4] emulator/hciemu: Add debug messages to error paths Luiz Augusto von Dentz
2026-05-05 20:47 ` [PATCH BlueZ v1 3/4] tools/gap-tester: Enable hciemu debug output Luiz Augusto von Dentz
2026-05-05 20:47 ` [PATCH BlueZ v1 4/4] tools/userchan-tester: " Luiz Augusto von Dentz
2026-05-05 21:53 ` [BlueZ,v1,1/4] emulator/vhci: Add debug messages to error paths bluez.test.bot
2026-05-06 13:30 ` [PATCH BlueZ v1 1/4] " patchwork-bot+bluetooth

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20260505204719.1348473-1-luiz.dentz@gmail.com \
    --to=luiz.dentz@gmail.com \
    --cc=linux-bluetooth@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox