如何检查内核驱动程序是否附带libusb-0.1?

时间:2013-07-31 05:05:55

标签: libusb libusb-1.0

在libusb-1.0中,可以使用libusb_kernel_driver_active

if (libusb_kernel_driver_active(dev_handle, 0) == 1) { //find out if kernel driver is attached
        cout<<"Kernel Driver Active"<<endl;
        if(libusb_detach_kernel_driver(dev_handle, 0) == 0) //detach it
            cout<<"Kernel Driver Detached!"<<endl;
    }

如何使用libusb-0.1进行检查?

1 个答案:

答案 0 :(得分:0)

对于libusb-compat,您可以使用usb_get_driver_np

API_EXPORTED int usb_get_driver_np(usb_dev_handle *dev, int interface,
    char *name, unsigned int namelen)
{
    int r = libusb_kernel_driver_active(dev->handle, interface);
    if (r == 1) {
        /* libusb-1.0 doesn't expose driver name, so fill in a dummy value */
        snprintf(name, namelen, "dummy");
        return 0;
    } else if (r == 0) {
        return -(errno=ENODATA);
    } else {
        return compat_err(r);
    }
}