diff options
| -rw-r--r-- | Modules/FindUSB.cmake | 2 | ||||
| -rw-r--r-- | contrib/libusb-New-flag-LIBUSB_TRANSFER_ZERO_PACKET.patch | 72 | ||||
| -rw-r--r-- | daemon/CMakeLists.txt | 19 | ||||
| -rw-r--r-- | daemon/usb-linux.c | 7 |
4 files changed, 1 insertions, 99 deletions
diff --git a/Modules/FindUSB.cmake b/Modules/FindUSB.cmake index 8659ec2..d1d705a 100644 --- a/Modules/FindUSB.cmake +++ b/Modules/FindUSB.cmake | |||
| @@ -10,7 +10,7 @@ include(LibFindMacros) | |||
| 10 | # Dependencies | 10 | # Dependencies |
| 11 | 11 | ||
| 12 | # Use pkg-config to get hints about paths | 12 | # Use pkg-config to get hints about paths |
| 13 | libfind_pkg_check_modules(USB_PKGCONF libusb-1.0>=1.0.2) | 13 | libfind_pkg_check_modules(USB_PKGCONF libusb-1.0>=1.0.3) |
| 14 | 14 | ||
| 15 | # Include dir | 15 | # Include dir |
| 16 | find_path(USB_INCLUDE_DIR | 16 | find_path(USB_INCLUDE_DIR |
diff --git a/contrib/libusb-New-flag-LIBUSB_TRANSFER_ZERO_PACKET.patch b/contrib/libusb-New-flag-LIBUSB_TRANSFER_ZERO_PACKET.patch deleted file mode 100644 index 84d8a0a..0000000 --- a/contrib/libusb-New-flag-LIBUSB_TRANSFER_ZERO_PACKET.patch +++ /dev/null | |||
| @@ -1,72 +0,0 @@ | |||
| 1 | From 13123672fc1edb1e8ce52f60eef045e3c901e5d6 Mon Sep 17 00:00:00 2001 | ||
| 2 | From: Nikias Bassen <nikias@gmx.li> | ||
| 3 | Date: Sat, 5 Sep 2009 15:42:01 +0200 | ||
| 4 | Subject: [PATCH] New flag LIBUSB_TRANSFER_ZERO_PACKET for bulk/interrupt transfers. | ||
| 5 | |||
| 6 | This flag will let the kernel append an additional zero-length packet | ||
| 7 | to a tansfer. This is required for certain devices when sending packets | ||
| 8 | with a size that is a multiple of wMaxPacketSize. | ||
| 9 | --- | ||
| 10 | libusb/libusb.h | 18 +++++++++++++++++- | ||
| 11 | libusb/os/linux_usbfs.c | 3 +++ | ||
| 12 | libusb/os/linux_usbfs.h | 1 + | ||
| 13 | 3 files changed, 21 insertions(+), 1 deletions(-) | ||
| 14 | |||
| 15 | diff --git a/libusb/libusb.h b/libusb/libusb.h | ||
| 16 | index 1126380..bf7f02d 100644 | ||
| 17 | --- a/libusb/libusb.h | ||
| 18 | +++ b/libusb/libusb.h | ||
| 19 | @@ -672,7 +672,23 @@ enum libusb_transfer_flags { | ||
| 20 | * If this flag is set, it is illegal to call libusb_free_transfer() | ||
| 21 | * from your transfer callback, as this will result in a double-free | ||
| 22 | * when this flag is acted upon. */ | ||
| 23 | - LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2 | ||
| 24 | + LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2, | ||
| 25 | + | ||
| 26 | + /** If this flag is set, a zero-length packet will be appended to | ||
| 27 | + * the transfer indicating that the transfer is complete. | ||
| 28 | + * Some devices require to be notified when a transfer is complete. | ||
| 29 | + * Usually a device knows about the end of the transfer if the last | ||
| 30 | + * packet's size is less than wMaxPacketSize. | ||
| 31 | + * But if the last packet of a transfer has _exactly_ the size of | ||
| 32 | + * wMaxPacketSize, the device does not know that it is the last | ||
| 33 | + * packet. This is where a zero-length packet is required, which | ||
| 34 | + * will let the device know that the transfer is complete. | ||
| 35 | + * | ||
| 36 | + * This flag is valid for the following transfer types: | ||
| 37 | + * LIBUSB_TRANSFER_TYPE_BULK | ||
| 38 | + * LIBUSB_TRANSFER_TYPE_INTERRUPT | ||
| 39 | + */ | ||
| 40 | + LIBUSB_TRANSFER_ZERO_PACKET = 1<<3 | ||
| 41 | }; | ||
| 42 | |||
| 43 | /** \ingroup asyncio | ||
| 44 | diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c | ||
| 45 | index 1280188..816bcbf 100644 | ||
| 46 | --- a/libusb/os/linux_usbfs.c | ||
| 47 | +++ b/libusb/os/linux_usbfs.c | ||
| 48 | @@ -1307,6 +1307,9 @@ static int submit_bulk_transfer(struct usbi_transfer *itransfer, | ||
| 49 | else | ||
| 50 | urb->buffer_length = MAX_BULK_BUFFER_LENGTH; | ||
| 51 | |||
| 52 | + if (i == num_urbs -1 && (transfer->flags & LIBUSB_TRANSFER_ZERO_PACKET)) | ||
| 53 | + urb->flags |= USBFS_URB_ZERO_PACKET; | ||
| 54 | + | ||
| 55 | r = ioctl(dpriv->fd, IOCTL_USBFS_SUBMITURB, urb); | ||
| 56 | if (r < 0) { | ||
| 57 | int j; | ||
| 58 | diff --git a/libusb/os/linux_usbfs.h b/libusb/os/linux_usbfs.h | ||
| 59 | index fdf5e9b..9ed0b4f 100644 | ||
| 60 | --- a/libusb/os/linux_usbfs.h | ||
| 61 | +++ b/libusb/os/linux_usbfs.h | ||
| 62 | @@ -63,6 +63,7 @@ struct usbfs_getdriver { | ||
| 63 | #define USBFS_URB_DISABLE_SPD 1 | ||
| 64 | #define USBFS_URB_ISO_ASAP 2 | ||
| 65 | #define USBFS_URB_QUEUE_BULK 0x10 | ||
| 66 | +#define USBFS_URB_ZERO_PACKET 0x40 | ||
| 67 | |||
| 68 | enum usbfs_urb_type { | ||
| 69 | USBFS_URB_TYPE_ISO = 0, | ||
| 70 | -- | ||
| 71 | 1.6.0.4 | ||
| 72 | |||
diff --git a/daemon/CMakeLists.txt b/daemon/CMakeLists.txt index e5f9b11..8a5c417 100644 --- a/daemon/CMakeLists.txt +++ b/daemon/CMakeLists.txt | |||
| @@ -6,25 +6,6 @@ include_directories (${CMAKE_SOURCE_DIR}/common) | |||
| 6 | include_directories (${CMAKE_SOURCE_DIR}/daemon) | 6 | include_directories (${CMAKE_SOURCE_DIR}/daemon) |
| 7 | include_directories (${CMAKE_SOURCE_DIR}/libusbmuxd) | 7 | include_directories (${CMAKE_SOURCE_DIR}/libusbmuxd) |
| 8 | 8 | ||
| 9 | include(CheckConstantExists) | ||
| 10 | set(CMAKE_REQUIRED_INCLUDES ${USB_INCLUDE_DIRS}) | ||
| 11 | check_constant_exists(LIBUSB_TRANSFER_ZERO_PACKET libusb.h HAVE_LIBUSB_ZLP) | ||
| 12 | |||
| 13 | if(NOT HAVE_LIBUSB_ZLP) | ||
| 14 | message(" | ||
| 15 | ================================================================================ | ||
| 16 | ==================================== WARNING =================================== | ||
| 17 | ================================================================================ | ||
| 18 | Your libusb is missing proper Zero Length Packet support! If you are using a | ||
| 19 | recent libusb Git, things may or may not work. If you are using libusb 1.0.2 or | ||
| 20 | earlier, things will definitely not work properly. | ||
| 21 | |||
| 22 | Please apply the patch in the contrib/ directory to your libusb 1.0 tree. | ||
| 23 | ================================================================================ | ||
| 24 | ") | ||
| 25 | add_definitions(-DEXPLICIT_ZLP_TRANSACTION) | ||
| 26 | endif(NOT HAVE_LIBUSB_ZLP) | ||
| 27 | |||
| 28 | add_definitions(-Wall -O2 -g -DUSBMUXD_DAEMON -DUSBMUXD_VERSION="${USBMUXD_VERSION}") | 9 | add_definitions(-Wall -O2 -g -DUSBMUXD_DAEMON -DUSBMUXD_VERSION="${USBMUXD_VERSION}") |
| 29 | add_executable(usbmuxd main.c usb-linux.c log.c ../common/utils.c device.c client.c) | 10 | add_executable(usbmuxd main.c usb-linux.c log.c ../common/utils.c device.c client.c) |
| 30 | target_link_libraries(usbmuxd ${LIBS}) | 11 | target_link_libraries(usbmuxd ${LIBS}) |
diff --git a/daemon/usb-linux.c b/daemon/usb-linux.c index f1be612..0edc557 100644 --- a/daemon/usb-linux.c +++ b/daemon/usb-linux.c | |||
| @@ -134,18 +134,12 @@ int usb_send(struct usb_device *dev, const unsigned char *buf, int length) | |||
| 134 | struct libusb_transfer *xfer = libusb_alloc_transfer(0); | 134 | struct libusb_transfer *xfer = libusb_alloc_transfer(0); |
| 135 | libusb_fill_bulk_transfer(xfer, dev->dev, BULK_OUT, (void*)buf, length, tx_callback, dev, 0); | 135 | libusb_fill_bulk_transfer(xfer, dev->dev, BULK_OUT, (void*)buf, length, tx_callback, dev, 0); |
| 136 | xfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK; | 136 | xfer->flags = LIBUSB_TRANSFER_SHORT_NOT_OK; |
| 137 | #ifndef EXPLICIT_ZLP_TRANSACTION | ||
| 138 | if (length % dev->wMaxPacketSize == 0) { | ||
| 139 | xfer->flags |= LIBUSB_TRANSFER_ZERO_PACKET; | ||
| 140 | } | ||
| 141 | #endif | ||
| 142 | if((res = libusb_submit_transfer(xfer)) < 0) { | 137 | if((res = libusb_submit_transfer(xfer)) < 0) { |
| 143 | usbmuxd_log(LL_ERROR, "Failed to submit TX transfer %p len %d to device %d-%d: %d", buf, length, dev->bus, dev->address, res); | 138 | usbmuxd_log(LL_ERROR, "Failed to submit TX transfer %p len %d to device %d-%d: %d", buf, length, dev->bus, dev->address, res); |
| 144 | libusb_free_transfer(xfer); | 139 | libusb_free_transfer(xfer); |
| 145 | return res; | 140 | return res; |
| 146 | } | 141 | } |
| 147 | collection_add(&dev->tx_xfers, xfer); | 142 | collection_add(&dev->tx_xfers, xfer); |
| 148 | #ifdef EXPLICIT_ZLP_TRANSACTION | ||
| 149 | if (length % dev->wMaxPacketSize == 0) { | 143 | if (length % dev->wMaxPacketSize == 0) { |
| 150 | usbmuxd_log(LL_DEBUG, "Send ZLP"); | 144 | usbmuxd_log(LL_DEBUG, "Send ZLP"); |
| 151 | // Send Zero Length Packet | 145 | // Send Zero Length Packet |
| @@ -160,7 +154,6 @@ int usb_send(struct usb_device *dev, const unsigned char *buf, int length) | |||
| 160 | } | 154 | } |
| 161 | collection_add(&dev->tx_xfers, xfer); | 155 | collection_add(&dev->tx_xfers, xfer); |
| 162 | } | 156 | } |
| 163 | #endif | ||
| 164 | return 0; | 157 | return 0; |
| 165 | } | 158 | } |
| 166 | 159 | ||
