Exemplo n.º 1
0
/*
 *  This issues a Bulk-only Reset to the device in question, including
 *  clearing the subsequent endpoint halts that may occur.
 */
int  UMAS_BulkReset(UMAS_DATA_T *umas)
{
    int result;

    UMAS_VDEBUG("Bulk reset requested\n");
    printf("UMAS_BulkReset!\n");

    /* if the device was removed, then we're already reset */
    if(!umas->pusb_dev)
        return SUCCESS;

    result = USBH_SendCtrlMsg(umas->pusb_dev,
                              usb_sndctrlpipe(umas->pusb_dev, 0), UMAS_BULK_RESET_REQUEST,
                              USB_TYPE_CLASS | USB_RECIP_INTERFACE, 0, umas->ifnum,
                              NULL, 0, 0);
    if(result < 0)
    {
        UMAS_DEBUG("Bulk soft reset failed %d\n", result);
        return FAILED;
    }

    clear_halt(umas->pusb_dev, usb_rcvbulkpipe(umas->pusb_dev, umas->ep_in));
    clear_halt(umas->pusb_dev, usb_sndbulkpipe(umas->pusb_dev, umas->ep_out));

    UMAS_VDEBUG("Bulk soft reset completed\n");
    return SUCCESS;
}
Exemplo n.º 2
0
/* Determine what the maximum LUN supported is */
int  UMAS_BulkMaxLun(UMAS_DATA_T *umas)
{
    uint8_t     data;
    int     result;
    int     pipe;
    uint8_t     dma_buff[4];

    /* issue the command */
    pipe = usb_rcvctrlpipe(umas->pusb_dev, 0);
    result = USBH_SendCtrlMsg(umas->pusb_dev, pipe, UMAS_BULK_GET_MAX_LUN,
                              USB_DIR_IN | USB_TYPE_CLASS | USB_RECIP_INTERFACE,
                              0, umas->ifnum, dma_buff, 1, 0);

    data = dma_buff[0];

    UMAS_DEBUG("GetMaxLUN command result is %d, data is %d\n", result, data);

    /* if we have a successful request, return the result */
    if(result == 1)
        return data;

    /* if we get a STALL, clear the stall */
    if(result == USB_ERR_PIPE)
    {
        UMAS_DEBUG("clearing endpoint halt for pipe 0x%x\n", pipe);
        clear_halt(umas->pusb_dev, pipe);
    }

    /* return the default -- no LUNs */
    return 0;
}
Exemplo n.º 3
0
/*
 *  This issues a CB[I] Reset to the device in question
 */
int  UMAS_CbReset(UMAS_DATA_T *umas)
{
    uint8_t   cmd[12];
    int     result;

    /* if the device was removed, then we're already reset */
    if(!umas->pusb_dev)
        return SUCCESS;

    memset(cmd, 0xFF, sizeof(cmd));
    cmd[0] = SEND_DIAGNOSTIC;
    cmd[1] = 4;
    result = USBH_SendCtrlMsg(umas->pusb_dev, usb_sndctrlpipe(umas->pusb_dev, 0),
                              US_CBI_ADSC, USB_TYPE_CLASS | USB_RECIP_INTERFACE,
                              0, umas->ifnum, cmd, sizeof(cmd), 0);
    if(result < 0)
    {
        UMAS_DEBUG("UMAS_CbReset - CB[I] soft reset failed %d\n", result);
        return FAILED;
    }

    UMAS_VDEBUG("UMAS_CbReset - clearing endpoint halt\n");
    clear_halt(umas->pusb_dev, usb_rcvbulkpipe(umas->pusb_dev, umas->ep_in));
    clear_halt(umas->pusb_dev, usb_rcvbulkpipe(umas->pusb_dev, umas->ep_out));

    UMAS_VDEBUG("UMAS_CbReset - done\n");
    /* return a result code based on the result of the control message */
    return SUCCESS;
}
Exemplo n.º 4
0
static int  usb_get_port_status(USB_DEV_T *dev, int port, void *data)
{
    int             status;
    uint32_t        stack_buff[8];

    status = USBH_SendCtrlMsg(dev, usb_rcvctrlpipe(dev, 0),
                              USB_REQ_GET_STATUS, USB_DIR_IN | USB_RT_PORT, 0, port,
                              (void *)&stack_buff[0], sizeof(USB_PORT_STATUS_T), HZ * 5);
    memcpy((uint8_t *)data, (uint8_t *)&stack_buff[0], sizeof(USB_PORT_STATUS_T));
    return status;
}
Exemplo n.º 5
0
/* This is a version of usb_clear_halt() that doesn't read the status from
 * the device -- this is because some devices crash their internal firmware
 * when the status is requested after a halt
 */
static int  clear_halt(USB_DEV_T *dev, int pipe)
{
    int    result;
    int    endp = usb_pipeendpoint(pipe) | (usb_pipein(pipe) << 7);

    UMAS_DEBUG("clear_halt!\n");
    result = USBH_SendCtrlMsg(dev, usb_sndctrlpipe(dev, 0),
                              USB_REQ_CLEAR_FEATURE, USB_RECIP_ENDPOINT, 0,
                              endp, NULL, 0, 0);
    /* this is a failure case */
    if(result < 0)
    {
        UMAS_DEBUG("clear_halt failed!!\n");
        return result;
    }

    /* reset the toggles and endpoint flags */
    usb_endpoint_running(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe));
    usb_settoggle(dev, usb_pipeendpoint(pipe), usb_pipeout(pipe), 0x1000);

    return 0;
}
Exemplo n.º 6
0
static int  usb_set_port_feature(USB_DEV_T *dev, int port, int feature)
{
    USB_info("usb_set_port_feature, port:%d of hub:%d\n", port, dev->devnum);
    return USBH_SendCtrlMsg(dev, usb_sndctrlpipe(dev, 0),
                            USB_REQ_SET_FEATURE, USB_RT_PORT, feature, port, NULL, 0, HZ);
}
Exemplo n.º 7
0
static int  usb_clear_port_feature(USB_DEV_T *dev, int port, int feature)
{
    return USBH_SendCtrlMsg(dev, usb_sndctrlpipe(dev, 0),
                            USB_REQ_CLEAR_FEATURE, USB_RT_PORT, feature, port, NULL, 0, HZ);
}
Exemplo n.º 8
0
static int  usb_clear_hub_feature(USB_DEV_T *dev, int feature)
{
    return USBH_SendCtrlMsg(dev, usb_sndctrlpipe(dev, 0),
                            USB_REQ_CLEAR_FEATURE, USB_RT_HUB, feature, 0, NULL, 0, HZ);
}
Exemplo n.º 9
0
static int  usb_get_hub_descriptor(USB_DEV_T *dev, void *data, int size)
{
    return USBH_SendCtrlMsg(dev, usb_rcvctrlpipe(dev, 0),
                            USB_REQ_GET_DESCRIPTOR, USB_DIR_IN | USB_RT_HUB,
                            USB_DT_HUB << 8, 0, data, size, HZ);
}