⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 usbhubutility.c

📁 vxWorks下usb2.0的usbHUB驱动源码
💻 C
📖 第 1 页 / 共 5 页
字号:
                /* Free the memory allocated */                OS_FREE (pDeviceDescriptor);                /* Free the memory allocated */                OS_FREE (pConfigDescriptor);                return USBHST_INVALID_PARAMETER ;				}/* end of if(USBHST_SUCCESS != Result) */				/* this is valid interface descriptor */                /* this is default interface descriptor */                if(pParseDesc[3] == 0 )				    {                     pParseInterfaceDesc = (pUSBHST_INTERFACE_DESCRIPTOR)pParseDesc;                     uDescriptorSequence = (0x0001<<(4 * uCount)) | uDescriptorSequence ;				    }/* end of if(pParseDesc[3]......)*/                /* this is Alternate interface descriptor */                else				{                     pParseAlternateInterfaceDesc = (pUSBHST_INTERFACE_DESCRIPTOR)pParseDesc;                     uDescriptorSequence = (0x0004<<(4 * uCount)) | uDescriptorSequence ;				} /* end of else */         break;         /* this is a endpoint descriptor */         case USBHST_ENDPOINT_DESC :             /*validate the endpoint descriptor */             Result = usbHubValidateDescriptor                        (                        pParseDesc,                        pParseDeviceDesc->bcdUSB,                        USBHST_ENDPOINT_DESC                        );    	     if(USBHST_SUCCESS != Result)	      	    {                /* Debug Message */                OS_LOG_MESSAGE_HIGH(                  HUB,"usbHubConfigure:ValidateEndpointDescriptor fail \n",0,0,0,0);                /* Free the memory allocated */                OS_FREE (pDeviceDescriptor);                /* Free the memory allocated */                OS_FREE (pConfigDescriptor);                return USBHST_INVALID_PARAMETER ;				}/* end of if(USBHST_SUCCESS != Result) */				/* This is a valid endpoint descriptor */		        pParseEndpointDesc = (pUSBHST_ENDPOINT_DESCRIPTOR) pParseDesc;                uDescriptorSequence  =                                 (0x0002<<(4 * uCount)) | uDescriptorSequence ;            break;        /* this is a configuration descriptor */        case USBHST_CONFIG_DESC :         /* validate the configuration descriptor */	    Result = usbHubValidateDescriptor                (                pParseDesc,                pParseDeviceDesc->bcdUSB,                USBHST_CONFIG_DESC                );            if(USBHST_SUCCESS != Result)		        {                /* Debug Message */                OS_LOG_MESSAGE_HIGH(                   HUB,"usbHubConfigure:ValidateConfigurationDescriptor fail \n",0,0,0,0);                /* Free the memory allocated */                OS_FREE (pDeviceDescriptor);                /* Free the memory allocated */                OS_FREE (pConfigDescriptor);                return USBHST_INVALID_PARAMETER ;			}/* end of if(USBHST_SUCCESS != Result) */             /* This is a valid configuration descriptor */			 pParseConfigDesc = (pUSBHST_CONFIG_DESCRIPTOR)pParseDesc;             break;        default : /* invalid descriptor type */            /* Debug Message */            OS_LOG_MESSAGE_HIGH(                HUB,"usbHubConfigure:InvalidDesc fail \n",0,0,0,0);            /* Free the memory allocated */            OS_FREE (pDeviceDescriptor);             /* Free the memory allocated */            OS_FREE (pConfigDescriptor);            return USBHST_INVALID_PARAMETER ;		}/*end of switch (pParseDesc[1]) */    uDescLength= pParseDesc[0];    /* check are  we jumping off the  descriptor  */    if ( uDescLength + uLengthParsed >= USB_HUB_CONFIG_wTotalLength((UINT8 *)                                                           pParseConfigDesc))	{        break;    }/* end of if ( uDescLength + ....)*/     /* update the length parsed */     uLengthParsed += uDescLength ;     /*     * move the pointer to the next desc by adding the length of     * descriptor to the pointer     */     pParseDesc =(UINT8 *) ( ((UINT32)pParseDesc)+(UINT32)uDescLength);     uCount ++;     }/* end of  while(uCount < 3)    */    /* Validate if the  descriptor have arrived in correct sequence */    if(1!= ( USB_VALIDATE_DESCRIPTOR_SEQUENCE(uDescriptorSequence)                & (uCount <= 3)))	{        OS_LOG_MESSAGE_HIGH(            HUB,"usbHubConfigure:InvalidDescSequence fail \n",0,0,0,0);        /* Free the memory allocated */        OS_FREE (pDeviceDescriptor);        /* Free the memory allocated */        OS_FREE (pConfigDescriptor);         return USBHST_INVALID_PARAMETER ;	}/* end of if(1!= ( USB_VALIDATE_DESCRIPTOR_SEQUENCE(uDescriptorSequence).....)*/     /*     * Call USBHST_SetConfiguration() with configuration value and device     * handle. if failed:     * i.    Call OS_FREE() to free the configuration buffer.     * ii.   Return result.     */    Result= usbHstSetConfiguration ( uDeviceHandle,                                      USB_DEF_ACTIVE_HUB_CONFIG_INDEX);    /* Check the result */    if (USBHST_SUCCESS != Result)    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,"usbHubConfigure:setconf fail R=0x%x \n",Result,0,0,0);        /* Free the memory allocated */        OS_FREE (pDeviceDescriptor);        /* Free the memory allocated */        OS_FREE (pConfigDescriptor);        return Result;            } /* End of (USBHST_SUCCESS !=Result ) */    /* Set the Hub Descriptor length as 6 */    uLength = 6;    /*      * Call HUB_GetHubDescriptor() for uDeviceHandle,     * HUB_DESCRIPTOR and for 6 bytes. If call fails,     * i.    Call OS_FREE() to free the configuration buffer.     * ii.   Return USBHST_FAILURE.     */    Result= usbHubGetDescriptor(uDeviceHandle, /* Device Handle */                                 /* buffer to copy to */                                 (UINT8 *)pHubDescriptor,                                 /* Size of the descriptor */                                 &uLength);    /* Check the result */    if ( (USBHST_SUCCESS != Result) ||(6 != uLength) )    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubConfigureHub:gethubdesc fail R=0x%x L=%d\n",            Result,            uLength,            0,            0);        /* Free the memory allocated */        OS_FREE (pDeviceDescriptor);        /* Free the memory allocated */        OS_FREE (pConfigDescriptor);        return Result;    } /* End of (USBHST_SUCCESS !=Result ) */    /*     * Get the Power requirement of the hub      * - Do a get status to the hub.     * If the current status returns that the hub is     * self powered, it can supply 500 mA per port     * if it is bus powered, it can supply 100mA per port     */    Result = usbHstGetStatus(uDeviceHandle, /* Device Handle */                              USBHST_RECIPIENT_DEVICE, /* uRecipient */                              0,  /* Index */                              (UCHAR *) &uStatusOfHub);  /* Buffer */    /* Check the result */    if ( (USBHST_SUCCESS != Result) ||(6 != uLength) )    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubConfigure:getStatusOfDevice fail R=0x%x \n",            Result,            0,            0,            0);        /* Free the memory allocated */        OS_FREE (pDeviceDescriptor);        /* Free the memory allocated */        OS_FREE (pConfigDescriptor);        return Result;    } /* End of (USBHST_SUCCESS !=Result ) */    /* swap */    uStatusOfHub = OS_UINT16_LE_TO_CPU(uStatusOfHub);        /* Parse the number of ports from the hub descriptor.*/    uNumPorts=USB_HUB_DESC_bNbrPorts(pHubDescriptor);    /*     * Call OS_MALLOC() to allocate HUB_BYTE_GRANURALITY(number of ports + 1)     * bytes of status change data buffer. If failed,     * i.    Call OS_FREE() to free the configuration buffer.     * ii.    Return USBHST_INSUFFICIENT_MEMORY.     */    uLength= USB_HUB_BYTE_GRANULARITY(uNumPorts + 1);    /* allocate the memory */    pStatusChangeData= OS_MALLOC(uLength);    /* Check the result */    if (NULL == pStatusChangeData)    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubConfigure:INSUFF MEMORY-pStatusChngData %d\n",uLength,0,0,0);                    /* Free the memory allocated */        OS_FREE (pDeviceDescriptor);       /* Free the memory allocated */        OS_FREE (pConfigDescriptor);        return USBHST_INSUFFICIENT_MEMORY;    } /* End of (USBHST_SUCCESS !=Result ) */    /* allocate the memory */    pStatusData= OS_MALLOC(uLength);    /* Check the result */     if (NULL == pStatusData)    {        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,"usbHubConfigure:INSUFF MEMORY-pStatusData %d\n",uLength,0,0,0);        /* Free the memory allocated */        OS_FREE (pDeviceDescriptor);        OS_FREE (pConfigDescriptor);        /* Free the memory allocated */        OS_FREE (pStatusChangeData);        return USBHST_INSUFFICIENT_MEMORY;    } /* End of (USBHST_SUCCESS !=Result ) */    /* Clear the allocated buffer for status change data. */    OS_MEMSET(pStatusChangeData,0,uLength);    /* Clear the allocated buffer for the status data. */    OS_MEMSET(pStatusData,0,uLength);    /*     * Call OS_MALLOC() to allocate memory for HUB_INFO as     * sizeof(USB_HUB_INFO)+ ((number of ports-1)*sizeof(PHUB_PORT_INFO)) bytes.     * If Failed,     * i.    Call OS_FREE() to free the configuration buffer.     * ii.    Call OS_FREE() to free the status change buffer.     * iii.    Return USBHST_INSUFFICIENT_MEMORY.     */    /*     * This is an over allocation of the HUB_INFO structure.     * this allows us to access pPortList[n] count for all the ports.     * [<------------->y][y][y][y]...     * [<------------->y] is the normal size of HUB_INFO with pPortList[1]     * If there are two ports then it should be pPortList[2]. or:     * [<------------->yy]     * and so on.. we shud be still be able to access pPortList[uPortIndex].     * hence we allocate     * [<------------->y] bytes + (number of ports-1) * sizeof(y)     * thus for 5 ports we get automatically get     * [<------------->y]followed by[y][y][y][y] in one single memory chunk.     */    pNewHub=OS_MALLOC( sizeof(USB_HUB_INFO)+                       ((uNumPorts-1)* sizeof(pUSB_HUB_PORT_INFO)));    /* Check the result */    if (NULL == pNewHub)    {        /* Free the memory allocated */        OS_FREE (pDeviceDescriptor);        /* Free the memory allocated */        OS_FREE (pConfigDescriptor);        /* Free the memory allocated */        OS_FREE (pStatusChangeData);        /* Free the memory allocated */        OS_FREE (pStatusData);        /* Debug Message */        OS_LOG_MESSAGE_HIGH(            HUB,            "usbHubConfigure:INSUFF MEMORY-pNewHub: %d\n",            sizeof(USB_HUB_INFO)+((uNumPorts-1)* sizeof(pUSB_HUB_PORT_INFO)),            0,            0,            0);        return USBHST_INSUFFICIENT_MEMORY;    } /* End of (USBHST_SUCCESS !=Result ) */    /* Clear the allocated structure.*/    OS_MEMSET(pNewHub,0,        sizeof(USB_HUB_INFO)+((uNumPorts-1)* sizeof(pUSB_HUB_PORT_INFO)) );    /*Here we find the TT Organization  */    /* this switch checks the bDeviceProtocol field in device descriptor */    switch(pParseDeviceDesc->bDeviceProtocol)	{    case 0 :        /* this hub does not support TT */        pNewHub->uHubTTInfo = 0;        break;    case 1 :        /* this is a single TT Hub */        if(pParseInterfaceDesc->bInterfaceProtocol == 0)		{            pNewHub->uHubTTInfo = 1;		}/* end of if(pParseInterfaceDesc ....*/        /* invalid parameters in descriptor */        else		{            /* Debug Message */            OS_LOG_MESSAGE_HIGH(            HUB,"usbHubConfigure:InvalidInterfaceDesc fail \n",0,0,0,0);            /* Free the memory allocated */             OS_FREE (pDeviceDescriptor);            /* Free the memory allocated */             OS_FREE (pConfigDescriptor);            /* Free the memory allocated */            OS_FREE (pStatusChangeData);            /* Free the memory allocated */            OS_FREE (pStatusData);            /* Free the memory allocated */             OS_FREE (pNewHub);             return USBHST_INVALID_PARAMETER ;		}/* end of else  */        break;     case 2 :         /* check if we have recieved default i/f and alternate i/f descriptor*/        if(uDescriptorSequence == 0x24210)		{             /* this is a multiple TT hub */            if(pParseAlternateInterfaceDesc->bInterfaceProtocol == 2)			{                pNewHub->uHubTTInfo = 2;			}  /*  if != 2 then .....*/		}/* end of if(uDescriptorSequence == 0x24210) */        /* invalid descriptor */        else		{             /* Debug Message */             OS_LOG_MESSAGE_HIGH(                 HUB,"usbHubConfigure:InvalidAltInterfaceDesc fail \n",0,0,0,0);             /* Free the memory allocated */             OS_FREE (pDeviceDescriptor);             /* Free the memory allocated */             OS_FREE (pConfigDescriptor);             /* Free the memory allocated */             OS_FREE (pStatusChangeData);             /* Free the memory allocated */             OS_FREE (pStatusData);             /* Free the memory allocated */             OS_FREE (pNewHub);             return USBHST_INVALID_PARAMETER ;		} /* end of else */        break ;     default :          /* Debug Message */          OS_LOG_MESSAGE_HIGH(            HUB,"usbHubConfigure:UnknownInterfaceDesc fail \n",0,0,0,0);            /* Free the memory allocated */            OS_FREE (pDeviceDescriptor);            /* Free the memory allocated */             OS_FREE (pConfigDescriptor);            /* Free the memory allocated */            OS_FREE (pStatusChangeData);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -