/* Not in all libusb-1.0 versions, so we have to roll our own :-( */
static char * usb_strerror(int e)
/* Not in all libusb-1.0 versions, so we have to roll our own :-( */
static char * usb_strerror(int e)
err = libusb_open(dev, &devh);
if (err) {
fprintf(stderr, "Can't open device: %s\n", usb_strerror(err));
err = libusb_open(dev, &devh);
if (err) {
fprintf(stderr, "Can't open device: %s\n", usb_strerror(err));
return NULL;
}
err = libusb_detach_kernel_driver(devh, INTERFACE);
if ((err != 0) && (err != LIBUSB_ERROR_NOT_FOUND)) {
fprintf(stderr, "Can't detach kernel driver: %s\n", usb_strerror(err));
return NULL;
}
err = libusb_detach_kernel_driver(devh, INTERFACE);
if ((err != 0) && (err != LIBUSB_ERROR_NOT_FOUND)) {
fprintf(stderr, "Can't detach kernel driver: %s\n", usb_strerror(err));
return NULL;
}
err = libusb_claim_interface(devh, INTERFACE);
if ((err != 0)) {
fprintf(stderr, "Can't claim interface: %s\n", usb_strerror(err));
return NULL;
}
err = libusb_claim_interface(devh, INTERFACE);
if ((err != 0)) {
fprintf(stderr, "Can't claim interface: %s\n", usb_strerror(err));
-static struct libusb_transfer *hmcfgusb_prepare_int(libusb_device_handle *devh, libusb_transfer_cb_fn cb, void *data)
+static struct libusb_transfer *hmcfgusb_prepare_int(libusb_device_handle *devh, libusb_transfer_cb_fn cb, void *data, int in_size)
}
libusb_fill_interrupt_transfer(transfer, devh, EP_IN,
}
libusb_fill_interrupt_transfer(transfer, devh, EP_IN,
- data_buf, ASYNC_SIZE, cb, data, USB_TIMEOUT);
+ data_buf, in_size, cb, data, USB_TIMEOUT);
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
if (transfer->status != LIBUSB_TRANSFER_TIMED_OUT) {
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
if (transfer->status != LIBUSB_TRANSFER_TIMED_OUT) {
- fprintf(stderr, "Interrupt transfer not completed: %s!\n", usb_strerror(transfer->status));
- quit = EIO;
+ if (transfer->status != LIBUSB_TRANSFER_CANCELLED)
+ fprintf(stderr, "Interrupt transfer not completed: %s!\n", usb_strerror(transfer->status));
err = libusb_submit_transfer(transfer);
if (err != 0) {
fprintf(stderr, "Can't re-submit transfer: %s\n", usb_strerror(err));
err = libusb_submit_transfer(transfer);
if (err != 0) {
fprintf(stderr, "Can't re-submit transfer: %s\n", usb_strerror(err));
- libusb_free_transfer(transfer);
- cb_data->dev->transfer = NULL;
+ goto out;
+ }
+
+ return;
+
+out:
+ libusb_free_transfer(transfer);
+ if (cb_data) {
+ if (cb_data->dev && cb_data->dev->transfer) {
+ cb_data->dev->transfer = NULL;
+ }
- err = libusb_init(NULL);
- if (err != 0) {
- fprintf(stderr, "Can't initialize libusb: %s\n", usb_strerror(err));
- return NULL;
+ if (!libusb_initialized) {
+ err = libusb_init(NULL);
+ if (err != 0) {
+ fprintf(stderr, "Can't initialize libusb: %s\n", usb_strerror(err));
+ return NULL;
+ }
devh = hmcfgusb_find(ID_VENDOR, ID_PRODUCT);
if (!devh) {
devh = hmcfgusb_find(ID_VENDOR, ID_PRODUCT_BL);
if (!devh) {
fprintf(stderr, "Can't find/open hmcfgusb!\n");
devh = hmcfgusb_find(ID_VENDOR, ID_PRODUCT);
if (!devh) {
devh = hmcfgusb_find(ID_VENDOR, ID_PRODUCT_BL);
if (!devh) {
fprintf(stderr, "Can't find/open hmcfgusb!\n");
- dev->transfer = hmcfgusb_prepare_int(devh, hmcfgusb_interrupt, cb_data);
+ dev->transfer = hmcfgusb_prepare_int(devh, hmcfgusb_interrupt, cb_data, ASYNC_SIZE);
+
return NULL;
}
usb_pfd = libusb_get_pollfds(NULL);
if (!usb_pfd) {
fprintf(stderr, "Can't get FDset from libusb!\n");
return NULL;
}
usb_pfd = libusb_get_pollfds(NULL);
if (!usb_pfd) {
fprintf(stderr, "Can't get FDset from libusb!\n");
dev->pfd = malloc(dev->n_usb_pfd * sizeof(struct pollfd));
if (!dev->pfd) {
perror("Can't allocate memory for poll-fds");
dev->pfd = malloc(dev->n_usb_pfd * sizeof(struct pollfd));
if (!dev->pfd) {
perror("Can't allocate memory for poll-fds");