📄 usbh_hcds_vhub.c
字号:
return STATUS_SUCCESS;
}
/*======================================================================
// Function_Name: ClearFeature
//
// description : Clear Feature request
//
// Process for Clear Feature request
//
// argument : *psDeviceRequest Pointer of device request
//
// return : STATUS_SUCCESS Success
// STATUS_INVALID_PARAMETER Parameter error
========================================================================*/
Inline long ClearFeature( DEVICE_REQUEST *psDeviceRequest )
{
if( VHUBStatus.bmFlags.usbState == DEFAULT_STATE ){
/* Default state */
return STATUS_INVALID_PARAMETER;
}
if( (psDeviceRequest->bmRequestType & BMREQ_DIR_MASK) != DIR_HOST_TO_DEVICE ){
/* Direction of transfer is different */
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wLengthH || psDeviceRequest->wLengthL ){
/* wLength != 0 */
return STATUS_INVALID_PARAMETER;
}
switch( psDeviceRequest->bmRequestType & BMREQ_RECIPIENT_MASK ){
case RECIPIENT_DEVICE:
if( psDeviceRequest->wValueH ){
/* wValue.h != 0 */
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wValueL == SFEA_DEVICE_REMOTE_WAKEUP ){
/* Feature Select = DEVICE_REMOTE_WAKEUP */
if( psDeviceRequest->wIndexH || psDeviceRequest->wIndexL ){
/* wIndex != 0 */
return STATUS_INVALID_PARAMETER;
}
/*=============================================================/
Check whether the Remote Wakeup is supported and disable the Remote Wakeup /
/==============================================================*/
if( (StdConfigDesc[OFFSET_BMATTRIBUTES] & ATTRIB_REMOTE_WAKEUP) == 0 ){
/* When the Remote Wakeup is not supportrd */
return STATUS_INVALID_PARAMETER;
}
VHUBStatus.bmFlags.remoteWakeup = 0;
/* Disable the Remote Wakeup function */
USBH_HCDS_PortRemoteWakeupControl( USBH_HCDS_PORT_RMTWKUP_DISABLE );
}else{
return STATUS_INVALID_PARAMETER;
}
break;
case RECIPIENT_ENDPOINT:
if( psDeviceRequest->wValueH ){
/* wValue.h != 0 */
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wValueL != SFEA_ENDPOINT_HALT ){
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wIndexH ){
/* wIndex.h != 0 */
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wIndexL == 0 || psDeviceRequest->wIndexL != INT_EP_ADDRESS ){
/* Except for EndPoint 0 or Interrupt IN Endpoint */
return STATUS_INVALID_PARAMETER;
}
if( VHUBStatus.bmFlags.usbState == ADDRESSED_STATE ){
return STATUS_INVALID_PARAMETER;
}
/*================================/
/Initialize the specified Endpont /
/================================*/
VHUBStatus.bmFlags.epHalt = 0;
break;
default:
return STATUS_INVALID_PARAMETER;
}
return STATUS_SUCCESS;
}
/*======================================================================
// Function_Name: SetFeature
//
// description : Set Feature request
//
// Process for Set Feature request
//
// argument : *psDeviceRequest Pointer of device request
//
// return : STATUS_SUCCESS Success
// STATUS_INVALID_PARAMETER Error
// STATUS_NOT_IMPLEMENTED Not implemented
// STATUS_INVALID_PARAMETER Parameter error
========================================================================*/
Inline long SetFeature( DEVICE_REQUEST *psDeviceRequest )
{
if( VHUBStatus.bmFlags.usbState == DEFAULT_STATE ){
return STATUS_INVALID_PARAMETER;
}
if( (psDeviceRequest->bmRequestType & BMREQ_DIR_MASK) != DIR_HOST_TO_DEVICE ){
/* Direction of transfer is different */
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wLengthH || psDeviceRequest->wLengthL ){
/* wLength != 0 */
return STATUS_INVALID_PARAMETER;
}
switch( psDeviceRequest->bmRequestType & BMREQ_RECIPIENT_MASK ){
case RECIPIENT_DEVICE:
if( psDeviceRequest->wValueH ){
/* wValue.h != 0 */
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wValueL == SFEA_DEVICE_REMOTE_WAKEUP ){
/* Feature Selector = DEVIDCE_REMOTE_WAKEUP */
if( psDeviceRequest->wIndexH || psDeviceRequest->wIndexL ){
/* wIndex != 0 */
return STATUS_INVALID_PARAMETER;
}
/*=============================================================/
Check whether the Remote Wakeup is supported and disable the Remote Wakeup /
/=============================================================*/
if( (StdConfigDesc[OFFSET_BMATTRIBUTES] & ATTRIB_REMOTE_WAKEUP) == 0 ){
/* When the Remote Wakeup is not supportrd */
return STATUS_INVALID_PARAMETER;
}
VHUBStatus.bmFlags.remoteWakeup = 1;
/* Enable the Remote Wakeup function */
USBH_HCDS_PortRemoteWakeupControl( USBH_HCDS_PORT_RMTWKUP_ENABLE );
} else {
return STATUS_INVALID_PARAMETER;
}
break;
case RECIPIENT_ENDPOINT:
if( psDeviceRequest->wValueH ){
/* wValue.h != 0 */
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wValueL != SFEA_ENDPOINT_HALT ){
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wIndexH ){
/* wIndex.h != 0 */
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wIndexL == 0 || psDeviceRequest->wIndexL != INT_EP_ADDRESS ){
/* Except for EndPoint 0 or Interrupt IN Endpoint */
return STATUS_INVALID_PARAMETER;
}
if( VHUBStatus.bmFlags.usbState == ADDRESSED_STATE ){
return STATUS_INVALID_PARAMETER;
}
/*=========================================/
Specified Endpont is changed to STALL reply mode./
/=========================================*/
VHUBStatus.bmFlags.epHalt = 1;
break;
default:
return STATUS_INVALID_PARAMETER;
}
return STATUS_SUCCESS;
}
/*======================================================================
// Function_Name: SetAddress
//
// description : SetAddress request
//
// Process for SetAddress request
//
// argument : *psDeviceRequest Pointer of device request
//
// return : STATUS_SUCCESS Success
// STATUS_INVALID_PARAMETER Error
========================================================================*/
Inline long SetAddress( DEVICE_REQUEST *psDeviceRequest )
{
if( VHUBStatus.bmFlags.usbState == CONFIGURED_STATE ){
return STATUS_INVALID_PARAMETER;
}
if( (psDeviceRequest->bmRequestType & BMREQ_DIR_MASK) != DIR_HOST_TO_DEVICE ){
/* Direction of transfer is different */
return STATUS_INVALID_PARAMETER;
}
if( (psDeviceRequest->bmRequestType & BMREQ_RECIPIENT_MASK) != RECIPIENT_DEVICE ){
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wValueH ){
/* wValue.h != 0 */
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wIndexH || psDeviceRequest->wIndexL ){
/* wIndex != 0 */
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wLengthH || psDeviceRequest->wLengthL ){
/* wLength != 0 */
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wValueL > MAX_USB_ADDRESS){
/* For the given address exceeded the upper bound */
return STATUS_INVALID_PARAMETER;
}
/*======================/
Set the USB address/
/======================*/
VHUBStatus.usbAddress = psDeviceRequest->wValueL;
/*======================/
Change the USB state /
/======================*/
if( psDeviceRequest->wValueL != 0 ){
VHUBStatus.bmFlags.usbState = ADDRESSED_STATE;
} else {
VHUBStatus.bmFlags.usbState = DEFAULT_STATE;
}
return STATUS_SUCCESS;
}
/*======================================================================
// Function_Name: GetDescriptor
//
// description : GetDescriptor request
//
// Process for GetDescriptor request
//
// argument : *psDeviceRequest Pointer of device request
//
// return : STATUS_SUCCESS Success
// STATUS_INVALID_PARAMETER Error
// STATUS_NOT_IMPLEMENTED Not implemented
// STATUS_INVALID_PARAMETER Parameter error
========================================================================*/
Inline long GetDescriptor( DEVICE_REQUEST *psDeviceRequest )
{
USBH_HCD_URB *psUrb;
unsigned char *pBufAdrs;
const unsigned char *pSrcAdrs;
unsigned short dataLength;
psUrb = VHUBStatus.psUrb;
pBufAdrs = (unsigned char *)psUrb->pTransBuf;
if( (psDeviceRequest->bmRequestType & BMREQ_DIR_MASK) != DIR_DEVICE_TO_HOST ){
/* Direction of transfer is different */
return STATUS_INVALID_PARAMETER;
}
if( (psDeviceRequest->bmRequestType & BMREQ_RECIPIENT_MASK) != RECIPIENT_DEVICE ){
return STATUS_INVALID_PARAMETER;
}
dataLength = MAKEWORD(psDeviceRequest->wLengthL, psDeviceRequest->wLengthH);
switch( psDeviceRequest->wValueH ){
case DTYPE_DEVICE:
if( psDeviceRequest->wValueL ){
/* wValue.l != 0 */
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wIndexH || psDeviceRequest->wIndexL ){
/* wIndex != 0 */
return STATUS_INVALID_PARAMETER;
}
pSrcAdrs = StdDevDesc;
dataLength = MIN(dataLength, pSrcAdrs[OFFSET_BLENGTH]);
memcpy(pBufAdrs, pSrcAdrs, dataLength);
break;
case DTYPE_CONFIGURATION:
if( psDeviceRequest->wIndexH || psDeviceRequest->wIndexL ){
/* wIndex != 0 */
return STATUS_INVALID_PARAMETER;
}
pSrcAdrs = StdConfigDesc;
dataLength = MIN(dataLength, pSrcAdrs[OFFSET_WTOTALLENGTH]);
memcpy(pBufAdrs, pSrcAdrs, dataLength);
break;
case DTYPE_STRING:
if( psDeviceRequest->wValueL >= NUM_STRING_DESC ){
/* invalid Descriptor Index */
return STATUS_INVALID_PARAMETER;
}
pSrcAdrs = StdStringDesc[psDeviceRequest->wValueL];
dataLength = MIN(dataLength, pSrcAdrs[OFFSET_BLENGTH]);
memcpy(pBufAdrs, pSrcAdrs, dataLength);
break;
case DTYPE_DEVICE_QUALIFIER:
if( psDeviceRequest->wValueL ){
/* wValue.l != 0 */
return STATUS_INVALID_PARAMETER;
}
if( psDeviceRequest->wIndexH || psDeviceRequest->wIndexL ){
/* wIndex != 0 */
return STATUS_INVALID_PARAMETER;
}
pSrcAdrs = StdDevDesc;
dataLength = MIN(dataLength, DEVICE_QUALIFIER_BLENGTH);
memcpy(pBufAdrs, pSrcAdrs, dataLength);
pBufAdrs[OFFSET_BDESCTYPE] = DTYPE_DEVICE_QUALIFIER;
if( dataLength >= OFFSET_DQ_BNUMCONFIGURATIONS ){
pBufAdrs[OFFSET_DQ_BNUMCONFIGURATIONS] = pSrcAdrs[OFFSET_BNUMCONFIGURATIONS];
if( dataLength == DEVICE_QUALIFIER_BLENGTH ){
pBufAdrs[OFFSET_DQ_RESERVED] = 0x00;
}
}
break;
case DTYPE_OTHER_SPEED_CONFIGURATION:
if( psDeviceRequest->wIndexH || psDeviceRequest->wIndexL ){
/* wIndex != 0 */
return STATUS_INVALID_PARAMETER;
}
pSrcAdrs = StdConfigDesc;
dataLength = MIN(dataLength, pSrcAdrs[OFFSET_WTOTALLENGTH]);
memcpy(pBufAdrs, pSrcAdrs, dataLength);
pBufAdrs[OFFSET_BDESCTYPE] = DTYPE_OTHER_SPEED_CONFIGURATION;
break;
case DTYPE_INTERFACE_POWER:
/* Currently it is not supported for it is an option */
default:
return STATUS_INVALID_PARAMETER;
}
psUrb->actualLength = dataLength;
return STATUS_SUCCESS;
}
/*======================================================================
// Function_Name: GetConfiguration
//
// description : Get Configuration request
//
// Process for Get Configuration request
//
// argument : *psDeviceRequest Pointer of device request
//
// return : STATUS_SUCCESS Success
// STATUS_INVALID_PARAMETER Error
// STATUS_NOT_IMPLEMENTED Not implemented
// STATUS_INVALID_PARAMETER Parameter error
========================================================================*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -