📄 usbuhcdrhemulate.c
字号:
} /* Population of the values of hub descriptor - End */ /* Copy the descriptor to URB's buffer */ usbUhcdCopy (pUrb->pTransferBuffer, desc, &(pUrb->uTransferLength), desc[0]); OS_LOG_MESSAGE_MEDIUM(UHCD,"Exiting GetHubDescriptor\n",0,0,0,0); /* Return success */ return USB_UHCD_PASS; }/* End of usbUhcdGetHubDescriptor() *//***************************************************************************** usbUhcdGetHubStatus - handles the hub specific request for Root hub** This function handles the GET_HUB_STATUS hub specific request for the * Root hub , called by usbUhcdProcessRhControlTransfer.** RETURNS: USB_UHCD_FAIL if there is an error in retrieving the hub status** ERRNO:* None.** \NOMANUAL*/INT32 usbUhcdGetHubStatus ( USBHST_URB *pUrb ) { /* To hold the hub status string */ UCHAR buf[2]={0,0}; pUSBHST_SETUP_PACKET pSetupPacket = (pUSBHST_SETUP_PACKET )pUrb->pTransferSpecificData; UINT16 wValue = 0; UINT16 wIndex = 0; UINT16 wLength = 0; OS_LOG_MESSAGE_MEDIUM(UHCD,"Entering GetHubStatus\n",0,0,0,0); /* Check if the URB and DevRequest pointers are valid */ if (NULL == pUrb || NULL == pUrb->pTransferSpecificData) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Pointers are not valid \n",0,0,0,0); return USB_UHCD_FAIL; } wValue = OS_UINT16_CPU_TO_LE(pSetupPacket->wValue); wIndex = OS_UINT16_CPU_TO_LE(pSetupPacket->wIndex); wLength = OS_UINT16_CPU_TO_LE(pSetupPacket->wLength); OS_LOG_MESSAGE_MEDIUM(UHCD,"Checking Parameters\n",0,0,0,0); /* * Check whether there are any invalid conditions. * i.e invalid DevRequest parameters */ if (wLength !=2 || wValue != 0 || wIndex !=0) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Invalid conditions\n",0,0,0,0); return USB_UHCD_FAIL; } /* Check whether the Buffer passed is valid */ if (pUrb->pTransferBuffer==NULL) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Invalid buffer passed\n",0,0,0,0); return USB_UHCD_FAIL; } /* Copy the hub status to URB's buffer */ usbUhcdCopy (pUrb->pTransferBuffer, buf, NULL, 2); OS_LOG_MESSAGE_MEDIUM(UHCD,"Exiting GetHubStatus \n",0,0,0,0); /* Return success */ return USB_UHCD_PASS; }/* End of usbUhcdGetHubStatus () *//***************************************************************************** usbUhcdGetBusState - handles the hub specific request for Root hub** This function handles the GET_BUS_STATE hub specific request for the * Root hub, called by usbUhcdProcessRhControlTransfer.** RETURNS: USB_UHCD_FAIL if there is an error in retrieving the bus state** ERRNO:* None.** \NOMANUAL*/INT32 usbUhcdGetBusState ( PUHCD_DATA pHCDData, USBHST_URB *pUrb ) { /* To hold the Bus State 1 byte information */ UCHAR buf=0; /* To hold the offset of the register */ UINT8 offset = 0; /* To hold the port number */ UINT8 port = 0; UINT16 wValue = 0; UINT16 wIndex = 0; UINT16 wLength = 0; pUSBHST_SETUP_PACKET pSetupPacket = (pUSBHST_SETUP_PACKET )pUrb->pTransferSpecificData; OS_LOG_MESSAGE_MEDIUM(UHCD,"Entering GetBusState\n",0,0,0,0); /* Check if the URB and the DevRequest pointers are valid */ if (NULL == pUrb || NULL == pUrb->pTransferSpecificData) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Pointers are not valid \n",0,0,0,0); return USB_UHCD_FAIL; } wValue = OS_UINT16_CPU_TO_LE(pSetupPacket->wValue); wIndex = OS_UINT16_CPU_TO_LE(pSetupPacket->wIndex); wLength = OS_UINT16_CPU_TO_LE(pSetupPacket->wLength); /* Extract the port number from URB */ port = wIndex; OS_LOG_MESSAGE_MEDIUM(UHCD,"Checking parameters\n",0,0,0,0); /* * Check whether there are any invalid conditions. * i.e invalid port number */ if (port < USB_UHCD_PORT_1 || port > USB_UHCD_PORT_2) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Invalid condition\n",0,0,0,0); return USB_UHCD_FAIL; } /* * Check whether there are any invalid conditions. * i.e invalid DevRequest parameters */ if (wLength != 1 || wValue != 0 ) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Invalid DevRequest parameter\n",0,0,0,0); return USB_UHCD_FAIL; } /* Check whether the buffer pointer is valid */ if (pUrb->pTransferBuffer == NULL) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Invalid buffer pointer\n",0,0,0,0); return USB_UHCD_FAIL; } /* Get the correct offset based on port number */ offset = (port == 1) ? (USB_UHCD_PORT1) : (USB_UHCD_PORT2); /* * The request for GET_BUS_STATE returns an 1 byte information * with the following field interpretation * Bit 0 - Value of the D- signal * Bit 1 - Value of the D+ signal * Bits 2-7 - Reserved and reset to 0 */ /* Fill the buffer based on Line status field of PORTSC -Start */ /* Bit 4 - Gives the value of D+ signal logical level */ buf |= usbUhcdIsBitSet (pHCDData, offset, 4); buf = buf << 1; /* Bit 5 gives the value of D- signal logical level */ buf |= usbUhcdIsBitSet (pHCDData, offset, 5); /* Fill buffer based on Line status field of PORTSC -Start */ /* Copy the buf value to URB's buffer */ usbUhcdCopy (pUrb->pTransferBuffer, &buf, NULL, 1); OS_LOG_MESSAGE_MEDIUM(UHCD,"Exiting GetBusState\n",0,0,0,0); /* Return a success status */ return USB_UHCD_PASS; }/* End of usbUhcdGetBusState() *//***************************************************************************** usbUhcdGetDescriptor - handles the hub specific request for Root hub** This function handles the GET_DESCRIPTOR standard device request issued * to the Root hub , called by usbUhcdProcessRhControlTransfer.** RETURNS: USB_UHCD_FAIL if there is an error in retrieving the descriptor** ERRNO:* None.* * \NOMANUAL*/INT32 usbUhcdGetDescriptor ( USBHST_URB *pUrb ) { /* To hold the descriptor index */ UINT8 descIndex = 0; /* To hold the descriptor type */ UINT8 descType = 0; UINT16 wValue = 0; UINT16 wIndex = 0; UINT16 wLength = 0; pUSBHST_SETUP_PACKET pSetupPacket = (pUSBHST_SETUP_PACKET )pUrb->pTransferSpecificData; OS_LOG_MESSAGE_MEDIUM(UHCD,"Entering GetDescriptor()\n",0,0,0,0); /* Check if the URB and the DevRequest pointers are valid */ if (NULL == pUrb || NULL == pUrb->pTransferSpecificData) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Pointers are not valid \n",0,0,0,0); return USB_UHCD_FAIL; } wValue = OS_UINT16_CPU_TO_LE(pSetupPacket->wValue); wIndex = OS_UINT16_CPU_TO_LE(pSetupPacket->wIndex); wLength = OS_UINT16_CPU_TO_LE(pSetupPacket->wLength); /* Get the descriptor Index */ descIndex = wValue & (0xFF); /* Get the descriptor type */ descType = (wValue & (0xFF00)) >> 8; OS_LOG_MESSAGE_MEDIUM(UHCD,"Checking parameters\n",0,0,0,0); /* * Check whether there are any invalid conditions * ie invalid DevRequest parameters */ if (wIndex != 0 || descIndex != 0 || (descType != 1 && descType != 2)) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Invalid conditions\n",0,0,0,0); return USB_UHCD_FAIL; } /* Check if the buffer pointer is valid */ if (pUrb->pTransferBuffer == NULL) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Invalid buffer pointer\n",0,0,0,0); return USB_UHCD_FAIL; } OS_LOG_MESSAGE_MEDIUM(UHCD,"Switch for selecting descriptor needed\n",0,0,0,0); /* Switch based on the descriptor needed */ switch (descType) { case USB_UHCD_DESCRIPTOR:/* Device Descriptor request */ { OS_LOG_MESSAGE_MEDIUM(UHCD,"Case : Device Descriptor request\n",0,0,0,0); /* Copy the Device descriptor */ usbUhcdCopy ( pUrb->pTransferBuffer, usbUhcdGdDeviceDescriptor, &(pUrb->uTransferLength), 0x12); break; }/* End of case USB_UHCD_DESCRIPTOR */ case USB_UHCD_CONFIGURATION_DESCRIPTOR:/* Config descriptor request */ { OS_LOG_MESSAGE_MEDIUM(UHCD,"Case : Config Descriptor request\n",0,0,0,0); /* Copy the Configuration descriptor */ usbUhcdCopy (pUrb->pTransferBuffer, usbUhcdGdConfigDescriptor, &(pUrb->uTransferLength), 0x19); break; }/* End of case USB_UHCD_CONFIGURATION_DESCRIPTOR */ default: break; }/* End of switch () */ OS_LOG_MESSAGE_MEDIUM(UHCD,"Exiting GetDescriptor()\n",0,0,0,0); /* Return success */ return USB_UHCD_PASS; }/* End of usbUhcdGetDescriptor() *//***************************************************************************** usbUhcdSetConfiguration - handles the hub specific request for Root hub** This function handles the SET_CONFIGURATION standard device request issued to* the Root hub.** RETURNS: USB_UHCD_FAIL if there is an error in setting configuration** ERRNO:* None.** \NOMANUAL*/INT32 usbUhcdSetConfiguration ( PUHCD_DATA pHCDData, USBHST_URB *pUrb ) { UINT16 wValue = 0; UINT16 wIndex = 0; UINT16 wLength = 0; pUSBHST_SETUP_PACKET pSetupPacket = (pUSBHST_SETUP_PACKET )pUrb->pTransferSpecificData; OS_LOG_MESSAGE_MEDIUM(UHCD,"Entering SetConfiguration()\n",0,0,0,0); /* Check if the URB and DevRequest pointers are valid */ if (NULL == pUrb || NULL == pUrb->pTransferSpecificData) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Pointers are not valid\n",0,0,0,0); return USB_UHCD_FAIL; } wValue = OS_UINT16_CPU_TO_LE(pSetupPacket->wValue); wIndex = OS_UINT16_CPU_TO_LE(pSetupPacket->wIndex); wLength = OS_UINT16_CPU_TO_LE(pSetupPacket->wLength); OS_LOG_MESSAGE_MEDIUM(UHCD,"Checking parameters\n",0,0,0,0); /* * Check whether there are any invalid conditions * ie invalid DevRequest parameters */ if (wIndex != 0 || wLength !=0 || (wLength != USB_UHCD_CONFIG_VALUE && wLength != 0)) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Invalid Conditions\n",0,0,0,0); return USB_UHCD_FAIL; } /* Record the configuration value passed */ pHCDData->rootHub.uConfigValue = wLength; OS_LOG_MESSAGE_MEDIUM(UHCD,"Exiting SetConfiguration\n",0,0,0,0); /* Return success */ return USB_UHCD_PASS; }/* End of usbUhcdSetConfiguration() *//***************************************************************************** usbUhcdGetConfiguration - handles the hub specific request for Root hub** This function handles the GET_CONFIGURATION standard device request issued to* the Root hub, called by NoneusbUhcdProcessRhControlTransfer.** RETURNS: USB_UHCD_FAIL if there is an error in retrieving configuration** ERRNO:* None.** \NOMANUAL*/INT32 usbUhcdGetConfiguration ( PUHCD_DATA pHCDData, USBHST_URB *pUrb ) { UINT16 wValue = 0; UINT16 wIndex = 0; UINT16 wLength = 0; pUSBHST_SETUP_PACKET pSetupPacket = (pUSBHST_SETUP_PACKET )pUrb->pTransferSpecificData; OS_LOG_MESSAGE_MEDIUM(UHCD,"Entering GetConfiguration()\n",0,0,0,0); /* Check if the URB and DevRequest pointers are valid */ if (NULL == pUrb || NULL == pUrb->pTransferSpecificData) { OS_LOG_MESSAGE_MEDIUM(UHCD,"Pointers are not valid\n",0,0,0,0); return USB_UHCD_FAIL; } wValue = OS_UINT16_CPU_TO_LE(pSetupPacket->wValue); wIndex = OS_UINT16_CPU_TO_LE(pSetupPacket->wIndex); wLength = OS_UINT16_CPU_TO_LE(pSetupPacket->wLength); OS_LOG_MESSAGE_MEDIUM(UHCD,"Checking parameters\n",0,0,0,0); /* * Check whether there are any invalid conditions * ie invalid DevRequest parameters */ if (wIndex != 0 || wLength != 1 || wLength != 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -