aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--examples/custom-class/commandline/set-led.c23
1 files changed, 21 insertions, 2 deletions
diff --git a/examples/custom-class/commandline/set-led.c b/examples/custom-class/commandline/set-led.c
index 739792b..75e77e4 100644
--- a/examples/custom-class/commandline/set-led.c
+++ b/examples/custom-class/commandline/set-led.c
@@ -60,8 +60,27 @@ int cnt, vid, pid, isOn;
exit(1);
}
/* Since we use only control endpoint 0, we don't need to choose a
- * configuration and interface.
- */
+ * configuration and interface. Reading device descriptor and setting a
+ * configuration and interface is done through endpoint 0 after all.
+ * However, newer versions of Linux require that we claim an interface
+ * even for endpoint 0. Enable the following code if your operating system
+ * needs it: */
+#if 0
+ int retries = 1, usbConfiguration = 1, usbInterface = 0;
+ if(usb_set_configuration(handle, usbConfiguration) && showWarnings){
+ fprintf(stderr, "Warning: could not set configuration: %s\n", usb_strerror());
+ }
+ /* now try to claim the interface and detach the kernel HID driver on
+ * Linux and other operating systems which support the call. */
+ while((len = usb_claim_interface(handle, usbInterface)) != 0 && retries-- > 0){
+#ifdef LIBUSB_HAS_DETACH_KERNEL_DRIVER_NP
+ if(usb_detach_kernel_driver_np(handle, 0) < 0 && showWarnings){
+ fprintf(stderr, "Warning: could not detach kernel driver: %s\n", usb_strerror());
+ }
+#endif
+ }
+#endif
+
if(strcasecmp(argv[1], "status") == 0){
cnt = usb_control_msg(handle, USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN, CUSTOM_RQ_GET_STATUS, 0, 0, buffer, sizeof(buffer), 5000);
if(cnt < 1){