int usb_desc_get_descriptor(USBDevice *dev, int value, uint8_t *dest, size_t len)

{

    const USBDesc *desc = dev->info->usb_desc;

    uint8_t buf[256];

    uint8_t type = value >> 8;

    uint8_t index = value & 0xff;

    int ret = -1;



    switch(type) {

    case USB_DT_DEVICE:

        ret = usb_desc_device(&desc->id, desc->full, buf, sizeof(buf));

        trace_usb_desc_device(dev->addr, len, ret);

        break;

    case USB_DT_CONFIG:

        if (index < desc->full->bNumConfigurations) {

            ret = usb_desc_config(desc->full->confs + index, buf, sizeof(buf));

        }

        trace_usb_desc_config(dev->addr, index, len, ret);

        break;

    case USB_DT_STRING:

        ret = usb_desc_string(dev, index, buf, sizeof(buf));

        trace_usb_desc_string(dev->addr, index, len, ret);

        break;

    default:

        fprintf(stderr, "%s: %d unknown type %d (len %zd)\n", __FUNCTION__,

                dev->addr, type, len);

        break;

    }



    if (ret > 0) {

        if (ret > len) {

            ret = len;

        }

        memcpy(dest, buf, ret);

    }

    return ret;

}

int usb_desc_get_descriptor(USBDevice *dev, int value, uint8_t *dest, size_t len)

{

    const USBDesc *desc = dev->info->usb_desc;

    uint8_t buf[256];

    uint8_t type = value >> 8;

    uint8_t index = value & 0xff;

    int ret = -1;



    switch(type) {

    case USB_DT_DEVICE:

        ret = usb_desc_device(&desc->id, desc->full, buf, sizeof(buf));

        trace_usb_desc_device(dev->addr, len, ret);

        break;

    case USB_DT_CONFIG:

        if (index < desc->full->bNumConfigurations) {

            ret = usb_desc_config(desc->full->confs + index, buf, sizeof(buf));

        }

        trace_usb_desc_config(dev->addr, index, len, ret);

        break;

    case USB_DT_STRING:

        ret = usb_desc_string(dev, index, buf, sizeof(buf));

        trace_usb_desc_string(dev->addr, index, len, ret);

        break;

    default:

        fprintf(stderr, "%s: %d unknown type %d (len %zd)\n", __FUNCTION__,

                dev->addr, type, len);

        break;

    }



    if (ret > 0) {

        if (ret > len) {

            ret = len;

        }

        memcpy(dest, buf, ret);

    }

    return ret;

}

int FUNC_0(USBDevice *VAR_0, int VAR_1, uint8_t *VAR_2, size_t VAR_3)

{

    const USBDesc *VAR_4 = VAR_0->info->usb_desc;

    uint8_t buf[256];

    uint8_t type = VAR_1 >> 8;

    uint8_t index = VAR_1 & 0xff;

    int VAR_5 = -1;



    switch(type) {

    case USB_DT_DEVICE:

        VAR_5 = usb_desc_device(&VAR_4->id, VAR_4->full, buf, sizeof(buf));

        trace_usb_desc_device(VAR_0->addr, VAR_3, VAR_5);

        break;

    case USB_DT_CONFIG:

        if (index < VAR_4->full->bNumConfigurations) {

            VAR_5 = usb_desc_config(VAR_4->full->confs + index, buf, sizeof(buf));

        }

        trace_usb_desc_config(VAR_0->addr, index, VAR_3, VAR_5);

        break;

    case USB_DT_STRING:

        VAR_5 = usb_desc_string(VAR_0, index, buf, sizeof(buf));

        trace_usb_desc_string(VAR_0->addr, index, VAR_3, VAR_5);

        break;

    default:

        fprintf(stderr, "%s: %d unknown type %d (VAR_3 %zd)\n", __FUNCTION__,

                VAR_0->addr, type, VAR_3);

        break;

    }



    if (VAR_5 > 0) {

        if (VAR_5 > VAR_3) {

            VAR_5 = VAR_3;

        }

        memcpy(VAR_2, buf, VAR_5);

    }

    return VAR_5;

}

int FUNC_0(USBDevice *VAR_0, int VAR_1, uint8_t *VAR_2, size_t VAR_3)
{ const USBDesc *VAR_4 = VAR_0->info->usb_desc; uint8_t buf[256]; uint8_t type = VAR_1 >> 8; uint8_t index = VAR_1 & 0xff; int VAR_5 = -1; switch(type) { case USB_DT_DEVICE:
VAR_5 = usb_desc_device(&VAR_4->id, VAR_4->full, buf, sizeof(buf)); trace_usb_desc_device(VAR_0->addr, VAR_3, VAR_5); break; case USB_DT_CONFIG:
if (index < VAR_4->full->bNumConfigurations) { VAR_5 = usb_desc_config(VAR_4->full->confs + index, buf, sizeof(buf)); } trace_usb_desc_config(VAR_0->addr, index, VAR_3, VAR_5); break; case USB_DT_STRING:
VAR_5 = usb_desc_string(VAR_0, index, buf, sizeof(buf)); trace_usb_desc_string(VAR_0->addr, index, VAR_3, VAR_5); break; default:
fprintf(stderr, "%s: %d unknown type %d (VAR_3 %zd)\n", __FUNCTION__,
VAR_0->addr, type, VAR_3); break; } if (VAR_5 > 0) { if (VAR_5 > VAR_3) { VAR_5 = VAR_3; } memcpy(VAR_2, buf, VAR_5); } return VAR_5; }