From 200fe7158aa6dda2940c6b6b7d4702a9173130a9 Mon Sep 17 00:00:00 2001 From: Pete Batard Date: Thu, 17 Nov 2011 17:49:55 +0000 Subject: [core] is_device_interface_accessible() prototype * also introduces 3 new driver related error codes --- libusb/core.c | 29 +++++++++++++++++++++++++++++ libusb/libusb.h | 13 +++++++++++++ libusb/libusbi.h | 13 +++++++++++++ libusb/os/windows_usb.c | 6 ++++++ 4 files changed, 61 insertions(+) diff --git a/libusb/core.c b/libusb/core.c index 3969fd5..d5aa095 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -1566,6 +1566,35 @@ int API_EXPORTED libusb_attach_kernel_driver(libusb_device_handle *dev, return LIBUSB_ERROR_NOT_SUPPORTED; } +/** \ingroup dev + * Determine if libusb can access a device or interface. + * + * \param dev a device handle + * \param interface_number the interface to check. On Windows, it is acceptable + * to pass a negative value as the interface number, for composite devices that + * have been split by the OS into multiple ones (MI_##), in which case the + * interface associated with the Windows device is assumed. + * \returns LIBUSB_SUCCESS if libusb can access the interface + * \returns LIBUSB_ERROR_DETACHEABLE_DRIVER_IN_USE if a libusb incompatible + * but detacheable driver is preventing access. See libusb_detach_kernel_driver. + * \returns LIBUSB_ERROR_NON_DETACHEABLE_DRIVER_IN_USE if a libusb incompatible + * and non detacheable driver is preventing access + * \returns LIBUSB_ERROR_NO_DRIVER on Windows if no driver has been installed + * for this device + * \returns LIBUSB_ERROR_NOT_SUPPORTED on platforms where the functionality + * is not available + * \returns another LIBUSB_ERROR code on other failure + */ +int LIBUSB_CALL libusb_is_device_interface_accessible(libusb_device_handle *dev, + int interface_number) +{ + usbi_dbg("interface %d", interface_number); + if (usbi_backend->is_device_interface_accessible) + return usbi_backend->is_device_interface_accessible(dev, interface_number); + else + return LIBUSB_ERROR_NOT_SUPPORTED; +} + /** \ingroup lib * Set message verbosity. * - Level 0: no messages ever printed by the library (default) diff --git a/libusb/libusb.h b/libusb/libusb.h index e29c9b8..648f776 100644 --- a/libusb/libusb.h +++ b/libusb/libusb.h @@ -760,6 +760,16 @@ enum libusb_error { /** Operation not supported or unimplemented on this platform */ LIBUSB_ERROR_NOT_SUPPORTED = -12, + // TODO: libusb_strerror + /** A detacheable kernel driver is in use */ + LIBUSB_ERROR_DETACHEABLE_DRIVER_IN_USE = -13, + + /** A non-detacheable driver is in use */ + LIBUSB_ERROR_NON_DETACHEABLE_DRIVER_IN_USE = -14, + + /** A driver has not been installed for this device (Windows) */ + LIBUSB_ERROR_NO_DRIVER = -15, + /** Other error */ LIBUSB_ERROR_OTHER = -99 @@ -963,6 +973,9 @@ int LIBUSB_CALL libusb_detach_kernel_driver(libusb_device_handle *dev, int LIBUSB_CALL libusb_attach_kernel_driver(libusb_device_handle *dev, int interface_number); +int LIBUSB_CALL libusb_is_device_interface_accessible(libusb_device_handle *dev, + int interface_number); + /* async I/O */ /** \ingroup asyncio diff --git a/libusb/libusbi.h b/libusb/libusbi.h index 9651387..e449a2c 100644 --- a/libusb/libusbi.h +++ b/libusb/libusbi.h @@ -774,6 +774,19 @@ struct usbi_os_backend { int (*attach_kernel_driver)(struct libusb_device_handle *handle, int interface_number); + /* Determine if libusb can access a device or interface. + * + * Return: + * - LIBUSB_SUCCESS if libusb can access the interface + * - LIBUSB_ERROR_DETACHEABLE_DRIVER_IN_USE if a detacheable driver is in use + * - LIBUSB_ERROR_NON_DETACHEABLE_DRIVER_IN_USE if a libusb incompatible + * and non detacheable driver is in use + * - LIBUSB_ERROR_NO_DRIVER if no driver has been installed (Windows) + * - another LIBUSB_ERROR code on other failure + */ + int (*is_device_interface_accessible)(struct libusb_device_handle *handle, + int interface_number); + /* Destroy a device. Optional. * * This function is called when the last reference to a device is diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index 2922d54..1d51e74 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -1787,6 +1787,11 @@ static int windows_detach_kernel_driver(struct libusb_device_handle *dev_handle, return LIBUSB_ERROR_NOT_SUPPORTED; } +static int windows_is_device_interface_accessible(struct libusb_device_handle *handle, int iface) +{ + return LIBUSB_ERROR_NOT_SUPPORTED; +} + static void windows_destroy_device(struct libusb_device *dev) { windows_device_priv_release(dev); @@ -2181,6 +2186,7 @@ const struct usbi_os_backend windows_backend = { windows_kernel_driver_active, windows_detach_kernel_driver, windows_attach_kernel_driver, + windows_is_device_interface_accessible, windows_destroy_device, -- cgit v1.2.1