diff --git a/test_com.c b/test_com.c index 21f8fe8..cd7552a 100644 --- a/test_com.c +++ b/test_com.c @@ -2,6 +2,9 @@ #include #include +#define ID_VENDOR 0x0951 +#define ID_PRODUCT 0x01666 + // gcc file.c -l usb-1.0 int main(){ @@ -40,12 +43,10 @@ int main(){ // detach kernel for(int j=0; jbNumInterfaces; j++){ - for(int k=0; kinterface[j].num_altsetting; k++){ - int interface = config_desc->interface[j].altsetting[k].bInterfaceNumber; - if(libusb_kernel_driver_active(handle, interface)){ - status = libusb_detach_kernel_driver(handle, interface); - if(status != 0){ perror("libusb_detach_kernel_driver"); exit(-1); } - } + int interface = config_desc->interface[j].altsetting[0].bInterfaceNumber; + if(libusb_kernel_driver_active(handle, interface)){ + status = libusb_detach_kernel_driver(handle, interface); + if(status != 0){ perror("libusb_detach_kernel_driver"); exit(-1); } } } @@ -55,23 +56,23 @@ int main(){ // claim interfaces for(int j=0; jbNumInterfaces; j++){ - for(int k=0; kinterface[j].num_altsetting; k++){ - int interface = config_desc->interface[j].altsetting[k].bInterfaceNumber; - status = libusb_claim_interface(handle, interface); - if(status != 0){ perror("libusb_claim_interface"); exit(-1); } - } - } - - /* ... some code ... */ - // TODO endpoints - - // release interfaces - for(int j=0; jbNumInterfaces; j++){ - for(int k=0; kinterface[j].num_altsetting; k++){ - int interface = config_desc->interface[j].altsetting[k].bInterfaceNumber; - status = libusb_release_interface(handle, interface); - if(status != 0){ perror("libusb_release_interface"); exit(-1); } + libusb_interface_descriptor *interface_desc = config_desc->interface[j].altsetting[0]; + + int interface = interface_desc->bInterfaceNumber; + status = libusb_claim_interface(handle, interface); + if(status != 0){ perror("libusb_claim_interface"); exit(-1); } + + // find endpoints + for(int k=0; kbNumEndpoints; k++){ + libusb_endpoint_descriptor *endpoint_desc = interface_desc->endpoints + + /* ... some code ... */ + // TODO what to do next ? } + + // release interfaces + status = libusb_release_interface(handle, interface); + if(status != 0){ perror("libusb_release_interface"); exit(-1); } } // free config diff --git a/test_list_all.c b/test_list_all.c new file mode 100644 index 0000000..adf19e1 --- /dev/null +++ b/test_list_all.c @@ -0,0 +1,34 @@ +#include +#include +#include + +// gcc file.c -l usb-1.0 + +int main(){ + // init + libusb_context *context; + int status = libusb_init(&context); + if(status != 0){perror("libusb_init"); exit(-1);} + + // devices list + libusb_device **devices; + ssize_t devices_count = libusb_get_device_list(context, &devices); + if(devices_count < 0){perror("libusb_get_device_list");exit(-1);} + for(int i=0; i