📄 device.c
字号:
/* Invalid max packet size */ return FALSE; } } /* End if the device is FULL speed */ /* if the device speed if HIGH */ else if (pDeviceInfo->uDeviceSpeed == USBHST_HIGH_SPEED) { /* Max packet size should be 64 bytes */ if (uMaxPacketSize != 64) { OS_LOG_MESSAGE_HIGH( USBD, "usbdIsValidEndpoint() Failed Invalid max packet size.\n", 0, 0, 0, 0); /* Invalid max packet size */ return FALSE; } } /* End if the device is HIGH speed*/ } /* END if the end point transfer type is control */ /* if the end point transfer type is bulk */ else if ((pEndpointDesc->bmAttributes & 0x03) == USBHST_BULK_TRANSFER) { /* LOW speed devices should not have BULK endpoints */ if (pDeviceInfo->uDeviceSpeed == USBHST_LOW_SPEED) { OS_LOG_MESSAGE_HIGH( USBD, "usbdIsValidEndpoint() Failed: BULK endpoint for LOW speed" "device.\n", 0, 0, 0, 0); /* Invalid max packet size */ return FALSE; } /* If the device is FULL speed */ else if (pDeviceInfo->uDeviceSpeed == USBHST_FULL_SPEED) { /* Max packet size should be 8,16,32,64 bytes */ if ((uMaxPacketSize != 8) && (uMaxPacketSize != 16) && (uMaxPacketSize != 32) && (uMaxPacketSize != 64)) { OS_LOG_MESSAGE_HIGH( USBD, "usbdIsValidEndpoint() Failed: Invalid max packet size.\n", 0, 0, 0, 0); /* Invalid max packet size */ return FALSE; } }/* END if the device is FULL speed */ /* If the device is HIGH speed */ else if (pDeviceInfo->uDeviceSpeed == USBHST_HIGH_SPEED) { /* Max packet size should be 512 bytes */ if (uMaxPacketSize != 512) { OS_LOG_MESSAGE_HIGH( USBD, "usbdIsValidEndpoint() Failed: Invalid max packet size.\n", 0, 0, 0, 0); /* Invalid max packet size */ return FALSE; } }/* END if the device is HIGH speed */ } /* END if the end point transfer type is bulk */ /* if the end point transfer type is interrupt */ else if ((pEndpointDesc->bmAttributes & 0x03) == USBHST_INTERRUPT_TRANSFER) { /* If polling interval is invalid */ if (0 == pEndpointDesc->bInterval) { OS_LOG_MESSAGE_HIGH( USBD, "usbdIsValidEndpoint() Failed: Invalid max packet size.\n", 0, 0, 0, 0); return FALSE ; } /* END If polling interval is invalid */ /* if the device speed if LOW */ if (pDeviceInfo->uDeviceSpeed == USBHST_LOW_SPEED) { /* Max packet size should be 8 bytes */ if (uMaxPacketSize > 8) { OS_LOG_MESSAGE_HIGH( USBD, "usbdIsValidEndpoint() Failed: Invalid max packet size.\n", 0, 0, 0, 0); /* Invalid max packet size */ return FALSE; } } /* End if the device is LOW speed*/ /* if the device speed if FULL */ else if (pDeviceInfo->uDeviceSpeed == USBHST_FULL_SPEED) { /* Max packet size should be 64 bytes */ if (uMaxPacketSize > 64) { OS_LOG_MESSAGE_HIGH( USBD, "usbdIsValidEndpoint() Failed: Invalid max packet size.\n", 0, 0, 0, 0); /* Invalid max packet size */ return FALSE; } } /* End if the device is FULL speed*/ /* if the device speed if HIGH */ else if (pDeviceInfo->uDeviceSpeed == USBHST_HIGH_SPEED) { /* Max packet size should be 1024 bytes */ if (uMaxPacketSize > 1024) { OS_LOG_MESSAGE_HIGH( USBD, "usbdIsValidEndpoint() Failed: Invalid max packet size.\n", 0, 0, 0, 0); /* Invalid max packet size */ return FALSE; } } /* End if the device is HIGH speed*/ } /* END if the end point transfer type is interrupt */ /* if the end point transfer type is isochronous */ else if ((pEndpointDesc->bmAttributes & 0x03) == USBHST_ISOCHRONOUS_TRANSFER) { /* A LOW speed device should not use isochronous transfers */ if (pDeviceInfo->uDeviceSpeed == USBHST_LOW_SPEED) { OS_LOG_MESSAGE_HIGH( USBD, "usbdIsValidEndpoint() Failed: LOW speed device with " "isochronous endpoint.\n", 0, 0, 0, 0); /* Invalid max packet size */ return FALSE; } /* if the device speed if FULL */ else if (pDeviceInfo->uDeviceSpeed == USBHST_FULL_SPEED) { /* Max packet size should be 1023 bytes */ if (uMaxPacketSize > 1023) { OS_LOG_MESSAGE_HIGH( USBD, "usbdIsValidEndpoint() Failed: Invalid max packet size.\n", 0, 0, 0, 0); /* Invalid max packet size */ return FALSE; } } /* End if the device is FULL speed*/ /* if the device speed if HIGH */ else if (pDeviceInfo->uDeviceSpeed == USBHST_HIGH_SPEED) { /* Max packet size should be 1024 bytes */ if (uMaxPacketSize > 1024) { OS_LOG_MESSAGE_HIGH( USBD, "usbdIsValidEndpoint() Failed: Invalid max packet size.\n", 0, 0, 0, 0); /* Invalid max packet size */ return FALSE; } } /* End if the device is HIGH speed*/ /* If polling interval is invalid */ if ((pEndpointDesc->bInterval < 1) || (pEndpointDesc->bInterval > 16)) { OS_LOG_MESSAGE_HIGH( USBD, "usbdIsValidEndpoint() Failed: Invalid max packet size.\n", 0, 0, 0, 0); return FALSE ; } /* END If polling interval is invalid */ } /* END if the end point transfer type is isochronous */ OS_LOG_MESSAGE_LOW(USBD, "Exiting usbdIsValidEndpoint() Function.\n", 0, 0, 0, 0); return TRUE; } /* END of function usbdIsValidEndpoint() *//***************************************************************************** usbdParseConfiguration - parses the configuration.** This routine parses the configuration and update the device info with interface* info and endpoint info.** RETURNS: USBHST_SUCCESS, USBHST_INSUFFICIENT_MEMORY,** ERRNO: None** \NOMANUAL*/LOCAL USBHST_STATUS usbdParseConfiguration ( pUSBD_DEVICE_INFO pDeviceInfo, /* Ptr to USB Dev info */ UINT8 uParserFlag /* Parsing Flag type */ ) { pUSBHST_CONFIG_DESCRIPTOR pConfigDesc = NULL; /* Configuration descriptor */ pUSBD_BUS_INFO pUsbBusInfo = NULL; /* Device bus information */ pUSBHST_HC_DRIVER pHCDriverInfo = NULL; /* Host Controller info */ pUSBHST_INTERFACE_DESCRIPTOR pInterfaceDesc = NULL; /* Interface descriptor */ pUSBHST_ENDPOINT_DESCRIPTOR pEndpointDesc = NULL; /* Endpoint descriptor */ pUSBD_INTERFACE_INFO pInterfaceInfo = NULL; /* Interface information */ pUSBD_ENDPOINT_INFO pEndpointInfo = NULL; /* Endpoint information */ UINT16 uLength = 0; /* Config descriptor length */ UINT16 uTotalLength = 0; /* Config descriptor length */ UINT8 uInterfaceCount = 0; /* Interface counter */ UINT8 uEndpointCount = 0; /* Endpoint counter */ pUSBHST_DESCRIPTOR_HEADER pHeader = NULL; /* First 2 bytes of descr */ OS_LOG_MESSAGE_LOW(USBD, "Entering usbdParseConfiguration() Function.\n", 0, 0, 0, 0); /* Get the bus information for this request */ pUsbBusInfo = &(gUSBBusInfoList[pDeviceInfo->uBusIndex]); /* Get the HC driver information for this request */ pHCDriverInfo = &(gHCDriverList[pUsbBusInfo->hcdIndex]); /* get the first 9 bytes of the device current configuration */ pConfigDesc = (pUSBHST_CONFIG_DESCRIPTOR)pDeviceInfo->pCurrentConfiguration; /* update the total length with CPU endian conversion */ uTotalLength = OS_UINT16_LE_TO_CPU(pConfigDesc->wTotalLength); /* get the pointer to interfaces info stored in device info */ pInterfaceInfo = pDeviceInfo->pInterfacesInfo; /* Move the pointer to the interface */ uLength = pConfigDesc->bLength; /* * Gets all the interfaces with alternate setting zero and the * corresponding endpoints for the interface */ while (uInterfaceCount < pConfigDesc->bNumInterfaces) { /* * Check if whole configuration descriptor buffer is read before the * expected information is fetched. */ if (uLength >= uTotalLength) { OS_LOG_MESSAGE_HIGH( USBD, "usbdParseConfiguration() Failed: Invalid configuration\ descriptor.\n", 0, 0, 0, 0); /* Set back the interfaces information to zero */ OS_MEMSET(pInterfaceInfo, 0, pConfigDesc->bNumInterfaces * sizeof(USBD_INTERFACE_INFO)); /* For each interface information */ for (uInterfaceCount = 0; uInterfaceCount < pConfigDesc->bNumInterfaces; uInterfaceCount ++) { /* * Free the endpoint information allocated and * updated in each interface */ if (NULL != pInterfaceInfo[uInterfaceCount].pEndpointInformation) { OS_FREE ( pInterfaceInfo[uInterfaceCount].pEndpointInformation); /* Mark the endpoint information as NULL */ pInterfaceInfo[uInterfaceCount].pEndpointInformation = NULL; } }/* END for each interface */ return USBHST_FAILURE; }/* END if whole configuration descriptor buffer is read...*/ /* Copy the descriptor header from the buffer */ pHeader = (pUSBHST_DESCRIPTOR_HEADER) (pDeviceInfo->pCurrentConfiguration + uLength); while (pHeader->uDescriptorType != USBHST_INTERFACE_DESC) { /* Move the pointer to read the next descriptor */ uLength = uLength + pHeader->uLength; /* * Check if whole configuration descriptor buffer is read before the * expected information is fetched. */ if (uLength >= uTotalLength) { OS_LOG_MESSAGE_HIGH( USBD, "usbdParseConfiguration() Failed: Invalid configuration\ descriptor.\n", 0, 0, 0, 0); /* Set back the interfaces information to zero */ OS_MEMSET(pDeviceInfo->pInterfacesInfo, 0,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -