📄 device.c
字号:
pConfigDesc->bNumInterfaces * sizeof(USBD_INTERFACE_INFO)); /* For each interface information */ for (uInterfaceCount = 0; uInterfaceCount < pConfigDesc->bNumInterfaces; uInterfaceCount ++) { /* * Free the endpoint information allocated and * updated in each interface */ if (NULL != pInterfaceInfo[uInterfaceCount].pEndpointInformation) { OS_FREE ( pInterfaceInfo[uInterfaceCount].pEndpointInformation); /* Mark the endpoint inforation as NULL */ pInterfaceInfo[uInterfaceCount].pEndpointInformation = NULL; } }/* END for each interface */ return USBHST_FAILURE; }/* END if whole configuration descriptor buffer is read...*/ /* Copy the next descriptor header from the buffer */ pHeader = (pUSBHST_DESCRIPTOR_HEADER) (pDeviceInfo->pCurrentConfiguration + uLength); } /* Copy the interface info from the buffer */ pInterfaceDesc = (pUSBHST_INTERFACE_DESCRIPTOR)(pHeader); /* * if this interface's uAlternateSetting is >0 get the endpointnumber * and skip the memory regios for end points continue */ if (pInterfaceDesc->bAlternateSetting > 0) { /* Skip the size of interface desc size */ uLength = uLength + sizeof(USBHST_INTERFACE_DESCRIPTOR); continue; } /* Store the interface number */ pInterfaceInfo[uInterfaceCount].uInterfaceNum = pInterfaceDesc->bInterfaceNumber; /* Store the interface protocol */ pInterfaceInfo[uInterfaceCount].uInterfaceProtocol = pInterfaceDesc->bInterfaceProtocol; /* Store the interface class */ pInterfaceInfo[uInterfaceCount].uInterfaceClass = pInterfaceDesc->bInterfaceClass; /* Store the interface subclass */ pInterfaceInfo[uInterfaceCount].uInterfaceSubClass = pInterfaceDesc->bInterfaceSubClass; /* Store the number of endpoints */ pInterfaceInfo[uInterfaceCount].uNumEndpoints = pInterfaceDesc->bNumEndpoints; /* Store the alternate setting */ pInterfaceInfo[uInterfaceCount].uAlternateSetting = pInterfaceDesc->bAlternateSetting; /* Move the buffer pointer to point to the endpoint descriptor */ uLength = uLength + sizeof(USBHST_INTERFACE_DESCRIPTOR); /* Check if memory is allocated to store interface info */ if (uLength >= uTotalLength) { OS_LOG_MESSAGE_HIGH( USBD, "usbdParseConfiguration() Failed: Invalid configuration.\n", 0, 0, 0, 0); /* Set back the interfaces information to zero */ OS_MEMSET(pDeviceInfo->pInterfacesInfo, 0, pConfigDesc->bNumInterfaces * sizeof(USBD_INTERFACE_INFO)); /* For each interface information */ for (uInterfaceCount = 0; uInterfaceCount < pConfigDesc->bNumInterfaces; uInterfaceCount ++) { /* * Free the endpoint information allocated for each interface */ if (NULL != pInterfaceInfo[uInterfaceCount].pEndpointInformation) { OS_FREE ( pInterfaceInfo[uInterfaceCount].pEndpointInformation); pInterfaceInfo[uInterfaceCount].pEndpointInformation = NULL; } }/* END for each interface */ return USBHST_FAILURE; }/* END if memory is allocated...*/ /* Check if the number of endpoints greater than zero */ if (pInterfaceDesc->bNumEndpoints > 0) { /* Allocate memory to store endpoint info */ pEndpointInfo = (pUSBD_ENDPOINT_INFO)OS_MALLOC( sizeof(USBD_ENDPOINT_INFO) * pInterfaceDesc->bNumEndpoints); /* Check if memory is allocated to store interface info */ if (NULL == pEndpointInfo) { OS_LOG_MESSAGE_HIGH( USBD, "usbdParseConfiguration() Failed: INSUFFICIENT_MEMORY.\n", 0, 0, 0, 0); /* Set back the interfaces information to zero */ OS_MEMSET(pDeviceInfo->pInterfacesInfo, 0, pConfigDesc->bNumInterfaces * sizeof(USBD_INTERFACE_INFO)); /* For each interface information */ for (uInterfaceCount = 0; uInterfaceCount < pConfigDesc->bNumInterfaces; uInterfaceCount ++) { /* * Free the endpoint information allocated for each interface */ if (NULL != pInterfaceInfo[uInterfaceCount].pEndpointInformation) { OS_FREE ( pInterfaceInfo[uInterfaceCount].pEndpointInformation); pInterfaceInfo[uInterfaceCount].pEndpointInformation = NULL; } }/* END for each interface */ return USBHST_INSUFFICIENT_MEMORY; }/* END if memory is allocated...*/ /* Fill the endpoint info memory area with 0 */ OS_MEMSET(pEndpointInfo, 0, sizeof(USBD_ENDPOINT_INFO) * pInterfaceDesc->bNumEndpoints); } /* * For this interface read all the corresponding endpoint descriptors * and store them as endpoint info in the respective interface */ /* Initialize the endpoint count to zero */ uEndpointCount = 0; while (uEndpointCount < pInterfaceDesc->bNumEndpoints) { /* Copy the descriptor header from the buffer */ pHeader = (pUSBHST_DESCRIPTOR_HEADER) (pDeviceInfo->pCurrentConfiguration + uLength); /* Check if the descriptor is endpoint */ while (pHeader->uDescriptorType != USBHST_ENDPOINT_DESC) { /* Move the pointer to read the next descriptor */ uLength = uLength + pHeader->uLength; /* * Check if whole configuration descriptor buffer is read before * the expected information is fetched. */ if (uLength >= uTotalLength) { OS_LOG_MESSAGE_HIGH( USBD, "usbdParseConfiguration() Failed: Invalid configuration\ descriptor.\n", 0, 0, 0, 0); /* Set back the interfaces information to zero */ OS_MEMSET(pDeviceInfo->pInterfacesInfo, 0, pConfigDesc->bNumInterfaces * sizeof(USBD_INTERFACE_INFO)); /* * Free the allocated endpoint information which is not * yet updated in the interfaces inforamtion */ OS_FREE (pEndpointInfo); /* For each interface information */ for (uInterfaceCount = 0; uInterfaceCount < pConfigDesc->bNumInterfaces; uInterfaceCount ++) { /* * Free the endpoint information allocated and * updated in each interface */ if (NULL != pInterfaceInfo[uInterfaceCount].pEndpointInformation) { OS_FREE ( pInterfaceInfo[uInterfaceCount].pEndpointInformation); /* Mark the endpoint info as NULL */ pInterfaceInfo[uInterfaceCount].pEndpointInformation = NULL; } }/* END for each interface */ return USBHST_FAILURE; }/* END if whole configuration descriptor buffer is read...*/ /* Copy the next descriptor header from the buffer */ pHeader = (pUSBHST_DESCRIPTOR_HEADER) (pDeviceInfo->pCurrentConfiguration + uLength); } /* Copy the endpoint descriptor from the buffer */ pEndpointDesc = (pUSBHST_ENDPOINT_DESCRIPTOR) (pDeviceInfo->pCurrentConfiguration + uLength); /* Check if the end point is valid */ if (!usbdIsValidEndpoint(pDeviceInfo, pEndpointDesc)) { OS_LOG_MESSAGE_MEDIUM( USBD, "usbdParseConfiguration() Failed:Invalid parameter.\n", 0, 0, 0, 0); /* Set back the interfaces information to zero */ OS_MEMSET(pDeviceInfo->pInterfacesInfo, 0, pConfigDesc->bNumInterfaces * sizeof(USBD_INTERFACE_INFO)); /* * Free the allocated endpoint information which is not * yet updated in the interfaces inforamtion */ OS_FREE (pEndpointInfo); /* For each interface information */ for (uInterfaceCount = 0; uInterfaceCount < pConfigDesc->bNumInterfaces; uInterfaceCount ++) { /* * Free the endpoint information allocated and updated in each * interface */ if (NULL != pInterfaceInfo[uInterfaceCount].pEndpointInformation) { OS_FREE ( pInterfaceInfo[uInterfaceCount].pEndpointInformation); /* Mark the endpoint info as NULL */ pInterfaceInfo[uInterfaceCount].pEndpointInformation = NULL; } }/* END for each interface */ return USBHST_INVALID_PARAMETER; }/* END if endpoints are not valid...*/ /* Store the endpoint address */ pEndpointInfo[uEndpointCount].uEndpointAddress = pEndpointDesc->bEndpointAddress; /* * If the function is called with the flag * USBD_PARSE_AND_CREATE set */ if (USBD_PARSE_AND_CREATE == uParserFlag) { /* Call the HCD CreatePipe function to create the pipe */ pHCDriverInfo->createPipe( pUsbBusInfo->uRelativeBusIndex, pDeviceInfo->uDeviceAddress, pDeviceInfo->uDeviceSpeed, (UCHAR *) pEndpointDesc, pDeviceInfo->uHighSpeedHubInfo, &(pEndpointInfo[uEndpointCount].hPipe)); } /* If the function is called with the flag USBD_PARSE_ONLY set */ if (USBD_PARSE_ONLY == uParserFlag) { /* Initialize the pipe to zero */ pEndpointInfo[uEndpointCount].hPipe = 0; } /* Move the buffer pointer to point to the next descriptor */ uLength = uLength + sizeof(USBHST_ENDPOINT_DESCRIPTOR); /* Increment the endpoint count */ uEndpointCount = uEndpointCount + 1; } /* End of WHILE loop for endpoint */ /* Store the endpoint info in the interface info */ pInterfaceInfo[uInterfaceCount].pEndpointInformation = pEndpointInfo; /* Increment uInterfaceCount by 1 */ uInterfaceCount = uInterfaceCount + 1; } /* End of WHILE loop for interface */ OS_LOG_MESSAGE_LOW(USBD, "Exiting usbdParseConfiguration() Function.\n", 0, 0, 0, 0); return USBHST_SUCCESS; } /* End of usbdParseConfiguration() *//***************************************************************************** usbdGetInterfaceOffset - parses the configuration** This function parses the configration to obtain the interface offset* depending on the interface index specifed by <uInterfaceNum>.** RETURNS: USBHST_SUCCESS, USBHST_FAILURE if interface is not found in the* configuration** ERRNO: None** \NOMANUAL*/LOCAL USBHST_STATUS usbdGetInterfaceOffset ( UCHAR *pConfigBuffer, /* Ptr to config buffer */ UINT16 uInterfaceNum, /* Interface number */ UINT16 uAltIndex, /* Alternate setting index */ UINT32 *pStartOffset /* Ptr to start offset */ ) { UINT16 uTotalLength = 0; /* Config Descr Length */ UINT16 uLength = 0; /* Current position */ pUSBHST_DESCRIPTOR_HEADER pHeader = NULL; /* Descriptor header */ pUSBHST_INTERFACE_DESCRIPTOR pInterfaceDesc = NULL; /* Interface descriptor */ BOOL bMatchFlag = FALSE; /* Interface found */ OS_LOG_MESSAGE_LOW(USBD, "Entering usbdGetInterfaceOffset() Function.\n", 0, 0, 0, 0); /* get the total length of configuration with CPU endian conversion */ uTotalLength = OS_UINT16_LE_TO_CPU( ((pUSBHST_CONFIG_DESCRIPTOR)pConfigBuffer)->wTotalLength); /* Move the pointer to the interface */ uLength = ((pUSBHST_CONFIG_DESCRIPTOR) pConfigBuffer)->bLength;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -