Ejemplo n.º 1
0
static uint8_t PIOS_USBHOOK_CLASS_DataOut(void *pdev, uint8_t epnum)
{
    /* Remove the direction bit so we can use this as an index */
    uint8_t epnum_idx = epnum & 0x7F;

    if ((epnum_idx < NELEMENTS(usb_epout_table)) && usb_epout_table[epnum_idx].cb) {
        struct usb_ep_entry *ep = &(usb_epout_table[epnum_idx]);
        if (!ep->cb(ep->context, epnum_idx, USBD_GetRxCount(pdev, epnum))) {
            /* NOTE: use real endpoint number including direction bit */
            DCD_SetEPStatus(pdev, epnum, USB_OTG_EP_RX_NAK);
        }
    }

    return USBD_OK;
}
Ejemplo n.º 2
0
/**
* @brief  MSC_BOT_CBW_Decode
*         Decode the CBW command and set the BOT state machine accordingtly
* @param  pdev: device instance
* @retval None
*/
static void  MSC_BOT_CBW_Decode (USB_OTG_CORE_HANDLE  *pdev)
{

  MSC_BOT_csw.dTag = MSC_BOT_cbw.dTag;
  MSC_BOT_csw.dDataResidue = MSC_BOT_cbw.dDataLength;

  if ((USBD_GetRxCount (pdev ,MSC_OUT_EP) != BOT_CBW_LENGTH) ||
      (MSC_BOT_cbw.dSignature != BOT_CBW_SIGNATURE)||
        (MSC_BOT_cbw.bLUN > 1) ||
          (MSC_BOT_cbw.bCBLength < 1) ||
            (MSC_BOT_cbw.bCBLength > 16))
  {

    SCSI_SenseCode(MSC_BOT_cbw.bLUN,
                   ILLEGAL_REQUEST,
                   INVALID_CDB);
     MSC_BOT_Status = BOT_STATE_ERROR;
    MSC_BOT_Abort(pdev);

  }
  else
  {
    if(SCSI_ProcessCmd(pdev,
                              MSC_BOT_cbw.bLUN,
                              &MSC_BOT_cbw.CB[0]) < 0)
    {
      MSC_BOT_Abort(pdev);
    }
    /*Burst xfer handled internally*/
    else if ((MSC_BOT_State != BOT_DATA_IN) &&
             (MSC_BOT_State != BOT_DATA_OUT) &&
             (MSC_BOT_State != BOT_LAST_DATA_IN))
    {
      if (MSC_BOT_DataLen > 0)
      {
        MSC_BOT_SendData(pdev,
                         MSC_BOT_Data,
                         MSC_BOT_DataLen);
      }
      else if (MSC_BOT_DataLen == 0)
      {
        MSC_BOT_SendCSW (pdev,
                         CSW_CMD_PASSED);
      }
    }
  }
}
Ejemplo n.º 3
0
/**
  * @brief  CCID_BulkMessage_Out
  *         Proccess CCID OUT data
  * @param  pdev: device instance
  * @param  uint8_t epnum: endpoint index
  * @retval None
  */
void CCID_BulkMessage_Out (USB_CORE_HANDLE  *pdev, 
                           uint8_t epnum)
{
  uint16_t dataLen;
  dataLen = USBD_GetRxCount (pdev, CCID_BULK_OUT_EP);
   
  switch (Ccid_BulkState)
  {
  case CCID_STATE_IDLE:
    if (dataLen == 0x00)
    { /* Zero Length Packet Received */
      Ccid_BulkState = CCID_STATE_IDLE;
    }
    else  if (dataLen >= CCID_MESSAGE_HEADER_SIZE)
    {
      UsbMessageLength = dataLen;   /* Store for future use */
      
      /* Expected Data Length Packet Received */
      pUsbMessageBuffer = (uint8_t*) &Ccid_bulkout_data;
      
      /* Fill CCID_BulkOut Data Buffer from USB Buffer */
      CCID_ReceiveCmdHeader(pUsbMessageBuffer, dataLen); 
      
      /*
      Refer : 6 CCID Messages
      The response messages always contain the exact same slot number, 
      and sequence number fields from the header that was contained in 
      the Bulk-OUT command message.
      */
      Ccid_bulkin_data.bSlot = Ccid_bulkout_data.bSlot;
      Ccid_bulkin_data.bSeq = Ccid_bulkout_data.bSeq; 
      
      if (dataLen < CCID_BULK_EPOUT_SIZE)
      {/* Short message, less than the EP Out Size, execute the command,
        if parameter like dwLength is too big, the appropriate command will 
        give an error */
        CCID_CmdDecode(pdev);  
      }
      else
      { /* Long message, receive additional data with command */
        /* (u8dataLen == CCID_BULK_EPOUT_SIZE) */
        
        if (Ccid_bulkout_data.dwLength > ABDATA_SIZE)
        { /* Check if length of data to be sent by host is > buffer size */
          
          /* Too long data received.... Error ! */
          Ccid_BulkState = CCID_STATE_UNCORRECT_LENGTH;
        }
        
        else 
        { /* Expect more data on OUT EP */
          Ccid_BulkState = CCID_STATE_RECEIVE_DATA;
          pUsbMessageBuffer += dataLen;  /* Point to new offset */      
          
          /* Prepare EP to Receive next Cmd */
          DCD_EP_PrepareRx (pdev,
                            CCID_BULK_OUT_EP,
                            (uint8_t *)&BulkOut_Data_Buff[0], 
                            CCID_BULK_EPOUT_SIZE);  
          
        } /* if (dataLen == CCID_BULK_EPOUT_SIZE) ends */
      } /*  if (dataLen >= CCID_BULK_EPOUT_SIZE) ends */
    } /* if (dataLen >= CCID_MESSAGE_HEADER_SIZE) ends */
    break;
    
  case CCID_STATE_RECEIVE_DATA:
    
    UsbMessageLength += dataLen;
    
    if (dataLen < CCID_BULK_EPOUT_SIZE)
    {/* Short message, less than the EP Out Size, execute the command,
        if parameter like dwLength is too big, the appropriate command will 
        give an error */
      
      /* Full command is received, process the Command */
      CCID_ReceiveCmdHeader(pUsbMessageBuffer, dataLen);
      CCID_CmdDecode(pdev); 
    }
    else if (dataLen == CCID_BULK_EPOUT_SIZE)
    {  
      if (UsbMessageLength < (Ccid_bulkout_data.dwLength + CCID_CMD_HEADER_SIZE))
      {
        CCID_ReceiveCmdHeader(pUsbMessageBuffer, dataLen); /* Copy data */
        pUsbMessageBuffer += dataLen; 
        /* Increment the pointer to receive more data */
        
        /* Prepare EP to Receive next Cmd */
        DCD_EP_PrepareRx (pdev,
                          CCID_BULK_OUT_EP,
                          (uint8_t *)&BulkOut_Data_Buff[0], 
                          CCID_BULK_EPOUT_SIZE);  
      }
      else if (UsbMessageLength == (Ccid_bulkout_data.dwLength + CCID_CMD_HEADER_SIZE))
      { 
        /* Full command is received, process the Command */
        CCID_ReceiveCmdHeader(pUsbMessageBuffer, dataLen);
        CCID_CmdDecode(pdev);
      }
      else
      {
        /* Too long data received.... Error ! */
        Ccid_BulkState = CCID_STATE_UNCORRECT_LENGTH;
      }
    }
    
    break;
  
  case CCID_STATE_UNCORRECT_LENGTH:
    Ccid_BulkState = CCID_STATE_IDLE;
    break;
  
  default:
    break;
  }
}