aboutsummaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorChristian Starkjohann <cs+github@obdev.at>2008-06-09 12:02:57 +0000
committerChristian Starkjohann <cs+github@obdev.at>2008-06-09 12:02:57 +0000
commit24cb7a6f490d7f8d30336bee2a946a13db3dd913 (patch)
tree281ffac79cce58c813794af37bd3e555342f7de5 /examples
parent800274e264626df25821ac6c2f3a19f0746f0573 (diff)
downloadv-usb-24cb7a6f490d7f8d30336bee2a946a13db3dd913.tar.gz
v-usb-24cb7a6f490d7f8d30336bee2a946a13db3dd913.tar.bz2
v-usb-24cb7a6f490d7f8d30336bee2a946a13db3dd913.zip
- Optional code to claim an interface added
Diffstat (limited to 'examples')
-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){