sources/common/libs/STM32Cube_F4/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c
/**
  * @brief  USBD_SetConfig
  *         Handle Set device configuration request
  * @param  pdev: device instance
  * @param  req: usb request
  * @retval status
  */
@brief  USBD_SetConfig
Handle Set device configuration request
@param  pdev: device instance
@param  req: usb request
@retval status
@brief USBD_SetConfig Handle Set device configuration request @param pdev : device instance @param req : usb request @retval status
static USBD_StatusTypeDef USBD_SetConfig(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
{
  USBD_StatusTypeDef ret = USBD_OK;
  static uint8_t cfgidx;
  cfgidx = (uint8_t)(req->wValue);
  if (cfgidx > USBD_MAX_NUM_CONFIGURATION)
  {
    USBD_CtlError(pdev, req);
    return USBD_FAIL;
  }
  switch (pdev->dev_state)
  {
    case USBD_STATE_ADDRESSED:
      if (cfgidx != 0U)
      {
        pdev->dev_config = cfgidx;
        ret = USBD_SetClassConfig(pdev, cfgidx);
        if (ret != USBD_OK)
        {
          USBD_CtlError(pdev, req);
          pdev->dev_state = USBD_STATE_ADDRESSED;
        }
        else
        {
          (void)USBD_CtlSendStatus(pdev);
          pdev->dev_state = USBD_STATE_CONFIGURED;
        }
      }
      else
      {
        (void)USBD_CtlSendStatus(pdev);
      }
      break;
    case USBD_STATE_CONFIGURED:
      if (cfgidx == 0U)
      {
        pdev->dev_state = USBD_STATE_ADDRESSED;
        pdev->dev_config = cfgidx;
        (void)USBD_ClrClassConfig(pdev, cfgidx);
        (void)USBD_CtlSendStatus(pdev);
      }
      else if (cfgidx != pdev->dev_config)
      {
        (void)USBD_ClrClassConfig(pdev, (uint8_t)pdev->dev_config);
        pdev->dev_config = cfgidx;
        ret = USBD_SetClassConfig(pdev, cfgidx);
        if (ret != USBD_OK)
        {
          USBD_CtlError(pdev, req);
          (void)USBD_ClrClassConfig(pdev, (uint8_t)pdev->dev_config);
          pdev->dev_state = USBD_STATE_ADDRESSED;
        }
        else
        {
          (void)USBD_CtlSendStatus(pdev);
        }
      }
      else
      {
        (void)USBD_CtlSendStatus(pdev);
      }
      break;
    default:
      USBD_CtlError(pdev, req);
      (void)USBD_ClrClassConfig(pdev, cfgidx);
      ret = USBD_FAIL;
      break;
  }
  return ret;
}
static USBD_StatusTypeDef USBD_SetConfig ( USBD_HandleTypeDef * pdev , USBD_SetupReqTypedef * req ) { USBD_StatusTypeDef ret = USBD_OK ; static uint8_t cfgidx ; cfgidx = ( uint8_t ) ( req -> wValue ) ; if ( cfgidx > USBD_MAX_NUM_CONFIGURATION ) { USBD_CtlError ( pdev , req ) ; return USBD_FAIL ; } switch ( pdev -> dev_state ) { case USBD_STATE_ADDRESSED : if ( cfgidx != 0U ) { pdev -> dev_config = cfgidx ; ret = USBD_SetClassConfig ( pdev , cfgidx ) ; if ( ret != USBD_OK ) { USBD_CtlError ( pdev , req ) ; pdev -> dev_state = USBD_STATE_ADDRESSED ; } else { ( void ) USBD_CtlSendStatus ( pdev ) ; pdev -> dev_state = USBD_STATE_CONFIGURED ; } } else { ( void ) USBD_CtlSendStatus ( pdev ) ; } break ; case USBD_STATE_CONFIGURED : if ( cfgidx == 0U ) { pdev -> dev_state = USBD_STATE_ADDRESSED ; pdev -> dev_config = cfgidx ; ( void ) USBD_ClrClassConfig ( pdev , cfgidx ) ; ( void ) USBD_CtlSendStatus ( pdev ) ; } else if ( cfgidx != pdev -> dev_config ) { ( void ) USBD_ClrClassConfig ( pdev , ( uint8_t ) pdev -> dev_config ) ; pdev -> dev_config = cfgidx ; ret = USBD_SetClassConfig ( pdev , cfgidx ) ; if ( ret != USBD_OK ) { USBD_CtlError ( pdev , req ) ; ( void ) USBD_ClrClassConfig ( pdev , ( uint8_t ) pdev -> dev_config ) ; pdev -> dev_state = USBD_STATE_ADDRESSED ; } else { ( void ) USBD_CtlSendStatus ( pdev ) ; } } else { ( void ) USBD_CtlSendStatus ( pdev ) ; } break ; default : USBD_CtlError ( pdev , req ) ; ( void ) USBD_ClrClassConfig ( pdev , cfgidx ) ; ret = USBD_FAIL ; break ; } return ret ; }
@brief  USBD_SetConfig
         Handle Set device configuration request
 @param  pdev: device instance
 @param  req: usb request
 @retval status
@brief USBD_SetConfig Handle Set device configuration request @param pdev : device instance @param req : usb request @retval status
/* Clear old configuration */ /* set new configuration */