sources/common/libs/STM32Cube_F4/Middlewares/ST/STM32_USB_Device_Library/Class/CCID/Src/usbd_ccid_cmd.c
/**
  * @brief  PC_to_RDR_IccPowerOn
  *         PC_TO_RDR_ICCPOWERON message execution, apply voltage and get ATR
  * @param  pdev: device instance
  * @retval status of the command execution
  */
@brief  PC_to_RDR_IccPowerOn
PC_TO_RDR_ICCPOWERON message execution, apply voltage and get ATR
@param  pdev: device instance
@retval status of the command execution
@brief PC_to_RDR_IccPowerOn PC_TO_RDR_ICCPOWERON message execution apply voltage and get ATR @param pdev : device instance @retval status of the command execution
uint8_t PC_to_RDR_IccPowerOn(USBD_HandleTypeDef *pdev)
{
  USBD_CCID_HandleTypeDef  *hccid = (USBD_CCID_HandleTypeDef *)pdev->pClassDataCmsit[pdev->classId];
  uint8_t voltage;
  uint8_t sc_voltage = 0U;
  uint8_t index;
  uint8_t error;
  hccid->UsbBlkInData.dwLength = 0U;  
  error = CCID_CheckCommandParams(pdev, CHK_PARAM_SLOT | CHK_PARAM_DWLENGTH |
                                  CHK_PARAM_ABRFU2 | CHK_PARAM_CARD_PRESENT |
                                  CHK_PARAM_ABORT);
  if (error != 0U)
  {
    return error;
  }
  voltage = hccid->UsbBlkOutData.bSpecific_0;
  if (voltage >= VOLTAGE_SELECTION_1V8)
  {
    CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_ACTIVE));
    return SLOTERROR_BAD_POWERSELECT; 
  }
  if ((voltage == VOLTAGE_SELECTION_AUTOMATIC) || (voltage == VOLTAGE_SELECTION_3V))
  {
    sc_voltage = SC_VOLTAGE_3V;
  }
  else
  {
    if (voltage == VOLTAGE_SELECTION_5V)
    {
      sc_voltage = SC_VOLTAGE_5V;
    }
  }
  SC_Itf_IccPowerOn(sc_voltage);
  error = CCID_CheckCommandParams(pdev, (uint32_t)CHK_ACTIVE_STATE);
  if (error != 0U)
  {
    if (voltage != 0U)
    {
      return error;
    }
    else
    {
      if (sc_voltage != SC_VOLTAGE_5V)
      {
        sc_voltage = SC_VOLTAGE_5V;
        SC_Itf_IccPowerOn(sc_voltage);
        error = CCID_CheckCommandParams(pdev, (uint32_t)CHK_ACTIVE_STATE);
        if (error != 0U)
        {
          return error;
        }
      }
      else
      {
        CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_FAILED), (BM_ICC_PRESENT_INACTIVE));
        return error;
      }
    } 
  } 
  hccid->UsbBlkInData.dwLength = SIZE_OF_ATR;
  CCID_UpdateCommandStatus(pdev, (BM_COMMAND_STATUS_NO_ERROR), (BM_ICC_PRESENT_ACTIVE));
  for (index = 0U; index < SIZE_OF_ATR; index++)
  {
    hccid->UsbBlkInData.abData[index] = SC_ATR_Table[index];
  }
  return SLOT_NO_ERROR;
}
uint8_t PC_to_RDR_IccPowerOn ( USBD_HandleTypeDef * pdev ) { USBD_CCID_HandleTypeDef * hccid = ( USBD_CCID_HandleTypeDef * ) pdev -> pClassDataCmsit [ pdev -> classId ] ; uint8_t voltage ; uint8_t sc_voltage = 0U ; uint8_t index ; uint8_t error ; hccid -> UsbBlkInData . dwLength = 0U ; error = CCID_CheckCommandParams ( pdev , CHK_PARAM_SLOT | CHK_PARAM_DWLENGTH | CHK_PARAM_ABRFU2 | CHK_PARAM_CARD_PRESENT | CHK_PARAM_ABORT ) ; if ( error != 0U ) { return error ; } voltage = hccid -> UsbBlkOutData . bSpecific_0 ; if ( voltage >= VOLTAGE_SELECTION_1V8 ) { CCID_UpdateCommandStatus ( pdev , ( BM_COMMAND_STATUS_FAILED ) , ( BM_ICC_PRESENT_ACTIVE ) ) ; return SLOTERROR_BAD_POWERSELECT ; } if ( ( voltage == VOLTAGE_SELECTION_AUTOMATIC ) || ( voltage == VOLTAGE_SELECTION_3V ) ) { sc_voltage = SC_VOLTAGE_3V ; } else { if ( voltage == VOLTAGE_SELECTION_5V ) { sc_voltage = SC_VOLTAGE_5V ; } } SC_Itf_IccPowerOn ( sc_voltage ) ; error = CCID_CheckCommandParams ( pdev , ( uint32_t ) CHK_ACTIVE_STATE ) ; if ( error != 0U ) { if ( voltage != 0U ) { return error ; } else { if ( sc_voltage != SC_VOLTAGE_5V ) { sc_voltage = SC_VOLTAGE_5V ; SC_Itf_IccPowerOn ( sc_voltage ) ; error = CCID_CheckCommandParams ( pdev , ( uint32_t ) CHK_ACTIVE_STATE ) ; if ( error != 0U ) { return error ; } } else { CCID_UpdateCommandStatus ( pdev , ( BM_COMMAND_STATUS_FAILED ) , ( BM_ICC_PRESENT_INACTIVE ) ) ; return error ; } } } hccid -> UsbBlkInData . dwLength = SIZE_OF_ATR ; CCID_UpdateCommandStatus ( pdev , ( BM_COMMAND_STATUS_NO_ERROR ) , ( BM_ICC_PRESENT_ACTIVE ) ) ; for ( index = 0U ; index < SIZE_OF_ATR ; index ++ ) { hccid -> UsbBlkInData . abData [ index ] = SC_ATR_Table [ index ] ; } return SLOT_NO_ERROR ; }
@brief  PC_to_RDR_IccPowerOn
         PC_TO_RDR_ICCPOWERON message execution, apply voltage and get ATR
 @param  pdev: device instance
 @retval status of the command execution
@brief PC_to_RDR_IccPowerOn PC_TO_RDR_ICCPOWERON message execution apply voltage and get ATR @param pdev : device instance @retval status of the command execution
/* Apply the ICC VCC
  Fills the Response buffer with ICC ATR
  This Command is returned with RDR_to_PC_DataBlock();
  */ /* Reset Number of Bytes in abData */ /* Voltage that is applied to the ICC
  00h  Automatic Voltage Selection
  01h  5.0 volts
  02h  3.0 volts
  03h  1.8 volts
  */ /* UsbBlkOutData.bSpecific_0 Contains bPowerSelect */ /* The Voltage specified is out of Spec */ /* Correct Voltage Requested by the Host */ /* Check if the Card has come to Active State*/ /* Check if Voltage is not Automatic */ /* If Specific Voltage requested by Host i.e 3V or 5V*/ /* Automatic Voltage selection requested by Host */ /* If voltage selected was Automatic and 5V is not yet tried */ /* Check again the State */ /* Voltage requested from Host was 5V already*/ /* Voltage Selection was automatic */ /* If Active State */ /* ATR is received, No Error Condition Found */ /* Copy the ATR to the Response Buffer */