From c4586e80dc6f1a92513b466d8d43748ec733b7fd Mon Sep 17 00:00:00 2001 From: Jonathan Dieter Date: Mon, 2 Apr 2012 14:35:09 +0300 Subject: [PATCH 1/3] Use usb_bulk_[read|write] instead of homemade handlers. This allows us to run against libusb-compat as well as the old libusb. Signed-off-by: Jonathan Dieter --- src/host/usb-linux.c | 42 ++++++------------------------------------ 1 file changed, 6 insertions(+), 36 deletions(-) diff --git a/src/host/usb-linux.c b/src/host/usb-linux.c index 55cc0b5..65f94c4 100644 --- a/src/host/usb-linux.c +++ b/src/host/usb-linux.c @@ -49,20 +49,8 @@ #define USBDEVFS_IOCTL_TIMEOUT 2000 -struct myusb_dev_handle { - int fd; - - // other stuff here -}; - typedef struct { - union { - usb_dev_handle *handle; - - /* XXX cheezy hack to let us get to the file descriptor hidden in the libusb handle */ - struct myusb_dev_handle *myhandle; - }; - + usb_dev_handle *handle; novacom_usbll_handle_t usbll_handle; bool shutdown; @@ -218,7 +206,7 @@ static novacom_usb_handle_t *novacom_usb_open( void ) if (!handle) continue; #if USB_SCAN_TRACE - log_printf(LOG_SPEW, "opened usb handle: fd %d\n", ((struct myusb_dev_handle *)handle)->fd); + log_printf(LOG_SPEW, "opened usb handle: devnum %d\n", dev->devnum); #endif int eps[2]; @@ -281,17 +269,10 @@ int novacom_usb_transport_init(void) static int novacom_usb_read(novacom_usb_handle_t *handle, void *buf, size_t len) { // TRACEF("handle %p, buf %p, len %d, timeout %d\n", handle, buf, len, timeout); -// TRACEF("fd %d\n", handle->myhandle->fd); - - struct usbdevfs_bulktransfer bulktransfer; - - bulktransfer.ep = handle->rxep; - bulktransfer.len = len; - bulktransfer.timeout = handle->rx_timeout; - bulktransfer.data = buf; int rc; - rc = ioctl(handle->myhandle->fd, USBDEVFS_BULK, &bulktransfer); + + rc = usb_bulk_read(handle->handle, handle->rxep, buf, len, handle->rx_timeout); if (rc > 0) { //now check the packet header if (novacom_usbll_check_packet_header(buf, rc)) { //bad packet @@ -303,22 +284,11 @@ static int novacom_usb_read(novacom_usb_handle_t *handle, void *buf, size_t len) return rc; } -static int novacom_usb_write(novacom_usb_handle_t *handle, const void *buf, size_t len) +static int novacom_usb_write(novacom_usb_handle_t *handle, void *buf, size_t len) { // TRACEF("handle %p, buf %p, len %d, timeout %d\n", handle, buf, len, timeout); -// TRACEF("fd %d\n", handle->myhandle->fd); - - struct usbdevfs_bulktransfer bulktransfer; - bulktransfer.ep = handle->txep; - bulktransfer.len = len; - bulktransfer.timeout = handle->tx_timeout; - bulktransfer.data = (void *)buf; - - int rc; - rc = ioctl(handle->myhandle->fd, USBDEVFS_BULK, &bulktransfer); -// TRACEF("rc %d\n", rc); - return rc; + return usb_bulk_write(handle->handle, handle->txep, buf, len, handle->tx_timeout); } struct usb_thread_args { -- 1.7.10