summaryrefslogtreecommitdiffstats
path: root/scd/ccid-driver.c
diff options
context:
space:
mode:
authorWerner Koch <wk@gnupg.org>2022-08-22 12:04:40 +0200
committerWerner Koch <wk@gnupg.org>2022-08-22 12:05:18 +0200
commitf4b01ddc6a55acea49273e35f19e97ef9ef88d28 (patch)
treea618e347454e5f66b74560f2c4e41380263ea45b /scd/ccid-driver.c
parentcommon: New common option no-autostart. (diff)
downloadgnupg2-f4b01ddc6a55acea49273e35f19e97ef9ef88d28.tar.xz
gnupg2-f4b01ddc6a55acea49273e35f19e97ef9ef88d28.zip
scd: Add a libusb debug level.
* scd/ccid-driver.c (USE_LIBUSB_DEBUG_CB): New const. (debug_libusb_cb): new. (ccid_set_debug_level): Use it. -- This allows to see the libusb log in our usual debug output. For this the option debug-ccid-driver needs to be given 5 or more times.
Diffstat (limited to '')
-rw-r--r--scd/ccid-driver.c34
1 files changed, 33 insertions, 1 deletions
diff --git a/scd/ccid-driver.c b/scd/ccid-driver.c
index f63219d97..f527b49ff 100644
--- a/scd/ccid-driver.c
+++ b/scd/ccid-driver.c
@@ -166,6 +166,11 @@
#endif /* This source is not used by scdaemon. */
+#undef USE_LIBUSB_DEBUG_CB
+#if LIBUSB_API_VERSION >= 0x01000107
+# define USE_LIBUSB_DEBUG_CB 1
+#endif
+
#ifndef EAGAIN
#define EAGAIN EWOULDBLOCK
@@ -1231,6 +1236,23 @@ scan_devices (char **r_rid)
}
+#ifdef USE_LIBUSB_DEBUG_CB
+static void
+debug_libusb_cb (libusb_context *ctx, enum libusb_log_level level,
+ const char *str)
+{
+ int n = str? strlen (str):0;
+
+ (void)ctx;
+
+ /* Strip the LF so that our logging filter does not escape it. */
+ if (n && str[n-1] == '\n')
+ n--;
+ log_debug ("libusb{%d}: %.*s\n", level, n, str);
+}
+#endif /* USE_LIBUSB_DEBUG_CB */
+
+
/* Set the level of debugging to LEVEL and return the old level. -1
just returns the old level. A level of 0 disables debugging, 1
enables debugging, 2 enables additional tracing of the T=1
@@ -1245,6 +1267,16 @@ ccid_set_debug_level (int level)
int old = debug_level;
if (level != -1)
debug_level = level;
+#ifdef USE_LIBUSB_DEBUG_CB
+ if (level > 4)
+ {
+ log_debug ("libusb: Enable logging\n");
+ libusb_set_log_cb (NULL, debug_libusb_cb, LIBUSB_LOG_CB_GLOBAL);
+ libusb_set_option (NULL, LIBUSB_OPTION_LOG_LEVEL, LIBUSB_LOG_LEVEL_DEBUG);
+ }
+ else
+ libusb_set_log_cb (NULL, NULL, LIBUSB_LOG_CB_GLOBAL);
+#endif /* USE_LIBUSB_DEBUG_CB */
return old;
}
@@ -4050,7 +4082,7 @@ main (int argc, char **argv)
}
/*
- * Local Variables:
+ * Disabled Local Variables:
* compile-command: "gcc -DTEST -DGPGRT_ENABLE_ES_MACROS -DHAVE_NPTH -DUSE_NPTH -Wall -I/usr/include/libusb-1.0 -I/usr/local/include -lusb-1.0 -g ccid-driver.c -lnpth -lgpg-error"
* End:
*/