Hi.
I have fixed this. There were two problems in usb_comm.c when the update to libusb1.0:
1) It seems libusb1.0 changes the addres of the endpoint to talk to. The code made a bit operation that makes the device unachievable.
2) There were core code of libusb that only was execute with the -v (verbose) option, because an incorrect conditional anidation.
The patch I attach fix the two problems and works for me (now with libusb1.0 :P). I have tested garmin_get_info, garmin_save_runs and garmin_gpx. If you need more information about this fix, please, feel free to ask.
Thanks. :)
diff --git a/src/usb_comm.c b/src/usb_comm.c index f00f6d9..9c5afa3 100644 --- a/src/usb_comm.c +++ b/src/usb_comm.c @@ -72,9 +72,8 @@ garmin_open ( garmin_unit * garmin ) } } cnt = libusb_get_device_list(ctx,&dl); - + for (i = 0; i < cnt; ++i) { - { struct libusb_device_descriptor descriptor; struct libusb_config_descriptor *config; @@ -97,22 +96,28 @@ garmin_open ( garmin_unit * garmin ) if ( err ) { printf("libusb_open failed: %s\n",libusb_error_name(err)); garmin->usb.handle = NULL; - } else if ( garmin->verbose != 0 ) { - printf("[garmin] libusb_open = %p\n",garmin->usb.handle); + } else { + if ( garmin->verbose != 0 ) { + printf("[garmin] libusb_open = %p\n",garmin->usb.handle); + } - err = libusb_set_configuration(garmin->usb.handle,1); + err = libusb_set_configuration(garmin->usb.handle,1); if ( err ) { - printf("libusb_set_configuration failed: %s\n", + printf("libusb_set_configuration failed: %s\n", libusb_error_name(err)); - } else if ( garmin->verbose != 0 ) { - printf("[garmin] libusb_set_configuration[1] succeeded\n"); + } else { + if ( garmin->verbose != 0 ) { + printf("[garmin] libusb_set_configuration[1] succeeded\n"); + } err = libusb_claim_interface(garmin->usb.handle,0); if ( err ) { printf("libusb_claim_interface failed: %s\n", libusb_error_name(err)); - } else if ( garmin->verbose != 0 ) { - printf("[garmin] libusb_claim_interface[0] succeeded\n"); + } else { + if ( garmin->verbose != 0 ) { + printf("[garmin] libusb_claim_interface[0] succeeded\n"); + } err = libusb_get_config_descriptor_by_value(di,1,&config); if ( err ) { @@ -127,12 +132,10 @@ garmin_open ( garmin_unit * garmin ) } if ( !err ) { - /* We've succeeded in opening and claiming the interface Let's set the bulk and interrupt in and out endpoints. */ - for ( i = 0; i < config->interface->altsetting->bNumEndpoints; i++ ) { @@ -142,25 +145,22 @@ garmin_open ( garmin_unit * garmin ) switch ( ep->bmAttributes & LIBUSB_TRANSFER_TYPE_MASK ) { case LIBUSB_TRANSFER_TYPE_BULK: if ( ep->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK ) { - garmin->usb.bulk_in = - ep->bEndpointAddress & LIBUSB_ENDPOINT_ADDRESS_MASK; + garmin->usb.bulk_in = ep->bEndpointAddress; if ( garmin->verbose != 0 ) { - printf("[garmin] bulk IN = %d\n",garmin->usb.bulk_in); + printf("[garmin] bulk IN = 0x%02x\n",garmin->usb.bulk_in); } } else { - garmin->usb.bulk_out = - ep->bEndpointAddress & LIBUSB_ENDPOINT_ADDRESS_MASK; + garmin->usb.bulk_out = ep->bEndpointAddress; if ( garmin->verbose != 0 ) { - printf("[garmin] bulk OUT = %d\n",garmin->usb.bulk_out); + printf("[garmin] bulk OUT = 0x%02x\n",garmin->usb.bulk_out); } } break; case LIBUSB_TRANSFER_TYPE_INTERRUPT: if ( ep->bEndpointAddress & LIBUSB_ENDPOINT_DIR_MASK ) { - garmin->usb.intr_in = - ep->bEndpointAddress & LIBUSB_ENDPOINT_ADDRESS_MASK; + garmin->usb.intr_in = ep->bEndpointAddress; if ( garmin->verbose != 0 ) { - printf("[garmin] intr IN = %d\n",garmin->usb.intr_in); + printf("[garmin] intr IN = 0x%02x\n",garmin->usb.intr_in); } } break; @@ -174,10 +174,10 @@ garmin_open ( garmin_unit * garmin ) break; } - } if ( garmin->usb.handle != NULL ) break; } + libusb_free_device_list (dl, 1); } @@ -187,6 +187,7 @@ garmin_open ( garmin_unit * garmin ) it to NULL. */ + if ( garmin->usb.handle != NULL && err != 0 ) { if ( garmin->verbose != 0 ) { printf("[garmin] (err = %d) libusb_close(%p)\n",err,garmin->usb.handle); @@ -273,6 +274,7 @@ garmin_read ( garmin_unit * garmin, garmin_packet * p ) sizeof(garmin_packet), &r, INTR_TIMEOUT); + /* If the packet is a "Pid_Data_Available" packet, we need to read from the bulk endpoint until we get an empty packet. @@ -293,6 +295,7 @@ garmin_read ( garmin_unit * garmin, garmin_packet * p ) sizeof(garmin_packet), &r, BULK_TIMEOUT); + } } @@ -325,6 +328,7 @@ garmin_write ( garmin_unit * garmin, garmin_packet * p ) s, &r, BULK_TIMEOUT); + if ( r != s ) { printf("libusb_bulk_write failed: %s\n",libusb_error_name(err)); exit(1); @@ -352,7 +356,7 @@ garmin_start_session ( garmin_unit * garmin ) } else { garmin->id = 0; } - + return garmin->id; }