aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Kocialkowski <contact@paulk.fr>2016-02-24 11:07:20 +0100
committerPaul Kocialkowski <contact@paulk.fr>2016-02-24 11:07:23 +0100
commit69f43fd03d193d004f38db3271eed2da9fe5ad56 (patch)
treeb87ae12cb838be078e7008d9fabf92502d3d18d1 /src
parentd869d08a34929cc76b7062082ec9d66f4771a57a (diff)
downloadlg-downloader-69f43fd03d193d004f38db3271eed2da9fe5ad56.tar.gz
lg-downloader-69f43fd03d193d004f38db3271eed2da9fe5ad56.tar.bz2
lg-downloader-69f43fd03d193d004f38db3271eed2da9fe5ad56.zip
usb: Only set configuration when needed
Setting the USB configurations triggers a soft reset on most devices, thus it should be avoided as much as possible. In particular, this allows running multiple commands in a row. Signed-off-by: Paul Kocialkowski <contact@paulk.fr>
Diffstat (limited to 'src')
-rw-r--r--src/usb.c15
1 files changed, 12 insertions, 3 deletions
diff --git a/src/usb.c b/src/usb.c
index 8631c06..5742d7b 100644
--- a/src/usb.c
+++ b/src/usb.c
@@ -27,6 +27,7 @@
int usb_open(struct context *context)
{
struct libusb_device_handle *handle;
+ int configuration;
int rc;
if (context == NULL)
@@ -34,7 +35,7 @@ int usb_open(struct context *context)
rc = libusb_init(NULL);
if (rc < 0) {
- fprintf(stderr, "Initializing libusb failed\n");
+ fprintf(stderr, "Initializing USB failed\n");
return -1;
}
@@ -47,12 +48,20 @@ int usb_open(struct context *context)
libusb_detach_kernel_driver(handle, USB_INTERFACE);
- rc = libusb_set_configuration(handle, USB_CONFIGURATION);
+ rc = libusb_get_configuration(handle, &configuration);
if (rc < 0) {
- fprintf(stderr, "Setting USB configuration failed\n");
+ fprintf(stderr, "Getting USB configuration failed\n");
goto error;
}
+ if (configuration != USB_CONFIGURATION) {
+ rc = libusb_set_configuration(handle, USB_CONFIGURATION);
+ if (rc < 0) {
+ fprintf(stderr, "Setting USB configuration failed\n");
+ goto error;
+ }
+ }
+
rc = libusb_claim_interface(handle, USB_INTERFACE);
if (rc < 0) {
fprintf(stderr, "Claiming USB interface failed\n");