static int do_token_out(USBDevice *s, USBPacket *p)

{

    assert(p->devep == 0);



    switch(s->setup_state) {

    case SETUP_STATE_ACK:

        if (s->setup_buf[0] & USB_DIR_IN) {

            s->setup_state = SETUP_STATE_IDLE;

            /* transfer OK */

        } else {

            /* ignore additional output */

        }

        return 0;



    case SETUP_STATE_DATA:

        if (!(s->setup_buf[0] & USB_DIR_IN)) {

            int len = s->setup_len - s->setup_index;

            if (len > p->iov.size) {

                len = p->iov.size;

            }

            usb_packet_copy(p, s->data_buf + s->setup_index, len);

            s->setup_index += len;

            if (s->setup_index >= s->setup_len)

                s->setup_state = SETUP_STATE_ACK;

            return len;

        }



        s->setup_state = SETUP_STATE_IDLE;

        return USB_RET_STALL;



    default:

        return USB_RET_STALL;

    }

}

static int do_token_out(USBDevice *s, USBPacket *p)

{

    assert(p->devep == 0);



    switch(s->setup_state) {

    case SETUP_STATE_ACK:

        if (s->setup_buf[0] & USB_DIR_IN) {

            s->setup_state = SETUP_STATE_IDLE;

            

        } else {

            

        }

        return 0;



    case SETUP_STATE_DATA:

        if (!(s->setup_buf[0] & USB_DIR_IN)) {

            int len = s->setup_len - s->setup_index;

            if (len > p->iov.size) {

                len = p->iov.size;

            }

            usb_packet_copy(p, s->data_buf + s->setup_index, len);

            s->setup_index += len;

            if (s->setup_index >= s->setup_len)

                s->setup_state = SETUP_STATE_ACK;

            return len;

        }



        s->setup_state = SETUP_STATE_IDLE;

        return USB_RET_STALL;



    default:

        return USB_RET_STALL;

    }

}

static int FUNC_0(USBDevice *VAR_0, USBPacket *VAR_1)

{

    assert(VAR_1->devep == 0);



    switch(VAR_0->setup_state) {

    case SETUP_STATE_ACK:

        if (VAR_0->setup_buf[0] & USB_DIR_IN) {

            VAR_0->setup_state = SETUP_STATE_IDLE;

            

        } else {

            

        }

        return 0;



    case SETUP_STATE_DATA:

        if (!(VAR_0->setup_buf[0] & USB_DIR_IN)) {

            int VAR_2 = VAR_0->setup_len - VAR_0->setup_index;

            if (VAR_2 > VAR_1->iov.size) {

                VAR_2 = VAR_1->iov.size;

            }

            usb_packet_copy(VAR_1, VAR_0->data_buf + VAR_0->setup_index, VAR_2);

            VAR_0->setup_index += VAR_2;

            if (VAR_0->setup_index >= VAR_0->setup_len)

                VAR_0->setup_state = SETUP_STATE_ACK;

            return VAR_2;

        }



        VAR_0->setup_state = SETUP_STATE_IDLE;

        return USB_RET_STALL;



    default:

        return USB_RET_STALL;

    }

}

static int FUNC_0(USBDevice *VAR_0, USBPacket *VAR_1)
{ assert(VAR_1->devep == 0); switch(VAR_0->setup_state) { case SETUP_STATE_ACK:
if (VAR_0->setup_buf[0] & USB_DIR_IN) { VAR_0->setup_state = SETUP_STATE_IDLE; } else { } return 0; case SETUP_STATE_DATA:
if (!(VAR_0->setup_buf[0] & USB_DIR_IN)) { int VAR_2 = VAR_0->setup_len - VAR_0->setup_index; if (VAR_2 > VAR_1->iov.size) { VAR_2 = VAR_1->iov.size; } usb_packet_copy(VAR_1, VAR_0->data_buf + VAR_0->setup_index, VAR_2); VAR_0->setup_index += VAR_2; if (VAR_0->setup_index >= VAR_0->setup_len)
VAR_0->setup_state = SETUP_STATE_ACK; return VAR_2; } VAR_0->setup_state = SETUP_STATE_IDLE; return USB_RET_STALL; default:
return USB_RET_STALL; } }