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

  • libusb/core.c

    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) 
    283283 * kernel where boundaries occur between logical libusb-level transfers. When 
    284284 * a short transfer (or other error) occurs, the kernel will cancel all the 
    285285 * 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. 
    286295 */ 
    287296 
    288297/** 
  • libusb/io.c

    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) 
    12061206 * \returns 0 on success 
    12071207 * \returns LIBUSB_ERROR_NO_DEVICE if the device has been disconnected 
    12081208 * \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. 
    12091211 * \returns another LIBUSB_ERROR code on other failure 
    12101212 */ 
    12111213API_EXPORTED int libusb_submit_transfer(struct libusb_transfer *transfer) 
  • libusb/libusb.h

    diff --git a/libusb/libusb.h b/libusb/libusb.h
    index 2dbb9a5..b682ee8 100644
    a b enum libusb_transfer_flags { 
    672672         * If this flag is set, it is illegal to call libusb_free_transfer() 
    673673         * from your transfer callback, as this will result in a double-free 
    674674         * 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 
    676701}; 
    677702 
    678703/** \ingroup asyncio 
  • libusb/os/darwin_usb.c

    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) { 
    10461046 
    10471047  /* are we reading or writing? */ 
    10481048  is_read = transfer->endpoint & LIBUSB_ENDPOINT_IN; 
     1049 
     1050  if (!is_read & transfer->flags & LIBUSB_TRANSFER_ZERO_PACKET) 
     1051    return LIBUSB_ERROR_NOT_SUPPORTED; 
    10491052   
    10501053  if (ep_to_pipeRef (transfer->dev_handle, transfer->endpoint, &pipeRef, &iface) != 0) { 
    10511054    _usbi_log (TRANSFER_CTX (transfer), LOG_LEVEL_ERROR, "endpoint not found on any open interface"); 
  • libusb/os/linux_usbfs.c

    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, 
    13761376                if (i > 0 && supports_flag_bulk_continuation) 
    13771377                        urb->flags |= USBFS_URB_BULK_CONTINUATION; 
    13781378 
     1379                if (transfer->flags & LIBUSB_TRANSFER_ZERO_PACKET && i == num_urbs - 1) 
     1380                        urb->flags |= USBFS_URB_ZERO_PACKET; 
     1381 
    13791382                r = ioctl(dpriv->fd, IOCTL_USBFS_SUBMITURB, urb); 
    13801383                if (r < 0) { 
    13811384                        int j; 
  • libusb/os/linux_usbfs.h

    diff --git a/libusb/os/linux_usbfs.h b/libusb/os/linux_usbfs.h
    index bd02edc..7b737f6 100644
    a b struct usbfs_getdriver { 
    6464#define USBFS_URB_ISO_ASAP                      0x02 
    6565#define USBFS_URB_BULK_CONTINUATION     0x04 
    6666#define USBFS_URB_QUEUE_BULK            0x10 
     67#define USBFS_URB_ZERO_PACKET           0x40 
    6768 
    6869enum usbfs_urb_type { 
    6970        USBFS_URB_TYPE_ISO = 0,