Attachments you submit will be routed for moderation. If you have an account, please
log in first.
Ticket #6: 0001-Add-LIBUSB_TRANSFER_ZERO_PACKET-6.patch
| File 0001-Add-LIBUSB_TRANSFER_ZERO_PACKET-6.patch,
5.2 KB
(added by dsd, 3 years ago) |
|
my attempt
|
-
From 6779af1510d6f5412d444aac52c4d5badc912c01 Mon Sep 17 00:00:00 2001
From: Daniel Drake <dsd@gentoo.org>
Date: Sat, 7 Nov 2009 12:37:59 +0000
Subject: [PATCH] Add LIBUSB_TRANSFER_ZERO_PACKET (#6)
Add a transfer flag useful when working with protocols where logical
requests are divided by incomplete packets. Currently only supported on
Linux.
Based on earlier work by Nikias Bassen.
---
libusb/core.c | 9 +++++++++
libusb/io.c | 2 ++
libusb/libusb.h | 27 ++++++++++++++++++++++++++-
libusb/os/darwin_usb.c | 3 +++
libusb/os/linux_usbfs.c | 3 +++
libusb/os/linux_usbfs.h | 1 +
6 files changed, 44 insertions(+), 1 deletions(-)
diff --git a/libusb/core.c b/libusb/core.c
index 7e4fd24..04dcc3e 100644
|
a
|
b
|
if (cfg != desired) |
| 283 | 283 | * kernel where boundaries occur between logical libusb-level transfers. When |
| 284 | 284 | * a short transfer (or other error) occurs, the kernel will cancel all the |
| 285 | 285 | * subtransfers until the boundary without allowing those transfers to start. |
| | 286 | * |
| | 287 | * \section zlp Zero length packets |
| | 288 | * |
| | 289 | * - libusb is designed to be able to send a packet of zero-length to an |
| | 290 | * endpoint simply by submitting a transfer of zero length. On Linux, this did |
| | 291 | * not work with libusb versions prior to v1.0.3 and kernel versions prior to |
| | 292 | * v2.6.31. |
| | 293 | * - The \ref libusb_transfer_flags::LIBUSB_TRANSFER_ZERO_PACKET |
| | 294 | * "LIBUSB_TRANSFER_ZERO_PACKET" flag is unsupported on Darwin. |
| 286 | 295 | */ |
| 287 | 296 | |
| 288 | 297 | /** |
-
diff --git a/libusb/io.c b/libusb/io.c
index 65c2cf4..361057a 100644
|
a
|
b
|
API_EXPORTED void libusb_free_transfer(struct libusb_transfer *transfer) |
| 1206 | 1206 | * \returns 0 on success |
| 1207 | 1207 | * \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected |
| 1208 | 1208 | * \returns LIBUSB_ERROR_BUSY if the transfer has already been submitted. |
| | 1209 | * \returns LIBUSB_ERROR_NOT_SUPPORTED if the transfer flags are not supported |
| | 1210 | * by the operating system. |
| 1209 | 1211 | * \returns another LIBUSB_ERROR code on other failure |
| 1210 | 1212 | */ |
| 1211 | 1213 | API_EXPORTED int libusb_submit_transfer(struct libusb_transfer *transfer) |
-
diff --git a/libusb/libusb.h b/libusb/libusb.h
index 2dbb9a5..b682ee8 100644
|
a
|
b
|
enum libusb_transfer_flags { |
| 672 | 672 | * If this flag is set, it is illegal to call libusb_free_transfer() |
| 673 | 673 | * from your transfer callback, as this will result in a double-free |
| 674 | 674 | * when this flag is acted upon. */ |
| 675 | | LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2 |
| | 675 | LIBUSB_TRANSFER_FREE_TRANSFER = 1<<2, |
| | 676 | |
| | 677 | /** Terminate transfers that are a multiple of the endpoint's maximum |
| | 678 | * packet size with an extra zero-length packet. This is useful when a |
| | 679 | * device protocol mandates that each logical request is terminated by |
| | 680 | * an incomplete packet (i.e. the logical requests are not separated by |
| | 681 | * other means). |
| | 682 | * |
| | 683 | * This flag only affects host-to-device transfers to bulk and interrupt |
| | 684 | * endpoints. In other situations, it is ignored. |
| | 685 | * |
| | 686 | * This flag only affects transfers with a length that is a multiple of |
| | 687 | * the endpoint's packet size. On transfers of other lengths, this flag |
| | 688 | * has no effect. Therefore, if you are working with a device that needs |
| | 689 | * a ZLP whenever the end of the logical request falls on a packet boundary, |
| | 690 | * then it is sensible to set this flag on <em>every</em> transfer (you |
| | 691 | * do not have to worry about only setting it on transfers that end on the |
| | 692 | * boundary). |
| | 693 | * |
| | 694 | * This flag is unsupported on Darwin. On Darwin, libusb_submit_transfer() |
| | 695 | * will return LIBUSB_ERROR_NOT_SUPPORTED for every transfer where this flag |
| | 696 | * is set. |
| | 697 | * |
| | 698 | * Since v1.0.5. |
| | 699 | */ |
| | 700 | LIBUSB_TRANSFER_ZERO_PACKET = 1 << 3 |
| 676 | 701 | }; |
| 677 | 702 | |
| 678 | 703 | /** \ingroup asyncio |
-
diff --git a/libusb/os/darwin_usb.c b/libusb/os/darwin_usb.c
index 9c64b60..9c75ed0 100644
|
a
|
b
|
static int submit_bulk_transfer(struct usbi_transfer *itransfer) { |
| 1046 | 1046 | |
| 1047 | 1047 | /* are we reading or writing? */ |
| 1048 | 1048 | is_read = transfer->endpoint & LIBUSB_ENDPOINT_IN; |
| | 1049 | |
| | 1050 | if (!is_read & transfer->flags & LIBUSB_TRANSFER_ZERO_PACKET) |
| | 1051 | return LIBUSB_ERROR_NOT_SUPPORTED; |
| 1049 | 1052 | |
| 1050 | 1053 | if (ep_to_pipeRef (transfer->dev_handle, transfer->endpoint, &pipeRef, &iface) != 0) { |
| 1051 | 1054 | _usbi_log (TRANSFER_CTX (transfer), LOG_LEVEL_ERROR, "endpoint not found on any open interface"); |
-
diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
index ffa4088..f93e0c8 100644
|
a
|
b
|
static int submit_bulk_transfer(struct usbi_transfer *itransfer, |
| 1376 | 1376 | if (i > 0 && supports_flag_bulk_continuation) |
| 1377 | 1377 | urb->flags |= USBFS_URB_BULK_CONTINUATION; |
| 1378 | 1378 | |
| | 1379 | if (transfer->flags & LIBUSB_TRANSFER_ZERO_PACKET && i == num_urbs - 1) |
| | 1380 | urb->flags |= USBFS_URB_ZERO_PACKET; |
| | 1381 | |
| 1379 | 1382 | r = ioctl(dpriv->fd, IOCTL_USBFS_SUBMITURB, urb); |
| 1380 | 1383 | if (r < 0) { |
| 1381 | 1384 | int j; |
-
diff --git a/libusb/os/linux_usbfs.h b/libusb/os/linux_usbfs.h
index bd02edc..7b737f6 100644
|
a
|
b
|
struct usbfs_getdriver { |
| 64 | 64 | #define USBFS_URB_ISO_ASAP 0x02 |
| 65 | 65 | #define USBFS_URB_BULK_CONTINUATION 0x04 |
| 66 | 66 | #define USBFS_URB_QUEUE_BULK 0x10 |
| | 67 | #define USBFS_URB_ZERO_PACKET 0x40 |
| 67 | 68 | |
| 68 | 69 | enum usbfs_urb_type { |
| 69 | 70 | USBFS_URB_TYPE_ISO = 0, |
Download in other formats: