From f650a1611fc90ae1a388654c501b9d0512a193a3 Mon Sep 17 00:00:00 2001 From: Audiohacked Date: Tue, 25 Jun 2019 13:18:03 -0600 Subject: [PATCH 1/9] Improve Scan code --- logic/scan.c | 176 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 114 insertions(+), 62 deletions(-) diff --git a/logic/scan.c b/logic/scan.c index 8fe494e..bea1ba1 100644 --- a/logic/scan.c +++ b/logic/scan.c @@ -64,6 +64,114 @@ corsairlink_close( libusb_context* context ) return 0; } +int +corsairlink_device_setup( + libusb_device* device, + struct corsair_device_info* cl_device, + struct libusb_device_descriptor desc ) +{ + int rr; // This could be safely ignored. It is just a success flag for + // libusb functions. + // int ii; // Loops through USB devices. + uint8_t device_id = 0x00; + + // struct corsair_device_info* device; + // device = &corsairlink_devices[jj]; + + if ( ( cl_device->vendor_id == desc.idVendor ) + && ( cl_device->product_id == desc.idProduct ) ) + { + msg_debug( "Corsair product detected. Checking if device is %s... ", cl_device->name ); + rr = libusb_open( device, &scanlist[scanlist_count].handle ); + if ( scanlist[scanlist_count].handle != NULL ) // Maybe try 'if (rr == 0)' + { + rr = libusb_detach_kernel_driver( scanlist[scanlist_count].handle, 0 ); + if ( rr < 0 ) + { + msg_debug("Unable to detach kernel driver from Corsair Device\n"); + // return rr; + } + + rr = libusb_claim_interface( scanlist[scanlist_count].handle, 0 ); + if ( rr < 0 ) + { + msg_err("Unable to claim USB device interface\n"); + return rr; + } + + /* get device_id if we have a proper device handle */ + cl_device->driver->device_id( + cl_device, scanlist[scanlist_count].handle, &device_id ); + /* check to see if the device_id is the right one */ + if ( cl_device->device_id == device_id ) + { + /* if we have the right device id we can setup the rest + * of the device connections + */ + scanlist[scanlist_count].device = cl_device; + msg_info( + "Dev=%d, CorsairLink Device Found: %s!\n", scanlist_count, + cl_device->name ); + scanlist_count++; + // break; + return 1; + } + else + { + msg_debug( "No (device_id 0x%02X)\n", device_id ); + + corsairlink_handle_close( scanlist[scanlist_count].handle ); + // continue; + return 2; + } + } + else + { + msg_debug( "Could not open device %d:%d.", desc.idVendor, desc.idProduct ); + } + } + return 0; +} + +int +corsairlink_device_enumerate( libusb_device* devices ) +{ + int rr; // This could be safely ignored. It is just a success flag for + // libusb functions. + + int ii; // Loops through USB devices. + int jj; // Loops through known CorsairLink Devices. + + if ( scanlist_count >= 10 ) + { + msg_debug( "Limited to 10 CorsairLink devices\n" ); + // break; + return -1; + } + + struct libusb_device_descriptor desc; + // libusb_device usb_device = devices[ii]; + rr = libusb_get_device_descriptor( devices, &desc ); + msg_debug( "Checking USB device %d (%04x:%04x)...\n", ii, desc.idVendor, desc.idProduct ); + + for ( jj = 0; jj < corsairlink_device_list_count; jj++ ) + { + // struct corsair_device_info* device; + // device = &corsairlink_devices[jj]; + rr = corsairlink_device_setup( devices, &corsairlink_devices[jj], desc ); + if ( rr == 1 ) + { + break; + } + else if (rr == 2 ) + { + continue; + } + // return rr; + } + return 0; +} + int corsairlink_device_scanner( libusb_context* context, int* _scanlist_count ) { @@ -72,79 +180,23 @@ corsairlink_device_scanner( libusb_context* context, int* _scanlist_count ) /* Start: scan code */ int ii; // Loops through USB devices. - int jj; // Loops through known CorsairLink Devices. ssize_t cnt; - struct corsair_device_info* device; + // struct corsair_device_info* device; libusb_device** devices; - uint16_t device_id = 0x00; + // uint16_t device_id = 0x00; // uint16_t firmware_id = 0x0000; cnt = libusb_get_device_list( context, &devices ); for ( ii = 0; ii < cnt; ii++ ) { - if ( scanlist_count >= 10 ) + rr = corsairlink_device_enumerate( devices[ii] ); + if ( rr == 1 ) { - msg_debug( "Limited to 10 CorsairLink devices\n" ); break; } - - struct libusb_device_descriptor desc; - rr = libusb_get_device_descriptor( devices[ii], &desc ); - msg_debug( "Checking USB device %d (%04x:%04x)...\n", ii, desc.idVendor, desc.idProduct ); - - for ( jj = 0; jj < corsairlink_device_list_count; jj++ ) + else if (rr == 2 ) { - device = &corsairlink_devices[jj]; - - if ( ( device->vendor_id == desc.idVendor ) - && ( device->product_id == desc.idProduct ) ) - { - msg_debug( "Corsair product detected. Checking if device is %s... ", device->name ); - rr = libusb_open( devices[ii], &scanlist[scanlist_count].handle ); - if ( scanlist[scanlist_count].handle != NULL ) - { // Maybe try 'if (rr == 0)' - rr = libusb_set_auto_detach_kernel_driver( scanlist[scanlist_count].handle, 1 ); - if ( rr != LIBUSB_SUCCESS ) - { - msg_err("Platform does not support kernel detachment\n"); - } - - rr = libusb_claim_interface( scanlist[scanlist_count].handle, 0 ); - if ( rr < 0 ) - { - msg_err("Unable to claim USB device interface\n"); - return rr; - } - - /* get device_id if we have a proper device handle */ - device->driver->device_id( - device, scanlist[scanlist_count].handle, &device_id ); - /* check to see if the device_id is the right one */ - if ( device->device_id == device_id ) - { - /* if we have the right device id we can setup the rest - * of the device connections - */ - scanlist[scanlist_count].device = device; - msg_info( - "Dev=%d, CorsairLink Device Found: %s!\n", scanlist_count, - device->name ); - scanlist_count++; - break; - } - else - { - msg_debug( "No (device_id 0x%02X)\n", device_id ); - - corsairlink_handle_close( scanlist[scanlist_count].handle ); - continue; - } - } - else - { - msg_debug( "Could not open device %d:%d.", desc.idVendor, desc.idProduct ); - } - } + continue; } } msg_info( "\n" ); From e94da3e20a7833572d11657304fc5256861694ed Mon Sep 17 00:00:00 2001 From: Audiohacked Date: Thu, 27 Jun 2019 18:39:25 -0600 Subject: [PATCH 2/9] Improve Error handling of libusb function calls --- logic/scan.c | 209 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 169 insertions(+), 40 deletions(-) diff --git a/logic/scan.c b/logic/scan.c index bea1ba1..b418f92 100644 --- a/logic/scan.c +++ b/logic/scan.c @@ -40,10 +40,62 @@ corsairlink_handle_close( struct libusb_device_handle* handle ) int rr; rr = libusb_release_interface( handle, 0 ); - if ( rr < 0 ) + if ( rr == LIBUSB_ERROR_NOT_FOUND ) + { + msg_debug("Interface Not Claimed on Corsair Device\n"); + // return rr; + } + else if ( rr == LIBUSB_ERROR_NO_DEVICE ) + { + msg_debug("Corsair Device has been Disconnected\n"); + } + else if ( rr < 0 ) + { + msg_debug("Encountered LibUSB Error!\n"); + } + else + { + msg_debug("Claimed Interface on Corsair Device\n"); + } + // if ( rr < 0 ) + // { + // msg_err("Unable to release USB interface\n"); + // } + + rr = libusb_attach_kernel_driver( handle, 0 ); + if ( rr == LIBUSB_ERROR_NOT_FOUND ) + { + msg_debug("no kernel driver active on Corsair Device\n"); + // return rr; + } + else if ( rr == LIBUSB_ERROR_INVALID_PARAM ) + { + msg_debug("No existing Interface for Corsair Device\n"); + } + else if ( rr == LIBUSB_ERROR_NO_DEVICE ) + { + msg_debug("Corsair Device has been Disconnected\n"); + } + else if ( rr == LIBUSB_ERROR_NOT_SUPPORTED ) + { + msg_debug("Unsupported Action on Platform\n"); + } + else if ( rr == LIBUSB_ERROR_BUSY ) + { + msg_debug("The driver cannot be attached because the interface is alread claimed\n"); + } + else if ( rr < 0 ) { - msg_err("Unable to release USB interface\n"); + msg_debug("Encountered LibUSB Error!\n"); } + else + { + msg_debug("Attached kernel driver from Corsair Device\n"); + } + // if ( rr < 0 ) + // { + // msg_debug("Unable to attach kernel driver to USB device\n"); + // } libusb_close( handle ); @@ -53,17 +105,46 @@ corsairlink_handle_close( struct libusb_device_handle* handle ) int corsairlink_close( libusb_context* context ) { + int rr; int ii; for ( ii = 0; ii < scanlist_count; ii++ ) { - corsairlink_handle_close( scanlist[ii].handle ); + rr = corsairlink_handle_close( scanlist[ii].handle ); } libusb_exit( context ); return 0; } +int +corsairlink_check_device_id( struct corsair_device_info* cl_device ) +{ + uint8_t device_id = 0x00; + + /* get device_id if we have a proper device handle */ + cl_device->driver->device_id( cl_device, scanlist[scanlist_count].handle, &device_id ); + /* check to see if the device_id is the right one */ + if ( cl_device->device_id == device_id ) + { + /* if we have the right device id we can setup the rest + * of the device connections + */ + scanlist[scanlist_count].device = cl_device; + msg_info( "Dev=%d, CorsairLink Device Found: %s!\n", scanlist_count, cl_device->name ); + scanlist_count++; + // break; + return 1; + } + else + { + msg_debug( "No (device_id 0x%02X)\n", device_id ); + corsairlink_handle_close( scanlist[scanlist_count].handle ); + // continue; + return 2; + } +} + int corsairlink_device_setup( libusb_device* device, @@ -73,61 +154,103 @@ corsairlink_device_setup( int rr; // This could be safely ignored. It is just a success flag for // libusb functions. // int ii; // Loops through USB devices. - uint8_t device_id = 0x00; - // struct corsair_device_info* device; // device = &corsairlink_devices[jj]; - if ( ( cl_device->vendor_id == desc.idVendor ) - && ( cl_device->product_id == desc.idProduct ) ) + if ( ( cl_device->vendor_id == desc.idVendor ) && ( cl_device->product_id == desc.idProduct ) ) { msg_debug( "Corsair product detected. Checking if device is %s... ", cl_device->name ); rr = libusb_open( device, &scanlist[scanlist_count].handle ); - if ( scanlist[scanlist_count].handle != NULL ) // Maybe try 'if (rr == 0)' + if ( rr == LIBUSB_ERROR_NO_MEM ) + { + msg_debug( "Memory Allocation Error\n" ); + } + else if ( rr == LIBUSB_ERROR_ACCESS ) + { + msg_debug( "Device Access (User Permissions) Error\n" ); + } + else if ( rr == LIBUSB_ERROR_NO_DEVICE ) + { + msg_debug( "Device Disconnected\n" ); + } + else if ( rr < 0 ) { + msg_debug( "Could not open device %d:%d.", desc.idVendor, desc.idProduct ); + } + else + { + rr = libusb_kernel_driver_active( scanlist[scanlist_count].handle, 0 ); + if ( rr == 0 ) + { + msg_debug("Corsair Device has no kernel driver attached\n"); + } + else if (rr == 1) + { + msg_debug("Corsair Device has kernel driver attached\n"); + return -255; + } + else + { + msg_debug("Encountered LibUSB Error!\n"); + return rr; + } + rr = libusb_detach_kernel_driver( scanlist[scanlist_count].handle, 0 ); - if ( rr < 0 ) + if ( rr == LIBUSB_ERROR_NOT_FOUND ) { - msg_debug("Unable to detach kernel driver from Corsair Device\n"); + msg_debug("no kernel driver active on Corsair Device\n"); // return rr; } + else if ( rr == LIBUSB_ERROR_INVALID_PARAM ) + { + msg_debug("No existing Interface for Corsair Device\n"); + } + else if ( rr == LIBUSB_ERROR_NO_DEVICE ) + { + msg_debug("Corsair Device has been Disconnected\n"); + } + else if ( rr == LIBUSB_ERROR_NOT_SUPPORTED ) + { + msg_debug("Unsupported Action on Platform\n"); + } + else if ( rr < 0 ) + { + msg_debug("Encountered LibUSB Error!\n"); + } + else + { + msg_debug("Detached kernel driver from Corsair Device\n"); + } rr = libusb_claim_interface( scanlist[scanlist_count].handle, 0 ); - if ( rr < 0 ) + if ( rr == LIBUSB_ERROR_NOT_FOUND ) { - msg_err("Unable to claim USB device interface\n"); - return rr; + msg_debug("no kernel driver active on Corsair Device\n"); + // return rr; } - - /* get device_id if we have a proper device handle */ - cl_device->driver->device_id( - cl_device, scanlist[scanlist_count].handle, &device_id ); - /* check to see if the device_id is the right one */ - if ( cl_device->device_id == device_id ) + else if ( rr == LIBUSB_ERROR_BUSY ) { - /* if we have the right device id we can setup the rest - * of the device connections - */ - scanlist[scanlist_count].device = cl_device; - msg_info( - "Dev=%d, CorsairLink Device Found: %s!\n", scanlist_count, - cl_device->name ); - scanlist_count++; - // break; - return 1; + msg_debug("Interface Busy for Corsair Device\n"); + } + else if ( rr == LIBUSB_ERROR_NO_DEVICE ) + { + msg_debug("Corsair Device has been Disconnected\n"); + } + else if ( rr < 0 ) + { + msg_debug("Encountered LibUSB Error!\n"); } else { - msg_debug( "No (device_id 0x%02X)\n", device_id ); - - corsairlink_handle_close( scanlist[scanlist_count].handle ); - // continue; - return 2; + msg_debug("Claimed Interface on Corsair Device\n"); } - } - else - { - msg_debug( "Could not open device %d:%d.", desc.idVendor, desc.idProduct ); + // if ( rr < 0 ) + // { + // msg_err("Unable to claim USB device interface\n"); + // return rr; + // } + + return corsairlink_check_device_id( cl_device ); } } return 0; @@ -139,7 +262,7 @@ corsairlink_device_enumerate( libusb_device* devices ) int rr; // This could be safely ignored. It is just a success flag for // libusb functions. - int ii; // Loops through USB devices. + // int ii; // Loops through USB devices. int jj; // Loops through known CorsairLink Devices. if ( scanlist_count >= 10 ) @@ -152,7 +275,13 @@ corsairlink_device_enumerate( libusb_device* devices ) struct libusb_device_descriptor desc; // libusb_device usb_device = devices[ii]; rr = libusb_get_device_descriptor( devices, &desc ); - msg_debug( "Checking USB device %d (%04x:%04x)...\n", ii, desc.idVendor, desc.idProduct ); + if ( rr < 0 ) + { + return rr; + } + + // msg_debug( "Checking USB device %d (%04x:%04x)...\n", ii, desc.idVendor, desc.idProduct ); + msg_debug( "Checking USB device (%04x:%04x)...\n", desc.idVendor, desc.idProduct ); for ( jj = 0; jj < corsairlink_device_list_count; jj++ ) { From 44747425f4b9926bbc234cc8882112cc27bd5c3e Mon Sep 17 00:00:00 2001 From: Audiohacked Date: Thu, 27 Jun 2019 19:09:46 -0600 Subject: [PATCH 3/9] Return from function on libusb failure --- logic/scan.c | 159 ++++++++++++++++++++++++++------------------------- 1 file changed, 82 insertions(+), 77 deletions(-) diff --git a/logic/scan.c b/logic/scan.c index b418f92..8ef2602 100644 --- a/logic/scan.c +++ b/logic/scan.c @@ -153,9 +153,6 @@ corsairlink_device_setup( { int rr; // This could be safely ignored. It is just a success flag for // libusb functions. - // int ii; // Loops through USB devices. - // struct corsair_device_info* device; - // device = &corsairlink_devices[jj]; if ( ( cl_device->vendor_id == desc.idVendor ) && ( cl_device->product_id == desc.idProduct ) ) { @@ -164,95 +161,103 @@ corsairlink_device_setup( if ( rr == LIBUSB_ERROR_NO_MEM ) { msg_debug( "Memory Allocation Error\n" ); + return rr; } else if ( rr == LIBUSB_ERROR_ACCESS ) { msg_debug( "Device Access (User Permissions) Error\n" ); + return rr; } else if ( rr == LIBUSB_ERROR_NO_DEVICE ) { msg_debug( "Device Disconnected\n" ); + return rr; } else if ( rr < 0 ) { msg_debug( "Could not open device %d:%d.", desc.idVendor, desc.idProduct ); + return rr; } else { - rr = libusb_kernel_driver_active( scanlist[scanlist_count].handle, 0 ); - if ( rr == 0 ) - { - msg_debug("Corsair Device has no kernel driver attached\n"); - } - else if (rr == 1) - { - msg_debug("Corsair Device has kernel driver attached\n"); - return -255; - } - else - { - msg_debug("Encountered LibUSB Error!\n"); - return rr; - } - - rr = libusb_detach_kernel_driver( scanlist[scanlist_count].handle, 0 ); - if ( rr == LIBUSB_ERROR_NOT_FOUND ) - { - msg_debug("no kernel driver active on Corsair Device\n"); - // return rr; - } - else if ( rr == LIBUSB_ERROR_INVALID_PARAM ) - { - msg_debug("No existing Interface for Corsair Device\n"); - } - else if ( rr == LIBUSB_ERROR_NO_DEVICE ) - { - msg_debug("Corsair Device has been Disconnected\n"); - } - else if ( rr == LIBUSB_ERROR_NOT_SUPPORTED ) - { - msg_debug("Unsupported Action on Platform\n"); - } - else if ( rr < 0 ) - { - msg_debug("Encountered LibUSB Error!\n"); - } - else - { - msg_debug("Detached kernel driver from Corsair Device\n"); - } - - rr = libusb_claim_interface( scanlist[scanlist_count].handle, 0 ); - if ( rr == LIBUSB_ERROR_NOT_FOUND ) - { - msg_debug("no kernel driver active on Corsair Device\n"); - // return rr; - } - else if ( rr == LIBUSB_ERROR_BUSY ) - { - msg_debug("Interface Busy for Corsair Device\n"); - } - else if ( rr == LIBUSB_ERROR_NO_DEVICE ) - { - msg_debug("Corsair Device has been Disconnected\n"); - } - else if ( rr < 0 ) - { - msg_debug("Encountered LibUSB Error!\n"); - } - else - { - msg_debug("Claimed Interface on Corsair Device\n"); - } - // if ( rr < 0 ) - // { - // msg_err("Unable to claim USB device interface\n"); - // return rr; - // } - - return corsairlink_check_device_id( cl_device ); + msg_debug( "Device Opened\n" ); + } + + rr = libusb_kernel_driver_active( scanlist[scanlist_count].handle, 0 ); + if (rr == 1) + { + msg_debug("Corsair Device has kernel driver attached\n"); + return -255; + } + else if ( rr == 0 ) + { + msg_debug("Corsair Device has no kernel driver attached\n"); + } + else + { + msg_debug("Encountered LibUSB Error!\n"); + return rr; + } + + rr = libusb_detach_kernel_driver( scanlist[scanlist_count].handle, 0 ); + if ( rr == LIBUSB_ERROR_NOT_FOUND ) + { + msg_debug("no kernel driver active on Corsair Device\n"); + } + else if ( rr == LIBUSB_ERROR_INVALID_PARAM ) + { + msg_debug("No existing Interface for Corsair Device\n"); + return rr; + } + else if ( rr == LIBUSB_ERROR_NO_DEVICE ) + { + msg_debug("Corsair Device has been Disconnected\n"); + return rr; + } + else if ( rr == LIBUSB_ERROR_NOT_SUPPORTED ) + { + msg_debug("Unsupported Action on Platform\n"); + return rr; + } + else if ( rr < 0 ) + { + msg_debug("Encountered LibUSB Error!\n"); + return rr; } + else + { + msg_debug("Detached kernel driver from Corsair Device\n"); + } + + rr = libusb_claim_interface( scanlist[scanlist_count].handle, 0 ); + if ( rr == LIBUSB_ERROR_NOT_FOUND ) + { + msg_debug("the requested interface does not exist on Corsair Device\n"); + return rr; + } + else if ( rr == LIBUSB_ERROR_BUSY ) + { + msg_debug("another program or driver has claimed the interface on Corsair Device\n"); + return rr; + } + else if ( rr == LIBUSB_ERROR_NO_DEVICE ) + { + msg_debug("Corsair Device has been Disconnected\n"); + return rr; + } + else if ( rr < 0 ) + { + msg_debug("Encountered LibUSB Error!\n"); + return rr; + } + else + { + msg_debug("Claimed Interface on Corsair Device\n"); + } + + return corsairlink_check_device_id( cl_device ); } + return 0; } @@ -261,8 +266,6 @@ corsairlink_device_enumerate( libusb_device* devices ) { int rr; // This could be safely ignored. It is just a success flag for // libusb functions. - - // int ii; // Loops through USB devices. int jj; // Loops through known CorsairLink Devices. if ( scanlist_count >= 10 ) @@ -277,6 +280,7 @@ corsairlink_device_enumerate( libusb_device* devices ) rr = libusb_get_device_descriptor( devices, &desc ); if ( rr < 0 ) { + msg_debug( "Device Descriptor Error\n" ); return rr; } @@ -298,6 +302,7 @@ corsairlink_device_enumerate( libusb_device* devices ) } // return rr; } + return 0; } From 517a681c095894e76a546e46ed02c41891aaa1f3 Mon Sep 17 00:00:00 2001 From: Audiohacked Date: Thu, 27 Jun 2019 19:51:18 -0600 Subject: [PATCH 4/9] found libusb_strerror() --- logic/scan.c | 152 +++++++-------------------------------------------- 1 file changed, 21 insertions(+), 131 deletions(-) diff --git a/logic/scan.c b/logic/scan.c index 8ef2602..af9dd5a 100644 --- a/logic/scan.c +++ b/logic/scan.c @@ -40,62 +40,16 @@ corsairlink_handle_close( struct libusb_device_handle* handle ) int rr; rr = libusb_release_interface( handle, 0 ); - if ( rr == LIBUSB_ERROR_NOT_FOUND ) - { - msg_debug("Interface Not Claimed on Corsair Device\n"); - // return rr; - } - else if ( rr == LIBUSB_ERROR_NO_DEVICE ) - { - msg_debug("Corsair Device has been Disconnected\n"); - } - else if ( rr < 0 ) - { - msg_debug("Encountered LibUSB Error!\n"); - } - else + if ( rr < 0 ) { - msg_debug("Claimed Interface on Corsair Device\n"); + msg_err( "Encountered LibUSB Error: %s\n", libusb_strerror( rr ) ); } - // if ( rr < 0 ) - // { - // msg_err("Unable to release USB interface\n"); - // } rr = libusb_attach_kernel_driver( handle, 0 ); - if ( rr == LIBUSB_ERROR_NOT_FOUND ) - { - msg_debug("no kernel driver active on Corsair Device\n"); - // return rr; - } - else if ( rr == LIBUSB_ERROR_INVALID_PARAM ) - { - msg_debug("No existing Interface for Corsair Device\n"); - } - else if ( rr == LIBUSB_ERROR_NO_DEVICE ) - { - msg_debug("Corsair Device has been Disconnected\n"); - } - else if ( rr == LIBUSB_ERROR_NOT_SUPPORTED ) - { - msg_debug("Unsupported Action on Platform\n"); - } - else if ( rr == LIBUSB_ERROR_BUSY ) - { - msg_debug("The driver cannot be attached because the interface is alread claimed\n"); - } - else if ( rr < 0 ) - { - msg_debug("Encountered LibUSB Error!\n"); - } - else + if ( rr < 0 ) { - msg_debug("Attached kernel driver from Corsair Device\n"); + msg_err( "Encountered LibUSB Error: %s\n", libusb_strerror( rr ) ); } - // if ( rr < 0 ) - // { - // msg_debug("Unable to attach kernel driver to USB device\n"); - // } libusb_close( handle ); @@ -120,10 +74,12 @@ corsairlink_close( libusb_context* context ) int corsairlink_check_device_id( struct corsair_device_info* cl_device ) { - uint8_t device_id = 0x00; + int rr; /* get device_id if we have a proper device handle */ + uint8_t device_id = 0x00; cl_device->driver->device_id( cl_device, scanlist[scanlist_count].handle, &device_id ); + /* check to see if the device_id is the right one */ if ( cl_device->device_id == device_id ) { @@ -133,15 +89,14 @@ corsairlink_check_device_id( struct corsair_device_info* cl_device ) scanlist[scanlist_count].device = cl_device; msg_info( "Dev=%d, CorsairLink Device Found: %s!\n", scanlist_count, cl_device->name ); scanlist_count++; - // break; - return 1; + return 1; // break; + } else { msg_debug( "No (device_id 0x%02X)\n", device_id ); - corsairlink_handle_close( scanlist[scanlist_count].handle ); - // continue; - return 2; + rr = corsairlink_handle_close( scanlist[scanlist_count].handle ); + return 2; // continue; } } @@ -154,40 +109,21 @@ corsairlink_device_setup( int rr; // This could be safely ignored. It is just a success flag for // libusb functions. - if ( ( cl_device->vendor_id == desc.idVendor ) && ( cl_device->product_id == desc.idProduct ) ) + if ( ( cl_device->vendor_id == desc.idVendor ) + && ( cl_device->product_id == desc.idProduct ) ) { msg_debug( "Corsair product detected. Checking if device is %s... ", cl_device->name ); rr = libusb_open( device, &scanlist[scanlist_count].handle ); - if ( rr == LIBUSB_ERROR_NO_MEM ) - { - msg_debug( "Memory Allocation Error\n" ); - return rr; - } - else if ( rr == LIBUSB_ERROR_ACCESS ) - { - msg_debug( "Device Access (User Permissions) Error\n" ); - return rr; - } - else if ( rr == LIBUSB_ERROR_NO_DEVICE ) + if ( rr < 0 ) { - msg_debug( "Device Disconnected\n" ); + msg_err( "Encountered LibUSB Error: %s\n", libusb_strerror( rr ) ); return rr; } - else if ( rr < 0 ) - { - msg_debug( "Could not open device %d:%d.", desc.idVendor, desc.idProduct ); - return rr; - } - else - { - msg_debug( "Device Opened\n" ); - } rr = libusb_kernel_driver_active( scanlist[scanlist_count].handle, 0 ); if (rr == 1) { msg_debug("Corsair Device has kernel driver attached\n"); - return -255; } else if ( rr == 0 ) { @@ -195,33 +131,14 @@ corsairlink_device_setup( } else { - msg_debug("Encountered LibUSB Error!\n"); + msg_debug("Encountered LibUSB Error: %s!\n", libusb_strerror( rr ) ); return rr; } rr = libusb_detach_kernel_driver( scanlist[scanlist_count].handle, 0 ); - if ( rr == LIBUSB_ERROR_NOT_FOUND ) - { - msg_debug("no kernel driver active on Corsair Device\n"); - } - else if ( rr == LIBUSB_ERROR_INVALID_PARAM ) - { - msg_debug("No existing Interface for Corsair Device\n"); - return rr; - } - else if ( rr == LIBUSB_ERROR_NO_DEVICE ) - { - msg_debug("Corsair Device has been Disconnected\n"); - return rr; - } - else if ( rr == LIBUSB_ERROR_NOT_SUPPORTED ) - { - msg_debug("Unsupported Action on Platform\n"); - return rr; - } - else if ( rr < 0 ) + if ( rr < 0 ) { - msg_debug("Encountered LibUSB Error!\n"); + msg_debug("Encountered LibUSB Error: %s!\n", libusb_strerror( rr ) ); return rr; } else @@ -230,24 +147,9 @@ corsairlink_device_setup( } rr = libusb_claim_interface( scanlist[scanlist_count].handle, 0 ); - if ( rr == LIBUSB_ERROR_NOT_FOUND ) + if ( rr < 0 ) { - msg_debug("the requested interface does not exist on Corsair Device\n"); - return rr; - } - else if ( rr == LIBUSB_ERROR_BUSY ) - { - msg_debug("another program or driver has claimed the interface on Corsair Device\n"); - return rr; - } - else if ( rr == LIBUSB_ERROR_NO_DEVICE ) - { - msg_debug("Corsair Device has been Disconnected\n"); - return rr; - } - else if ( rr < 0 ) - { - msg_debug("Encountered LibUSB Error!\n"); + msg_debug("Encountered LibUSB Error: %s!\n", libusb_strerror( rr ) ); return rr; } else @@ -276,7 +178,6 @@ corsairlink_device_enumerate( libusb_device* devices ) } struct libusb_device_descriptor desc; - // libusb_device usb_device = devices[ii]; rr = libusb_get_device_descriptor( devices, &desc ); if ( rr < 0 ) { @@ -289,8 +190,6 @@ corsairlink_device_enumerate( libusb_device* devices ) for ( jj = 0; jj < corsairlink_device_list_count; jj++ ) { - // struct corsair_device_info* device; - // device = &corsairlink_devices[jj]; rr = corsairlink_device_setup( devices, &corsairlink_devices[jj], desc ); if ( rr == 1 ) { @@ -315,7 +214,6 @@ corsairlink_device_scanner( libusb_context* context, int* _scanlist_count ) /* Start: scan code */ int ii; // Loops through USB devices. ssize_t cnt; - // struct corsair_device_info* device; libusb_device** devices; // uint16_t device_id = 0x00; // uint16_t firmware_id = 0x0000; @@ -323,15 +221,7 @@ corsairlink_device_scanner( libusb_context* context, int* _scanlist_count ) cnt = libusb_get_device_list( context, &devices ); for ( ii = 0; ii < cnt; ii++ ) { - rr = corsairlink_device_enumerate( devices[ii] ); - if ( rr == 1 ) - { - break; - } - else if (rr == 2 ) - { - continue; - } + corsairlink_device_enumerate( devices[ii] ); } msg_info( "\n" ); *_scanlist_count = scanlist_count; From 523b00ff2e653824d1f3e32f63cb18570d13170c Mon Sep 17 00:00:00 2001 From: Audiohacked Date: Thu, 27 Jun 2019 20:08:06 -0600 Subject: [PATCH 5/9] detach driver only if there is an active kernel driver --- logic/scan.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/logic/scan.c b/logic/scan.c index af9dd5a..09ba0b3 100644 --- a/logic/scan.c +++ b/logic/scan.c @@ -124,6 +124,18 @@ corsairlink_device_setup( if (rr == 1) { msg_debug("Corsair Device has kernel driver attached\n"); + + rr = libusb_detach_kernel_driver( scanlist[scanlist_count].handle, 0 ); + if ( rr < 0 ) + { + msg_debug("Encountered LibUSB Error: %s!\n", libusb_strerror( rr ) ); + return rr; + } + else + { + msg_debug("Detached kernel driver from Corsair Device\n"); + } + } else if ( rr == 0 ) { @@ -135,17 +147,6 @@ corsairlink_device_setup( return rr; } - rr = libusb_detach_kernel_driver( scanlist[scanlist_count].handle, 0 ); - if ( rr < 0 ) - { - msg_debug("Encountered LibUSB Error: %s!\n", libusb_strerror( rr ) ); - return rr; - } - else - { - msg_debug("Detached kernel driver from Corsair Device\n"); - } - rr = libusb_claim_interface( scanlist[scanlist_count].handle, 0 ); if ( rr < 0 ) { From 57dc2b3c86e723004ec24842fd5b9095b4d343df Mon Sep 17 00:00:00 2001 From: Audiohacked Date: Thu, 27 Jun 2019 20:39:18 -0600 Subject: [PATCH 6/9] minor fixes --- logic/scan.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/logic/scan.c b/logic/scan.c index 09ba0b3..ba6a7c8 100644 --- a/logic/scan.c +++ b/logic/scan.c @@ -42,13 +42,13 @@ corsairlink_handle_close( struct libusb_device_handle* handle ) rr = libusb_release_interface( handle, 0 ); if ( rr < 0 ) { - msg_err( "Encountered LibUSB Error: %s\n", libusb_strerror( rr ) ); + msg_err( "Encountered LibUSB Error: %s!\n", libusb_strerror( rr ) ); } rr = libusb_attach_kernel_driver( handle, 0 ); if ( rr < 0 ) { - msg_err( "Encountered LibUSB Error: %s\n", libusb_strerror( rr ) ); + msg_err( "Encountered LibUSB Error: %s!\n", libusb_strerror( rr ) ); } libusb_close( handle ); @@ -116,7 +116,7 @@ corsairlink_device_setup( rr = libusb_open( device, &scanlist[scanlist_count].handle ); if ( rr < 0 ) { - msg_err( "Encountered LibUSB Error: %s\n", libusb_strerror( rr ) ); + msg_err( "Encountered LibUSB Error: %s!\n", libusb_strerror( rr ) ); return rr; } @@ -147,6 +147,10 @@ corsairlink_device_setup( return rr; } + // libusb_reset_device() + // libusb_get_device() + // libusb_set_configuration() + rr = libusb_claim_interface( scanlist[scanlist_count].handle, 0 ); if ( rr < 0 ) { @@ -158,7 +162,13 @@ corsairlink_device_setup( msg_debug("Claimed Interface on Corsair Device\n"); } - return corsairlink_check_device_id( cl_device ); + // libusb_set_interface_alt_setting + // libusb_get_device_descriptor + // libusb_get_bus_number + // libusb_get_device_address + // libusb_get_string_descriptor_ascii + + // return corsairlink_check_device_id( cl_device ); } return 0; @@ -174,15 +184,14 @@ corsairlink_device_enumerate( libusb_device* devices ) if ( scanlist_count >= 10 ) { msg_debug( "Limited to 10 CorsairLink devices\n" ); - // break; - return -1; + return 1; // break; } struct libusb_device_descriptor desc; rr = libusb_get_device_descriptor( devices, &desc ); if ( rr < 0 ) { - msg_debug( "Device Descriptor Error\n" ); + msg_err( "Encountered LibUSB Error: %s!\n", libusb_strerror( rr ) ); return rr; } @@ -222,7 +231,11 @@ corsairlink_device_scanner( libusb_context* context, int* _scanlist_count ) cnt = libusb_get_device_list( context, &devices ); for ( ii = 0; ii < cnt; ii++ ) { - corsairlink_device_enumerate( devices[ii] ); + rr = corsairlink_device_enumerate( devices[ii] ); + if ( rr == 1 ) + { + break; + } } msg_info( "\n" ); *_scanlist_count = scanlist_count; From fbcc4cf24e13fd33b90886a5ac94ebacde5109e3 Mon Sep 17 00:00:00 2001 From: Audiohacked Date: Thu, 27 Jun 2019 20:40:30 -0600 Subject: [PATCH 7/9] don't comment the important function call... --- logic/scan.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/logic/scan.c b/logic/scan.c index ba6a7c8..ccae602 100644 --- a/logic/scan.c +++ b/logic/scan.c @@ -168,7 +168,7 @@ corsairlink_device_setup( // libusb_get_device_address // libusb_get_string_descriptor_ascii - // return corsairlink_check_device_id( cl_device ); + return corsairlink_check_device_id( cl_device ); } return 0; From 08be64469c867f9eb671411a2e89cea9cc72d003 Mon Sep 17 00:00:00 2001 From: Audiohacked Date: Fri, 28 Jun 2019 14:22:24 -0600 Subject: [PATCH 8/9] split options.h --- include/logic/options.h | 142 +------------------------------------ include/logic/suboptions.h | 120 +++++++++++++++++++++++++++++++ include/logic/support.h | 95 +++++++++++++++++++++++++ logic/options.c | 3 +- 4 files changed, 219 insertions(+), 141 deletions(-) create mode 100644 include/logic/suboptions.h create mode 100644 include/logic/support.h diff --git a/include/logic/options.h b/include/logic/options.h index 9aca2af..e5f940a 100644 --- a/include/logic/options.h +++ b/include/logic/options.h @@ -24,45 +24,8 @@ #include #include -struct color { - uint8_t red; - uint8_t green; - uint8_t blue; -}; - -struct led_temperatures { - uint8_t temp1; - uint8_t temp2; - uint8_t temp3; -}; - -enum led_modes { - STATIC = 0, - BLINK = 1, - PULSE = 2, - SHIFT = 3, - RAINBOW = 4, - TEMPERATURE = 5, -}; - -struct temp_speed_pair { - /** temperature */ - int8_t temperature; - - /** fan speed PWM */ - int8_t speed; -}; - -enum motor_modes { - PWM = 0, - RPM = 1, - DEFAULT = 2, - QUIET = 3, - BALANCED = 4, - PERFORMANCE = 5, - CUSTOM = 6, - UNDEFINED = 7, -}; +#include "logic/support.h" +#include "logic/suboptions.h" struct option_flags { // flags @@ -73,47 +36,6 @@ struct option_flags { unsigned int set_pump : 1; }; -struct led_control { - uint8_t channel; - enum led_modes mode; - struct color led_colors[7]; - uint16_t temperatures[3]; - uint8_t speed; - uint8_t count; - uint8_t led_type; // commanderpro - uint8_t direction; // commanderpro - uint8_t change_style; // commanderpro -}; - -struct fan_control { - uint8_t channel; - enum motor_modes mode; - struct temp_speed_pair table[7]; - - // data returns - uint8_t fan_count; - uint8_t fan_type; - uint8_t temp_sensor_id; - uint16_t data; - uint16_t speed; - uint8_t speed_pwm; - uint16_t speed_rpm; - uint16_t max_speed; - char mode_string[64]; -}; - -struct pump_control { - uint8_t channel; - enum motor_modes mode; - struct temp_speed_pair table[6]; - - // data returns - uint16_t speed; - uint8_t speed_pwm; - uint16_t speed_rpm; - uint16_t max_speed; -}; - struct option_parse_return { struct led_control led_ctrl; struct fan_control fan_ctrl; @@ -177,66 +99,6 @@ static struct option long_options[] = { xx[6].green = 0x00; \ xx[6].blue = 0xff; -enum { - SUBOPTION_FAN_CHANNEL = 0, - SUBOPTION_FAN_MODE, - SUBOPTION_FAN_PWM, - SUBOPTION_FAN_RPM, - SUBOPTION_FAN_TEMPERATURES, - SUBOPTION_FAN_SPEEDS, - SUBOPTION_FAN_LIST_END, -}; - -enum { - SUBOPTION_LED_CHANNEL = 0, - SUBOPTION_LED_MODE, - SUBOPTION_LED_SPEED, - SUBOPTION_LED_COLORS, - SUBOPTION_LED_WARN, - SUBOPTION_LED_TEMPERATURES, - SUBOPTION_LED_LIST_END, -}; - -enum { - SUBOPTION_PUMP_MODE = 0, - SUBOPTION_PUMP_PWM, - SUBOPTION_PUMP_RPM, - SUBOPTION_PUMP_TEMPERATURES, - SUBOPTION_PUMP_SPEEDS, - SUBOPTION_PUMP_LIST_END, -}; - -static char *fan_options[] = {[SUBOPTION_FAN_CHANNEL] = "channel", - [SUBOPTION_FAN_MODE] = "mode", - [SUBOPTION_FAN_PWM] = "pwm", - [SUBOPTION_FAN_RPM] = "rpm", - [SUBOPTION_FAN_TEMPERATURES] = "temps", - [SUBOPTION_FAN_SPEEDS] = "speeds", - [SUBOPTION_FAN_LIST_END] = 0}; - -static char *led_options[] = {[SUBOPTION_LED_CHANNEL] = "channel", - [SUBOPTION_LED_MODE] = "mode", - [SUBOPTION_LED_SPEED] = "speed", - [SUBOPTION_LED_COLORS] = "colors", - [SUBOPTION_LED_WARN] = "warning_color", - [SUBOPTION_LED_TEMPERATURES] = "temps", - [SUBOPTION_LED_LIST_END] = 0}; - -static char *pump_options[] = {[SUBOPTION_PUMP_MODE] = "mode", - [SUBOPTION_PUMP_PWM] = "pwm", - [SUBOPTION_PUMP_RPM] = "rpm", - [SUBOPTION_PUMP_TEMPERATURES] = "temps", - [SUBOPTION_PUMP_SPEEDS] = "speeds", - [SUBOPTION_PUMP_LIST_END] = 0}; - -void fan_suboptions_parse(char *subopts, struct fan_control *settings); -void led_suboptions_parse(char *subopts, struct led_control *settings); -void pump_suboptions_parse(char *subopts, struct pump_control *settings); - -void fan_control_init(struct fan_control *settings); -void led_control_init(struct led_control *settings); -void pump_control_init(struct pump_control *settings); - void options_print(void); int options_parse(int argc, char **argv, struct option_flags *flags, diff --git a/include/logic/suboptions.h b/include/logic/suboptions.h new file mode 100644 index 0000000..42a1490 --- /dev/null +++ b/include/logic/suboptions.h @@ -0,0 +1,120 @@ +/* + * This file is part of OpenCorsairLink. + * Copyright (C) 2017-2019 Sean Nelson + + * OpenCorsairLink is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * any later version. + + * OpenCorsairLink is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with OpenCorsairLink. If not, see . + */ + +#ifndef _SUBOPTIONS_H +#define _SUBOPTIONS_H + +enum { + SUBOPTION_FAN_CHANNEL = 0, + SUBOPTION_FAN_MODE, + SUBOPTION_FAN_PWM, + SUBOPTION_FAN_RPM, + SUBOPTION_FAN_TEMPERATURES, + SUBOPTION_FAN_SPEEDS, + SUBOPTION_FAN_LIST_END, +}; + +enum { + SUBOPTION_LED_CHANNEL = 0, + SUBOPTION_LED_MODE, + SUBOPTION_LED_SPEED, + SUBOPTION_LED_COLORS, + SUBOPTION_LED_WARN, + SUBOPTION_LED_TEMPERATURES, + SUBOPTION_LED_LIST_END, +}; + +enum { + SUBOPTION_PUMP_MODE = 0, + SUBOPTION_PUMP_PWM, + SUBOPTION_PUMP_RPM, + SUBOPTION_PUMP_TEMPERATURES, + SUBOPTION_PUMP_SPEEDS, + SUBOPTION_PUMP_LIST_END, +}; + +struct led_control { + uint8_t channel; + enum led_modes mode; + struct color led_colors[7]; + uint16_t temperatures[3]; + uint8_t speed; + uint8_t count; +}; + +struct fan_control { + uint8_t channel; + enum motor_modes mode; + struct temp_speed_pair table[7]; + + // data returns + uint8_t fan_count; + uint8_t fan_type; + uint8_t temp_sensor_id; + uint16_t data; + uint16_t speed; + uint8_t speed_pwm; + uint16_t speed_rpm; + uint16_t max_speed; + char mode_string[64]; +}; + +struct pump_control { + uint8_t channel; + enum motor_modes mode; + struct temp_speed_pair table[6]; + + // data returns + uint16_t speed; + uint8_t speed_pwm; + uint16_t speed_rpm; + uint16_t max_speed; +}; + +static char *fan_options[] = {[SUBOPTION_FAN_CHANNEL] = "channel", + [SUBOPTION_FAN_MODE] = "mode", + [SUBOPTION_FAN_PWM] = "pwm", + [SUBOPTION_FAN_RPM] = "rpm", + [SUBOPTION_FAN_TEMPERATURES] = "temps", + [SUBOPTION_FAN_SPEEDS] = "speeds", + [SUBOPTION_FAN_LIST_END] = 0}; + +static char *led_options[] = {[SUBOPTION_LED_CHANNEL] = "channel", + [SUBOPTION_LED_MODE] = "mode", + [SUBOPTION_LED_SPEED] = "speed", + [SUBOPTION_LED_COLORS] = "colors", + [SUBOPTION_LED_WARN] = "warning_color", + [SUBOPTION_LED_TEMPERATURES] = "temps", + [SUBOPTION_LED_LIST_END] = 0}; + +static char *pump_options[] = {[SUBOPTION_PUMP_MODE] = "mode", + [SUBOPTION_PUMP_PWM] = "pwm", + [SUBOPTION_PUMP_RPM] = "rpm", + [SUBOPTION_PUMP_TEMPERATURES] = "temps", + [SUBOPTION_PUMP_SPEEDS] = "speeds", + [SUBOPTION_PUMP_LIST_END] = 0}; + +void fan_suboptions_parse(char *subopts, struct fan_control *settings); +void led_suboptions_parse(char *subopts, struct led_control *settings); +void pump_suboptions_parse(char *subopts, struct pump_control *settings); + +void fan_control_init(struct fan_control *settings); +void led_control_init(struct led_control *settings); +void pump_control_init(struct pump_control *settings); + +#endif diff --git a/include/logic/support.h b/include/logic/support.h new file mode 100644 index 0000000..c1ad558 --- /dev/null +++ b/include/logic/support.h @@ -0,0 +1,95 @@ +/* + * This file is part of OpenCorsairLink. + * Copyright (C) 2017-2019 Sean Nelson + + * OpenCorsairLink is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * any later version. + + * OpenCorsairLink is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + + * You should have received a copy of the GNU General Public License + * along with OpenCorsairLink. If not, see . + */ + +#ifndef _SUPPORT_H +#define _SUPPORT_H + +struct color { + uint8_t red; + uint8_t green; + uint8_t blue; +}; + +struct led_temperatures { + uint8_t temp1; + uint8_t temp2; + uint8_t temp3; +}; + +enum led_modes { + STATIC = 0, + BLINK = 1, + PULSE = 2, + SHIFT = 3, + RAINBOW = 4, + TEMPERATURE = 5, +}; + +struct temp_speed_pair { + /** temperature */ + int8_t temperature; + + /** fan speed PWM */ + int8_t speed; +}; + +enum motor_modes { + PWM = 0, + RPM = 1, + DEFAULT = 2, + QUIET = 3, + BALANCED = 4, + PERFORMANCE = 5, + CUSTOM = 6, + UNDEFINED = 7, +}; + +#define INIT_WARNING_LED(xx) \ + xx.red = 0xFF; \ + xx.green = 0x00; \ + xx.blue = 0x00; + +#define INIT_DEFAULT_LED(xx) \ + xx.red = 0xFF; \ + xx.green = 0xFF; \ + xx.blue = 0x00; + +#define INIT_RAINBOW_LED(xx) \ + xx[0].red = 0xff; \ + xx[0].green = 0x00; \ + xx[0].blue = 0x00; \ + xx[1].red = 0xff; \ + xx[1].green = 0x80; \ + xx[1].blue = 0x00; \ + xx[2].red = 0xff; \ + xx[2].green = 0xff; \ + xx[2].blue = 0x00; \ + xx[3].red = 0x00; \ + xx[3].green = 0xff; \ + xx[3].blue = 0x00; \ + xx[4].red = 0x00; \ + xx[4].green = 0x00; \ + xx[4].blue = 0xff; \ + xx[5].red = 0x4b; \ + xx[5].green = 0x00; \ + xx[5].blue = 0x82; \ + xx[6].red = 0x7f; \ + xx[6].green = 0x00; \ + xx[6].blue = 0xff; + +#endif diff --git a/logic/options.c b/logic/options.c index 6f3ad0c..10c05a7 100644 --- a/logic/options.c +++ b/logic/options.c @@ -16,7 +16,8 @@ * along with OpenCorsairLink. If not, see . */ -#include "common.h" +// #include "logic/support.h" +// #include "logic/suboptions.h" #include "logic/options.h" #include "logic/print.h" From fc88731ca805bb940c9e686511392fb91332b092 Mon Sep 17 00:00:00 2001 From: Audiohacked Date: Mon, 25 May 2020 10:27:25 -0600 Subject: [PATCH 9/9] fix device_id size --- logic/scan.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/logic/scan.c b/logic/scan.c index ccae602..686408e 100644 --- a/logic/scan.c +++ b/logic/scan.c @@ -77,7 +77,7 @@ corsairlink_check_device_id( struct corsair_device_info* cl_device ) int rr; /* get device_id if we have a proper device handle */ - uint8_t device_id = 0x00; + uint16_t device_id = 0x00; cl_device->driver->device_id( cl_device, scanlist[scanlist_count].handle, &device_id ); /* check to see if the device_id is the right one */ @@ -225,8 +225,6 @@ corsairlink_device_scanner( libusb_context* context, int* _scanlist_count ) int ii; // Loops through USB devices. ssize_t cnt; libusb_device** devices; - // uint16_t device_id = 0x00; - // uint16_t firmware_id = 0x0000; cnt = libusb_get_device_list( context, &devices ); for ( ii = 0; ii < cnt; ii++ )