Attachments you submit will be routed for moderation. If you have an account, please log in first.

Ticket #6: 0001-New-flag-LIBUSB_TRANSFER_ZERO_PACKET-for-terminating.patch

File 0001-New-flag-LIBUSB_TRANSFER_ZERO_PACKET-for-terminating.patch, 3.1 KB (added by nikias, 3 years ago)
  • libusb/libusb.h

    From 8c57d8966ea966d23fbc4db77f7a8cdc0623b544 Mon Sep 17 00:00:00 2001
    From: Nikias Bassen <nikias@gmx.li>
    Date: Fri, 28 Aug 2009 00:05:45 +0200
    Subject: [PATCH] New flag LIBUSB_TRANSFER_ZERO_PACKET for terminating bulk transfers
    
    This patch fixes the Zero Length Packet issue by allowing the client
    program to specify the LIBUSB_TRANSFER_ZERO_PACKET flag when calling
    libusb_submit_transfer when the packet size is a multiple of
    wMaxPacketSize. This will pass the URB_ZERO_PACKET flag to the
    appropriate ioctl and thus triggers sending of the packet inside the
    kernel. Otherwise such a packet would never get sent.
    ---
     libusb/libusb.h         |   23 ++++++++++++++++++++++-
     libusb/os/linux_usbfs.c |    3 +++
     libusb/os/linux_usbfs.h |    1 +
     3 files changed, 26 insertions(+), 1 deletions(-)
    
    diff --git a/libusb/libusb.h b/libusb/libusb.h
    index 1126380..ce7bfcf 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 bulk transfer by a zero length URB. 
     678         * According to the USB spec the last packet of a bulk transfer _must_ 
     679         * be terminated by a zero length URB if it has the exact size of the 
     680         * endpoint's maximum packet size (wMaxPacketSize). 
     681         * By setting this flag the URB_ZERO_PACKET flag will be set before 
     682         * performing IOCTL_USBFS_SUBMITURB. This will trigger sending of the 
     683         * mentioned packet which otherwise would never get transmitted. 
     684         * 
     685         * @note Implementers: You need to read the wMaxPacketSize attribute 
     686         *       of the usb endpoint you are writing to. If the size of the 
     687         *       packet you are submitting is a multiple of wMaxPacketSize 
     688         *       you need to set the LIBUSB_TRANSFER_ZERO_PACKET flag before 
     689         *       calling libusb_submit_transfer(), something like: 
     690         * 
     691         *       if (length % dev->wMaxPacketSize == 0) { 
     692         *           xfer->flags |= LIBUSB_TRANSFER_ZERO_PACKET; 
     693         *       } 
     694         *       libusb_submit_transfer(xfer); 
     695         */ 
     696        LIBUSB_TRANSFER_ZERO_PACKET = 1<<3 
    676697}; 
    677698 
    678699/** \ingroup asyncio 
  • libusb/os/linux_usbfs.c

    diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
    index 1280188..1f6c989 100644
    a b static int submit_bulk_transfer(struct usbi_transfer *itransfer, 
    13071307                else 
    13081308                        urb->buffer_length = MAX_BULK_BUFFER_LENGTH; 
    13091309 
     1310                if (transfer->flags & LIBUSB_TRANSFER_ZERO_PACKET) 
     1311                        urb->flags |= USBFS_URB_ZERO_PACKET; 
     1312 
    13101313                r = ioctl(dpriv->fd, IOCTL_USBFS_SUBMITURB, urb); 
    13111314                if (r < 0) { 
    13121315                        int j; 
  • libusb/os/linux_usbfs.h

    diff --git a/libusb/os/linux_usbfs.h b/libusb/os/linux_usbfs.h
    index fdf5e9b..9ed0b4f 100644
    a b struct usbfs_getdriver { 
    6363#define USBFS_URB_DISABLE_SPD   1 
    6464#define USBFS_URB_ISO_ASAP      2 
    6565#define USBFS_URB_QUEUE_BULK    0x10 
     66#define USBFS_URB_ZERO_PACKET   0x40 
    6667 
    6768enum usbfs_urb_type { 
    6869        USBFS_URB_TYPE_ISO = 0,