/* HM-CFG-USB libusb-driver
*
- * Copyright (c) 2013 Michael Gernoth <michael@gernoth.net>
+ * Copyright (c) 2013-16 Michael Gernoth <michael@gernoth.net>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to
static int libusb_initialized = 0;
/* Not in all libusb-1.0 versions, so we have to roll our own :-( */
-static char * usb_strerror(int e)
+static const char* usb_strerror(int e)
{
static char unknerr[256];
return unknerr;
}
+static const char* usb_str_transfer_status(int e)
+{
+ static char unknerr[256];
+
+ switch (e) {
+ case LIBUSB_TRANSFER_COMPLETED:
+ return "Transfer completed";
+ case LIBUSB_TRANSFER_ERROR:
+ return "Transfer error";
+ case LIBUSB_TRANSFER_TIMED_OUT:
+ return "Transfer timed out";
+ case LIBUSB_TRANSFER_CANCELLED:
+ return "Transfer cancelled";
+ case LIBUSB_TRANSFER_STALL:
+ return "For bulk/interrupt endpoints: endpoint stalled. For control endpoints: control request not supported.";
+ case LIBUSB_TRANSFER_NO_DEVICE:
+ return "No device";
+ case LIBUSB_TRANSFER_OVERFLOW:
+ return "Transfer overflow";
+ };
+ snprintf(unknerr, sizeof(unknerr), "Unknown transfer status %d / 0x%02x", e, e);
+ return unknerr;
+}
+
static libusb_device_handle *hmcfgusb_find(int vid, int pid, char *serial) {
libusb_device_handle *devh = NULL;
libusb_device **list;
if (transfer->status != LIBUSB_TRANSFER_COMPLETED) {
if (transfer->status != LIBUSB_TRANSFER_TIMED_OUT) {
if (transfer->status != LIBUSB_TRANSFER_CANCELLED)
- fprintf(stderr, "Interrupt transfer not completed: %s!\n", usb_strerror(transfer->status));
+ fprintf(stderr, "Interrupt transfer not completed: %s!\n", usb_str_transfer_status(transfer->status));
quit = EIO;
goto out;