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

{

    int request, value, index;

    int ret = 0;



    assert(p->devep == 0);



    request = (s->setup_buf[0] << 8) | s->setup_buf[1];

    value   = (s->setup_buf[3] << 8) | s->setup_buf[2];

    index   = (s->setup_buf[5] << 8) | s->setup_buf[4];

 

    switch(s->setup_state) {

    case SETUP_STATE_ACK:

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

            ret = usb_device_handle_control(s, p, request, value, index,

                                            s->setup_len, s->data_buf);

            if (ret == USB_RET_ASYNC) {

                return USB_RET_ASYNC;

            }

            s->setup_state = SETUP_STATE_IDLE;

            if (ret > 0)

                return 0;

            return ret;

        }



        /* return 0 byte */

        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_in(USBDevice *s, USBPacket *p)

{

    int request, value, index;

    int ret = 0;



    assert(p->devep == 0);



    request = (s->setup_buf[0] << 8) | s->setup_buf[1];

    value   = (s->setup_buf[3] << 8) | s->setup_buf[2];

    index   = (s->setup_buf[5] << 8) | s->setup_buf[4];

 

    switch(s->setup_state) {

    case SETUP_STATE_ACK:

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

            ret = usb_device_handle_control(s, p, request, value, index,

                                            s->setup_len, s->data_buf);

            if (ret == USB_RET_ASYNC) {

                return USB_RET_ASYNC;

            }

            s->setup_state = SETUP_STATE_IDLE;

            if (ret > 0)

                return 0;

            return ret;

        }



        

        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)

{

    int VAR_2, VAR_3, VAR_4;

    int VAR_5 = 0;



    assert(VAR_1->devep == 0);



    VAR_2 = (VAR_0->setup_buf[0] << 8) | VAR_0->setup_buf[1];

    VAR_3   = (VAR_0->setup_buf[3] << 8) | VAR_0->setup_buf[2];

    VAR_4   = (VAR_0->setup_buf[5] << 8) | VAR_0->setup_buf[4];

 

    switch(VAR_0->setup_state) {

    case SETUP_STATE_ACK:

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

            VAR_5 = usb_device_handle_control(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4,

                                            VAR_0->setup_len, VAR_0->data_buf);

            if (VAR_5 == USB_RET_ASYNC) {

                return USB_RET_ASYNC;

            }

            VAR_0->setup_state = SETUP_STATE_IDLE;

            if (VAR_5 > 0)

                return 0;

            return VAR_5;

        }



        

        return 0;



    case SETUP_STATE_DATA:

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

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

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

                VAR_6 = VAR_1->iov.size;

            }

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

            VAR_0->setup_index += VAR_6;

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

                VAR_0->setup_state = SETUP_STATE_ACK;

            return VAR_6;

        }



        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)
{ int VAR_2, VAR_3, VAR_4; int VAR_5 = 0; assert(VAR_1->devep == 0); VAR_2 = (VAR_0->setup_buf[0] << 8) | VAR_0->setup_buf[1]; VAR_3   = (VAR_0->setup_buf[3] << 8) | VAR_0->setup_buf[2]; VAR_4   = (VAR_0->setup_buf[5] << 8) | VAR_0->setup_buf[4]; switch(VAR_0->setup_state) { case SETUP_STATE_ACK:
if (!(VAR_0->setup_buf[0] & USB_DIR_IN)) { VAR_5 = usb_device_handle_control(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4,
VAR_0->setup_len, VAR_0->data_buf); if (VAR_5 == USB_RET_ASYNC) { return USB_RET_ASYNC; } VAR_0->setup_state = SETUP_STATE_IDLE; if (VAR_5 > 0)
return 0; return VAR_5; } return 0; case SETUP_STATE_DATA:
if (VAR_0->setup_buf[0] & USB_DIR_IN) { int VAR_6 = VAR_0->setup_len - VAR_0->setup_index; if (VAR_6 > VAR_1->iov.size) { VAR_6 = VAR_1->iov.size; } usb_packet_copy(VAR_1, VAR_0->data_buf + VAR_0->setup_index, VAR_6); VAR_0->setup_index += VAR_6; if (VAR_0->setup_index >= VAR_0->setup_len)
VAR_0->setup_state = SETUP_STATE_ACK; return VAR_6; } VAR_0->setup_state = SETUP_STATE_IDLE; return USB_RET_STALL; default:
return USB_RET_STALL; } }