/* This function will do USB_REQ_GET_DESCRIPTO' bRequest for the usb device instance, */
rt_err_t rt_usbh_get_descriptor(uinst_t device, rt_uint8_t type, void *buffer, int nbytes)
/* This function will do USB_REQ_GET_DESCRIPTO' bRequest for the usb device instance, */
rt_err_t rt_usbh_get_descriptor(uinst_t device, rt_uint8_t type, void *buffer, int nbytes)
{
    struct urequest setup;
    int timeout = USB_TIMEOUT_BASIC;
    RT_ASSERT(device != RT_NULL);
    setup.request_type = USB_REQ_TYPE_DIR_IN | USB_REQ_TYPE_STANDARD |
        USB_REQ_TYPE_DEVICE;
    setup.bRequest = USB_REQ_GET_DESCRIPTOR;
    setup.wIndex = 0;
    setup.wLength = nbytes;
    setup.wValue = type << 8;
    if(rt_usb_hcd_setup_xfer(device->hcd, device->pipe_ep0_out, &setup, timeout) == 8)
    {
        if(rt_usb_hcd_pipe_xfer(device->hcd, device->pipe_ep0_in, buffer, nbytes, timeout) == nbytes)
        {
            if(rt_usb_hcd_pipe_xfer(device->hcd, device->pipe_ep0_out, RT_NULL, 0, timeout) == 0)
            {
                return RT_EOK;
            }
        }
    }
    return -RT_ERROR;
}