summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Batard <pbatard@gmail.com>2010-03-01 16:43:48 +0000
committerPete Batard <pbatard@gmail.com>2010-03-01 16:43:48 +0000
commit1c727411238253a5d6f734c7c5c7ac3ca0054544 (patch)
tree214272d7aecd4c7f5c08f58d0a2fa809f1a80025
parent158799ca3f9edb946f152dccb5d9f0a3d607fa0c (diff)
downloadlibusb-r183.tar.gz
reattach driver when detached in xusb (Xiaofan Chen)r183
-rw-r--r--examples/xusb.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/examples/xusb.c b/examples/xusb.c
index e53b474..6bc3b4f 100644
--- a/examples/xusb.c
+++ b/examples/xusb.c
@@ -553,6 +553,9 @@ int test_device(uint16_t vid, uint16_t pid)
const struct libusb_endpoint_descriptor *endpoint;
int i, j, k, r;
int iface, nb_ifaces, nb_strings;
+#ifndef OS_WINDOWS
+ int iface_detached = -1;
+#endif
int test_scsi = 0;
struct libusb_device_descriptor dev_desc;
char string[128];
@@ -624,6 +627,7 @@ int test_device(uint16_t vid, uint16_t pid)
// Maybe we need to detach the driver
perr(" Failed. Trying to detach driver...\n");
libusb_detach_kernel_driver(handle, iface);
+ iface_detached = iface;
printf(" Claiming interface again...\n");
libusb_claim_interface(handle, iface);
} else {
@@ -668,6 +672,13 @@ int test_device(uint16_t vid, uint16_t pid)
libusb_release_interface(handle, iface);
}
+#ifndef OS_WINDOWS
+ if (iface_detached >= 0) {
+ printf("Re-attaching kernel driver...\n");
+ libusb_attach_kernel_driver(handle, iface_detached);
+ }
+#endif
+
printf("Closing device...\n");
libusb_close(handle);