static int usbredir_handle_iso_data(USBRedirDevice *dev, USBPacket *p,

                                     uint8_t ep)

{

    int status, len;



    if (!dev->endpoint[EP2I(ep)].iso_started &&

            !dev->endpoint[EP2I(ep)].iso_error) {

        struct usb_redir_start_iso_stream_header start_iso = {

            .endpoint = ep,

            /* TODO maybe do something with these depending on ep interval? */

            .pkts_per_urb = 32,

            .no_urbs = 3,

        };

        /* No id, we look at the ep when receiving a status back */

        usbredirparser_send_start_iso_stream(dev->parser, 0, &start_iso);

        usbredirparser_do_write(dev->parser);

        DPRINTF("iso stream started ep %02X\n", ep);

        dev->endpoint[EP2I(ep)].iso_started = 1;

    }



    if (ep & USB_DIR_IN) {

        struct buf_packet *isop;



        isop = QTAILQ_FIRST(&dev->endpoint[EP2I(ep)].bufpq);

        if (isop == NULL) {

            DPRINTF2("iso-token-in ep %02X, no isop\n", ep);

            /* Check iso_error for stream errors, otherwise its an underrun */

            status = dev->endpoint[EP2I(ep)].iso_error;

            dev->endpoint[EP2I(ep)].iso_error = 0;

            return usbredir_handle_status(dev, status, 0);

        }

        DPRINTF2("iso-token-in ep %02X status %d len %d\n", ep, isop->status,

                 isop->len);



        status = isop->status;

        if (status != usb_redir_success) {

            bufp_free(dev, isop, ep);

            return usbredir_handle_status(dev, status, 0);

        }



        len = isop->len;

        if (len > p->len) {

            ERROR("received iso data is larger then packet ep %02X\n", ep);

            bufp_free(dev, isop, ep);

            return USB_RET_NAK;

        }

        memcpy(p->data, isop->data, len);

        bufp_free(dev, isop, ep);

        return len;

    } else {

        /* If the stream was not started because of a pending error don't

           send the packet to the usb-host */

        if (dev->endpoint[EP2I(ep)].iso_started) {

            struct usb_redir_iso_packet_header iso_packet = {

                .endpoint = ep,

                .length = p->len

            };

            /* No id, we look at the ep when receiving a status back */

            usbredirparser_send_iso_packet(dev->parser, 0, &iso_packet,

                                           p->data, p->len);

            usbredirparser_do_write(dev->parser);

        }

        status = dev->endpoint[EP2I(ep)].iso_error;

        dev->endpoint[EP2I(ep)].iso_error = 0;

        DPRINTF2("iso-token-out ep %02X status %d len %d\n", ep, status,

                 p->len);

        return usbredir_handle_status(dev, status, p->len);

    }

}

static int usbredir_handle_iso_data(USBRedirDevice *dev, USBPacket *p,

                                     uint8_t ep)

{

    int status, len;



    if (!dev->endpoint[EP2I(ep)].iso_started &&

            !dev->endpoint[EP2I(ep)].iso_error) {

        struct usb_redir_start_iso_stream_header start_iso = {

            .endpoint = ep,

            

            .pkts_per_urb = 32,

            .no_urbs = 3,

        };

        

        usbredirparser_send_start_iso_stream(dev->parser, 0, &start_iso);

        usbredirparser_do_write(dev->parser);

        DPRINTF("iso stream started ep %02X\n", ep);

        dev->endpoint[EP2I(ep)].iso_started = 1;

    }



    if (ep & USB_DIR_IN) {

        struct buf_packet *isop;



        isop = QTAILQ_FIRST(&dev->endpoint[EP2I(ep)].bufpq);

        if (isop == NULL) {

            DPRINTF2("iso-token-in ep %02X, no isop\n", ep);

            

            status = dev->endpoint[EP2I(ep)].iso_error;

            dev->endpoint[EP2I(ep)].iso_error = 0;

            return usbredir_handle_status(dev, status, 0);

        }

        DPRINTF2("iso-token-in ep %02X status %d len %d\n", ep, isop->status,

                 isop->len);



        status = isop->status;

        if (status != usb_redir_success) {

            bufp_free(dev, isop, ep);

            return usbredir_handle_status(dev, status, 0);

        }



        len = isop->len;

        if (len > p->len) {

            ERROR("received iso data is larger then packet ep %02X\n", ep);

            bufp_free(dev, isop, ep);

            return USB_RET_NAK;

        }

        memcpy(p->data, isop->data, len);

        bufp_free(dev, isop, ep);

        return len;

    } else {

        



        if (dev->endpoint[EP2I(ep)].iso_started) {

            struct usb_redir_iso_packet_header iso_packet = {

                .endpoint = ep,

                .length = p->len

            };

            

            usbredirparser_send_iso_packet(dev->parser, 0, &iso_packet,

                                           p->data, p->len);

            usbredirparser_do_write(dev->parser);

        }

        status = dev->endpoint[EP2I(ep)].iso_error;

        dev->endpoint[EP2I(ep)].iso_error = 0;

        DPRINTF2("iso-token-out ep %02X status %d len %d\n", ep, status,

                 p->len);

        return usbredir_handle_status(dev, status, p->len);

    }

}

        if (len > p->len) {         memcpy(p->data, isop->data, len);                 .length = p->len                                            p->data, p->len);         DPRINTF2("iso-token-out ep %02X status %d len %d\n", ep, status,                  p->len);         return usbredir_handle_status(dev, status, p->len);         if (len > p->len) {
static int FUNC_0(USBRedirDevice *VAR_0, USBPacket *VAR_1,

                                     uint8_t VAR_2)

{

    int VAR_3, VAR_4;



    if (!VAR_0->endpoint[EP2I(VAR_2)].iso_started &&

            !VAR_0->endpoint[EP2I(VAR_2)].iso_error) {

        struct usb_redir_start_iso_stream_header VAR_5 = {

            .endpoint = VAR_2,

            

            .pkts_per_urb = 32,

            .no_urbs = 3,

        };

        

        usbredirparser_send_start_iso_stream(VAR_0->parser, 0, &VAR_5);

        usbredirparser_do_write(VAR_0->parser);

        DPRINTF("iso stream started VAR_2 %02X\n", VAR_2);

        VAR_0->endpoint[EP2I(VAR_2)].iso_started = 1;

    }



    if (VAR_2 & USB_DIR_IN) {

        struct buf_packet *VAR_6;



        VAR_6 = QTAILQ_FIRST(&VAR_0->endpoint[EP2I(VAR_2)].bufpq);

        if (VAR_6 == NULL) {

            DPRINTF2("iso-token-in VAR_2 %02X, no VAR_6\n", VAR_2);

            

            VAR_3 = VAR_0->endpoint[EP2I(VAR_2)].iso_error;

            VAR_0->endpoint[EP2I(VAR_2)].iso_error = 0;

            return usbredir_handle_status(VAR_0, VAR_3, 0);

        }

        DPRINTF2("iso-token-in VAR_2 %02X VAR_3 %d VAR_4 %d\n", VAR_2, VAR_6->VAR_3,

                 VAR_6->VAR_4);



        VAR_3 = VAR_6->VAR_3;

        if (VAR_3 != usb_redir_success) {

            bufp_free(VAR_0, VAR_6, VAR_2);

            return usbredir_handle_status(VAR_0, VAR_3, 0);

        }



        VAR_4 = VAR_6->VAR_4;

        if (VAR_4 > VAR_1->VAR_4) {

            ERROR("received iso data is larger then packet VAR_2 %02X\n", VAR_2);

            bufp_free(VAR_0, VAR_6, VAR_2);

            return USB_RET_NAK;

        }

        memcpy(VAR_1->data, VAR_6->data, VAR_4);

        bufp_free(VAR_0, VAR_6, VAR_2);

        return VAR_4;

    } else {

        



        if (VAR_0->endpoint[EP2I(VAR_2)].iso_started) {

            struct usb_redir_iso_packet_header VAR_7 = {

                .endpoint = VAR_2,

                .length = VAR_1->VAR_4

            };

            

            usbredirparser_send_iso_packet(VAR_0->parser, 0, &VAR_7,

                                           VAR_1->data, VAR_1->VAR_4);

            usbredirparser_do_write(VAR_0->parser);

        }

        VAR_3 = VAR_0->endpoint[EP2I(VAR_2)].iso_error;

        VAR_0->endpoint[EP2I(VAR_2)].iso_error = 0;

        DPRINTF2("iso-token-out VAR_2 %02X VAR_3 %d VAR_4 %d\n", VAR_2, VAR_3,

                 VAR_1->VAR_4);

        return usbredir_handle_status(VAR_0, VAR_3, VAR_1->VAR_4);

    }

}

static int FUNC_0(USBRedirDevice *VAR_0, USBPacket *VAR_1,
uint8_t VAR_2)
{ int VAR_3, VAR_4; if (!VAR_0->endpoint[EP2I(VAR_2)].iso_started &&
!VAR_0->endpoint[EP2I(VAR_2)].iso_error) { struct usb_redir_start_iso_stream_header VAR_5 = { .endpoint = VAR_2,
.pkts_per_urb = 32,
.no_urbs = 3,
}; usbredirparser_send_start_iso_stream(VAR_0->parser, 0, &VAR_5); usbredirparser_do_write(VAR_0->parser); DPRINTF("iso stream started VAR_2 %02X\n", VAR_2); VAR_0->endpoint[EP2I(VAR_2)].iso_started = 1; } if (VAR_2 & USB_DIR_IN) { struct buf_packet *VAR_6; VAR_6 = QTAILQ_FIRST(&VAR_0->endpoint[EP2I(VAR_2)].bufpq); if (VAR_6 == NULL) { DPRINTF2("iso-token-in VAR_2 %02X, no VAR_6\n", VAR_2); VAR_3 = VAR_0->endpoint[EP2I(VAR_2)].iso_error; VAR_0->endpoint[EP2I(VAR_2)].iso_error = 0; return usbredir_handle_status(VAR_0, VAR_3, 0); } DPRINTF2("iso-token-in VAR_2 %02X VAR_3 %d VAR_4 %d\n", VAR_2, VAR_6->VAR_3,
VAR_6->VAR_4); VAR_3 = VAR_6->VAR_3; if (VAR_3 != usb_redir_success) { bufp_free(VAR_0, VAR_6, VAR_2); return usbredir_handle_status(VAR_0, VAR_3, 0); } VAR_4 = VAR_6->VAR_4; if (VAR_4 > VAR_1->VAR_4) { ERROR("received iso data is larger then packet VAR_2 %02X\n", VAR_2); bufp_free(VAR_0, VAR_6, VAR_2); return USB_RET_NAK; } memcpy(VAR_1->data, VAR_6->data, VAR_4); bufp_free(VAR_0, VAR_6, VAR_2); return VAR_4; } else { if (VAR_0->endpoint[EP2I(VAR_2)].iso_started) { struct usb_redir_iso_packet_header VAR_7 = { .endpoint = VAR_2,
.length = VAR_1->VAR_4
}; usbredirparser_send_iso_packet(VAR_0->parser, 0, &VAR_7,
VAR_1->data, VAR_1->VAR_4); usbredirparser_do_write(VAR_0->parser); } VAR_3 = VAR_0->endpoint[EP2I(VAR_2)].iso_error; VAR_0->endpoint[EP2I(VAR_2)].iso_error = 0; DPRINTF2("iso-token-out VAR_2 %02X VAR_3 %d VAR_4 %d\n", VAR_2, VAR_3,
VAR_1->VAR_4); return usbredir_handle_status(VAR_0, VAR_3, VAR_1->VAR_4); } }