From 1c4d8790aa0283eae85b0f85d8c2ede0eab9cf2c Mon Sep 17 00:00:00 2001 From: Nikolai Kondrashov Date: Wed, 21 Jul 2010 08:10:10 +0000 Subject: Fixed stream dumping. --- include/hid_dump/iface.h | 28 +++++++++++++++++----------- lib/iface.c | 34 ++++++++++++++++++++++++---------- src/hid-dump.c | 12 ++++++------ 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; } -- cgit v1.2.1