如何在android中分离ftdi内核驱动程序?

时间:2013-08-08 05:49:28

标签: android kernel libusb ftdi

我试图在android中分离ftdi内核驱动程序(libftdi-0.x代码):

#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.
fprintf(stderr, "detaching kernel driver... \n");
if (ftdi->module_detach_mode == AUTO_DETACH_SIO_MODULE)
{
    fprintf(stderr, "usb_detach_kernel_driver_np() ...\n");
    if (usb_detach_kernel_driver_np(ftdi->usb_dev, ftdi->interface) != 0 && errno != ENODATA) {
        fprintf(stderr, "failed to detach\n");
        detach_errno = errno;
    }
}
#endif

由于设备的所有下一次调用均以错误= 32(EPIPE)而失败,我相信它实际上并未脱离:

fprintf(stderr, "ftdi set configuration\n");
    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;
            fprintf(stderr, "trying to set configuration %i\n", config_val);
        }

        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 the default FTDI driver is not in use");
            }
        }
    }

日志:

08-08 11:40:54.197: WARN/System.err(31772): trying to set configuration 1
08-08 11:40:54.197: WARN/System.err(31772): libusb-compat debug: usb_set_configuration: configuration 1
08-08 11:40:54.197: WARN/System.err(31772): libusb: 0.005311 debug [libusb_set_configuration] configuration 1
08-08 11:40:54.197: WARN/System.err(31772): libusb: 0.007173 error [op_set_configuration] failed, error -1 errno 32

根据上面的评论,它似乎并没有脱离,但结果还可以。

关于如何分离或获得实际结果的任何想法?任何走动?

更新:我已经在2个Android设备上试过它,在android 4.0.x上都有usb-host支持,在android 4.1上有2个不同的FTDI设备。

更新:我已创建android issue

1 个答案:

答案 0 :(得分:1)

前一段时间我遇到过以下问题:

http://developer.intra2net.com/mailarchive/html/libftdi/2011/msg00024.html

它提到分离可能需要root权限才能正常工作。 那么,如果在root设备上运行,结果是否相同?