📄 usbhubporteventhandler.c
字号:
(UINT32)pHub, uPortIndex, (UINT32)pPortStatus, 0); /* If the pHub is NULL then return USBHST_INVALID_PARAMETER */ if (NULL == pHub) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB,"usbHubPortConnectChangeHandler: pHub is NULL \n",0,0,0,0); return USBHST_INVALID_PARAMETER; }/* End of (NULL == pHub) */ /* * If the uPortIndex greater than pHub::HubDescriptor::bNbrPorts then * return USBHST_INVALID_PARAMETER. * Note: the actual port number is the port index + 1 */ if (uPortIndex >= pHub->HubDescriptor.bNbrPorts) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "usbHubPortConnectChangeHandler :port= %d >%d \n", uPortIndex, pHub->HubDescriptor.bNbrPorts, 0, 0); return USBHST_INVALID_PARAMETER; }/* End of if (uPortIndex >= pHub->HubDescriptor.bNbrPorts) */ /* * Retrieve the HUB_PORT_INFO structure from pHub::pPortList * for the uPortIndex. */ pPort=pHub->pPortList[uPortIndex]; /* * If the port is enabled then Call the * HUB_RemoveDevice() function with * HUB_PORT_INFO::uDeviceHandle. * 9/5/2k3:NM: Changed here to centralise the effect */ usbHubRemoveDevice(pHub,uPortIndex); /* * Call HUB_CLEAR_PORT_FEATURE() to clear the C_PORT_CONNECTION. * If failed return result. * Note: the actual port number is the port index + 1 */ Result = USB_HUB_CLEAR_PORT_FEATURE(pHub,uPortIndex,USB_C_PORT_CONNECTION); if (USBHST_SUCCESS != Result) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubPortConnectChangeHandler : Clear port feature failed 0x%x\n", Result, 0, 0, 0); return Result; }/* End of USBHST_SUCCESS... */ /* * If the pPortStatus::wPortStatus is DISCONNECTED then return * USBHST_SUCCESS. */ if (0 == (pPortStatus->wPortStatus & USB_PORT_CONNECTION_VALUE)) { /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubPortConnectChangeHandler : Device disconnected\n", Result, 0, 0, 0); return USBHST_SUCCESS; } /* End of (0== (pPortStatus... */ /* * Call OS_MALLOC() to allocate memory for HUB_PORT_INFO and set * it to pPort. If failed, then return with USBHST_INSUFFICIENT_MEMORY. */ pPort = OS_MALLOC(sizeof(USB_HUB_PORT_INFO)); if (NULL == pPort) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubPortConnectChangeHandler :Insfficient memory - pPort\n", 0, 0, 0, 0); return USBHST_INSUFFICIENT_MEMORY; }/* End of if (NULL == pPort) */ /* Clear the allocated buffer. */ OS_MEMSET(pPort,0,sizeof(USB_HUB_PORT_INFO)); /* * Store the current time HUB_PORT_INFO::uConnectFrame as * USBHST_GetFrameNumber() */ Result = usbHstGetFrameNumber(pHub->uDeviceHandle,&(pPort->uConnectFrame)); OS_ASSERT(USBHST_SUCCESS == Result); /* Verify */ /* * Reset the number of retries for connection by setting the * HUB_PORT_INFO::uConnectRetries as HUB_CONFIG_RETRY_MAX */ pPort->uConnectRetry = USB_HUB_CONFIG_RETRY_MAX; /* Set pHub::pPortList[uPortIndex] as the hub_PORT_INFO structure. */ pHub->pPortList[uPortIndex] = pPort; /* Set the HUB_PORT_INFO::StateOfPort as HUB_DEBOUNCE_PENDING. */ pPort->StateOfPort = USB_HUB_DEBOUNCE_PENDING; /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_EVENT_HANDLER, "Exiting usbHubPortConnectChangeHandler() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubPortConnectChangeHandler : Done " "pHub=0x%x uPortIndex=%d pPortStatus=0x%x\n", (UINT32)pHub, uPortIndex, (UINT32)pPortStatus, 0); /* Return USBHST_SUCCESS. */ return USBHST_SUCCESS; } /* End of HUB_PortConnectChangeHandler () *//***************************************************************************** usbHubPortEnableChangeHandler - handle the port enable change** This routine handles the port enable change.** RETURNS: USBHST_SUCCESS, USBHST_INVALID_PARAMETER, USBHST_FAILURE If any event * handler failed.** ERRNO: None** \NOMANUAL*/LOCAL USBHST_STATUS usbHubPortEnableChangeHandler ( pUSB_HUB_INFO pHub, UINT8 uPortIndex, pUSB_HUB_PORT_STATUS pPortStatus ) { /* Storage for the port information */ pUSB_HUB_PORT_INFO pPort=NULL; /* To store the result of submissions */ USBHST_STATUS Result; /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_EVENT_HANDLER, "Entering usbHubPortEnableChangeHandler() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubPortEnableChangeHandler: Called " "pHub=0x%x uPortIndex=%d pPortStatus=0x%x\n", (UINT32)pHub, uPortIndex, (UINT32)pPortStatus, 0); /* If the pHub is NULL then return USBHST_INVALID_PARAMETER */ if (NULL == pHub) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB,"usbHubPortEnableChangeHandler: pHub is NULL \n",0,0,0,0); return USBHST_INVALID_PARAMETER; }/* End of (NULL == pHub) */ /* * If the uPortIndex greater than pHub::HubDescriptor::bNbrPorts then * return USBHST_INVALID_PARAMETER. * Note: the actual port number is the port index + 1 */ if (uPortIndex >= pHub->HubDescriptor.bNbrPorts) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "usbHubPortEnableChangeHandler: port= %d >%d \n", uPortIndex, pHub->HubDescriptor.bNbrPorts, 0, 0); return USBHST_INVALID_PARAMETER; }/* End of if (uPortIndex >= pHub->HubDescriptor.bNbrPorts) */ /* * Call HUB_CLEAR_PORT_FEATURE() to clear the C_PORT_ENABLE. * If failed return result. * Note: the actual port number is the port index + 1 */ Result = USB_HUB_CLEAR_PORT_FEATURE(pHub,uPortIndex,USB_C_PORT_ENABLE); if (USBHST_SUCCESS != Result) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubPortEnableChangeHandler: Clear port feature failed 0x%x\n", Result, 0, 0, 0); return Result; }/* End of USBHST_SUCCESS != Result */ /* * Retrieve the HUB_PORT_INFO structure from pHub::pPortList for the * uPortIndex, if there is no port then, there is no device in topology, * hence return USBHST_SUCCESS. */ pPort=pHub->pPortList[uPortIndex]; if (NULL == pPort) { /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubPortEnableChangeHandler:port is NULL\n", 0, 0, 0, 0); return USBHST_SUCCESS; }/* End of if (NULL != pPort ) */ /* Set the HUB_PORT_INFO::StateOfPort as MARKED_FOR_DELETION */ USB_MARK_FOR_DELETE_PORT(pHub,pPort); /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_EVENT_HANDLER, "Exiting usbHubPortEnableChangeHandler() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubPortEnableChangeHandler:Done" " pHub=0x%x uPortIndex=%d pPortStatus=0x%x\n", (UINT32)pHub, uPortIndex, (UINT32)pPortStatus, 0); /* Return USBHST_SUCCESS */ return USBHST_SUCCESS; } /* End of HUB_PortEnableChangeHandler() *//***************************************************************************** usbHubPortSuspendChangeHandler - handler for the port suspend change.** This routine handles the the port suspend change.** RETURNS: USBHST_SUCCESS, USBHST_INVALID_PARAMETER, USBHST_FAILURE If any event * handler failed.** ERRNO: None** \NOMANUAL*/LOCAL USBHST_STATUS usbHubPortSuspendChangeHandler ( pUSB_HUB_INFO pHub, UINT8 uPortIndex, pUSB_HUB_PORT_STATUS pPortStatus ) { /* Storage for the port information */ pUSB_HUB_PORT_INFO pPort=NULL; /* to store the result of submissions */ USBHST_STATUS Result; /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_EVENT_HANDLER, "Entering usbHubPortSuspendChangeHandler() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubPortSuspendChangeHandler: Called " "pHub=0x%x uPortIndex=%d pPortStatus=0x%x\n", (UINT32)pHub, uPortIndex, (UINT32)pPortStatus, 0); /* If the pHub is NULL then return USBHST_INVALID_PARAMETER */ if (NULL ==pHub) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB,"usbHubPortSuspendChangeHandler:pHub is NULL \n",0,0,0,0); return USBHST_INVALID_PARAMETER; }/* End of (NULL == pHub) */ /* * If the uPortIndex greater than pHub::HubDescriptor::bNbrPorts then * return USBHST_INVALID_PARAMETER. * Note: the actual port number is the port index + 1 */ if (uPortIndex >= pHub->HubDescriptor.bNbrPorts) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "usbHubPortSuspendChangeHandler: port= %d >%d \n", uPortIndex, pHub->HubDescriptor.bNbrPorts, 0, 0); return USBHST_INVALID_PARAMETER; }/* End of if (uPortIndex >= pHub->HubDescriptor.bNbrPorts) */ /* * Call HUB_CLEAR_PORT_FEATURE() to clear the C_PORT_SUSPEND. * If failed return result. * Note: the actual port number is the port index + 1 */ Result = USB_HUB_CLEAR_PORT_FEATURE(pHub,uPortIndex,USB_C_PORT_SUSPEND); if (USBHST_SUCCESS != Result) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubPortSuspendChangeHandler: Clear port feature failed 0x%x\n", Result, 0, 0, 0); return Result; }/* End of USBHST_SUCCESS != Result */ /* * Retrieve the HUB_PORT_INFO structure from pHub::pPortList for the * uPortIndex, if there is no port then, there is no device in topology, * hence return USBHST_SUCCESS. */ pPort = pHub->pPortList[uPortIndex]; if (NULL == pPort) { /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB,"usbHubPortSuspendChangeHandler: port is NULL :)\n",0,0,0,0); return USBHST_SUCCESS; }/* End of if (NULL != pPort ) */ /* * If the suspend status is enabled in the pPortStatus::wPortStatus * i. Call g_USBHSTFunctionList::USBHST_SuspendDevice() with * HUB_PORT_INFO::uDeviceHandle to suspend the device driver. * ii. Return USBHST_SUCCESS */ if (0 != (pPortStatus->wPortStatus & USB_PORT_SUSPEND_VALUE)) { /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubPortSuspendChangeHandler:Calling UBHST suspend " "with udev handle %d\n", pPort->uDeviceHandle, 0, 0, 0); g_usbHstFunctionList.UsbdToHubFunctionList.suspendDevice(pPort->uDeviceHandle); return USBHST_SUCCESS; } /* End of (0== (pPortStatus... */ /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubPortSuspendChangeHandler: Calling UBHST resume with " "udev handle %d\n", pPort->uDeviceHandle, 0, 0, 0); /* Call the g_USBHSTFunctionList::USBHST_ResumeDevice() with * HUB_PORT_INFO::uDeviceHandle to notify the resume the device driver. */ g_usbHstFunctionList.UsbdToHubFunctionList.resumeDevice(pPort->uDeviceHandle); /* WindView Instrumentation */ USB_HUB_LOG_EVENT( USB_HUB_WV_EVENT_HANDLER, "Exiting usbHubPortSuspendChangeHandler() Function", USB_HUB_WV_FILTER); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubPortSuspendChangeHandler: Done " "pHub=0x%x uPortIndex=%d pPortStatus=0x%x\n", (UINT32)pHub, uPortIndex, (UINT32)pPortStatus, 0); /* Return USBHST_SUCCESS */ return USBHST_SUCCESS; } /* End of HUB_PortSuspendChangeHandler () *//***************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -