sources/common/libs/STM32Cube_F4/Middlewares/ST/STM32_USB_Device_Library/Core/Src/usbd_ctlreq.c
/**
  * @brief  USBD_StdEPReq
  *         Handle standard usb endpoint requests
  * @param  pdev: device instance
  * @param  req: usb request
  * @retval status
  */
@brief  USBD_StdEPReq
Handle standard usb endpoint requests
@param  pdev: device instance
@param  req: usb request
@retval status
@brief USBD_StdEPReq Handle standard usb endpoint requests @param pdev : device instance @param req : usb request @retval status
USBD_StatusTypeDef USBD_StdEPReq(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req)
{
  USBD_EndpointTypeDef *pep;
  uint8_t ep_addr;
  uint8_t idx;
  USBD_StatusTypeDef ret = USBD_OK;
  ep_addr = LOBYTE(req->wIndex);
  switch (req->bmRequest & USB_REQ_TYPE_MASK)
  {
    case USB_REQ_TYPE_CLASS:
    case USB_REQ_TYPE_VENDOR:
      idx = USBD_CoreFindEP(pdev, ep_addr);
      if (((uint8_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS))
      {
        pdev->classId = idx;
        if (pdev->pClass[idx]->Setup != NULL)
        {
          ret = (USBD_StatusTypeDef)pdev->pClass[idx]->Setup(pdev, req);
        }
      }
      break;
    case USB_REQ_TYPE_STANDARD:
      switch (req->bRequest)
      {
        case USB_REQ_SET_FEATURE:
          switch (pdev->dev_state)
          {
            case USBD_STATE_ADDRESSED:
              if ((ep_addr != 0x00U) && (ep_addr != 0x80U))
              {
                (void)USBD_LL_StallEP(pdev, ep_addr);
                (void)USBD_LL_StallEP(pdev, 0x80U);
              }
              else
              {
                USBD_CtlError(pdev, req);
              }
              break;
            case USBD_STATE_CONFIGURED:
              if (req->wValue == USB_FEATURE_EP_HALT)
              {
                if ((ep_addr != 0x00U) && (ep_addr != 0x80U) && (req->wLength == 0x00U))
                {
                  (void)USBD_LL_StallEP(pdev, ep_addr);
                }
              }
              (void)USBD_CtlSendStatus(pdev);
              break;
            default:
              USBD_CtlError(pdev, req);
              break;
          }
          break;
        case USB_REQ_CLEAR_FEATURE:
          switch (pdev->dev_state)
          {
            case USBD_STATE_ADDRESSED:
              if ((ep_addr != 0x00U) && (ep_addr != 0x80U))
              {
                (void)USBD_LL_StallEP(pdev, ep_addr);
                (void)USBD_LL_StallEP(pdev, 0x80U);
              }
              else
              {
                USBD_CtlError(pdev, req);
              }
              break;
            case USBD_STATE_CONFIGURED:
              if (req->wValue == USB_FEATURE_EP_HALT)
              {
                if ((ep_addr & 0x7FU) != 0x00U)
                {
                  (void)USBD_LL_ClearStallEP(pdev, ep_addr);
                }
                (void)USBD_CtlSendStatus(pdev);
                idx = USBD_CoreFindEP(pdev, ep_addr);
                if (((uint8_t)idx != 0xFFU) && (idx < USBD_MAX_SUPPORTED_CLASS))
                {
                  pdev->classId = idx;
                  if (pdev->pClass[idx]->Setup != NULL)
                  {
                    ret = (USBD_StatusTypeDef)(pdev->pClass[idx]->Setup(pdev, req));
                  }
                }
              }
              break;
            default:
              USBD_CtlError(pdev, req);
              break;
          }
          break;
        case USB_REQ_GET_STATUS:
          switch (pdev->dev_state)
          {
            case USBD_STATE_ADDRESSED:
              if ((ep_addr != 0x00U) && (ep_addr != 0x80U))
              {
                USBD_CtlError(pdev, req);
                break;
              }
              pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU] : \
                    &pdev->ep_out[ep_addr & 0x7FU];
              pep->status = 0x0000U;
              (void)USBD_CtlSendData(pdev, (uint8_t *)&pep->status, 2U);
              break;
            case USBD_STATE_CONFIGURED:
              if ((ep_addr & 0x80U) == 0x80U)
              {
                if (pdev->ep_in[ep_addr & 0xFU].is_used == 0U)
                {
                  USBD_CtlError(pdev, req);
                  break;
                }
              }
              else
              {
                if (pdev->ep_out[ep_addr & 0xFU].is_used == 0U)
                {
                  USBD_CtlError(pdev, req);
                  break;
                }
              }
              pep = ((ep_addr & 0x80U) == 0x80U) ? &pdev->ep_in[ep_addr & 0x7FU] : \
                    &pdev->ep_out[ep_addr & 0x7FU];
              if ((ep_addr == 0x00U) || (ep_addr == 0x80U))
              {
                pep->status = 0x0000U;
              }
              else if (USBD_LL_IsStallEP(pdev, ep_addr) != 0U)
              {
                pep->status = 0x0001U;
              }
              else
              {
                pep->status = 0x0000U;
              }
              (void)USBD_CtlSendData(pdev, (uint8_t *)&pep->status, 2U);
              break;
            default:
              USBD_CtlError(pdev, req);
              break;
          }
          break;
        default:
          USBD_CtlError(pdev, req);
          break;
      }
      break;
    default:
      USBD_CtlError(pdev, req);
      break;
  }
  return ret;
}
USBD_StatusTypeDef USBD_StdEPReq ( USBD_HandleTypeDef * pdev , USBD_SetupReqTypedef * req ) { USBD_EndpointTypeDef * pep ; uint8_t ep_addr ; uint8_t idx ; USBD_StatusTypeDef ret = USBD_OK ; ep_addr = LOBYTE ( req -> wIndex ) ; switch ( req -> bmRequest & USB_REQ_TYPE_MASK ) { case USB_REQ_TYPE_CLASS : case USB_REQ_TYPE_VENDOR : idx = USBD_CoreFindEP ( pdev , ep_addr ) ; if ( ( ( uint8_t ) idx != 0xFFU ) && ( idx < USBD_MAX_SUPPORTED_CLASS ) ) { pdev -> classId = idx ; if ( pdev -> pClass [ idx ] -> Setup != NULL ) { ret = ( USBD_StatusTypeDef ) pdev -> pClass [ idx ] -> Setup ( pdev , req ) ; } } break ; case USB_REQ_TYPE_STANDARD : switch ( req -> bRequest ) { case USB_REQ_SET_FEATURE : switch ( pdev -> dev_state ) { case USBD_STATE_ADDRESSED : if ( ( ep_addr != 0x00U ) && ( ep_addr != 0x80U ) ) { ( void ) USBD_LL_StallEP ( pdev , ep_addr ) ; ( void ) USBD_LL_StallEP ( pdev , 0x80U ) ; } else { USBD_CtlError ( pdev , req ) ; } break ; case USBD_STATE_CONFIGURED : if ( req -> wValue == USB_FEATURE_EP_HALT ) { if ( ( ep_addr != 0x00U ) && ( ep_addr != 0x80U ) && ( req -> wLength == 0x00U ) ) { ( void ) USBD_LL_StallEP ( pdev , ep_addr ) ; } } ( void ) USBD_CtlSendStatus ( pdev ) ; break ; default : USBD_CtlError ( pdev , req ) ; break ; } break ; case USB_REQ_CLEAR_FEATURE : switch ( pdev -> dev_state ) { case USBD_STATE_ADDRESSED : if ( ( ep_addr != 0x00U ) && ( ep_addr != 0x80U ) ) { ( void ) USBD_LL_StallEP ( pdev , ep_addr ) ; ( void ) USBD_LL_StallEP ( pdev , 0x80U ) ; } else { USBD_CtlError ( pdev , req ) ; } break ; case USBD_STATE_CONFIGURED : if ( req -> wValue == USB_FEATURE_EP_HALT ) { if ( ( ep_addr & 0x7FU ) != 0x00U ) { ( void ) USBD_LL_ClearStallEP ( pdev , ep_addr ) ; } ( void ) USBD_CtlSendStatus ( pdev ) ; idx = USBD_CoreFindEP ( pdev , ep_addr ) ; if ( ( ( uint8_t ) idx != 0xFFU ) && ( idx < USBD_MAX_SUPPORTED_CLASS ) ) { pdev -> classId = idx ; if ( pdev -> pClass [ idx ] -> Setup != NULL ) { ret = ( USBD_StatusTypeDef ) ( pdev -> pClass [ idx ] -> Setup ( pdev , req ) ) ; } } } break ; default : USBD_CtlError ( pdev , req ) ; break ; } break ; case USB_REQ_GET_STATUS : switch ( pdev -> dev_state ) { case USBD_STATE_ADDRESSED : if ( ( ep_addr != 0x00U ) && ( ep_addr != 0x80U ) ) { USBD_CtlError ( pdev , req ) ; break ; } pep = ( ( ep_addr & 0x80U ) == 0x80U ) ? & pdev -> ep_in [ ep_addr & 0x7FU ] : & pdev -> ep_out [ ep_addr & 0x7FU ] ; pep -> status = 0x0000U ; ( void ) USBD_CtlSendData ( pdev , ( uint8_t * ) & pep -> status , 2U ) ; break ; case USBD_STATE_CONFIGURED : if ( ( ep_addr & 0x80U ) == 0x80U ) { if ( pdev -> ep_in [ ep_addr & 0xFU ] . is_used == 0U ) { USBD_CtlError ( pdev , req ) ; break ; } } else { if ( pdev -> ep_out [ ep_addr & 0xFU ] . is_used == 0U ) { USBD_CtlError ( pdev , req ) ; break ; } } pep = ( ( ep_addr & 0x80U ) == 0x80U ) ? & pdev -> ep_in [ ep_addr & 0x7FU ] : & pdev -> ep_out [ ep_addr & 0x7FU ] ; if ( ( ep_addr == 0x00U ) || ( ep_addr == 0x80U ) ) { pep -> status = 0x0000U ; } else if ( USBD_LL_IsStallEP ( pdev , ep_addr ) != 0U ) { pep -> status = 0x0001U ; } else { pep -> status = 0x0000U ; } ( void ) USBD_CtlSendData ( pdev , ( uint8_t * ) & pep -> status , 2U ) ; break ; default : USBD_CtlError ( pdev , req ) ; break ; } break ; default : USBD_CtlError ( pdev , req ) ; break ; } break ; default : USBD_CtlError ( pdev , req ) ; break ; } return ret ; }
@brief  USBD_StdEPReq
         Handle standard usb endpoint requests
 @param  pdev: device instance
 @param  req: usb request
 @retval status
@brief USBD_StdEPReq Handle standard usb endpoint requests @param pdev : device instance @param req : usb request @retval status
/* Get the class index relative to this endpoint */ /* Call the class data out function to manage the request */ /* Get the class index relative to this interface */ /* Call the class data out function to manage the request */