static int usb_serial_handle_data(USBDevice *dev, USBPacket *p)

{

    USBSerialState *s = (USBSerialState *)dev;

    int ret = 0;

    uint8_t devep = p->devep;

    uint8_t *data = p->data;

    int len = p->len;

    int first_len;



    switch (p->pid) {

    case USB_TOKEN_OUT:

        if (devep != 2)

            goto fail;

        qemu_chr_write(s->cs, data, len);

        break;



    case USB_TOKEN_IN:

        if (devep != 1)

            goto fail;

        first_len = RECV_BUF - s->recv_ptr;

        if (len <= 2) {

            ret = USB_RET_NAK;

            break;

        }

        *data++ = usb_get_modem_lines(s) | 1;

        /* We do not have the uart details */

        /* handle serial break */

        if (s->event_trigger && s->event_trigger & FTDI_BI) {

            s->event_trigger &= ~FTDI_BI;

            *data = FTDI_BI;

            ret = 2;

            break;

        } else {

            *data++ = 0;

        }

        len -= 2;

        if (len > s->recv_used)

            len = s->recv_used;

        if (!len) {

            ret = USB_RET_NAK;

            break;

        }

        if (first_len > len)

            first_len = len;

        memcpy(data, s->recv_buf + s->recv_ptr, first_len);

        if (len > first_len)

            memcpy(data + first_len, s->recv_buf, len - first_len);

        s->recv_used -= len;

        s->recv_ptr = (s->recv_ptr + len) % RECV_BUF;

        ret = len + 2;

        break;



    default:

        DPRINTF("Bad token\n");

    fail:

        ret = USB_RET_STALL;

        break;

    }



    return ret;

}

static int usb_serial_handle_data(USBDevice *dev, USBPacket *p)

{

    USBSerialState *s = (USBSerialState *)dev;

    int ret = 0;

    uint8_t devep = p->devep;

    uint8_t *data = p->data;

    int len = p->len;

    int first_len;



    switch (p->pid) {

    case USB_TOKEN_OUT:

        if (devep != 2)

            goto fail;

        qemu_chr_write(s->cs, data, len);

        break;



    case USB_TOKEN_IN:

        if (devep != 1)

            goto fail;

        first_len = RECV_BUF - s->recv_ptr;

        if (len <= 2) {

            ret = USB_RET_NAK;

            break;

        }

        *data++ = usb_get_modem_lines(s) | 1;

        

        

        if (s->event_trigger && s->event_trigger & FTDI_BI) {

            s->event_trigger &= ~FTDI_BI;

            *data = FTDI_BI;

            ret = 2;

            break;

        } else {

            *data++ = 0;

        }

        len -= 2;

        if (len > s->recv_used)

            len = s->recv_used;

        if (!len) {

            ret = USB_RET_NAK;

            break;

        }

        if (first_len > len)

            first_len = len;

        memcpy(data, s->recv_buf + s->recv_ptr, first_len);

        if (len > first_len)

            memcpy(data + first_len, s->recv_buf, len - first_len);

        s->recv_used -= len;

        s->recv_ptr = (s->recv_ptr + len) % RECV_BUF;

        ret = len + 2;

        break;



    default:

        DPRINTF("Bad token\n");

    fail:

        ret = USB_RET_STALL;

        break;

    }



    return ret;

}

    uint8_t *data = p->data;     int len = p->len;     uint8_t *data = p->data;     int len = p->len;     uint8_t *data = p->data;     int len = p->len;
static int FUNC_0(USBDevice *VAR_0, USBPacket *VAR_1)

{

    USBSerialState *s = (USBSerialState *)VAR_0;

    int VAR_2 = 0;

    uint8_t devep = VAR_1->devep;

    uint8_t *data = VAR_1->data;

    int VAR_3 = VAR_1->VAR_3;

    int VAR_4;



    switch (VAR_1->pid) {

    case USB_TOKEN_OUT:

        if (devep != 2)

            goto fail;

        qemu_chr_write(s->cs, data, VAR_3);

        break;



    case USB_TOKEN_IN:

        if (devep != 1)

            goto fail;

        VAR_4 = RECV_BUF - s->recv_ptr;

        if (VAR_3 <= 2) {

            VAR_2 = USB_RET_NAK;

            break;

        }

        *data++ = usb_get_modem_lines(s) | 1;

        

        

        if (s->event_trigger && s->event_trigger & FTDI_BI) {

            s->event_trigger &= ~FTDI_BI;

            *data = FTDI_BI;

            VAR_2 = 2;

            break;

        } else {

            *data++ = 0;

        }

        VAR_3 -= 2;

        if (VAR_3 > s->recv_used)

            VAR_3 = s->recv_used;

        if (!VAR_3) {

            VAR_2 = USB_RET_NAK;

            break;

        }

        if (VAR_4 > VAR_3)

            VAR_4 = VAR_3;

        memcpy(data, s->recv_buf + s->recv_ptr, VAR_4);

        if (VAR_3 > VAR_4)

            memcpy(data + VAR_4, s->recv_buf, VAR_3 - VAR_4);

        s->recv_used -= VAR_3;

        s->recv_ptr = (s->recv_ptr + VAR_3) % RECV_BUF;

        VAR_2 = VAR_3 + 2;

        break;



    default:

        DPRINTF("Bad token\n");

    fail:

        VAR_2 = USB_RET_STALL;

        break;

    }



    return VAR_2;

}

static int FUNC_0(USBDevice *VAR_0, USBPacket *VAR_1)
{ USBSerialState *s = (USBSerialState *)VAR_0; int VAR_2 = 0; uint8_t devep = VAR_1->devep; uint8_t *data = VAR_1->data; int VAR_3 = VAR_1->VAR_3; int VAR_4; switch (VAR_1->pid) { case USB_TOKEN_OUT:
if (devep != 2)
goto fail; qemu_chr_write(s->cs, data, VAR_3); break; case USB_TOKEN_IN:
if (devep != 1)
goto fail; VAR_4 = RECV_BUF - s->recv_ptr; if (VAR_3 <= 2) { VAR_2 = USB_RET_NAK; break; } *data++ = usb_get_modem_lines(s) | 1; if (s->event_trigger && s->event_trigger & FTDI_BI) { s->event_trigger &= ~FTDI_BI; *data = FTDI_BI; VAR_2 = 2; break; } else { *data++ = 0; } VAR_3 -= 2; if (VAR_3 > s->recv_used)
VAR_3 = s->recv_used; if (!VAR_3) { VAR_2 = USB_RET_NAK; break; } if (VAR_4 > VAR_3)
VAR_4 = VAR_3; memcpy(data, s->recv_buf + s->recv_ptr, VAR_4); if (VAR_3 > VAR_4)
memcpy(data + VAR_4, s->recv_buf, VAR_3 - VAR_4); s->recv_used -= VAR_3; s->recv_ptr = (s->recv_ptr + VAR_3) % RECV_BUF; VAR_2 = VAR_3 + 2; break; default:
DPRINTF("Bad token\n"); fail:
VAR_2 = USB_RET_STALL; break; } return VAR_2; }