summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPete Batard <pbatard@gmail.com>2010-04-16 10:47:37 +0100
committerPete Batard <pbatard@gmail.com>2010-04-16 10:47:37 +0100
commitfc2b212758df6eef5d30899628ce7db40474d8eb (patch)
tree82083958f00ead568647c2abb1b63387a7cf6de6
parent32a674508af7f83ad5b0d1c1ec9cc0683fea5d69 (diff)
downloadlibusb-fc2b212758df6eef5d30899628ce7db40474d8eb.tar.gz
better handling of attach/detach for Linux in xusb.cr254
-rw-r--r--examples/xusb.c26
1 files changed, 14 insertions, 12 deletions
diff --git a/examples/xusb.c b/examples/xusb.c
index 661201b..ee98613 100644
--- a/examples/xusb.c
+++ b/examples/xusb.c
@@ -600,7 +600,8 @@ 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
+#ifdef OS_LINUX
+ // Attaching/detaching the kernel driver is only relevant for Linux
int iface_detached = -1;
#endif
bool test_scsi = false;
@@ -669,17 +670,18 @@ int test_device(uint16_t vid, uint16_t pid)
{
printf("\nClaiming interface %d...\n", iface);
r = libusb_claim_interface(handle, iface);
+#ifdef OS_LINUX
+ if ((r != LIBUSB_SUCCESS) && (iface == 0)) {
+ // 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");
+ r = libusb_claim_interface(handle, iface);
+ }
+#endif
if (r != LIBUSB_SUCCESS) {
- if (iface == 0) {
- // 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 {
- printf("failed.\n");
- }
+ perr(" Failed.\n");
}
}
#endif
@@ -719,7 +721,7 @@ int test_device(uint16_t vid, uint16_t pid)
libusb_release_interface(handle, iface);
}
-#ifndef OS_WINDOWS
+#ifdef OS_LINUX
if (iface_detached >= 0) {
printf("Re-attaching kernel driver...\n");
libusb_attach_kernel_driver(handle, iface_detached);