📄 usbhubutility.c
字号:
* [<------------->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); /* Free memory allocated for hub descriptor */ OS_FREE (pHubDescriptor); /* Free memory allocated for hub status */ OS_FREE (pStatusOfHub); /* 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); /* Free memory allocated for hub descriptor */ OS_FREE (pHubDescriptor); /* Free memory allocated for hub status */ OS_FREE (pStatusOfHub); 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); /* Free memory allocated for hub descriptor */ OS_FREE (pHubDescriptor); /* Free memory allocated for hub status */ OS_FREE (pStatusOfHub); 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); /* Free the memory allocated */ OS_FREE (pStatusData); /* Free the memory allocated */ OS_FREE (pNewHub); /* Free memory allocated for hub descriptor */ OS_FREE (pHubDescriptor); /* Free memory allocated for hub status */ OS_FREE (pStatusOfHub); return USBHST_INVALID_PARAMETER; }/* end of switch(pParseDeviceDesc.......)*/ /* check if Hub is a Multiple TT hub */ if(pNewHub->uHubTTInfo == 2) { Result = usbHstSetInterface (uDeviceHandle, 0, /* interface number */ 1); /* alternate interface Setting*/ /* Check the result */ if ( USBHST_SUCCESS != Result) { /* 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); /* Free the memory allocated */ OS_FREE (pStatusChangeData); /* Free the memory allocated */ OS_FREE (pStatusData); /* Free the memory allocated */ OS_FREE (pNewHub); /* Free memory allocated for hub descriptor */ OS_FREE (pHubDescriptor); /* Free memory allocated for hub status */ OS_FREE (pStatusOfHub); return Result; } /* End of (USBHST_SUCCESS !=Result ) */ }/*end of if(pNewHub->uHubTTInfo ...*/ /* * Populate the HUB_INFO structure, HUB_INFO::HubDescriptor structure by * taking the necessary values including parsing the hub descriptor and * the configuration descriptor. */ /* the device handle */ pNewHub->uDeviceHandle=uDeviceHandle; /*The pointer to the status change bit map */ pNewHub->pStatus = pStatusData; /* store the parent bus */ pNewHub->pBus=pBus; /* * how much power can this device provide to each port? * if this is a self powered config, then we can support 500 mA. * if this is a bus powered, we can support a max of 100 mA. */ pNewHub->uPowerPerPort = (((UINT8)(*pStatusOfHub&0xFF))&(0x01))? /* Self powered?*/ 250:50 ; /* multiply by 2 to get mA */ /* The interrupt endpoint for the Hub */ pNewHub->uInterruptEndpointNumber = pParseEndpointDesc->bEndpointAddress; /* * check if the parent of the given hub is NULL or not * NULL parent implies root hub. set the tier as 1. */ if (NULL==pParentHub) { /* root hub, the tier is 1 */ pNewHub->uCurrentTier = 1; } else { /* The current Tier is 1 more than the parent hub */ pNewHub->uCurrentTier = pParentHub->uCurrentTier + 1; }/* End of if (NULL == pParentHub) */ /* Set the Hub state as default no state */ pNewHub->StateOfHub = USB_HUB_NO_STATE; /* Init the Hub descriptor params */ /* number of ports */ pNewHub->HubDescriptor.bNbrPorts = USB_HUB_DESC_bNbrPorts(pHubDescriptor); /* Hub characteristics */ pNewHub->HubDescriptor.wHubCharacteristics = USB_HUB_DESC_wHubCharacteristics(pHubDescriptor); /* Time for the power to stabilize on power on */ pNewHub->HubDescriptor.bPwrOn2PwrGood = USB_HUB_DESC_bPwrOn2PwrGood(pHubDescriptor); /* hub electronics power requirements */ pNewHub->HubDescriptor.bHubContrCurrent = USB_HUB_DESC_bHubContrCurrent(pHubDescriptor); /* Free the memory allocated for hub descriptor */ OS_FREE(pHubDescriptor); /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "usbHubConfigure:pNewHub->uDeviceHandle=%d\n", pNewHub->uDeviceHandle, 0, 0, 0); /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "usbHubConfigure:pNewHub->uPowerPerPort=%d\n", pNewHub->uPowerPerPort, 0, 0, 0); /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "usbHubConfigure:pNewHub->uInterruptEpNumber=%d\n", pNewHub->uInterruptEndpointNumber, 0, 0, 0); /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "usbHubConfigure:pNewHub->uCurrentTier=%d\n", pNewHub->uCurrentTier, 0, 0, 0); /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "usbHubConfigure:pNewHub->StateOfHub=%d\n", pNewHub->StateOfHub, 0, 0, 0); /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "usbHubConfigure:pNewHub->bNbrPorts=%d\n", pNewHub->HubDescriptor.bNbrPorts, 0, 0, 0); /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "usbHubConfigure:pNewHub->wHubCharac=0x%x\n", pNewHub->HubDescriptor.wHubCharacteristics, 0, 0, 0); /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "usbHubConfigure:pNewHub->bPwrOn2PwrGood=0x%x\n", pNewHub->HubDescriptor.bPwrOn2PwrGood, 0, 0, 0); /* Debug Message */ OS_LOG_MESSAGE_MEDIUM( HUB, "usbHubConfigure:pNewHub->bHubContrCurrent=0x%x\n", pNewHub->HubDescriptor.bHubContrCurrent, 0, 0, 0); /* POWER ON PORTS (BEGIN) */ /* for all ports that are enabled, * i. Call HUB_PowerOnPort() with pHub and port count to re enable the * port. If the call fails, then free memory and return failure result. */ for (uPortCount = 0; uPortCount < pNewHub->HubDescriptor.bNbrPorts; uPortCount++) { /* power on the port */ Result = usbHubPowerOnPort(pNewHub,uPortCount); if (USBHST_SUCCESS !=Result) { /* Debug Message */ OS_LOG_MESSAGE_HIGH( HUB, "usbHubEventHandler:power on port %d failed\n", uPortCount, 0, 0, 0); /* Call OS_FREE() to free the configuration buffer.*/ OS_FREE (pDeviceDescriptor); OS_FREE(pConfigDescriptor); /* Free the memory allocated */ OS_FREE (pStatusChangeData); /* Free the memory allocated */ OS_FREE (pStatusData); /* Free the memory allocated */ OS_FREE(pNewHub); /* Reset the return value */ *pHub=NULL; /* return failure result */ return Result; }/* End of if (USBHST_SUCCESS !=Result) */ } /* End of for (uPortCount.... */ /* POWER ON PORTS (END) */ /* * Call the USBHST_FILL_INT_URB() to populate the * HUB_INFO::StatusChangeURB. * Set the HUB_INFO::StatusChangeURB::pfCallBack as * HUB_InterruptRequestCallback function. */ USBHST_FILL_INTERRUPT_URB( (&(pNewHub->StatusChangeURB)),/* pointer to URB */ uDeviceHandle, /* Device Handle */ pNewHub->uInterruptEndpointNumber, /* EP no: */ pStatusChangeData, /* transfer buffer */ uLength, /* uTransferBufferLen */ USBHST_SHORT_TRANSFER_OK, /* TransferFlags */ usbHubInterruptRequestCallback, /* pfCallback */ pNewHub, /* pContext */ USBHST_FAILURE /* uStatus */ ); /* Call OS_FREE() to free the buffer.*/ OS_FREE (pDeviceDescriptor); OS_FREE(pConfigDescriptor); /* Free memory allocated for hub status */ OS_FREE (pStatusOfHub); /* Set pHub as HUB_INFO structure.*/ *pHub=pNewHub; /* * Set the URB Submitted flag as true - This is being done here coz the * callback can be called when the SubmitURB is called. */ pNewHub->bURBSubmitted = TRUE; /* * Call USBHSTSubmitURB() to submit the URB. If this fails * i. Call OS_FREE() to free the status change buffer. * ii. Return USBHST_INSUFFICIENT_MEMORY. */ Result = usbHstURBSubmit(&(pNewHub->StatusChangeURB)); /* Check the result */ if ( USBHST_SUCCESS != Result) { /* Debug Me
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -