diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2013-11-26 11:31:27 +0100 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2013-11-26 12:01:43 +0100 |
commit | 53cabad7a225b3607e6920fff50c24016ceec1f5 (patch) | |
tree | b86d11b00741021ef00bcc83e07b9bbd0f9d33da /libk8055 | |
parent | b1da188cedec2b0b0fe6551265a33b2e0c0a087d (diff) | |
download | k8055-53cabad7a225b3607e6920fff50c24016ceec1f5.zip k8055-53cabad7a225b3607e6920fff50c24016ceec1f5.tar.gz |
fix k8055_takeover_device
libusb_detach_kernel_driver() -> LIBUSB_ERROR_NOT_FOUND is not fatal
libusb_set_configuration() must be called before libusb_claim_interface()
Diffstat (limited to 'libk8055')
-rw-r--r-- | libk8055/libk8055.c | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/libk8055/libk8055.c b/libk8055/libk8055.c index db4ddf3..cea2587 100644 --- a/libk8055/libk8055.c +++ b/libk8055/libk8055.c @@ -215,14 +215,23 @@ static int k8055_takeover_device( struct k8055_dev* dev, int interface ) { memset( driver_name, 0, STR_BUFF ); int ret = K8055_ERROR; assert( handle != NULL ); - if( libusb_detach_kernel_driver( handle, interface )!=0 ) { - if( dev->debug_level>0 ) fprintf( stderr, "usb_detach_kernel_driver fanalog_inputlure\n" ); + int r; + r = libusb_detach_kernel_driver( handle, interface ); + if( r!=0 && r!=LIBUSB_ERROR_NOT_FOUND) { + if( dev->debug_level>0 ) fprintf( stderr, "usb_detach_kernel_driver failure: %d\n", r); + return K8055_ERROR; + } + r = libusb_set_configuration( handle, 1 ); + if ( r!= 0) + { + if( dev->debug_level>0 ) fprintf( stderr, "usb_set_configuration failure: %d\n", r); + return K8055_ERROR; } - if ( libusb_claim_interface( handle, interface )!=0 ) { - if( dev->debug_level>0 ) fprintf( stderr, "usb_claim_interface failure\n" ); + r = libusb_claim_interface( handle, interface ); + if ( r!=0 ) { + if( dev->debug_level>0 ) fprintf( stderr, "usb_claim_interface failure: %d\n", r); return K8055_ERROR; } - libusb_set_configuration( handle, 1 ); if ( dev->debug_level>0 ) fprintf( stderr, "Found interface %d, took over the device\n", interface ); return 0; } |