static void usbredir_buffered_bulk_in_complete_ftdi(USBRedirDevice *dev,
    USBPacket *p, uint8_t ep)
{
    const int maxp = dev->endpoint[EP2I(ep)].max_packet_size;
    uint8_t header[2] = { 0, 0 };
    struct buf_packet *bulkp;
    int count;

    while ((bulkp = QTAILQ_FIRST(&dev->endpoint[EP2I(ep)].bufpq)) &&
           p->actual_length < p->iov.size && p->status == USB_RET_SUCCESS) {
        if (bulkp->len < 2) {
            WARNING("malformed ftdi bulk in packet\n");
            bufp_free(dev, bulkp, ep);
            continue;
        }

        if ((p->actual_length % maxp) == 0) {
            usb_packet_copy(p, bulkp->data, 2);
            memcpy(header, bulkp->data, 2);
        } else {
            if (bulkp->data[0] != header[0] || bulkp->data[1] != header[1]) {
                break; /* Different header, add to next packet */
            }
        }

        if (bulkp->offset == 0) {
            bulkp->offset = 2; /* Skip header */
        }
        count = bulkp->len - bulkp->offset;
        /* Must repeat the header at maxp interval */
        if (count > (maxp - (p->actual_length % maxp))) {
            count = maxp - (p->actual_length % maxp);
        }
        usbredir_buffered_bulk_add_data_to_packet(dev, bulkp, count, p, ep);
    }
}
static void usbredir_buffered_bulk_in_complete_ftdi(USBRedirDevice *dev,
    USBPacket *p, uint8_t ep)
{
    const int maxp = dev->endpoint[EP2I(ep)].max_packet_size;
    uint8_t header[2] = { 0, 0 };
    struct buf_packet *bulkp;
    int count;

    while ((bulkp = QTAILQ_FIRST(&dev->endpoint[EP2I(ep)].bufpq)) &&
           p->actual_length < p->iov.size && p->status == USB_RET_SUCCESS) {
        if (bulkp->len < 2) {
            WARNING("malformed ftdi bulk in packet\n");
            bufp_free(dev, bulkp, ep);
            continue;
        }

        if ((p->actual_length % maxp) == 0) {
            usb_packet_copy(p, bulkp->data, 2);
            memcpy(header, bulkp->data, 2);
        } else {
            if (bulkp->data[0] != header[0] || bulkp->data[1] != header[1]) {
                break;  
            }
        }

        if (bulkp->offset == 0) {
            bulkp->offset = 2;  
        }
        count = bulkp->len - bulkp->offset;
         
        if (count > (maxp - (p->actual_length % maxp))) {
            count = maxp - (p->actual_length % maxp);
        }
        usbredir_buffered_bulk_add_data_to_packet(dev, bulkp, count, p, ep);
    }
}