/** * @brief USBD_CDC_Setup * Handle the CDC specific requests * @param pdev: instance * @param req: usb requests * @retval status */ static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { USBD_CDC_HandleTypeDef *hcdc = (USBD_CDC_HandleTypeDef*) pdev->pClassData; static uint8_t ifalt = 0; switch (req->bmRequest & USB_REQ_TYPE_MASK) { case USB_REQ_TYPE_CLASS : if (req->wLength) { if (req->bmRequest & 0x80) { ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, (uint8_t *)hcdc->data, req->wLength); USBD_CtlSendData (pdev, (uint8_t *)hcdc->data, req->wLength); } else { hcdc->CmdOpCode = req->bRequest; hcdc->CmdLength = req->wLength; USBD_CtlPrepareRx (pdev, (uint8_t *)hcdc->data, req->wLength); } } else { ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, (uint8_t*)req, 0); } break; case USB_REQ_TYPE_STANDARD: switch (req->bRequest) { case USB_REQ_GET_INTERFACE : USBD_CtlSendData (pdev, &ifalt, 1); break; case USB_REQ_SET_INTERFACE : break; } case USB_REQ_TYPE_VENDOR: return USBD_WinUSBComm_SetupVendor(pdev, req); default: break; } return USBD_OK; }
/** * @brief USBD_GetConfig * Handle Get device configuration request * @param pdev: device instance * @param req: usb request * @retval status */ static void USBD_GetConfig(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { if (req->wLength != 1) { dbg_printf(DBGMODE_ERR, "USBD_GetConfig Stall, bad wLength 0x%04X (should be 1), file " __FILE__ ":%d\r\n", req->wLength, __LINE__); USBD_CtlError(pdev , req); } else { switch (pdev->dev.device_status ) { case USB_OTG_ADDRESSED: USBD_CtlSendData (pdev, (uint8_t *)&USBD_default_cfg, 1); break; case USB_OTG_CONFIGURED: USBD_CtlSendData (pdev, &pdev->dev.device_config, 1); break; default: dbg_printf(DBGMODE_ERR, "USBD_GetConfig Stall, unknown device_status 0x%02X, file " __FILE__ ":%d\r\n", pdev->dev.device_status, __LINE__); USBD_CtlError(pdev , req); break; } } }
//-------------------------------------------------------------- static void USBD_GetConfig(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { if (req->wLength != 1) { USBD_CtlError(pdev , req); } else { switch (pdev->dev.device_status ) { case USB_OTG_ADDRESSED: USBD_CtlSendData (pdev, (uint8_t *)&USBD_default_cfg, 1); break; case USB_OTG_CONFIGURED: USBD_CtlSendData (pdev, &pdev->dev.device_config, 1); break; default: USBD_CtlError(pdev , req); break; } } }
/** * @brief USBD_GetConfig * Handle Get device configuration request * @param pdev: device instance * @param req: usb request * @retval status */ static void USBD_GetConfig(USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) { if (req->wLength != 1) { USBD_CtlError(pdev , req); } else { switch (pdev->dev_state ) { case USBD_STATE_ADDRESSED: pdev->dev_default_config = 0; USBD_CtlSendData (pdev, (uint8_t *)&pdev->dev_default_config, 1); break; case USBD_STATE_CONFIGURED: USBD_CtlSendData (pdev, (uint8_t *)&pdev->dev_config, 1); break; default: USBD_CtlError(pdev , req); break; } } }
static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { USBD_CDC_HID_HandleTypeDef *handle = (USBD_CDC_HID_HandleTypeDef*) pdev->pClassData; static uint8_t ifalt = 0; switch (req->bmRequest & USB_REQ_TYPE_MASK) { case USB_REQ_TYPE_CLASS : if (req->wLength) { if (req->bmRequest & 0x80) { CDC_Control_FS(req->bRequest, (uint8_t *)handle->data, req->wLength); USBD_CtlSendData (pdev, (uint8_t *)handle->data, req->wLength); } else { handle->CmdOpCode = req->bRequest; handle->CmdLength = (uint8_t)req->wLength; USBD_CtlPrepareRx (pdev, (uint8_t *)handle->data, req->wLength); } } else { CDC_Control_FS(req->bRequest, (uint8_t*)req, 0); } break; case USB_REQ_TYPE_STANDARD: switch (req->bRequest) { case USB_REQ_GET_INTERFACE : USBD_CtlSendData (pdev, &ifalt, 1); break; case USB_REQ_SET_INTERFACE : break; } default: break; } return USBD_OK; }
static uint8_t USBD_DEV_Setup(void *pdev, USB_SETUP_REQ *req) { printf("USB SETUP request: bmRequest: 0x%x, bRequest: 0x%x, wValue: 0x%x, wIndex: 0x%x, wLength: 0x%x\r\n", req->bmRequest, req->bRequest, req->wValue, req->wIndex, req->wLength ); switch (req->bmRequest & USB_REQ_TYPE_MASK) { case USB_REQ_TYPE_VENDOR: switch(req->bRequest) { case USB_REQ_SET_VALUE: value = req->wValue; break; case USB_REQ_GET_VALUE: USBD_CtlSendData(pdev, (uint8_t*)&value, sizeof(value)); break; default: USBD_CtlError(pdev, req); return USBD_FAIL; } } return USBD_OK; }
/** * @brief USBD_GetStatus * Handle Get Status request * @param pdev: device instance * @param req: usb request * @retval status */ static void USBD_GetStatus(USB_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { uint32_t USBD_cfg_status = 0; switch (pdev->dev.device_status) { case USB_ADDRESSED: case USB_CONFIGURED: #ifdef USBD_SELF_POWERED USBD_cfg_status = USB_CONFIG_SELF_POWERED; #else USBD_cfg_status = 0x00; #endif if (pdev->dev.DevRemoteWakeup) { USBD_cfg_status |= USB_CONFIG_REMOTE_WAKEUP; } USBD_CtlSendData (pdev, (uint8_t *)&USBD_cfg_status, 2); break; default : USBD_CtlError(pdev , req); break; } }
/** * @brief DFU_Req_GETSTATUS * Handles the DFU GETSTATUS request. * @param pdev: instance * @retval status */ static void DFU_Req_GETSTATUS(void *pdev) { switch (DeviceState) { case STATE_dfuDNLOAD_SYNC: if (wlength != 0) { DeviceState = STATE_dfuDNBUSY; DeviceStatus[4] = DeviceState; if ((wBlockNum == 0) && (MAL_Buffer[0] == CMD_ERASE)) { MAL_GetStatus(usbd_dfu_AltSet, Pointer, 0, DeviceStatus); } else { MAL_GetStatus(usbd_dfu_AltSet, Pointer, 1, DeviceStatus); } } else /* (wlength==0)*/ { DeviceState = STATE_dfuDNLOAD_IDLE; DeviceStatus[4] = DeviceState; } break; case STATE_dfuMANIFEST_SYNC : if (Manifest_State == Manifest_In_Progress) { // continue to disconnect USB and eventually reset asynchornously to ensure // the response to this message is returned correctly. DeviceState = STATE_dfuMANIFEST; // get a nice output from dfu-util - original code entered STATE_dfuMANIFEST // but this leaves a message Transitioning to dfuMANIFEST state as the last line, which just lingers with no clear indication of what to do next. DeviceStatus[4] = STATE_dfuDNLOAD_IDLE; //break; } else if ((Manifest_State == Manifest_complete) && \ ((usbd_dfu_CfgDesc[(11 + (9 * USBD_DFU_INT_NUM))]) & 0x04)) { DeviceState = STATE_dfuIDLE; DeviceStatus[4] = DeviceState; //break; } break; case STATE_dfuMANIFEST: { DeviceState = STATE_dfuIDLE; DeviceStatus[4] = DeviceState; } default : break; } /* Send the status data over EP0 */ USBD_CtlSendData (pdev, (uint8_t *)(&(DeviceStatus[0])), 6); }
/** * @brief AUDIO_Req_GetCurrent * Handles the GET_CUR Audio control request. * @param pdev: instance * @param req: setup class request * @retval status */ static void AUDIO_Req_GetCurrent(void *pdev, USB_SETUP_REQ *req) { /* Send the current mute state */ USBD_CtlSendData (pdev, AudioCtl, req->wLength); }
//-------------------------------------------------------------- static void USBD_GetStatus(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { switch (pdev->dev.device_status) { case USB_OTG_ADDRESSED: case USB_OTG_CONFIGURED: if (pdev->dev.DevRemoteWakeup) { USBD_cfg_status = USB_CONFIG_SELF_POWERED | USB_CONFIG_REMOTE_WAKEUP; } else { USBD_cfg_status = USB_CONFIG_SELF_POWERED; } USBD_CtlSendData (pdev, (uint8_t *)&USBD_cfg_status, 1); break; default : USBD_CtlError(pdev , req); break; } }
/** * @brief USBD_GetStatus * Handle Get Status request * @param pdev: device instance * @param req: usb request * @retval status */ static void USBD_GetStatus(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { switch (pdev->dev.device_status) { case USB_OTG_ADDRESSED: case USB_OTG_CONFIGURED: #ifdef USBD_SELF_POWERED USBD_cfg_status = USB_CONFIG_SELF_POWERED; #else USBD_cfg_status = 0x00; #endif if (pdev->dev.DevRemoteWakeup) { USBD_cfg_status |= USB_CONFIG_REMOTE_WAKEUP; } USBD_CtlSendData (pdev, (uint8_t *)&USBD_cfg_status, 2); break; default : dbg_printf(DBGMODE_ERR, "USBD_GetStatus Stall, unknown device_status 0x%02X, file " __FILE__ ":%d\r\n", pdev->dev.device_status, __LINE__); USBD_CtlError(pdev , req); break; } }
/** * @brief DFU_Req_GETSTATE * Handles the DFU GETSTATE request. * @param pdev: device instance * @retval None */ static void DFU_Req_GETSTATE(void *pdev) { /* Return the current state of the DFU interface */ USBD_CtlSendData (pdev, &DeviceState, 1); }
/** * @brief USBD_CDC_Setup * Handle the CDC specific requests * @param pdev: instance * @param req: usb requests * @retval status */ static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { USBD_CDC_HandleTypeDef *hcdc = pdev->pClassData; switch (req->bmRequest & USB_REQ_TYPE_MASK) { case USB_REQ_TYPE_CLASS : if (req->wLength) { if (req->bmRequest & 0x80) { ((USBD_CDC_ItfTypeDef *)pdev->pUserData)->Control(req->bRequest, (uint8_t *)hcdc->data, req->wLength); USBD_CtlSendData (pdev, (uint8_t *)hcdc->data, req->wLength); } else { hcdc->CmdOpCode = req->bRequest; hcdc->CmdLength = req->wLength; USBD_CtlPrepareRx (pdev, (uint8_t *)hcdc->data, req->wLength); } break; } } return USBD_OK; }
/** * @brief USBD_GetStatus * Handle Get Status request * @param pdev: device instance * @param req: usb request * @retval status */ static void USBD_GetStatus(USBD_HandleTypeDef *pdev , USBD_SetupReqTypedef *req) { switch (pdev->dev_state) { case USBD_STATE_ADDRESSED: case USBD_STATE_CONFIGURED: #if ( USBD_SELF_POWERED == 1) pdev->dev_config_status = USB_CONFIG_SELF_POWERED; #else pdev->dev_config_status = 0; #endif if (pdev->dev_remote_wakeup) { pdev->dev_config_status |= USB_CONFIG_REMOTE_WAKEUP; } USBD_CtlSendData (pdev, (uint8_t *)& pdev->dev_config_status, 2); break; default : USBD_CtlError(pdev , req); break; } }
static uint8_t usbd_rndis_setup(void *pdev, USB_SETUP_REQ *req) { switch (req->bmRequest & USB_REQ_TYPE_MASK) { case USB_REQ_TYPE_CLASS : if (req->wLength != 0) // is data setup packet? { /* Check if the request is Device-to-Host */ if (req->bmRequest & 0x80) { USBD_CtlSendData(pdev, encapsulated_buffer, ((rndis_generic_msg_t *)encapsulated_buffer)->MessageLength); } else /* Host-to-Device requeset */ { USBD_CtlPrepareRx(pdev, encapsulated_buffer, req->wLength); } } return USBD_OK; default: return USBD_OK; // USBD_CtlError (pdev, req); // return USBD_FAIL; } }
/** * @brief DFU_Req_GETSTATUS * Handles the DFU GETSTATUS request. * @param pdev: instance * @retval status */ static void DFU_Req_GETSTATUS(void *pdev) { switch (DeviceState) { case STATE_dfuDNLOAD_SYNC: if (wlength != 0) { DeviceState = STATE_dfuDNBUSY; DeviceStatus[4] = DeviceState; if ((wBlockNum == 0) && (MAL_Buffer[0] == CMD_ERASE)) { MAL_GetStatus(Pointer, 0, DeviceStatus); } else { MAL_GetStatus(Pointer, 1, DeviceStatus); } } else /* (wlength==0)*/ { DeviceState = STATE_dfuDNLOAD_IDLE; DeviceStatus[4] = DeviceState; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; } break; case STATE_dfuMANIFEST_SYNC : if (Manifest_State == Manifest_In_Progress) { DeviceState = STATE_dfuMANIFEST; DeviceStatus[4] = DeviceState; DeviceStatus[1] = 1; /*bwPollTimeout = 1ms*/ DeviceStatus[2] = 0; DeviceStatus[3] = 0; //break; } else if ((Manifest_State == Manifest_complete) && \ ((usbd_dfu_CfgDesc[(11 + (9 * USBD_ITF_MAX_NUM))]) & 0x04)) { DeviceState = STATE_dfuIDLE; DeviceStatus[4] = DeviceState; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; //break; } break; default : break; } /* Send the status data over EP0 */ USBD_CtlSendData (pdev, (uint8_t *)(&(DeviceStatus[0])), 6); }
uint8_t USBD_Composite_Handle_Msft_Request(void* pdev, USB_SETUP_REQ* req) { if (req->wIndex == 0x0004) { USBD_CtlSendData(pdev, USBD_Composite_MsftExtCompatIdOsDescr, req->wLength); } else if (req->wIndex == 0x0005) { if ((req->wValue & 0xff) == 0x02) { USBD_CtlSendData(pdev, USBD_Composite_MsftExtPropOsDescr, req->wLength); } else { // Send dummy uint8_t dummy[10] = {0}; USBD_CtlSendData(pdev, dummy, req->wLength); } } else { return USBD_FAIL; } return USBD_OK; }
//CLASS SPECIFIC REQUEST static void VIDEO_Req_GetCurrent(void *pdev, USB_SETUP_REQ *req) { /* Send the current mute state */ DCD_EP_Flush (pdev,USB_ENDPOINT_OUT(0)); if(req->wValue == 256) { //Probe Request USBD_CtlSendData (pdev, (uint8_t*)&videoProbeControl, req->wLength); } else if (req->wValue == 512) { //Commit Request USBD_CtlSendData (pdev, (uint8_t*)&videoCommitControl, req->wLength); } }
/** * @brief AUDIO_Req_GetCurrent * Handles the GET_CUR Audio control request. * @param pdev: instance * @param req: setup class request * @retval status */ static void AUDIO_REQ_GetCurrent(USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { USBD_AUDIO_HandleTypeDef *haudio; haudio = (USBD_AUDIO_HandleTypeDef*) pdev->pClassData; memset(haudio->control.data, 0, 64); /* Send the current mute state */ USBD_CtlSendData (pdev, haudio->control.data, req->wLength); }
/** * @brief DFU_GetState * Handles the DFU GETSTATE request. * @param pdev: device instance * @retval None */ static void DFU_GetState(USBD_HandleTypeDef *pdev) { USBD_DFU_HandleTypeDef *hdfu; hdfu = pdev->pClassData; /* Return the current state of the DFU interface */ USBD_CtlSendData (pdev, &hdfu->dev_state, 1); }
static uint8_t USBD_WinUSBComm_GetMSExtendedCompatIDOSDescriptor (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { switch (req->wIndex) { case 0x04: USBD_CtlSendData (pdev, USBD_WinUSBComm_Extended_Compat_ID_OS_Desc, req->wLength); break; default: USBD_CtlError(pdev , req); return USBD_FAIL; } return USBD_OK; }
void Process_USB_Get_Request(USB_SETUP_REQ *req) { uint16_t i, *dest, *source; if ((req->wValue & 0xFF) == REPORT_MEMORY) { source = (uint16_t*)(RTC_BASE + 0x50); dest = (uint16_t*)&buffer[1]; for (i = 0; i < BCKP_STRUCT_LENGTH; i++) *dest++ = *source++; buffer[0] = REPORT_MEMORY; USBD_CtlSendData(&USB_OTG_dev,buffer,sizeof(buffer)); } }
static uint8_t USBD_CDC_Setup (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { USBD_CDC_HandleTypeDef *hcdc = context; unsigned index; for (index = 0; index < NUM_OF_CDC_UARTS; index++,hcdc++) { if (parameters[index].command_itf != req->wIndex) continue; switch (req->bmRequest & USB_REQ_TYPE_MASK) { case USB_REQ_TYPE_CLASS : if (req->wLength) { if (req->bmRequest & 0x80) { CDC_Itf_Control(hcdc, req->bRequest, (uint8_t *)hcdc->SetupBuffer, req->wLength); USBD_CtlSendData (pdev, (uint8_t *)hcdc->SetupBuffer, req->wLength); } else { hcdc->CmdOpCode = req->bRequest; hcdc->CmdLength = req->wLength; USBD_CtlPrepareRx (pdev, (uint8_t *)hcdc->SetupBuffer, req->wLength); } } else { CDC_Itf_Control(hcdc, req->bRequest, NULL, 0); } break; default: break; } break; } return USBD_OK; }
static uint8_t USBD_WinUSBComm_GetMSExtendedPropertiesOSDescriptor (USBD_HandleTypeDef *pdev, USBD_SetupReqTypedef *req) { uint8_t byInterfaceIndex = (uint8_t)req->wValue; if ( req->wIndex != 0x05 ) { USBD_CtlError(pdev , req); return USBD_FAIL; } switch ( byInterfaceIndex ) { case 0: #if NUM_INTERFACES == 2 case 1: #endif USBD_CtlSendData (pdev, USBD_WinUSBComm_Extended_Properties_OS_Desc, req->wLength); break; default: USBD_CtlError(pdev , req); return USBD_FAIL; } return USBD_OK; }
/** * @brief usbd_cdc_Setup * Handle the CDC specific requests * @param pdev: instance * @param req: usb requests * @retval status */ static uint8_t usbd_cdc_Setup (void *pdev, USB_SETUP_REQ *req) { uint16_t len = 0; uint8_t *pbuf; switch (req->bmRequest & USB_REQ_TYPE_MASK) { /* CDC Class Requests -------------------------------*/ case USB_REQ_TYPE_CLASS : /* Check if the request is a data setup packet */ if (req->wLength) { /* Check if the request is Device-to-Host */ if (req->bmRequest & 0x80) { /* Get the data to be sent to Host from interface layer */ APP_FOPS.pIf_Ctrl(req->bRequest, CmdBuff, req->wLength); /* Send the data to the host */ USBD_CtlSendData (pdev, CmdBuff, req->wLength); } else /* Host-to-Device requeset */ { /* Set the value of the current command to be processed */ cdcCmd = req->bRequest; cdcLen = req->wLength; /* Prepare the reception of the buffer over EP0 Next step: the received data will be managed in usbd_cdc_EP0_TxSent() function. */ USBD_CtlPrepareRx (pdev, CmdBuff, req->wLength); } } else /* No Data request */ { /* Transfer the command to the interface layer */ APP_FOPS.pIf_Ctrl(req->bRequest, NULL, 0); } return USBD_OK; default: USBD_CtlError (pdev, req); return USBD_FAIL; /* Standard Requests -------------------------------*/ case USB_REQ_TYPE_STANDARD: switch (req->bRequest) { case USB_REQ_GET_DESCRIPTOR: if( (req->wValue >> 8) == CDC_DESCRIPTOR_TYPE) { #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED pbuf = usbd_cdc_Desc; #else pbuf = usbd_cdc_CfgDesc + 9 + (9 * USBD_ITF_MAX_NUM); #endif len = MIN(USB_CDC_DESC_SIZ , req->wLength); } USBD_CtlSendData (pdev, pbuf, len); break; case USB_REQ_GET_INTERFACE : USBD_CtlSendData (pdev, (uint8_t *)&usbd_cdc_AltSet, 1); break; case USB_REQ_SET_INTERFACE : if ((uint8_t)(req->wValue) < USBD_ITF_MAX_NUM) { usbd_cdc_AltSet = (uint8_t)(req->wValue); } else { /* Call the error management function (command will be nacked */ USBD_CtlError (pdev, req); } break; } } return USBD_OK; }
/** * @brief USBD_GetDescriptor * Handle Get Descriptor requests * @param pdev: device instance * @param req: usb request * @retval status */ static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { uint16_t len; uint8_t *pbuf; switch (req->wValue >> 8) { case USB_DESC_TYPE_DEVICE: pbuf = pdev->dev.usr_device->GetDeviceDescriptor(pdev->cfg.speed, &len); if ((req->wLength == 64) ||( pdev->dev.device_status == USB_OTG_DEFAULT)) { len = 8; } break; case USB_DESC_TYPE_CONFIGURATION: pbuf = (uint8_t *)pdev->dev.class_cb->GetConfigDescriptor(pdev->cfg.speed, &len); #ifdef USB_OTG_HS_CORE if((pdev->cfg.speed == USB_OTG_SPEED_FULL )&& (pdev->cfg.phy_itface == USB_OTG_ULPI_PHY)) { pbuf = (uint8_t *)pdev->dev.class_cb->GetOtherConfigDescriptor(pdev->cfg.speed, &len); } #endif pbuf[1] = USB_DESC_TYPE_CONFIGURATION; pdev->dev.pConfig_descriptor = pbuf; break; case USB_DESC_TYPE_STRING: switch ((uint8_t)(req->wValue)) { case USBD_IDX_LANGID_STR: pbuf = pdev->dev.usr_device->GetLangIDStrDescriptor(pdev->cfg.speed, &len); break; case USBD_IDX_MFC_STR: pbuf = pdev->dev.usr_device->GetManufacturerStrDescriptor(pdev->cfg.speed, &len); break; case USBD_IDX_PRODUCT_STR: pbuf = pdev->dev.usr_device->GetProductStrDescriptor(pdev->cfg.speed, &len); break; case USBD_IDX_SERIAL_STR: pbuf = pdev->dev.usr_device->GetSerialStrDescriptor(pdev->cfg.speed, &len); break; case USBD_IDX_CONFIG_STR: pbuf = pdev->dev.usr_device->GetConfigurationStrDescriptor(pdev->cfg.speed, &len); break; case USBD_IDX_INTERFACE_STR: pbuf = pdev->dev.usr_device->GetInterfaceStrDescriptor(pdev->cfg.speed, &len); break; default: #ifdef USB_SUPPORT_USER_STRING_DESC pbuf = pdev->dev.class_cb->GetUsrStrDescriptor(pdev->cfg.speed, (req->wValue) , &len); break; #else USBD_CtlError(pdev , req); return; #endif /* USBD_CtlError(pdev , req); */ } break; case USB_DESC_TYPE_DEVICE_QUALIFIER: #ifdef USB_OTG_HS_CORE if(pdev->cfg.speed == USB_OTG_SPEED_HIGH ) { pbuf = (uint8_t *)pdev->dev.class_cb->GetConfigDescriptor(pdev->cfg.speed, &len); USBD_DeviceQualifierDesc[4]= pbuf[14]; USBD_DeviceQualifierDesc[5]= pbuf[15]; USBD_DeviceQualifierDesc[6]= pbuf[16]; pbuf = USBD_DeviceQualifierDesc; len = USB_LEN_DEV_QUALIFIER_DESC; break; } else { USBD_CtlError(pdev , req); return; } #else USBD_CtlError(pdev , req); return; #endif case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION: #ifdef USB_OTG_HS_CORE if(pdev->cfg.speed == USB_OTG_SPEED_HIGH ) { pbuf = (uint8_t *)pdev->dev.class_cb->GetOtherConfigDescriptor(pdev->cfg.speed, &len); pbuf[1] = USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION; break; } else { USBD_CtlError(pdev , req); return; } #else USBD_CtlError(pdev , req); return; #endif default: USBD_CtlError(pdev , req); return; } if((len != 0)&& (req->wLength != 0)) { len = MIN(len , req->wLength); USBD_CtlSendData (pdev, pbuf, len); } }
/** * @brief DFU_Req_UPLOAD * Handles the DFU UPLOAD request. * @param pdev: instance * @param req: pointer to the request structure * @retval status */ static void DFU_Req_UPLOAD(void *pdev, USB_SETUP_REQ *req) { const uint8_t *Phy_Addr = NULL; uint32_t Addr = 0; /* Data setup request */ if (req->wLength > 0) { if ((DeviceState == STATE_dfuIDLE) || (DeviceState == STATE_dfuUPLOAD_IDLE)) { /* Update the global langth and block number */ wBlockNum = req->wValue; wlength = req->wLength; /* DFU Get Command */ if (wBlockNum == 0) { /* Update the state machine */ DeviceState = (wlength > 3)? STATE_dfuIDLE:STATE_dfuUPLOAD_IDLE; DeviceStatus[4] = DeviceState; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; /* Store the values of all supported commands */ MAL_Buffer[0] = CMD_GETCOMMANDS; MAL_Buffer[1] = CMD_SETADDRESSPOINTER; MAL_Buffer[2] = CMD_ERASE; /* Send the status data over EP0 */ USBD_CtlSendData (pdev, (uint8_t *)(&(MAL_Buffer[0])), 3); } else if (wBlockNum > 1) { DeviceState = STATE_dfuUPLOAD_IDLE ; DeviceStatus[4] = DeviceState; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; Addr = ((wBlockNum - 2) * XFERSIZE) + Pointer; /* Change is Accelerated*/ /* Return the physical address where data are stored */ Phy_Addr = MAL_Read(Addr, wlength); /* Send the status data over EP0 */ USBD_CtlSendData (pdev, Phy_Addr, wlength); } else /* unsupported wBlockNum */ { DeviceState = STATUS_ERRSTALLEDPKT; DeviceStatus[4] = DeviceState; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; /* Call the error management function (command will be nacked */ USBD_CtlError (pdev, req); } } /* Unsupported state */ else { wlength = 0; wBlockNum = 0; /* Call the error management function (command will be nacked */ USBD_CtlError (pdev, req); } } /* No Data setup request */ else { DeviceState = STATE_dfuIDLE; DeviceStatus[1] = 0; DeviceStatus[2] = 0; DeviceStatus[3] = 0; DeviceStatus[4] = DeviceState; } }
/** * @brief usbd_dfu_Setup * Handles the DFU request parsing. * @param pdev: instance * @param req: usb requests * @retval status */ static uint8_t usbd_dfu_Setup (void *pdev, USB_SETUP_REQ *req) { uint16_t len = 0; uint8_t *pbuf = NULL; switch (req->bmRequest & USB_REQ_TYPE_MASK) { /* DFU Class Requests -------------------------------*/ case USB_REQ_TYPE_CLASS : switch (req->bRequest) { case DFU_DNLOAD: DFU_Req_DNLOAD(pdev, req); break; case DFU_UPLOAD: DFU_Req_UPLOAD(pdev, req); break; case DFU_GETSTATUS: DFU_Req_GETSTATUS(pdev); break; case DFU_CLRSTATUS: DFU_Req_CLRSTATUS(pdev); break; case DFU_GETSTATE: DFU_Req_GETSTATE(pdev); break; case DFU_ABORT: DFU_Req_ABORT(pdev); break; case DFU_DETACH: DFU_Req_DETACH(pdev, req); break; default: USBD_CtlError (pdev, req); return USBD_FAIL; } break; /* Standard Requests -------------------------------*/ case USB_REQ_TYPE_STANDARD: switch (req->bRequest) { case USB_REQ_GET_DESCRIPTOR: if( (req->wValue >> 8) == DFU_DESCRIPTOR_TYPE) { #ifdef USB_OTG_HS_INTERNAL_DMA_ENABLED pbuf = usbd_dfu_Desc; #else pbuf = usbd_dfu_CfgDesc + 9 + (9 * USBD_ITF_MAX_NUM); #endif len = MIN(USB_DFU_DESC_SIZ , req->wLength); } USBD_CtlSendData (pdev, pbuf, len); break; case USB_REQ_GET_INTERFACE : USBD_CtlSendData (pdev, (uint8_t *)&usbd_dfu_AltSet, 1); break; case USB_REQ_SET_INTERFACE : if ((uint8_t)(req->wValue) < USBD_ITF_MAX_NUM) { usbd_dfu_AltSet = (uint8_t)(req->wValue); } else { /* Call the error management function (command will be nacked */ USBD_CtlError (pdev, req); } break; } } return USBD_OK; }
//-------------------------------------------------------------- USBD_Status USBD_StdEPReq (USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { uint8_t ep_addr; USBD_Status ret = USBD_OK; ep_addr = LOBYTE(req->wIndex); switch (req->bRequest) { case USB_REQ_SET_FEATURE : switch (pdev->dev.device_status) { case USB_OTG_ADDRESSED: if ((ep_addr != 0x00) && (ep_addr != 0x80)) { DCD_EP_Stall(pdev , ep_addr); } break; case USB_OTG_CONFIGURED: if (req->wValue == USB_FEATURE_EP_HALT) { if ((ep_addr != 0x00) && (ep_addr != 0x80)) { DCD_EP_Stall(pdev , ep_addr); } } pdev->dev.class_cb->Setup (pdev, req); USBD_CtlSendStatus(pdev); break; default: USBD_CtlError(pdev , req); break; } break; case USB_REQ_CLEAR_FEATURE : switch (pdev->dev.device_status) { case USB_OTG_ADDRESSED: if ((ep_addr != 0x00) && (ep_addr != 0x80)) { DCD_EP_Stall(pdev , ep_addr); } break; case USB_OTG_CONFIGURED: if (req->wValue == USB_FEATURE_EP_HALT) { if ((ep_addr != 0x00) && (ep_addr != 0x80)) { DCD_EP_ClrStall(pdev , ep_addr); pdev->dev.class_cb->Setup (pdev, req); } USBD_CtlSendStatus(pdev); } break; default: USBD_CtlError(pdev , req); break; } break; case USB_REQ_GET_STATUS: switch (pdev->dev.device_status) { case USB_OTG_ADDRESSED: if ((ep_addr != 0x00) && (ep_addr != 0x80)) { DCD_EP_Stall(pdev , ep_addr); } break; case USB_OTG_CONFIGURED: if ((ep_addr & 0x80)== 0x80) { if(pdev->dev.in_ep[ep_addr & 0x7F].is_stall) { USBD_ep_status = 0x0001; } else { USBD_ep_status = 0x0000; } } else if ((ep_addr & 0x80)== 0x00) { if(pdev->dev.out_ep[ep_addr].is_stall) { USBD_ep_status = 0x0001; } else { USBD_ep_status = 0x0000; } } USBD_CtlSendData (pdev, (uint8_t *)&USBD_ep_status, 2); break; default: USBD_CtlError(pdev , req); break; } break; default: break; } return ret; }
//-------------------------------------------------------------- static void USBD_GetDescriptor(USB_OTG_CORE_HANDLE *pdev, USB_SETUP_REQ *req) { uint16_t len; uint8_t *pbuf; switch (req->wValue >> 8) { case USB_DESC_TYPE_DEVICE: pbuf = pdev->dev.usr_device->GetDeviceDescriptor(pdev->cfg.speed, &len); if ((req->wLength == 64) ||( pdev->dev.device_status == USB_OTG_DEFAULT)) { len = 8; } break; case USB_DESC_TYPE_CONFIGURATION: pbuf = (uint8_t *)pdev->dev.class_cb->GetConfigDescriptor(pdev->cfg.speed, &len); pbuf[1] = USB_DESC_TYPE_CONFIGURATION; pdev->dev.pConfig_descriptor = pbuf; break; case USB_DESC_TYPE_STRING: switch ((uint8_t)(req->wValue)) { case USBD_IDX_LANGID_STR: pbuf = pdev->dev.usr_device->GetLangIDStrDescriptor(pdev->cfg.speed, &len); break; case USBD_IDX_MFC_STR: pbuf = pdev->dev.usr_device->GetManufacturerStrDescriptor(pdev->cfg.speed, &len); break; case USBD_IDX_PRODUCT_STR: pbuf = pdev->dev.usr_device->GetProductStrDescriptor(pdev->cfg.speed, &len); break; case USBD_IDX_SERIAL_STR: pbuf = pdev->dev.usr_device->GetSerialStrDescriptor(pdev->cfg.speed, &len); break; case USBD_IDX_CONFIG_STR: pbuf = pdev->dev.usr_device->GetConfigurationStrDescriptor(pdev->cfg.speed, &len); break; case USBD_IDX_INTERFACE_STR: pbuf = pdev->dev.usr_device->GetInterfaceStrDescriptor(pdev->cfg.speed, &len); break; default: USBD_CtlError(pdev , req); return; } break; case USB_DESC_TYPE_DEVICE_QUALIFIER: USBD_CtlError(pdev , req); return; case USB_DESC_TYPE_OTHER_SPEED_CONFIGURATION: USBD_CtlError(pdev , req); return; default: USBD_CtlError(pdev , req); return; } if((len != 0)&& (req->wLength != 0)) { len = MIN(len , req->wLength); USBD_CtlSendData (pdev, pbuf, len); } }