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 20:46:56 +0800
On Tue, May 18, 2010 at 8:37 PM, Uwe Bonnes
<bon@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:

> libftdi stores the result of usb_detach_kernel_driver_np and checks and
> reports EPERM with usb_set_configuration() and usb_claim_interface(). The
> messages seem quite hintfull for plain users.

I was also thinking the codes in libftdi is better. But then I am not
sure why the they are enclosed by the __WIN32__ ifdef. In
this case, the code does not really help. On the other hand,
Windows user will probably puzzled by the error message
about permission and ftdi_sio. ;-)

So I think the codes in libftdi also needs to be changed.

BTW, as one of the new admin of libusb-win32, I think we have
already made the usb_set_configuration() not necessary
in the SVN version of libusb-win32. And I believe the
NULL pointer issue has also been solved.


#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.
    if (usb_detach_kernel_driver_np(ftdi->usb_dev, ftdi->interface) !=
0 && errno != ENODATA)
        detach_errno = errno;
#endif

#ifdef __WIN32__
    // 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 (dev->descriptor.bNumConfigurations > 0)
    {
        // libusb-win32 on Windows 64 can return a null pointer for a
valid device
        if (dev->config)
            config_val = dev->config[0].bConfigurationValue;

        if (usb_set_configuration(ftdi->usb_dev, config_val) &&
            errno != EBUSY)
        {
            ftdi_usb_close_internal (ftdi);
            if (detach_errno == EPERM)
            {
                ftdi_error_return(-8, "inappropriate permissions on device!");
            }
            else
            {
                ftdi_error_return(-3, "unable to set usb
configuration. Make sure ftdi_sio is unloaded!");
            }
        }
    }
#endif


-- 
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