summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHans de Goede <hdegoede@redhat.com>2013-06-14 11:06:47 +0200
committerHans de Goede <hdegoede@redhat.com>2013-06-19 11:04:15 +0200
commit02281fda6ee5ed7456f381105d159e15dc1b6da6 (patch)
tree668ba0e5aecf2bd62cf3be7ae0e3c882bc8d357e
parent08befee03cff76f62918a82d92696aa84d01515c (diff)
downloadlibusb-02281fda6ee5ed7456f381105d159e15dc1b6da6.tar.gz
examples: use libusb_set_auto_detach_kernel_driver()
What better way to show how useful libusb_set_auto_detach_kernel_driver() is, then to use it in our examples? Signed-off-by: Hans de Goede <hdegoede@redhat.com>
-rw-r--r--examples/fxload.c8
-rw-r--r--examples/xusb.c19
-rw-r--r--libusb/version_nano.h2
3 files changed, 3 insertions, 26 deletions
diff --git a/examples/fxload.c b/examples/fxload.c
index d8e9941..14226ca 100644
--- a/examples/fxload.c
+++ b/examples/fxload.c
@@ -242,14 +242,8 @@ int main(int argc, char*argv[])
}
/* We need to claim the first interface */
+ libusb_set_auto_detach_kernel_driver(device, 1);
status = libusb_claim_interface(device, 0);
-#if defined(__linux__)
- if (status != LIBUSB_SUCCESS) {
- /* Maybe we need to detach the driver */
- libusb_detach_kernel_driver(device, 0);
- status = libusb_claim_interface(device, 0);
- }
-#endif
if (status != LIBUSB_SUCCESS) {
logerror("libusb_claim_interface failed: %s\n", libusb_error_name(status));
goto err;
diff --git a/examples/xusb.c b/examples/xusb.c
index 3d3b853..bdb9794 100644
--- a/examples/xusb.c
+++ b/examples/xusb.c
@@ -785,8 +785,6 @@ static int test_device(uint16_t vid, uint16_t pid)
const struct libusb_endpoint_descriptor *endpoint;
int i, j, k, r;
int iface, nb_ifaces, first_iface = -1;
- // For attaching/detaching the kernel driver, if needed
- int iface_detached = -1;
struct libusb_device_descriptor dev_desc;
const char* speed_name[5] = { "Unknown", "1.5 Mbit/s (USB LowSpeed)", "12 Mbit/s (USB FullSpeed)",
"480 Mbit/s (USB HighSpeed)", "5000 Mbit/s (USB SuperSpeed)"};
@@ -894,21 +892,11 @@ static int test_device(uint16_t vid, uint16_t pid)
}
libusb_free_config_descriptor(conf_desc);
+ libusb_set_auto_detach_kernel_driver(handle, 1);
for (iface = 0; iface < nb_ifaces; iface++)
{
printf("\nClaiming interface %d...\n", iface);
r = libusb_claim_interface(handle, iface);
- if ((r != LIBUSB_SUCCESS) && libusb_has_capability(LIBUSB_CAP_SUPPORTS_DETACH_KERNEL_DRIVER)
- && (libusb_kernel_driver_active(handle, iface) > 0)) {
- // Try to detach the kernel driver
- perr(" A kernel driver is active, trying to detach it...\n");
- r = libusb_detach_kernel_driver(handle, iface);
- if (r == LIBUSB_SUCCESS) {
- iface_detached = iface;
- printf(" Claiming interface again...\n");
- r = libusb_claim_interface(handle, iface);
- }
- }
if (r != LIBUSB_SUCCESS) {
perr(" Failed.\n");
}
@@ -957,11 +945,6 @@ static int test_device(uint16_t vid, uint16_t pid)
libusb_release_interface(handle, iface);
}
- if (iface_detached >= 0) {
- printf("Re-attaching kernel driver...\n");
- libusb_attach_kernel_driver(handle, iface_detached);
- }
-
printf("Closing device...\n");
libusb_close(handle);
diff --git a/libusb/version_nano.h b/libusb/version_nano.h
index 24d4bb2..4d18db8 100644
--- a/libusb/version_nano.h
+++ b/libusb/version_nano.h
@@ -1 +1 @@
-#define LIBUSB_NANO 10744
+#define LIBUSB_NANO 10745