From: Daniel Drake Date: Sat, 3 May 2008 15:50:58 +0000 (+0100) Subject: Well-defined error codes for some operations X-Git-Tag: upstream/1.0.21~1077 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=a74106a9b48b88bae0e099be34a18d653a8f1238;p=platform%2Fupstream%2Flibusb.git Well-defined error codes for some operations Also renamed set_interface_altsetting to set_interface_alt_setting for better consistency --- diff --git a/libusb/core.c b/libusb/core.c index 3924eb2..479f919 100644 --- a/libusb/core.c +++ b/libusb/core.c @@ -575,7 +575,11 @@ API_EXPORTED int libusb_set_configuration(libusb_device_handle *dev, * \param dev a device handle * \param interface_number the bInterfaceNumber of the interface you * wish to claim - * \returns 0 on success, or a LIBUSB_ERROR code on failure + * \returns 0 on success + * \returns LIBUSB_ERROR_NOT_FOUND if the requested interface does not exist + * \returns LIBUSB_ERROR_BUSY if another program or driver has claimed the + * interface + * \returns a LIBUSB_ERROR code on other failure */ API_EXPORTED int libusb_claim_interface(libusb_device_handle *dev, int interface_number) @@ -632,11 +636,24 @@ out: return r; } -/* FIXME docs */ -API_EXPORTED int libusb_set_interface_altsetting(libusb_device_handle *dev, - int interface_number, int altsetting) +/** \ingroup dev + * Activate an alternate setting for an interface. The interface must have + * been previously claimed with libusb_claim_interface(). + * + * \param dev a device handle + * \param interface_number the bInterfaceNumber of the + * previously-claimed interface + * \param altsetting the bAlternateSetting of the alternate setting + * to activate + * \returns 0 on success + * \returns LIBUSB_ERROR_NOT_FOUND if the interface was not claimed, or the + * requested alternate setting does not exist + * \returns another LIBUSB_ERROR code on other failure + */ +API_EXPORTED int libusb_set_interface_alt_setting(libusb_device_handle *dev, + int interface_number, int alternate_setting) { - usbi_dbg("interface %d altsetting %d", interface_number, altsetting); + usbi_dbg("interface %d altsetting %d", interface_number, alternate_setting); if (interface_number >= sizeof(dev->claimed_interfaces) * 8) return LIBUSB_ERROR_INVALID_PARAM; @@ -648,7 +665,7 @@ API_EXPORTED int libusb_set_interface_altsetting(libusb_device_handle *dev, pthread_mutex_unlock(&dev->lock); return usbi_backend->set_interface_altsetting(dev, interface_number, - altsetting); + alternate_setting); } /** \ingroup lib diff --git a/libusb/libusb.h b/libusb/libusb.h index e1dcf3a..dc88a16 100644 --- a/libusb/libusb.h +++ b/libusb/libusb.h @@ -658,8 +658,8 @@ libusb_device_handle *libusb_open_device_with_vid_pid(uint16_t vendor_id, uint16_t product_id); -int libusb_set_interface_altsetting(libusb_device_handle *dev, int iface, - int altsetting); +int libusb_set_interface_alt_setting(libusb_device_handle *dev, + int interface_number, int alternate_setting); /* async I/O */ diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c index 5849864..d1c1100 100644 --- a/libusb/os/linux_usbfs.c +++ b/libusb/os/linux_usbfs.c @@ -442,8 +442,12 @@ static int op_claim_interface(struct libusb_device_handle *handle, int iface) int fd = __device_handle_priv(handle)->fd; int r = ioctl(fd, IOCTL_USBFS_CLAIMINTF, &iface); if (r) { - usbi_err("claim interface failed, error %d", r); - /* FIXME interpret error codes better */ + if (errno == ENOENT) + return LIBUSB_ERROR_NOT_FOUND; + else if (errno == EBUSY) + return LIBUSB_ERROR_BUSY; + + usbi_err("claim interface failed, error %d errno %d", r, errno); return LIBUSB_ERROR_OTHER; } return 0; @@ -454,7 +458,7 @@ static int op_release_interface(struct libusb_device_handle *handle, int iface) int fd = __device_handle_priv(handle)->fd; int r = ioctl(fd, IOCTL_USBFS_RELEASEINTF, &iface); if (r) { - usbi_err("release interface failed, error %d", r); + usbi_err("release interface failed, error %d errno %d", r, errno); return LIBUSB_ERROR_OTHER; } return 0; @@ -471,7 +475,10 @@ static int op_set_interface(struct libusb_device_handle *handle, int iface, setintf.altsetting = altsetting; r = ioctl(fd, IOCTL_USBFS_SETINTF, &setintf); if (r) { - usbi_err("setintf failed error %d", r); + if (errno == EINVAL) + return LIBUSB_ERROR_NOT_FOUND; + + usbi_err("setintf failed error %d errno %d", r, errno); return LIBUSB_ERROR_OTHER; }