libftdi Archives

Subject: Re: (Corrected)In linusb-1.0, libusb_detach_kernel_driver is available unconditional

From: Xiaofan Chen <xiaofanc@xxxxxxxxx>
To: libftdi@xxxxxxxxxxxxxxxxxxxxxxx
Date: Tue, 18 May 2010 22:02:39 +0800
On Tue, May 18, 2010 at 9:50 PM, Xiaofan Chen <xiaofanc@xxxxxxxxx> wrote:

> As mentioned before, libftdi-1.0 should not return error if the
> detach_errorno is LIBUSB_NOT_FOUND (Linux, kernel driver already detached)
> or LIBUSB_NOT_SUPPORTED (Windows and Mac OS X/Darwin).
>

Here is my proposed patch.

For libusb-1.0 Windows (WinUSB backened), you do not really need to call
libusb_set_configuration. And there is no LIBUSB_HAS_GET_DRIVER_NP
for libusb-1.0.

diff --git a/src/ftdi.c b/src/ftdi.c
index df25d44..70232c6 100644
--- a/src/ftdi.c
+++ b/src/ftdi.c
@@ -458,34 +458,19 @@ int ftdi_usb_open_dev(struct ftdi_context *ftdi,
libusb_device *dev)
     cfg0 = config0->bConfigurationValue;
     libusb_free_config_descriptor (config0);

-#ifdef LIBUSB_HAS_GET_DRIVER_NP
     // Try to detach ftdi_sio kernel module.
-    // Returns ENODATA if driver is not loaded.
     //
     // The return code is kept in a separate variable and only parsed
     // if usb_set_configuration() or usb_claim_interface() fails as the
     // detach operation might be denied and everything still works fine.
     // Likely scenario is a static ftdi_sio kernel module.
     ret = libusb_detach_kernel_driver(ftdi->usb_dev, ftdi->interface);
-    if (ret < 0 && ret != LIBUSB_ERROR_NOT_FOUND)
-        ftdi_error_return(-11, "libusb_detach_kernel_driver () failed");
-#endif
+    if (ret < 0 && ret != LIBUSB_ERROR_NOT_FOUND && ret !=
LIBUSB_NOT_SUPPORTED)
+        ftdi_error_return(-11, "libusb_detach_kernel_driver () failed
abnormally");

     if (libusb_get_configuration (ftdi->usb_dev, &cfg) < 0)
         ftdi_error_return(-12, "libusb_get_configuration () failed");

-    // set configuration (needed especially for windows)
-    // tolerate EBUSY: one device with one configuration, but two interfaces
-    //    and libftdi sessions to both interfaces (e.g. FT2232)
-    if (desc.bNumConfigurations > 0 && cfg != cfg0)
-    {
-        if (libusb_set_configuration(ftdi->usb_dev, cfg0) < 0)
-        {
-            ftdi_usb_close_internal (ftdi);
-            ftdi_error_return(-3, "unable to set usb configuration.
Make sure ftdi_sio is unloaded!");
-        }
-    }
-
     if (libusb_claim_interface(ftdi->usb_dev, ftdi->interface) < 0)
     {
         ftdi_usb_close_internal (ftdi);


-- 
Xiaofan http://mcuee.blogspot.com

--
libftdi - see http://www.intra2net.com/en/developer/libftdi for details.
To unsubscribe send a mail to libftdi+unsubscribe@xxxxxxxxxxxxxxxxxxxxxxx   

Current Thread