static int usb_wacom_handle_control(USBDevice *dev, int request, int value,

                                    int index, int length, uint8_t *data)

{

    USBWacomState *s = (USBWacomState *) dev;

    int ret;



    ret = usb_desc_handle_control(dev, request, value, index, length, data);

    if (ret >= 0) {

        return ret;

    }



    ret = 0;

    switch (request) {

    case DeviceRequest | USB_REQ_GET_STATUS:

        data[0] = (1 << USB_DEVICE_SELF_POWERED) |

            (dev->remote_wakeup << 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;

        } else {

            goto fail;

        }

        ret = 0;

        break;

    case DeviceOutRequest | USB_REQ_SET_FEATURE:

        if (value == USB_DEVICE_REMOTE_WAKEUP) {

            dev->remote_wakeup = 1;

        } else {

            goto fail;

        }

        ret = 0;

        break;

    case DeviceRequest | USB_REQ_GET_CONFIGURATION:

        data[0] = 1;

        ret = 1;

        break;

    case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:

        ret = 0;

        break;

    case DeviceRequest | USB_REQ_GET_INTERFACE:

        data[0] = 0;

        ret = 1;

        break;

    case DeviceOutRequest | USB_REQ_SET_INTERFACE:

        ret = 0;

        break;

    case WACOM_SET_REPORT:

        if (s->mouse_grabbed) {

            qemu_remove_mouse_event_handler(s->eh_entry);

            s->mouse_grabbed = 0;

        }

        s->mode = data[0];

        ret = 0;

        break;

    case WACOM_GET_REPORT:

        data[0] = 0;

        data[1] = s->mode;

        ret = 2;

        break;

    /* USB HID requests */

    case HID_GET_REPORT:

        if (s->mode == WACOM_MODE_HID)

            ret = usb_mouse_poll(s, data, length);

        else if (s->mode == WACOM_MODE_WACOM)

            ret = usb_wacom_poll(s, data, length);

        break;

    case HID_GET_IDLE:

        ret = 1;

        data[0] = s->idle;

        break;

    case HID_SET_IDLE:

        s->idle = (uint8_t) (value >> 8);

        ret = 0;

        break;

    default:

    fail:

        ret = USB_RET_STALL;

        break;

    }

    return ret;

}

static int usb_wacom_handle_control(USBDevice *dev, int request, int value,

                                    int index, int length, uint8_t *data)

{

    USBWacomState *s = (USBWacomState *) dev;

    int ret;



    ret = usb_desc_handle_control(dev, request, value, index, length, data);

    if (ret >= 0) {

        return ret;

    }



    ret = 0;

    switch (request) {

    case DeviceRequest | USB_REQ_GET_STATUS:

        data[0] = (1 << USB_DEVICE_SELF_POWERED) |

            (dev->remote_wakeup << 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;

        } else {

            goto fail;

        }

        ret = 0;

        break;

    case DeviceOutRequest | USB_REQ_SET_FEATURE:

        if (value == USB_DEVICE_REMOTE_WAKEUP) {

            dev->remote_wakeup = 1;

        } else {

            goto fail;

        }

        ret = 0;

        break;

    case DeviceRequest | USB_REQ_GET_CONFIGURATION:

        data[0] = 1;

        ret = 1;

        break;

    case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:

        ret = 0;

        break;

    case DeviceRequest | USB_REQ_GET_INTERFACE:

        data[0] = 0;

        ret = 1;

        break;

    case DeviceOutRequest | USB_REQ_SET_INTERFACE:

        ret = 0;

        break;

    case WACOM_SET_REPORT:

        if (s->mouse_grabbed) {

            qemu_remove_mouse_event_handler(s->eh_entry);

            s->mouse_grabbed = 0;

        }

        s->mode = data[0];

        ret = 0;

        break;

    case WACOM_GET_REPORT:

        data[0] = 0;

        data[1] = s->mode;

        ret = 2;

        break;

    

    case HID_GET_REPORT:

        if (s->mode == WACOM_MODE_HID)

            ret = usb_mouse_poll(s, data, length);

        else if (s->mode == WACOM_MODE_WACOM)

            ret = usb_wacom_poll(s, data, length);

        break;

    case HID_GET_IDLE:

        ret = 1;

        data[0] = s->idle;

        break;

    case HID_SET_IDLE:

        s->idle = (uint8_t) (value >> 8);

        ret = 0;

        break;

    default:

    fail:

        ret = USB_RET_STALL;

        break;

    }

    return ret;

}

static int FUNC_0(USBDevice *VAR_0, int VAR_1, int VAR_2,

                                    int VAR_3, int VAR_4, uint8_t *VAR_5)

{

    USBWacomState *s = (USBWacomState *) VAR_0;

    int VAR_6;



    VAR_6 = usb_desc_handle_control(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5);

    if (VAR_6 >= 0) {

        return VAR_6;

    }



    VAR_6 = 0;

    switch (VAR_1) {

    case DeviceRequest | USB_REQ_GET_STATUS:

        VAR_5[0] = (1 << USB_DEVICE_SELF_POWERED) |

            (VAR_0->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP);

        VAR_5[1] = 0x00;

        VAR_6 = 2;

        break;

    case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:

        if (VAR_2 == USB_DEVICE_REMOTE_WAKEUP) {

            VAR_0->remote_wakeup = 0;

        } else {

            goto fail;

        }

        VAR_6 = 0;

        break;

    case DeviceOutRequest | USB_REQ_SET_FEATURE:

        if (VAR_2 == USB_DEVICE_REMOTE_WAKEUP) {

            VAR_0->remote_wakeup = 1;

        } else {

            goto fail;

        }

        VAR_6 = 0;

        break;

    case DeviceRequest | USB_REQ_GET_CONFIGURATION:

        VAR_5[0] = 1;

        VAR_6 = 1;

        break;

    case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:

        VAR_6 = 0;

        break;

    case DeviceRequest | USB_REQ_GET_INTERFACE:

        VAR_5[0] = 0;

        VAR_6 = 1;

        break;

    case DeviceOutRequest | USB_REQ_SET_INTERFACE:

        VAR_6 = 0;

        break;

    case WACOM_SET_REPORT:

        if (s->mouse_grabbed) {

            qemu_remove_mouse_event_handler(s->eh_entry);

            s->mouse_grabbed = 0;

        }

        s->mode = VAR_5[0];

        VAR_6 = 0;

        break;

    case WACOM_GET_REPORT:

        VAR_5[0] = 0;

        VAR_5[1] = s->mode;

        VAR_6 = 2;

        break;

    

    case HID_GET_REPORT:

        if (s->mode == WACOM_MODE_HID)

            VAR_6 = usb_mouse_poll(s, VAR_5, VAR_4);

        else if (s->mode == WACOM_MODE_WACOM)

            VAR_6 = usb_wacom_poll(s, VAR_5, VAR_4);

        break;

    case HID_GET_IDLE:

        VAR_6 = 1;

        VAR_5[0] = s->idle;

        break;

    case HID_SET_IDLE:

        s->idle = (uint8_t) (VAR_2 >> 8);

        VAR_6 = 0;

        break;

    default:

    fail:

        VAR_6 = USB_RET_STALL;

        break;

    }

    return VAR_6;

}

static int FUNC_0(USBDevice *VAR_0, int VAR_1, int VAR_2,
int VAR_3, int VAR_4, uint8_t *VAR_5)
{ USBWacomState *s = (USBWacomState *) VAR_0; int VAR_6; VAR_6 = usb_desc_handle_control(VAR_0, VAR_1, VAR_2, VAR_3, VAR_4, VAR_5); if (VAR_6 >= 0) { return VAR_6; } VAR_6 = 0; switch (VAR_1) { case DeviceRequest | USB_REQ_GET_STATUS:
VAR_5[0] = (1 << USB_DEVICE_SELF_POWERED) |
(VAR_0->remote_wakeup << USB_DEVICE_REMOTE_WAKEUP); VAR_5[1] = 0x00; VAR_6 = 2; break; case DeviceOutRequest | USB_REQ_CLEAR_FEATURE:
if (VAR_2 == USB_DEVICE_REMOTE_WAKEUP) { VAR_0->remote_wakeup = 0; } else { goto fail; } VAR_6 = 0; break; case DeviceOutRequest | USB_REQ_SET_FEATURE:
if (VAR_2 == USB_DEVICE_REMOTE_WAKEUP) { VAR_0->remote_wakeup = 1; } else { goto fail; } VAR_6 = 0; break; case DeviceRequest | USB_REQ_GET_CONFIGURATION:
VAR_5[0] = 1; VAR_6 = 1; break; case DeviceOutRequest | USB_REQ_SET_CONFIGURATION:
VAR_6 = 0; break; case DeviceRequest | USB_REQ_GET_INTERFACE:
VAR_5[0] = 0; VAR_6 = 1; break; case DeviceOutRequest | USB_REQ_SET_INTERFACE:
VAR_6 = 0; break; case WACOM_SET_REPORT:
if (s->mouse_grabbed) { qemu_remove_mouse_event_handler(s->eh_entry); s->mouse_grabbed = 0; } s->mode = VAR_5[0]; VAR_6 = 0; break; case WACOM_GET_REPORT:
VAR_5[0] = 0; VAR_5[1] = s->mode; VAR_6 = 2; break; case HID_GET_REPORT:
if (s->mode == WACOM_MODE_HID)
VAR_6 = usb_mouse_poll(s, VAR_5, VAR_4); else if (s->mode == WACOM_MODE_WACOM)
VAR_6 = usb_wacom_poll(s, VAR_5, VAR_4); break; case HID_GET_IDLE:
VAR_6 = 1; VAR_5[0] = s->idle; break; case HID_SET_IDLE:
s->idle = (uint8_t) (VAR_2 >> 8); VAR_6 = 0; break; default:
fail:
VAR_6 = USB_RET_STALL; break; } return VAR_6; }