📄 usbhubutility.c
字号:
OS_ASSERT(USBHST_SUCCESS == Result); /* verify */ /* * Call the HUB_TIME_DIFF() function with HUB_PORT_INFO::uConnectFrame and * current time. If the return value is less than HUB_PORT_DEBOUNCE_TIME, * return USBHST_SUCCESS. */ /* Get the time diference */ uTimeDiff = USB_HUB_TIME_DIFF(uCurrentFrame,pPort->uConnectFrame); /* Check for the time value */ if ( USB_HUB_PORT_DEBOUNCE_TIME > uTimeDiff ) { /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubPortDebounceHandler:pHub=0x%x port=%d WAITING\n", (UINT32)pHub, uPortIndex, 0, 0); return USBHST_SUCCESS; }/* End of if ( HUB_PORT_DEBOUNCE_TIME.... */ /* Allocate memory for the port status */ pPortStatus = OS_MALLOC(4); /* Check if memory allocation is successful */ if (pPortStatus == NULL) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubPortDebounceHandler:getPortStatus memory alloc fail:0x%x\n", USBHST_INSUFFICIENT_MEMORY, 0, 0, 0); return USBHST_INSUFFICIENT_MEMORY; } /* Initialize the memory allocated */ OS_MEMSET(pPortStatus, 0, 4); /* * Call HUB_GET_PORT_STATUS() to get the HUB_PORT_STATUS structure. * If this fails then return result. */ Result = USB_HUB_GET_PORT_STATUS(pHub, uPortIndex, (PUINT8)(pPortStatus), &uLength); if (USBHST_SUCCESS !=Result) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubPortDebounceHandler:getPortStatus FAIL:0x%x\n", Result, 0, 0, 0); /* Release memory allocated for port status */ OS_FREE(pPortStatus); return Result; }/* End of if (USBHST_SUCCESS... */ /* swap the members of the structure */ pPortStatus->wPortChange = OS_UINT16_LE_TO_CPU(pPortStatus->wPortChange); pPortStatus->wPortStatus = OS_UINT16_LE_TO_CPU(pPortStatus->wPortStatus); /* * If the HUB_PORT_STATUS:;wPortStatus is DISCONNECTED then * i. Set the HUB_PORT_INFO::StateOfPort as MARKED_FOR_DELETION * ii. Return USBHST_SUCCESS */ if (0 ==( pPortStatus->wPortStatus & USB_PORT_CONNECTION_VALUE) ) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubPortDebounceHandler:DisConnection:0x%x\n", pPortStatus->wPortStatus, 0, 0, 0); /* Mark the port for deletion */ USB_MARK_FOR_DELETE_PORT(pHub,pPort); /* Release memory allocated for port status */ OS_FREE(pPortStatus); return USBHST_SUCCESS; } /* End of if (0==... */ /* Release memory allocated for port status */ OS_FREE(pPortStatus); /* * If the device is connected to a High speed bus, * The max tiers allowed is as per 2.00 spec * else * The max tiers allowed is as per 1.1 spec */ if (USBHST_HIGH_SPEED != pHub->pBus->uBusSpeed) { uMaxTier = HUB_MAX_ALLOWED_DEPTH_USB1_1 ; } else { uMaxTier = HUB_MAX_ALLOWED_DEPTH_USB2_0; } /* * if pHub::uCurrentTier is HUB_MAX_ALLOWED_DEPTH then * i. Set the HUB_PORT_INFO::StateOfPort as MARKED_FOR_DELETION * ii. Return USBHST_SUCCESS */ if (uMaxTier == pHub->uCurrentTier) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubPortDebounceHandler:Number of Tiers exceeded Max %d\n", pHub->uCurrentTier, 0, 0, 0); /* Mark the port for deletion */ USB_MARK_FOR_DELETE_PORT(pHub,pPort); return USBHST_SUCCESS; }/* End of if (HUB_MAX_ALLO... */ /* Update the StateOfPort as HUB_RESET_PENDING.*/ pPort->StateOfPort=USB_HUB_RESET_PENDING; /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB,"usbHubPortDebounceHandler:Done\n",0,0,0,0); /* Return USBHST_SUCCESS*/ return USBHST_SUCCESS;} /* End of HUB_PortDebounceHandler() *//***************************************************************************** usbHubConfigure - Configures a given hub.*** This routine configures a given hub.** RETURNS: USBHST_SUCCESS, USBHST_FAILURE,* USBHST_INSUFFICIENT_MEMORY if the memory allocation failed.** ERRNO: None** \NOMANUAL*/LOCAL USBHST_STATUS usbHubConfigure ( pUSB_HUB_INFO * pHub, UINT32 uDeviceHandle, pUSB_HUB_BUS_INFO pBus, pUSB_HUB_INFO pParentHub ) { /* To store the return value */ USBHST_STATUS Result = USBHST_FAILURE; /* Buffer to store incoming Device descriptor */ UINT8 * pDeviceDescriptor= NULL; /* Buffer to store incoming Configuration descriptor */ UINT8 * pConfigDescriptor= NULL; /* Pointer to parse Configuration descriptor */ UINT8 * pParseDesc = NULL ; /* Pointer to the hub descriptor */ UINT8 * pHubDescriptor = NULL; /* Buffer for the status change interrupt IN bit map data */ UINT8 * pStatusChangeData = NULL; /* Data Store for the status change interrupt IN bit map data */ UINT8 * pStatusData = NULL; /* Hub Structure for this hub */ pUSB_HUB_INFO pNewHub = NULL; /* Length of descriptor to be stored here */ UINT32 uLength = 0; /* Number of ports */ UINT8 uNumPorts = 0; /* Counter for the port number */ UINT8 uPortCount = 0; /* Structure to parse the device descriptor */ pUSBHST_DEVICE_DESCRIPTOR pParseDeviceDesc = NULL; /* Structure to parse the configuration descriptor */ pUSBHST_CONFIG_DESCRIPTOR pParseConfigDesc = NULL; /* Structure to parse the interface descriptor */ pUSBHST_INTERFACE_DESCRIPTOR pParseInterfaceDesc = NULL; /* Structure to parse the interface descriptor */ pUSBHST_INTERFACE_DESCRIPTOR pParseAlternateInterfaceDesc = NULL; /* Structure to parse the endpoint descriptor */ pUSBHST_ENDPOINT_DESCRIPTOR pParseEndpointDesc = NULL; /* Variable to store the sequence of descriptors */ UINT32 uDescriptorSequence = 0; /* Count for number of descriptors which follow config desc */ UINT8 uCount = 0; /* parsed length of desc to be updated here */ UINT16 uLengthParsed = 0; /* length of desc to be stored here */ UINT16 uDescLength =0 ; UINT16 * pStatusOfHub = NULL; /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_DEVICE, "Entering usbHubconfigure() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubconfigure:Called uDevHndl:0x%x pPHub=0x%x, pBus=0x%x\n", uDeviceHandle, (UINT32)pParentHub, (UINT32)pBus, 0); OS_ASSERT(NULL != pHub); /* Verify */ OS_ASSERT(NULL != pBus); /* Verify */ /* * Call OS_MALLOC() to allocate Buffer of 18 bytes. If call failed, * return USBHST_INSUFFICIENT_MEMORY. */ pDeviceDescriptor = (UINT8 *) OS_MALLOC(18*sizeof(UINT8)); /* Check for call failure */ if (NULL == pDeviceDescriptor) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB,"usbHubConfigure:INSUFF MEMORY-pDeviceDescriptor 18\n",0,0,0,0); return USBHST_INSUFFICIENT_MEMORY; }/* End of if (NULL == pDeviceDescriptor ) */ /* Clear the allocated buffer.*/ OS_MEMSET(pDeviceDescriptor,0,sizeof(UINT8)*18); uLength = 18; /* * Call USBHST_GetDescriptor() for uDeviceHandle, * DEVICE_DESCRIPTOR and for 18 bytes. If call fails, * i. Call OS_FREE() to free the Buffer. * ii. Return result. */ Result= usbHstGetDescriptor( uDeviceHandle, /* Device Handle */ USBHST_DEVICE_DESC, /* Desc type */ 0, /* descriptor index */ 0, /* language ID */ &uLength, /* Size of the descriptor */ /* buffer to copy to */ (UINT8 *)pDeviceDescriptor ); if (( USBHST_SUCCESS != Result)||(18 != uLength )) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubConfigure:GetDeviceDesc fail R=0x%x L=%d\n", Result, uLength, 0, 0); /* Free the memory allocated */ OS_FREE (pDeviceDescriptor); return Result; }/* End of if ( USBHST_SUCCESS !=Result) */ /* Parse the Device Descriptor buffer */ pParseDeviceDesc = (pUSBHST_DEVICE_DESCRIPTOR) pDeviceDescriptor; /* Validate the device descriptor */ Result = usbHubValidateDescriptor(pDeviceDescriptor,pParseDeviceDesc->bcdUSB ,USBHST_DEVICE_DESC ); if(USBHST_SUCCESS != Result) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubConfigure:ValidateDeviceDesc fail \n", 0, 0, 0, 0); /* Free the memory allocated */ OS_FREE (pDeviceDescriptor); return USBHST_INVALID_PARAMETER; } /* * Call OS_MALLOC() to allocate Buffer of 8 bytes. If call failed, * return USBHST_INSUFFICIENT_MEMORY. */ pConfigDescriptor = (UINT8 * ) OS_MALLOC(8*sizeof(UINT8)); /* Set the desc length as 8 */ uLength=8; /* Check for call failure */ if (NULL == pConfigDescriptor) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB,"usbHubConfigure:INSUFF MEMORY-pConfigdesc 8\n",0,0,0,0); OS_FREE (pDeviceDescriptor); return USBHST_INSUFFICIENT_MEMORY; }/* End of if (NULL == pConfigDescriptor ) */ /* Clear the allocated buffer.*/ OS_MEMSET(pConfigDescriptor,0,sizeof(UINT8)*8); /* * Call USBHST_GetDescriptor() for uDeviceHandle, * CONFIGURATION_DESCRIPTOR and for 8 bytes. If call fails, * i. Call OS_FREE() to free the Buffer. * ii. Return result. */ Result= usbHstGetDescriptor( uDeviceHandle, /* Device Handle */ USBHST_CONFIG_DESC, /* Desc type */ /* descriptor index */ USB_DEF_ACTIVE_HUB_CONFIG_INDEX, 0 , /* language ID */ &uLength, /* Size of the descriptor */ /* buffer to copy to */ (UINT8 *)pConfigDescriptor ); if (( USBHST_SUCCESS != Result)||(8 != uLength )) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubConfigure:getconfdesc fail R=0x%x L=%d\n", Result, uLength, 0, 0); /* Free the memory allocated */ OS_FREE (pDeviceDescriptor); OS_FREE (pConfigDescriptor); return Result; }/* End of if ( USBHST_SUCCESS !=Result) */ /* * Parse the configuration descriptor and find the complete length of the * descriptor. */ uLength=USB_HUB_CONFIG_wTotalLength(pConfigDescriptor); /* Call OS_FREE to free the Buffer.*/ OS_FREE(pConfigDescriptor); /* * Call OS_MALLOC() to allocate configuration buffer for the complete length * of the descriptor. If call failed, return USBHST_INSUFFICIENT_MEMORY. */ pConfigDescriptor = (UINT8 *) OS_MALLOC(uLength*sizeof(UINT8)); /* Check for call failure */ if (NULL == pConfigDescriptor) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubConfigure:INSUFF MEMORY-pConfigdesc %d\n", uLength*sizeof(UINT8), 0, 0, 0); OS_FREE (pDeviceDescriptor); return USBHST_INSUFFICIENT_MEMORY; }/* End of if (NULL == pConfigDescriptor ) */ /* Clear the allocated buffer */ OS_MEMSET(pConfigDescriptor,0,sizeof(UINT8)*uLength); /* * Call HUB_GetDescriptor() for uDeviceHandle, CONFIGURATION_DESCRIPTOR and * for complete length. If call fails, * i. Call OS_FREE() to free the configuration buffer. * ii. Return USBHST_FAILURE. */ Result= usbHstGetDescriptor( uDeviceHandle, /* Device Handle */ USBHST_CONFIG_DESC, /* Desc type */ /* descriptor index */ USB_DEF_ACTIVE_HUB_CONFIG_INDEX, 0 , /* language ID */ &uLength , /* Size of the descriptor */ /* buffer to copy to */ (UINT8 *)pConfigDescriptor ); /* check the result and lenth of descriptor*/ if (( USBHST_SUCCESS != Result)|| (uLength != (UINT32)USB_HUB_CONFIG_wTotalLength(pConfigDescriptor)) ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -