📄 urb.c
字号:
} /* End if the end point info is not null */ } /* End of FOR loop for the interfaces */ } /* end if the interface info is not NULL */ /* Check if its not default configuration */ if (USBHST_DEFAULT_CONFIGURATION_INDEX != uIndex) { /* * If device driver is vendor specific then the reallocate * the memory area for the new interface info */ if (((USBHST_VENDOR_SPECIFIC == pDeviceInfo->uDeviceClass) || (1 < pDeviceInfo->uNumConfigurations)) && (pDeviceInfo->uInterfaceCount != ConfigDesc.bNumInterfaces)) { /* Check if the interface info is not NULL */ if (NULL != pDeviceInfo->pInterfacesInfo) { /* free the memory area for the old interfaces info */ OS_FREE(pDeviceInfo->pInterfacesInfo); /* Mark the Interfaces info as NULL */ pDeviceInfo->pInterfacesInfo = NULL; } } /* End if device driver is vendor specific */ /* * Interfaces info is NULL - Note this is done for non-vendor * specific drivers also as during Driver Deregisteration, * interfaces info is freed for the devices having driver info * in the deviceInfo */ if (NULL == pDeviceInfo->pInterfacesInfo) { /* allocate the memory area for new interfaces info */ pDeviceInfo->pInterfacesInfo = (pUSBD_INTERFACE_INFO)OS_MALLOC( sizeof(USBD_INTERFACE_INFO) * ConfigDesc.bNumInterfaces); /* if memory allocation fails */ if (NULL == pDeviceInfo->pInterfacesInfo) { OS_LOG_MESSAGE_HIGH( USBD, "usbHstSetConfiguration() Failed: \ INSUFFICIENT_MEMORY.\n", 0, 0, 0, 0); /* Free the setup packet memory area allocated */ OS_FREE(pSetup); /* Free the USB request packet memory area allocated */ OS_FREE(pUrb); /* Destroy the event */ OS_DESTROY_EVENT(EventId); /* Release the Bus operation event */ OS_RELEASE_EVENT(pUsbBusInfo->busOperationLock); /* * Free the Config buffer memory area only if it was * allocated i.e. * ( USBHST_DEFAULT_CONFIGURATION_INDEX != uIndex) */ OS_FREE(pConfigBuffer); return USBHST_INSUFFICIENT_MEMORY; } /* END if memory allocation fails */ /* memset the allocated interfaces info to zero */ OS_MEMSET(pDeviceInfo->pInterfacesInfo, 0, sizeof(USBD_INTERFACE_INFO)* (ConfigDesc.bNumInterfaces)); } /* End Interfaces info is NULL */ /* Update the interface count */ pDeviceInfo->uInterfaceCount = ConfigDesc.bNumInterfaces; /* Free the old configuration */ if (NULL != pDeviceInfo->pCurrentConfiguration) { OS_FREE(pDeviceInfo->pCurrentConfiguration); } /* Update the device information with the new configuration*/ pDeviceInfo->pCurrentConfiguration = pConfigBuffer; /* Create pipes for all the end points in new configuration */ nReturnStatus = usbdParseConfiguration(pDeviceInfo, USBD_PARSE_AND_CREATE); if (USBHST_SUCCESS != nReturnStatus) { OS_LOG_MESSAGE_HIGH( USBD, "USBHST_SetConfiguration() Failed: usbdParseConfiguration\ failed .\n", 0, 0, 0, 0); /* Free the setup packet memory area allocated */ OS_FREE(pSetup); /* Free the USB request packet memory area allocated */ OS_FREE(pUrb); /* Destroy the event */ OS_DESTROY_EVENT(EventId); /* Release the Bus operation event */ OS_RELEASE_EVENT(pUsbBusInfo->busOperationLock); /* Free the memory area for the old interfaces info */ OS_FREE(pDeviceInfo->pInterfacesInfo); /* Mark the Interfaces info as NULL */ pDeviceInfo->pInterfacesInfo = NULL; /* * Free the Config buffer memory area only if it was allocated * since (USBHST_DEFAULT_CONFIGURATION_INDEX ==uIndex) */ OS_FREE(pConfigBuffer); pDeviceInfo->pCurrentConfiguration = NULL; return nReturnStatus; } /*Update the device information with the new configuration*/ pDeviceInfo->uConfigCRCValue = usbdComputeCRC(pConfigBuffer,uSize); } else { /* * if the device driver is vendor specific then free the * memory area for the interfaces */ if ((USBHST_VENDOR_SPECIFIC == pDeviceInfo->uDeviceClass) || (1 < pDeviceInfo->uNumConfigurations)) { /* If the interface info is not NULL */ if (NULL != pDeviceInfo->pInterfacesInfo) { /* free the memory area for the old interfaces info */ OS_FREE(pDeviceInfo->pInterfacesInfo); /* Mark interfaces info as NULL */ pDeviceInfo->pInterfacesInfo = NULL; } } /* End if the device driver is vendor specific */ /* free the configuration buffer stored in the device info */ if (NULL != pDeviceInfo->pCurrentConfiguration) { OS_FREE(pDeviceInfo->pCurrentConfiguration ); } /*Update the device information with the new configuration*/ pDeviceInfo->pCurrentConfiguration = NULL; /* Update the device information with the new configuration*/ pDeviceInfo->uConfigCRCValue = USBD_INVALID_CRC_VALUE; } /* End of if-else for defualt configuration */ } else { /* * Free the Config buffer memory area only if it was allocated i.e * if (USBHST_DEFAULT_CONFIGURATION_INDEX != uIndex) */ if (USBHST_DEFAULT_CONFIGURATION_INDEX != uIndex) { OS_FREE(pConfigBuffer); } } /*end of if - else URB Status is successfull*/ /* Update the return status */ nReturnStatus = pUrb->nStatus; /* Free the setup packet memory area allocated */ OS_FREE(pSetup); /* Free the USB request packet memory area allocated */ OS_FREE(pUrb); /* Destroy the event */ OS_DESTROY_EVENT(EventId); /* Release the Bus operation event */ OS_RELEASE_EVENT(pUsbBusInfo->busOperationLock); OS_LOG_MESSAGE_LOW(USBD, "Exiting usbHstSetConfiguration() Function.\n", 0, 0, 0, 0); /* Return the status of URB */ return nReturnStatus; } /* End of function usbHstSetConfiguration() *//**************************************************************************** usbHstSetFeature - set feature USB request** This function is called by the class driver layer to issue the SetFeature * USB Standard Request** RETURNS: USBHST_SUCCESS, USBHST_INVALID_PARAMETERS,* USBHST_INSUFFICIENT_MEMORY, USBHST_TIMEOUT if request submitted* to Host controller Driver is timed out** ERRNO: None*/USBHST_STATUS usbHstSetFeature ( UINT32 hDevice, /* USB Device handle */ UINT8 uRecipient, /* Desired recipient */ UINT16 uIndex, /* Recipient info list index */ UINT16 uFeature, /* Feature selector */ UINT8 uTestSelector /* Test mode selector */ ) { /* To store the device info */ pUSBD_DEVICE_INFO pDeviceInfo = NULL; /* To store the usb status returned on submission of request */ USBHST_STATUS nReturnStatus = USBHST_FAILURE; /* size of the data to be fetched */ UINT32 uSize = 0; /* WindView Instrumentation */ USB_USBD_LOG_EVENT( USB_USBD_WV_REQUEST, "Entering usbHstSetFeature() Function.", USB_USBD_WV_FILTER); OS_LOG_MESSAGE_LOW(USBD, "Entering usbHstSetFeature() Function.\n", 0, 0, 0, 0); /* * if recipient is device then feature should be remote wakeup or test mode * if recipient is endpoint then feature should be endpoint halt */ if (((USBHST_RECIPIENT_DEVICE == uRecipient) && ((USBHST_FEATURE_DEVICE_REMOTE_WAKEUP != uFeature)|| (USBHST_FEATURE_TEST_MODE != uFeature))) || ((USBHST_RECIPIENT_ENDPOINT == uRecipient) && (USBHST_FEATURE_ENDPOINT_HALT != uFeature))) { OS_LOG_MESSAGE_MEDIUM( USBD, "usbHstSetFeature() Failed:Invalid parameter.\n", 0, 0, 0, 0); return USBHST_INVALID_PARAMETER; } /* If uTestSelector is requested for some feature other then test mode */ if ( (0 != uTestSelector) && (USBHST_FEATURE_TEST_MODE != uFeature) ) { OS_LOG_MESSAGE_MEDIUM( USBD, "usbHstSetFeature() Failed:Invalid parameter.\n", 0, 0, 0, 0); return USBHST_INVALID_PARAMETER; } /* uIndex must be zero for the Test mode feature */ if ( (0 != uIndex) && (USBHST_FEATURE_TEST_MODE == uFeature) ) { OS_LOG_MESSAGE_MEDIUM( USBD, "usbHstSetFeature() Failed:Invalid parameter.\n", 0, 0, 0, 0); return USBHST_INVALID_PARAMETER; } /* Obtain the device info of the device handle */ usbdTranslateDeviceHandle(hDevice, &pDeviceInfo); /* Check if the device info obtained is valid */ if (NULL == pDeviceInfo) { OS_LOG_MESSAGE_MEDIUM( USBD, "usbHstSetFeature() Failed:Invalid parameter.\n", 0, 0, 0, 0); return USBHST_INVALID_PARAMETER; } nReturnStatus = usbdSubmitRequest(pDeviceInfo, uRecipient, USBHST_REQ_SET_FEATURE, uFeature, uIndex, &uSize, NULL); /* Return the status returned from submit request call */ return nReturnStatus; } /* End of function usbHstSetFeature() *//**************************************************************************** usbHstSetDescriptor - set descriptor USB request** This function is called from the class driver layer to issue the * SetDescriptor USB Standard Request** RETURNS: USBHST_SUCCESS, USBHST_INVALID_PARAMETERS,* USBHST_INSUFFICIENT_MEMORY, USBHST_TIMEOUT if request submitted* to Host controller Driver is timed out** ERRNO: None*/USBHST_STATUS usbHstSetDescriptor ( UINT32 hDevice, /* USB Device handle */ UINT8 uDescType, /* USB Descriptor type */ UINT8 uDescIndex, /* USB Descrinptor index */ UINT16 swLangID, /* String descriptor language ID */ UCHAR *pBuffer, /* Ptr to data buffer */ UINT32 uSize /* Num bytes of descriptor to fetch */ ) { /* To store the device info */ pUSBD_DEVICE_INFO pDeviceInfo = NULL; /* To store the usb status returned on submission of request */ USBHST_STATUS nReturnStatus = USBHST_FAILURE; /* WindView Instrumentation */ USB_USBD_LOG_EVENT( USB_USBD_WV_REQUEST, "Entering usbHstSetDescriptor() Function.", USB_USBD_WV_FILTER); OS_LOG_MESSAGE_LOW(USBD, "Entering usbHstSetDescriptor() Function.\n", 0, 0, 0, 0); /* Check if uSize and buffer are valid */ if ((0 == uSize) || (NULL == pBuffer)) { OS_LOG_MESSAGE_MEDIUM( USBD, "usbHstSetDescriptor() Failed:Invalid parameter.\n", 0, 0, 0, 0); return USBHST_INVALID_PARAMETER; } /* * Check if uDescType is device, configuration or string. * If not any of these then return USBHST_INVALID_PARAMETER. * If uDescType is device then uDescIndex should be zero. * Else if uDescType is configuration or string then uDescIndex can be * zero or non zero value. */ if ((USBHST_CONFIG_DESC != uDescType) && (USBHST_STRING_DESC != uDescType)) { if (0 != uDescIndex) { OS_LOG_MESSAGE_MEDIUM( USBD, "usbHstSetDescriptor() Failed:Invalid parameter.\n", 0, 0, 0, 0); return USBHST_INVALID_PARAMETER; } if (USBHST_DEVICE_DESC != uDescType)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -