?? usbhubutility.c
字號:
/* usbHubUtility.c - Utility functions to provide the functionality of HUB class driver *//* Copyright 2003 Wind River Systems, Inc. *//*Modification history--------------------01a,27jun03,nrv Changing the code to WRS standards*//*DESCRIPTIONThis module provides the utility functions required for the functioning of the USB Hub Class Driver.INCLUDE FILES: usb2/usbOsal.h usb2/usbHst.h usb2/usbHubUtility.h usb2/usbHubGlobalVariables.h usb2/usbHubBusManager.h usb2/usbHubEventHandler.h*//*INTERNAL ******************************************************************************* * Filename : HUB_Utility.c * * Copyright : * * THE COPYRIGHT IN THE CONTENTS OF THIS SOFTWARE VEST WITH WIPRO * LIMITED A COMPANY INCORPORATED UNDER THE LAWS OF INDIA AND HAVING * ITS REGISTERED OFFICE AT DODDAKANNELLI SARJAPUR ROAD BANGALORE * 560 035. DISTRIBUTION OR COPYING OF THIS SOFTWARE BY * ANY INDIVIDUAL OR ENTITY OTHER THAN THE ADDRESSEE IS STRICTLY * PROHIBITED AND MAY INCUR LEGAL LIABILITY. IF YOU ARE NOT THE * ADDRESSEE PLEASE NOTIFY US IMMEDIATELY BY PHONE OR BY RETURN EMAIL. * THE ADDRESSEE IS ADVISED TO MAINTAIN THE PROPRIETARY INTERESTS OF * THIS COPYRIGHT AS PER APPLICABLE LAWS. * * * Description : This module provides the utility functions required for * the functioning of the USB Hub Class Driver. * * ******************************************************************************//************************** INCLUDE FILES *************************************/#include "usb2/usbOsal.h"#include "usb2/usbHst.h"#include "usb2/usbHubUtility.h"#include "usb2/usbHubGlobalVariables.h"#include "usb2/usbHubBusManager.h"#include "usb2/usbHubEventHandler.h"/****************** MODULE SPECIFIC FUNCTIONS DECLARATION *********************//* * This function is used as a call back for the Reset. On failure, reset is * retried for a maximum number of tries. If the maximum number of retries * expires, the port is disabled. */LOCAL USBHST_STATUS usbHubResetCallback ( pUSBHST_URB pResetURB);/* * This function is a general purpose call back function that can be used for * issuing a blocking request. */LOCAL USBHST_STATUSusbHubBlockingCallback (pUSBHST_URB pUrb);/* * This function is the call back for the status change interrupt IN pipe * completion. */LOCAL USBHST_STATUSusbHubInterruptRequestCallback (pUSBHST_URB pURB);/* * This Function is used to validate the Standard Descriptors */LOCAL USBHST_STATUS usbHubValidateDescriptor (UINT8 * pDescriptor, UINT16 uUsbDeviceVersion,UINT8 uDescriptorType);/* * This function is the call back function for the completion of a * Clear TT request to a High Speed Hub. */LOCAL USBHST_STATUS usbHubClearTTRequestCallback (pUSBHST_URB pURB);/* * This function is the call back function for the completion of a * Reset TT request to a High Speed Hub. */LOCAL USBHST_STATUS usbHubResetTTRequestCallback (pUSBHST_URB pURB);/************************ GLOBAL FUNCTIONS DEFINITION *************************//***************************************************************************** usbHubFindPortNumber - finds the port number of a device .** This routine finds the port number of a device.** RETURNS: port number, PORT_NUMBER_NOT_FOUND if the match was not* found/invalid params.** ERRNO: None** \NOMANUAL*/LOCAL UINT8 usbHubFindPortNumber ( pUSB_HUB_INFO pHub, UINT32 uDeviceHandle ) { /* Counter for the port number */ UINT8 uPortCount = 0; /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubFindPortNumber:Called pHub=0x%x,devh=0x%x\n", (UINT32)pHub, uDeviceHandle, 0, 0); /* If pHub is NULL then return PORT_NUMBER_NOT_FOUND*/ if (NULL == pHub) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB,"usbHubFindPortNumber:pHub null \n",0,0,0,0); return USB_PORT_NUMBER_NOT_FOUND; }/* End of if (NULL==pHub) */ /* * For all ports in the pHub::pPortList that are enabled * i. Retrieve the HUB_PORT_INFO from pHub::pPortList[ port count ]. * ii. If the HUB_PORT_INFO::uDeviceHandle is equal to uDeviceHandle then * return the portcount. */ for (uPortCount = 0; uPortCount < pHub->HubDescriptor.bNbrPorts; uPortCount++) { /* Retrieve the HUB_PORT_INFO structure */ pUSB_HUB_PORT_INFO pPort = pHub->pPortList[uPortCount]; /* Check if the port is enabled */ if (NULL != pPort) { /* Check for uDeviceHandle */ if ( uDeviceHandle == pPort->uDeviceHandle ) { /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubFindPortNumber:found %d\n", uPortCount, 0, 0, 0); return uPortCount; }/* End of if (uDeviceHandle... */ } /* End of If (NULL != pPort) */ } /* End of for (uPortCount.... */ /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB,"usbHubFindPortNumber:Not Found\n",0,0,0,0); /* Return PORT_NUMBER_NOT_FOUND.*/ return USB_PORT_NUMBER_NOT_FOUND;}/* End of HUB_FindPortNumber() *//***************************************************************************** usbHubFindParentHubInBuses - searches for a parent hub.** This routine searches for a parent hub.** RETURNS: pointer to the PHUB_INFO, NULL if the match was not found/invalid* params.** ERRNO: None** \NOMANUAL*/LOCAL pUSB_HUB_INFO usbHubFindParentHubInBuses ( UINT32 uDeviceHandle ) { /* The bus List pointer to be used for browsing the list */ pUSB_HUB_BUS_INFO pBusList = gpGlobalBus; /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubFindParentHubInBuses:Called,devh=0x%x\n", uDeviceHandle, 0, 0, 0); /* * For every bus in the gpGlobalBus do: * i. Call HUB_FindParentHub () function to find the matching hub. * If this returns a non NULL value, return the value. */ while (NULL != pBusList) { /* Find matching hub */ pUSB_HUB_INFO pHub = usbHubFindParentHub(uDeviceHandle,pBusList->pRootHubInfo); /* if found return the value */ if (NULL != pHub) { /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB,"usbHubFindParentHubInBuses:Found\n",0,0,0,0); return pHub; }/* End of if (NULL!=pHub) */ /* move the bus list pointer to the next bus pointer */ pBusList=pBusList->pNextBus; }/* End of While (NULL != pBusList) */ /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB,"usbHubFindParentHubInBuses:Not Found\n",0,0,0,0); /* Return NULL*/ return NULL;} /* End of HUB_FindParentHubInBuses() *//***************************************************************************** usbHubFindParentHub - recursively searches for the parent hub.** This routine recursively searches for the parent hub of the specified device.** RETURNS: pointer to the PHUB_INFO, NULL if the match was not found/invalid* params.** ERRNO: None** \NOMANUAL*/LOCAL pUSB_HUB_INFO usbHubFindParentHub ( UINT32 uDeviceHandle , pUSB_HUB_INFO pHub ) { /* Counter for the port number */ UINT8 uPortCount = 0; /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubFindParentHub:Called uDevHandle=0x%x pHub=0x%x\n", uDeviceHandle, (UINT32)pHub, 0, 0); /* If pHub is NULL then return NULL*/ if (NULL==pHub) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB,"usbHubFindParentHub:pHub null \n",0,0,0,0); return NULL; }/* End of (NULL == pHub) */ /* * For all ports in the pHub::pPortList that are not NULL * i. Retrieve the HUB_PORT_INFO from pHub::pPortList[ port count] * ii. If uDeviceHandle is same as HUB_PORT_INFO::uDeviceHandle then * return pHub */ for (uPortCount = 0; uPortCount < pHub->HubDescriptor.bNbrPorts; uPortCount++) { /* Retrieve the HUB_PORT_INFO structure */ pUSB_HUB_PORT_INFO pPort = pHub->pPortList[uPortCount]; /* Check if the port is enabled */ if (NULL != pPort) { /* Check for uDeviceHandle */ if ( uDeviceHandle == pPort->uDeviceHandle ) { /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB,"usbHubFindParentHub:found\n",0,0,0,0); return pHub; }/* End of if (uDeviceHandle... */ } /* End of If (NULL != pPort) */ } /* End of for (uPortCount.... */ /* * For all ports in the pHub::pPortList that are not NULL * i. Retrieve the HUB_PORT_INFO from pHub::pPortList[ port count] * ii. If HUB_PORT_INFO::pHub is not NULL then: * iii. Call HUB_FindParentHub () function to find the matching hub. If * this * returns a non NULL value, return the value. */ for (uPortCount = 0; uPortCount < pHub->HubDescriptor.bNbrPorts; uPortCount++) { /* Retrieve the HUB_PORT_INFO structure */ pUSB_HUB_PORT_INFO pPort = pHub->pPortList[uPortCount]; /* Check if the port is enabled */ if (NULL != pPort) { /* Check for Hub device */ if ( NULL != pPort->pHub) { /* storage for storing the result */ pUSB_HUB_INFO pResultHub ; /* Call for matching hub in this sub tree. */ pResultHub = usbHubFindParentHub(uDeviceHandle,pPort->pHub); /* Check if the hub was found */ if (NULL !=pResultHub) { return pResultHub; }/* End of if (NULL != pResultHub ) */ }/* End of if (NULL != pPort->pHub) */ } /* End of If (NULL != pPort) */ } /* End of for (uPortCount.... */ /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB,"usbHUbFindParentHub:not found\n",0,0,0,0); /* Return NULL*/ return NULL; }/* End of HUB_FindParentHub() *//***************************************************************************** usbHubCreateBusStructure - Creates a bus structure .** Creates a bus structure and connects the same to the global Bus list.* This also launches a thread to handle the events occurring on the Bus.** RETURNS: HUB_BUS_INFO, NULL .** ERRNO: None** \NOMANUAL*/LOCAL pUSB_HUB_BUS_INFO usbHubCreateBusStructure ( UINT8 uBusHandle ) { /* Bus List pointer */ pUSB_HUB_BUS_INFO pBusList = gpGlobalBus; /* Bus Manager Thread Name */ UCHAR * pBusManagerName = (UCHAR *)"BusM "; /* Set the tag as the bus handle */ pBusManagerName[5] = 'A' +(uBusHandle%26); /* Debug Message */ OS_LOG_MESSAGE_LOW( HUB, "usbHubCreateBusStructure:Called 0x%x \n", uBusHandle, 0, 0, 0); /* * Browse the HUB_BUS_INFO list and check if gpGlobalBus exists. If it * exists, return NULL. */ while (NULL != pBusList) { /* Check for duplicate entries */ if (pBusList->uBusHandle == uBusHandle) { /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "usbHubCreateBusStructure:already there 0x%x \n", uBusHandle, 0, 0, 0); return NULL; } /* End of if (pBusList->....*/ /* move to the next bus */ pBusList=pBusList->pNextBus; } /* End of While (NULL != pBusList) */ /* * Call OS_MALLOC() to allocate memory for HUB_BUS_INFO structure. * If failed, return NULL */ pBusList = OS_MALLOC(sizeof(USB_HUB_BUS_INFO)); /* Check the result */ if (NULL == pBusList)
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -