int usb_desc_handle_control(USBDevice *dev, USBPacket *p,

        int request, int value, int index, int length, uint8_t *data)

{

    const USBDesc *desc = usb_device_get_usb_desc(dev);

    int ret = -1;



    assert(desc != NULL);

    switch(request) {

    case DeviceOutRequest | USB_REQ_SET_ADDRESS:

        dev->addr = value;

        trace_usb_set_addr(dev->addr);

        ret = 0;

        break;



    case DeviceRequest | USB_REQ_GET_DESCRIPTOR:

        ret = usb_desc_get_descriptor(dev, value, data, length);

        break;



    case DeviceRequest | USB_REQ_GET_CONFIGURATION:

        data[0] = dev->config->bConfigurationValue;

        ret = 1;

        break;

    case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:

        ret = usb_desc_set_config(dev, value);

        trace_usb_set_config(dev->addr, value, ret);

        break;



    case DeviceRequest | USB_REQ_GET_STATUS:

        data[0] = 0;

        if (dev->config->bmAttributes & 0x40) {

            data[0] |= 1 << USB_DEVICE_SELF_POWERED;

        }

        if (dev->remote_wakeup) {

            data[0] |= 1 << USB_DEVICE_REMOTE_WAKEUP;

        }

        data[1] = 0x00;

        ret = 2;

        break;

    case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:

        if (value == USB_DEVICE_REMOTE_WAKEUP) {

            dev->remote_wakeup = 0;

            ret = 0;

        }

        trace_usb_clear_device_feature(dev->addr, value, ret);

        break;

    case DeviceOutRequest | USB_REQ_SET_FEATURE:

        if (value == USB_DEVICE_REMOTE_WAKEUP) {

            dev->remote_wakeup = 1;

            ret = 0;

        }

        trace_usb_set_device_feature(dev->addr, value, ret);

        break;



    case InterfaceRequest | USB_REQ_GET_INTERFACE:

        if (index < 0 || index >= dev->ninterfaces) {

            break;

        }

        data[0] = dev->altsetting[index];

        ret = 1;

        break;

    case InterfaceOutRequest | USB_REQ_SET_INTERFACE:

        ret = usb_desc_set_interface(dev, index, value);

        trace_usb_set_interface(dev->addr, index, value, ret);

        break;



    }

    return ret;

}

int usb_desc_handle_control(USBDevice *dev, USBPacket *p,

        int request, int value, int index, int length, uint8_t *data)

{

    const USBDesc *desc = usb_device_get_usb_desc(dev);

    int ret = -1;



    assert(desc != NULL);

    switch(request) {

    case DeviceOutRequest | USB_REQ_SET_ADDRESS:

        dev->addr = value;

        trace_usb_set_addr(dev->addr);

        ret = 0;

        break;



    case DeviceRequest | USB_REQ_GET_DESCRIPTOR:

        ret = usb_desc_get_descriptor(dev, value, data, length);

        break;



    case DeviceRequest | USB_REQ_GET_CONFIGURATION:

        data[0] = dev->config->bConfigurationValue;

        ret = 1;

        break;

    case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:

        ret = usb_desc_set_config(dev, value);

        trace_usb_set_config(dev->addr, value, ret);

        break;



    case DeviceRequest | USB_REQ_GET_STATUS:

        data[0] = 0;

        if (dev->config->bmAttributes & 0x40) {

            data[0] |= 1 << USB_DEVICE_SELF_POWERED;

        }

        if (dev->remote_wakeup) {

            data[0] |= 1 << USB_DEVICE_REMOTE_WAKEUP;

        }

        data[1] = 0x00;

        ret = 2;

        break;

    case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:

        if (value == USB_DEVICE_REMOTE_WAKEUP) {

            dev->remote_wakeup = 0;

            ret = 0;

        }

        trace_usb_clear_device_feature(dev->addr, value, ret);

        break;

    case DeviceOutRequest | USB_REQ_SET_FEATURE:

        if (value == USB_DEVICE_REMOTE_WAKEUP) {

            dev->remote_wakeup = 1;

            ret = 0;

        }

        trace_usb_set_device_feature(dev->addr, value, ret);

        break;



    case InterfaceRequest | USB_REQ_GET_INTERFACE:

        if (index < 0 || index >= dev->ninterfaces) {

            break;

        }

        data[0] = dev->altsetting[index];

        ret = 1;

        break;

    case InterfaceOutRequest | USB_REQ_SET_INTERFACE:

        ret = usb_desc_set_interface(dev, index, value);

        trace_usb_set_interface(dev->addr, index, value, ret);

        break;



    }

    return ret;

}

        data[0] = dev->config->bConfigurationValue;     case DeviceRequest | USB_REQ_GET_STATUS:         if (dev->config->bmAttributes & 0x40) {
int FUNC_0(USBDevice *VAR_0, USBPacket *VAR_1,

        int VAR_2, int VAR_3, int VAR_4, int VAR_5, uint8_t *VAR_6)

{

    const USBDesc *VAR_7 = usb_device_get_usb_desc(VAR_0);

    int VAR_8 = -1;



    assert(VAR_7 != NULL);

    switch(VAR_2) {

    case DeviceOutRequest | USB_REQ_SET_ADDRESS:

        VAR_0->addr = VAR_3;

        trace_usb_set_addr(VAR_0->addr);

        VAR_8 = 0;

        break;



    case DeviceRequest | USB_REQ_GET_DESCRIPTOR:

        VAR_8 = usb_desc_get_descriptor(VAR_0, VAR_3, VAR_6, VAR_5);

        break;



    case DeviceRequest | USB_REQ_GET_CONFIGURATION:

        VAR_6[0] = VAR_0->config->bConfigurationValue;

        VAR_8 = 1;

        break;

    case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:

        VAR_8 = usb_desc_set_config(VAR_0, VAR_3);

        trace_usb_set_config(VAR_0->addr, VAR_3, VAR_8);

        break;



    case DeviceRequest | USB_REQ_GET_STATUS:

        VAR_6[0] = 0;

        if (VAR_0->config->bmAttributes & 0x40) {

            VAR_6[0] |= 1 << USB_DEVICE_SELF_POWERED;

        }

        if (VAR_0->remote_wakeup) {

            VAR_6[0] |= 1 << USB_DEVICE_REMOTE_WAKEUP;

        }

        VAR_6[1] = 0x00;

        VAR_8 = 2;

        break;

    case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:

        if (VAR_3 == USB_DEVICE_REMOTE_WAKEUP) {

            VAR_0->remote_wakeup = 0;

            VAR_8 = 0;

        }

        trace_usb_clear_device_feature(VAR_0->addr, VAR_3, VAR_8);

        break;

    case DeviceOutRequest | USB_REQ_SET_FEATURE:

        if (VAR_3 == USB_DEVICE_REMOTE_WAKEUP) {

            VAR_0->remote_wakeup = 1;

            VAR_8 = 0;

        }

        trace_usb_set_device_feature(VAR_0->addr, VAR_3, VAR_8);

        break;



    case InterfaceRequest | USB_REQ_GET_INTERFACE:

        if (VAR_4 < 0 || VAR_4 >= VAR_0->ninterfaces) {

            break;

        }

        VAR_6[0] = VAR_0->altsetting[VAR_4];

        VAR_8 = 1;

        break;

    case InterfaceOutRequest | USB_REQ_SET_INTERFACE:

        VAR_8 = usb_desc_set_interface(VAR_0, VAR_4, VAR_3);

        trace_usb_set_interface(VAR_0->addr, VAR_4, VAR_3, VAR_8);

        break;



    }

    return VAR_8;

}

int FUNC_0(USBDevice *VAR_0, USBPacket *VAR_1,
int VAR_2, int VAR_3, int VAR_4, int VAR_5, uint8_t *VAR_6)
{ const USBDesc *VAR_7 = usb_device_get_usb_desc(VAR_0); int VAR_8 = -1; assert(VAR_7 != NULL); switch(VAR_2) { case DeviceOutRequest | USB_REQ_SET_ADDRESS:
VAR_0->addr = VAR_3; trace_usb_set_addr(VAR_0->addr); VAR_8 = 0; break; case DeviceRequest | USB_REQ_GET_DESCRIPTOR:
VAR_8 = usb_desc_get_descriptor(VAR_0, VAR_3, VAR_6, VAR_5); break; case DeviceRequest | USB_REQ_GET_CONFIGURATION:
VAR_6[0] = VAR_0->config->bConfigurationValue; VAR_8 = 1; break; case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
VAR_8 = usb_desc_set_config(VAR_0, VAR_3); trace_usb_set_config(VAR_0->addr, VAR_3, VAR_8); break; case DeviceRequest | USB_REQ_GET_STATUS:
VAR_6[0] = 0; if (VAR_0->config->bmAttributes & 0x40) { VAR_6[0] |= 1 << USB_DEVICE_SELF_POWERED; } if (VAR_0->remote_wakeup) { VAR_6[0] |= 1 << USB_DEVICE_REMOTE_WAKEUP; } VAR_6[1] = 0x00; VAR_8 = 2; break; case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
if (VAR_3 == USB_DEVICE_REMOTE_WAKEUP) { VAR_0->remote_wakeup = 0; VAR_8 = 0; } trace_usb_clear_device_feature(VAR_0->addr, VAR_3, VAR_8); break; case DeviceOutRequest | USB_REQ_SET_FEATURE:
if (VAR_3 == USB_DEVICE_REMOTE_WAKEUP) { VAR_0->remote_wakeup = 1; VAR_8 = 0; } trace_usb_set_device_feature(VAR_0->addr, VAR_3, VAR_8); break; case InterfaceRequest | USB_REQ_GET_INTERFACE:
if (VAR_4 < 0 || VAR_4 >= VAR_0->ninterfaces) { break; } VAR_6[0] = VAR_0->altsetting[VAR_4]; VAR_8 = 1; break; case InterfaceOutRequest | USB_REQ_SET_INTERFACE:
VAR_8 = usb_desc_set_interface(VAR_0, VAR_4, VAR_3); trace_usb_set_interface(VAR_0->addr, VAR_4, VAR_3, VAR_8); break; } return VAR_8; }