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

Ticket #6: 0001-Linux-Correctly-terminate-bulk-packets-of-size-wMax.patch

File 0001-Linux-Correctly-terminate-bulk-packets-of-size-wMax.patch, 2.4 KB (added by nikias, 3 years ago)
  • libusb/os/linux_usbfs.c

    From 3a99da700874289ab4b000840cd8e0e0cbe8646e Mon Sep 17 00:00:00 2001
    From: Nikias Bassen <nikias@gmx.li>
    Date: Sat, 29 Aug 2009 16:40:31 +0200
    Subject: [PATCH] Linux: Correctly terminate bulk packets of size wMaxPacketSize
    
    ... and multiples. This patch will automatically set the URB_ZERO_PACKET
    flag if the packet size is a multiple of the endpoint's wMaxPacketSize
    so that the kernel actually submits bulk packet. This is only for
    outgoing transfers.
    ---
     libusb/os/linux_usbfs.c |   18 ++++++++++++++++++
     libusb/os/linux_usbfs.h |    1 +
     2 files changed, 19 insertions(+), 0 deletions(-)
    
    diff --git a/libusb/os/linux_usbfs.c b/libusb/os/linux_usbfs.c
    index 1280188..ad1dc89 100644
    a b static int submit_bulk_transfer(struct usbi_transfer *itransfer, 
    12651265        int r; 
    12661266        int i; 
    12671267        size_t alloc_size; 
     1268        uint8_t is_read; /* 0 = we're reading, 1 = we're writing */ 
     1269        uint8_t flag_zero_packet = 0; /* 0 = don't flag, 1 = flag */ 
    12681270 
    12691271        if (tpriv->urbs) 
    12701272                return LIBUSB_ERROR_BUSY; 
    static int submit_bulk_transfer(struct usbi_transfer *itransfer, 
    12941296        tpriv->num_retired = 0; 
    12951297        tpriv->reap_action = NORMAL; 
    12961298 
     1299        /* are we reading or writing? */ 
     1300        is_read = transfer->endpoint & LIBUSB_ENDPOINT_IN; 
     1301        if (!is_read) { 
     1302                libusb_device *tdev = libusb_get_device(transfer->dev_handle); 
     1303                int max_packet_size = libusb_get_max_packet_size(tdev, transfer->endpoint); 
     1304                if ((max_packet_size > 0) && (transfer->length > 0) 
     1305                        && (transfer->length % max_packet_size == 0)) { 
     1306                        flag_zero_packet = 1; 
     1307                } 
     1308        } 
     1309 
    12971310        for (i = 0; i < num_urbs; i++) { 
    12981311                struct usbfs_urb *urb = &urbs[i]; 
    12991312                urb->usercontext = itransfer; 
    static int submit_bulk_transfer(struct usbi_transfer *itransfer, 
    13071320                else 
    13081321                        urb->buffer_length = MAX_BULK_BUFFER_LENGTH; 
    13091322 
     1323                if ((i == num_urbs - 1) && (flag_zero_packet)) { 
     1324                        printf("flagging URB_ZERO_PACKET\n"); 
     1325                        urb->flags |= USBFS_URB_ZERO_PACKET; 
     1326                } 
     1327 
    13101328                r = ioctl(dpriv->fd, IOCTL_USBFS_SUBMITURB, urb); 
    13111329                if (r < 0) { 
    13121330                        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,