sources/common/libs/STM32Cube_F4/Middlewares/ST/STM32_USB_Device_Library/Class/CCID/Src/usbd_ccid_cmd.c
/**
  * @brief  CCID_CheckCommandParams
  *         Checks the specific parameters requested by the function and update
  *          status accordingly. This function is called from all
  *          PC_to_RDR functions
  * @param  pdev: device instance
  * @param  param_type : Parameter enum to be checked by calling function
  * @retval status
  */
@brief  CCID_CheckCommandParams
Checks the specific parameters requested by the function and update
status accordingly. This function is called from all
PC_to_RDR functions
@param  pdev: device instance
@param  param_type : Parameter enum to be checked by calling function
@retval status
@brief CCID_CheckCommandParams Checks the specific parameters requested by the function and update status accordingly . This function is called from all PC_to_RDR functions @param pdev : device instance @param param_type : Parameter enum to be checked by calling function @retval status
static uint8_t CCID_CheckCommandParams(USBD_HandleTypeDef  *pdev, uint32_t param_type)
{
  USBD_CCID_HandleTypeDef  *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
  uint32_t parameter;
  uint8_t GetState = SC_GetState();
  hccid->UsbBlkInData.bStatus = BM_ICC_PRESENT_ACTIVE | BM_COMMAND_STATUS_NO_ERROR;
  parameter = (uint32_t)param_type;
  if ((parameter & CHK_PARAM_SLOT) != 0U)
  {
    if (hccid->UsbBlkOutData.bSlot >= CCID_NUMBER_OF_SLOTS)
    {
      CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_NO_ICC_PRESENT));
      return SLOTERROR_BAD_SLOT;
    }
  }
  if ((parameter & CHK_PARAM_CARD_PRESENT) != 0U)
  {
    if (SC_Detect() == 0U)
    {
      CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_NO_ICC_PRESENT));
      return SLOTERROR_ICC_MUTE;
    }
  }
  if ((parameter & CHK_PARAM_DWLENGTH) != 0U)
  {
    if (hccid->UsbBlkOutData.dwLength != 0U)
    {
      CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
      return SLOTERROR_BAD_LENTGH;
    }
  }
  if ((parameter & CHK_PARAM_ABRFU2) != 0U)
  {
    if ((hccid->UsbBlkOutData.bSpecific_1 != 0U) || (hccid->UsbBlkOutData.bSpecific_2 != 0U))
    {
      CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
      return SLOTERROR_BAD_ABRFU_2B;        
    }
  }
  if ((parameter & CHK_PARAM_ABRFU3) != 0U)
  {
    if ((hccid->UsbBlkOutData.bSpecific_0 != 0U) ||
        (hccid->UsbBlkOutData.bSpecific_1 != 0U) ||
        (hccid->UsbBlkOutData.bSpecific_2 != 0U))
    {
      CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
      return SLOTERROR_BAD_ABRFU_3B;
    }
  }
  if ((parameter & CHK_PARAM_ABORT) != 0U)
  {
    if (hccid->USBD_CCID_Param.bAbortRequestFlag != 0U)
    {
      CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_INACTIVE));
      return SLOTERROR_CMD_ABORTED;
    }
  }
  if ((parameter & CHK_ACTIVE_STATE) != 0U)
  {
    if ((GetState != (uint8_t)SC_ACTIVE_ON_T0) && (GetState != (uint8_t)SC_ACTIVE_ON_T1))
    {
      CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_INACTIVE));
      return SLOTERROR_HW_ERROR;
    }
  }
  return 0U;
}
static uint8_t CCID_CheckCommandParams ( USBD_HandleTypeDef * pdev , uint32_t param_type ) { USBD_CCID_HandleTypeDef * hccid = ( USBD_CCID_HandleTypeDef * ) pdev -> pClassDataCmsit [ pdev -> classId ] ; uint32_t parameter ; uint8_t GetState = SC_GetState ( ) ; hccid -> UsbBlkInData . bStatus = BM_ICC_PRESENT_ACTIVE | BM_COMMAND_STATUS_NO_ERROR ; parameter = ( uint32_t ) param_type ; if ( ( parameter & CHK_PARAM_SLOT ) != 0U ) { if ( hccid -> UsbBlkOutData . bSlot >= CCID_NUMBER_OF_SLOTS ) { CCID_UpdateCommandStatus ( pdev , ( BM_COMMAND_STATUS_FAILED ) , ( BM_ICC_NO_ICC_PRESENT ) ) ; return SLOTERROR_BAD_SLOT ; } } if ( ( parameter & CHK_PARAM_CARD_PRESENT ) != 0U ) { if ( SC_Detect ( ) == 0U ) { CCID_UpdateCommandStatus ( pdev , ( BM_COMMAND_STATUS_FAILED ) , ( BM_ICC_NO_ICC_PRESENT ) ) ; return SLOTERROR_ICC_MUTE ; } } if ( ( parameter & CHK_PARAM_DWLENGTH ) != 0U ) { if ( hccid -> UsbBlkOutData . dwLength != 0U ) { CCID_UpdateCommandStatus ( pdev , ( BM_COMMAND_STATUS_FAILED ) , ( BM_ICC_PRESENT_ACTIVE ) ) ; return SLOTERROR_BAD_LENTGH ; } } if ( ( parameter & CHK_PARAM_ABRFU2 ) != 0U ) { if ( ( hccid -> UsbBlkOutData . bSpecific_1 != 0U ) || ( hccid -> UsbBlkOutData . bSpecific_2 != 0U ) ) { CCID_UpdateCommandStatus ( pdev , ( BM_COMMAND_STATUS_FAILED ) , ( BM_ICC_PRESENT_ACTIVE ) ) ; return SLOTERROR_BAD_ABRFU_2B ; } } if ( ( parameter & CHK_PARAM_ABRFU3 ) != 0U ) { if ( ( hccid -> UsbBlkOutData . bSpecific_0 != 0U ) || ( hccid -> UsbBlkOutData . bSpecific_1 != 0U ) || ( hccid -> UsbBlkOutData . bSpecific_2 != 0U ) ) { CCID_UpdateCommandStatus ( pdev , ( BM_COMMAND_STATUS_FAILED ) , ( BM_ICC_PRESENT_ACTIVE ) ) ; return SLOTERROR_BAD_ABRFU_3B ; } } if ( ( parameter & CHK_PARAM_ABORT ) != 0U ) { if ( hccid -> USBD_CCID_Param . bAbortRequestFlag != 0U ) { CCID_UpdateCommandStatus ( pdev , ( BM_COMMAND_STATUS_FAILED ) , ( BM_ICC_PRESENT_INACTIVE ) ) ; return SLOTERROR_CMD_ABORTED ; } } if ( ( parameter & CHK_ACTIVE_STATE ) != 0U ) { if ( ( GetState != ( uint8_t ) SC_ACTIVE_ON_T0 ) && ( GetState != ( uint8_t ) SC_ACTIVE_ON_T1 ) ) { CCID_UpdateCommandStatus ( pdev , ( BM_COMMAND_STATUS_FAILED ) , ( BM_ICC_PRESENT_INACTIVE ) ) ; return SLOTERROR_HW_ERROR ; } } return 0U ; }
@brief  CCID_CheckCommandParams
         Checks the specific parameters requested by the function and update
          status accordingly.
@brief CCID_CheckCommandParams Checks the specific parameters requested by the function and update status accordingly .
/*
    The slot number (bSlot) identifies which ICC slot is being addressed
    by the message*/ /* SLOT Number is 0 onwards, so always < CCID_NUMBER_OF_SLOTs */ /* Error Condition !!! */ /* Slot requested is more than supported by Firmware */ /* Commands Parameters ok, Check the Card Status */ /* Card is Not detected */ /* Check that DwLength is 0 */ /* abRFU 2 : Reserved for Future Use*/ /* bSpecific_1 */ /* abRFU 3 : Reserved for Future Use*/ /* Commands Parameters ok, Check the Card Status */ /* Card is detected */ /* Check that from Lower Layers, the SmartCard come to known state */