summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNikolai Kondrashov <spbnick@gmail.com>2010-07-21 08:10:10 +0000
committerNikolai Kondrashov <spbnick@gmail.com>2010-07-21 08:10:10 +0000
commit1c4d8790aa0283eae85b0f85d8c2ede0eab9cf2c (patch)
tree5de1cde565b9704d580a739f2dbf8036f0d4ae34
parent44a3ec34e675b940b36496a271f24ef6fc8085e0 (diff)
downloadusbhid-dump-1c4d8790aa0283eae85b0f85d8c2ede0eab9cf2c.tar.gz
Fixed stream dumping.
-rw-r--r--include/hid_dump/iface.h28
-rw-r--r--lib/iface.c34
-rw-r--r--src/hid-dump.c12
3 files changed, 47 insertions, 27 deletions
diff --git a/include/hid_dump/iface.h b/include/hid_dump/iface.h
index 58cd63c..5348681 100644
--- a/include/hid_dump/iface.h
+++ b/include/hid_dump/iface.h
@@ -38,21 +38,27 @@ typedef struct hid_dump_iface hid_dump_iface;
struct hid_dump_iface {
hid_dump_iface *next;
- libusb_device_handle *handle; /**< Device handle */
- uint8_t number; /**< Interface number */
- uint8_t int_in_ep; /**< Interrupt IN EP address */
- bool detached; /**< True if the interface was
- detached from the kernel
- driver, false otherwise */
- bool claimed; /**< True if the interface was
- claimed */
+ libusb_device_handle *handle; /**< Device handle */
+ uint8_t number; /**< Interface number */
+ uint8_t int_in_ep_addr; /**< Interrupt IN EP address */
+ uint16_t int_in_ep_maxp; /**< Interrupt IN EP maximum
+ packet size */
+ bool detached; /**< True if the interface was
+ detached from the kernel
+ driver, false otherwise */
+ bool claimed; /**< True if the interface was
+ claimed */
};
extern bool hid_dump_iface_valid(const hid_dump_iface *iface);
-extern hid_dump_iface *hid_dump_iface_new(libusb_device_handle *handle,
- uint8_t number,
- uint8_t int_in_ep);
+extern hid_dump_iface *hid_dump_iface_new(
+ libusb_device_handle *handle,
+ uint8_t number,
+ uint8_t int_in_ep_addr,
+ uint16_t int_in_ep_maxp);
+
+extern void hid_dump_iface_free(hid_dump_iface *iface);
extern bool hid_dump_iface_list_valid(const hid_dump_iface *list);
diff --git a/lib/iface.c b/lib/iface.c
index 41b1630..f78fef5 100644
--- a/lib/iface.c
+++ b/lib/iface.c
@@ -40,7 +40,8 @@ hid_dump_iface_valid(const hid_dump_iface *iface)
hid_dump_iface *
hid_dump_iface_new(libusb_device_handle *handle,
uint8_t number,
- uint8_t int_in_ep)
+ uint8_t int_in_ep_addr,
+ uint16_t int_in_ep_maxp)
{
hid_dump_iface *iface;
@@ -48,17 +49,30 @@ hid_dump_iface_new(libusb_device_handle *handle,
if (iface == NULL)
return NULL;
- iface->next = NULL;
- iface->handle = handle;
- iface->number = number;
- iface->int_in_ep = int_in_ep;
- iface->detached = false;
- iface->claimed = false;
+ iface->next = NULL;
+ iface->handle = handle;
+ iface->number = number;
+ iface->int_in_ep_addr = int_in_ep_addr;
+ iface->int_in_ep_maxp = int_in_ep_maxp;
+ iface->detached = false;
+ iface->claimed = false;
return iface;
}
+void
+hid_dump_iface_free(hid_dump_iface *iface)
+{
+ if (iface == NULL)
+ return;
+
+ assert(hid_dump_iface_valid(iface));
+
+ free(iface);
+}
+
+
bool
hid_dump_iface_list_valid(const hid_dump_iface *list)
{
@@ -90,7 +104,7 @@ hid_dump_iface_list_free(hid_dump_iface *list)
for (; list != NULL; list = next)
{
next = list->next;
- free(list);
+ hid_dump_iface_free(list);
}
}
@@ -141,7 +155,7 @@ hid_dump_iface_list_new_from_dev(libusb_device_handle *handle,
iface = hid_dump_iface_new(
handle,
libusb_iface->altsetting->bInterfaceNumber,
- ep->bEndpointAddress);
+ ep->bEndpointAddress, ep->wMaxPacketSize);
if (iface == NULL)
{
err = LIBUSB_ERROR_NO_MEM;
@@ -278,7 +292,7 @@ hid_dump_iface_list_clear_halt(hid_dump_iface *list)
for (; list != NULL; list = list->next)
{
- err = libusb_clear_halt(list->handle, list->int_in_ep);
+ err = libusb_clear_halt(list->handle, list->int_in_ep_addr);
if (err != LIBUSB_SUCCESS)
return err;
}
diff --git a/src/hid-dump.c b/src/hid-dump.c
index 30173af..0c4c21b 100644
--- a/src/hid-dump.c
+++ b/src/hid-dump.c
@@ -245,23 +245,23 @@ dump_iface_list_stream(libusb_context *ctx, const hid_dump_iface *list)
(size_t)(ptransfer - transfer_list) < transfer_num;
ptransfer++, iface = iface->next)
{
- void *buf;
- static const size_t len = UINT16_MAX; /* wLength maximum */
+ void *buf;
+ const size_t len = iface->int_in_ep_maxp;
/* Allocate the transfer buffer */
- buf = malloc(UINT16_MAX);
+ buf = malloc(len);
if (len > 0 && buf == NULL)
FAILURE_CLEANUP("allocate a transfer buffer");
/* Initialize the transfer */
libusb_fill_interrupt_transfer(*ptransfer,
- iface->handle, iface->int_in_ep,
+ iface->handle, iface->int_in_ep_addr,
buf, len,
dump_iface_list_stream_cb,
(void *)iface,
- TIMEOUT);
+ 0);
- /* Ask to free the buffer when transfer is freed */
+ /* Ask to free the buffer when the transfer is freed */
(*ptransfer)->flags |= LIBUSB_TRANSFER_FREE_BUFFER;
}