diff options
| author | Chaoqiong Xiao <[email protected]> | 2023-05-12 07:01:07 +0000 |
|---|---|---|
| committer | Chaoqiong Xiao <[email protected]> | 2023-05-12 07:01:07 +0000 |
| commit | ef2fa7717be8ab751fdfb5d3f91e24fbbaea8dd6 (patch) | |
| tree | e252f4e5e52617043c6d6ed59a6891a173d07781 /common/core | |
| parent | 3af3626c9b4b5fefbe4016582b896ad79287df62 (diff) | |
Update on 12 May 2023. Expand to see details.
8b59a1d4 Add support for Get String requests with 0 wIndex
106c1b06 Update cfs usage
2d45d315 Optimize SRAM for extracted USB descriptors
cf97e6e9 Fixed allocated buffer pointer checking issue.
6468c588 Guard basic types.
60b3a232 Update CFS usage
Diffstat (limited to 'common/core')
| -rw-r--r-- | common/core/inc/ux_api.h | 187 | ||||
| -rw-r--r-- | common/core/inc/ux_user_sample.h | 10 | ||||
| -rw-r--r-- | common/core/inc/ux_utility.h | 8 | ||||
| -rw-r--r-- | common/core/src/ux_device_stack_descriptor_send.c | 12 | ||||
| -rw-r--r-- | common/core/src/ux_system_initialize.c | 19 | ||||
| -rw-r--r-- | common/core/src/ux_utility_descriptor_pack.c | 89 | ||||
| -rw-r--r-- | common/core/src/ux_utility_descriptor_parse.c | 176 | ||||
| -rw-r--r-- | common/core/src/ux_utility_memory_allocate.c | 7 |
8 files changed, 342 insertions, 166 deletions
diff --git a/common/core/inc/ux_api.h b/common/core/inc/ux_api.h index e8b54d6..51c98db 100644 --- a/common/core/inc/ux_api.h +++ b/common/core/inc/ux_api.h @@ -134,6 +134,7 @@ /* added a new error code, */ /* resulting in version 6.2.1 */ /* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* optimized USB descriptors, */ /* added error checks support, */ /* resulting in version 6.x */ /* */ @@ -1814,12 +1815,13 @@ typedef struct UX_TRANSFER_STRUCT typedef struct UX_ENDPOINT_DESCRIPTOR_STRUCT { - ULONG bLength; - ULONG bDescriptorType; - ULONG bEndpointAddress; - ULONG bmAttributes; - ULONG wMaxPacketSize; - ULONG bInterval; + UCHAR bLength; + UCHAR bDescriptorType; + UCHAR bEndpointAddress; + UCHAR bmAttributes; + USHORT wMaxPacketSize; + UCHAR bInterval; + UCHAR _align_size[1]; } UX_ENDPOINT_DESCRIPTOR; #define UX_ENDPOINT_DESCRIPTOR_ENTRIES 6 @@ -1852,39 +1854,42 @@ typedef struct UX_ENDPOINT_STRUCT typedef struct UX_DEVICE_DESCRIPTOR_STRUCT { - ULONG bLength; - ULONG bDescriptorType; - ULONG bcdUSB; - ULONG bDeviceClass; - ULONG bDeviceSubClass; - ULONG bDeviceProtocol; - ULONG bMaxPacketSize0; - ULONG idVendor; - ULONG idProduct; - ULONG bcdDevice; - ULONG iManufacturer; - ULONG iProduct; - ULONG iSerialNumber; - ULONG bNumConfigurations; + UCHAR bLength; + UCHAR bDescriptorType; + USHORT bcdUSB; + UCHAR bDeviceClass; + UCHAR bDeviceSubClass; + UCHAR bDeviceProtocol; + UCHAR bMaxPacketSize0; + USHORT idVendor; + USHORT idProduct; + USHORT bcdDevice; + UCHAR iManufacturer; + UCHAR iProduct; + UCHAR iSerialNumber; + UCHAR bNumConfigurations; + UCHAR _align_size[2]; } UX_DEVICE_DESCRIPTOR; #define UX_DEVICE_DESCRIPTOR_ENTRIES 14 #define UX_DEVICE_DESCRIPTOR_LENGTH 18 + /* Define USBX Device Qualifier Descriptor structure. */ typedef struct UX_DEVICE_QUALIFIER_DESCRIPTOR_STRUCT { - ULONG bLength; - ULONG bDescriptorType; - ULONG bcdUSB; - ULONG bDeviceClass; - ULONG bDeviceSubClass; - ULONG bDeviceProtocol; - ULONG bMaxPacketSize0; - ULONG bNumConfigurations; - ULONG bReserved; + UCHAR bLength; + UCHAR bDescriptorType; + USHORT bcdUSB; + UCHAR bDeviceClass; + UCHAR bDeviceSubClass; + UCHAR bDeviceProtocol; + UCHAR bMaxPacketSize0; + UCHAR bNumConfigurations; + UCHAR bReserved; + UCHAR _align_size[2]; } UX_DEVICE_QUALIFIER_DESCRIPTOR; #define UX_DEVICE_QUALIFIER_DESCRIPTOR_ENTRIES 9 @@ -1896,47 +1901,50 @@ typedef struct UX_DEVICE_QUALIFIER_DESCRIPTOR_STRUCT typedef struct UX_OTHER_SPEED_DESCRIPTOR_STRUCT { - ULONG bLength; - ULONG bDescriptorType; - ULONG wTotalLength; - ULONG bNumInterfaces; - ULONG bConfigurationValue; - ULONG iConfiguration; - ULONG bmAttributes; + UCHAR bLength; + UCHAR bDescriptorType; + USHORT wTotalLength; + UCHAR bNumInterfaces; + UCHAR bConfigurationValue; + UCHAR iConfiguration; + UCHAR bmAttributes; ULONG MaxPower; } UX_OTHER_SPEED_DESCRIPTOR; #define UX_OTHER_SPEED_DESCRIPTOR_ENTRIES 8 #define UX_OTHER_SPEED_DESCRIPTOR_LENGTH 9 + /* Define USBX OTG Descriptor structure. */ typedef struct UX_OTG_DESCRIPTOR_STRUCT { - ULONG bLength; - ULONG bDescriptorType; - ULONG bmAttributes; - ULONG bcdOTG; + UCHAR bLength; + UCHAR bDescriptorType; + UCHAR bmAttributes; + UCHAR _align_bcdOTG[1]; + USHORT bcdOTG; + UCHAR _algin_size[2]; } UX_OTG_DESCRIPTOR; #define UX_OTG_DESCRIPTOR_ENTRIES 4 #define UX_OTG_DESCRIPTOR_LENGTH 5 + /* Define USBX Interface Association Descriptor structure. */ typedef struct UX_INTERFACE_ASSOCIATION_DESCRIPTOR_STRUCT { - ULONG bLength; - ULONG bDescriptorType; - ULONG bFirstInterface; - ULONG bInterfaceCount; - ULONG bFunctionClass; - ULONG bFunctionSubClass; - ULONG bFunctionProtocol; - ULONG iFunction; - + UCHAR bLength; + UCHAR bDescriptorType; + UCHAR bFirstInterface; + UCHAR bInterfaceCount; + UCHAR bFunctionClass; + UCHAR bFunctionSubClass; + UCHAR bFunctionProtocol; + UCHAR iFunction; } UX_INTERFACE_ASSOCIATION_DESCRIPTOR; #define UX_INTERFACE_ASSOCIATION_DESCRIPTOR_ENTRIES 8 @@ -2060,16 +2068,17 @@ typedef struct UX_DEVICE_STRUCT typedef struct UX_CONFIGURATION_DESCRIPTOR_STRUCT { - ULONG bLength; - ULONG bDescriptorType; - ULONG wTotalLength; - ULONG bNumInterfaces; - ULONG bConfigurationValue; - ULONG iConfiguration; - ULONG bmAttributes; + UCHAR bLength; + UCHAR bDescriptorType; + USHORT wTotalLength; + UCHAR bNumInterfaces; + UCHAR bConfigurationValue; + UCHAR iConfiguration; + UCHAR bmAttributes; ULONG MaxPower; } UX_CONFIGURATION_DESCRIPTOR; + #define UX_CONFIGURATION_DESCRIPTOR_ENTRIES 8 #define UX_CONFIGURATION_DESCRIPTOR_LENGTH 9 @@ -2107,15 +2116,16 @@ typedef struct UX_CONFIGURATION_STRUCT typedef struct UX_INTERFACE_DESCRIPTOR_STRUCT { - ULONG bLength; - ULONG bDescriptorType; - ULONG bInterfaceNumber; - ULONG bAlternateSetting; - ULONG bNumEndpoints; - ULONG bInterfaceClass; - ULONG bInterfaceSubClass; - ULONG bInterfaceProtocol; - ULONG iInterface; + UCHAR bLength; + UCHAR bDescriptorType; + UCHAR bInterfaceNumber; + UCHAR bAlternateSetting; + UCHAR bNumEndpoints; + UCHAR bInterfaceClass; + UCHAR bInterfaceSubClass; + UCHAR bInterfaceProtocol; + UCHAR iInterface; + UCHAR _align_size[3]; } UX_INTERFACE_DESCRIPTOR; #define UX_INTERFACE_DESCRIPTOR_ENTRIES 9 @@ -2153,9 +2163,9 @@ typedef struct UX_INTERFACE_STRUCT typedef struct UX_STRING_DESCRIPTOR_STRUCT { - ULONG bLength; - ULONG bDescriptorType; - ULONG bString[1]; + UCHAR bLength; + UCHAR bDescriptorType; + UCHAR bString[2]; } UX_STRING_DESCRIPTOR; #define UX_STRING_DESCRIPTOR_ENTRIES 3 @@ -2166,10 +2176,11 @@ typedef struct UX_STRING_DESCRIPTOR_STRUCT typedef struct UX_BOS_DESCRIPTOR_STRUCT { - ULONG bLength; - ULONG bDescriptorType; - ULONG wTotalLength; - ULONG bNumDeviceCaps; + UCHAR bLength; + UCHAR bDescriptorType; + USHORT wTotalLength; + UCHAR bNumDeviceCaps; + UCHAR _align_size[3]; } UX_BOS_DESCRIPTOR; #define UX_BOS_DESCRIPTOR_ENTRIES 4 @@ -2180,9 +2191,10 @@ typedef struct UX_BOS_DESCRIPTOR_STRUCT typedef struct UX_USB_2_0_EXTENSION_DESCRIPTOR_STRUCT { - ULONG bLength; - ULONG bDescriptorType; - ULONG bDevCapabilityType; + UCHAR bLength; + UCHAR bDescriptorType; + UCHAR bDevCapabilityType; + UCHAR _align_bmAttributes[1]; ULONG bmAttributes; } UX_USB_2_0_EXTENSION_DESCRIPTOR; @@ -2194,14 +2206,14 @@ typedef struct UX_USB_2_0_EXTENSION_DESCRIPTOR_STRUCT typedef struct UX_CONTAINER_ID_DESCRIPTOR_STRUCT { - ULONG bLength; - ULONG bDescriptorType; - ULONG bDevCapabilityType; - ULONG bReserved; + UCHAR bLength; + UCHAR bDescriptorType; + UCHAR bDevCapabilityType; + UCHAR bReserved; ULONG ContainerID[4]; } UX_CONTAINER_ID_DESCRIPTOR; -#define UX_CONTAINER_ID_DESCRIPTOR_ENTRIES 5 +#define UX_CONTAINER_ID_DESCRIPTOR_ENTRIES 8 #define UX_CONTAINER_ID_DESCRIPTOR_LENGTH 20 @@ -2210,17 +2222,20 @@ typedef struct UX_CONTAINER_ID_DESCRIPTOR_STRUCT typedef struct UX_DFU_FUNCTIONAL_DESCRIPTOR_STRUCT { - ULONG bLength; - ULONG bDescriptorType; - ULONG bmAttributes; - ULONG wDetachTimeOut; - ULONG wTransferSize; - ULONG bcdDFUVersion; + UCHAR bLength; + UCHAR bDescriptorType; + UCHAR bmAttributes; + UCHAR _align_wDetachTimeOut[1]; + USHORT wDetachTimeOut; + USHORT wTransferSize; + USHORT bcdDFUVersion; + UCHAR _align_size[2]; } UX_DFU_FUNCTIONAL_DESCRIPTOR; #define UX_DFU_FUNCTIONAL_DESCRIPTOR_ENTRIES 6 #define UX_DFU_FUNCTIONAL_DESCRIPTOR_LENGTH 9 + /* Define USBX Host Controller structure. */ typedef struct UX_HCD_STRUCT diff --git a/common/core/inc/ux_user_sample.h b/common/core/inc/ux_user_sample.h index f974505..216f3ec 100644 --- a/common/core/inc/ux_user_sample.h +++ b/common/core/inc/ux_user_sample.h @@ -26,7 +26,7 @@ /* PORT SPECIFIC C INFORMATION RELEASE */ /* */ /* ux_user.h PORTABLE C */ -/* 6.2.1 */ +/* 6.x */ /* */ /* AUTHOR */ /* */ @@ -99,6 +99,10 @@ /* added option to enable */ /* basic USBX error checking, */ /* resulting in version 6.2.1 */ +/* xx-xx-xxxx Xiuwen Cai Modified comment(s), */ +/* added option for get string */ +/* requests with zero wIndex, */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ @@ -224,6 +228,10 @@ #define UX_SLAVE_REQUEST_DATA_MAX_LENGTH (1024 * 2) +/* Defined, this enables processing of Get String Descriptor requests with zero Language ID. + The first language ID in the language ID framwork will be used if the request has a zero + Language ID. */ +/* #define UX_DEVICE_ENABLE_GET_STRING_WITH_ZERO_LANGUAGE_ID */ /* Defined, this value includes code to handle storage Multi-Media Commands (MMC). E.g., DVD-ROM. */ diff --git a/common/core/inc/ux_utility.h b/common/core/inc/ux_utility.h index 39bd50d..8b42fae 100644 --- a/common/core/inc/ux_utility.h +++ b/common/core/inc/ux_utility.h @@ -26,7 +26,7 @@ /* COMPONENT DEFINITION RELEASE */ /* */ /* ux_utility.h PORTABLE C */ -/* 6.1.12 */ +/* 6.x */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -57,6 +57,10 @@ /* added macros for RTOS calls,*/ /* fixed OHCI PRSC issue, */ /* resulting in version 6.1.12 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* added new function to check */ +/* parsed size of descriptor, */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ @@ -70,6 +74,8 @@ VOID _ux_utility_descriptor_parse(UCHAR * raw_descriptor, UCHAR * de UINT descriptor_entries, UCHAR * descriptor); VOID _ux_utility_descriptor_pack(UCHAR * descriptor, UCHAR * descriptor_structure, UINT descriptor_entries, UCHAR * raw_descriptor); +ULONG _ux_utility_descriptor_parse_size(UCHAR * descriptor_structure, UINT descriptor_entries, UINT size_align_mask); + ULONG _ux_utility_long_get(UCHAR * address); VOID _ux_utility_long_put(UCHAR * address, ULONG value); VOID _ux_utility_long_put_big_endian(UCHAR * address, ULONG value); diff --git a/common/core/src/ux_device_stack_descriptor_send.c b/common/core/src/ux_device_stack_descriptor_send.c index f8dae5a..4ce10a8 100644 --- a/common/core/src/ux_device_stack_descriptor_send.c +++ b/common/core/src/ux_device_stack_descriptor_send.c @@ -91,6 +91,8 @@ /* resulting in version 6.1.11 */ /* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ /* moved compile option check, */ +/* added support for get string*/ +/* requests with zero wIndex, */ /* resulting in version 6.x */ /* */ /**************************************************************************/ @@ -399,6 +401,16 @@ ULONG string_length; } else { +#ifdef UX_DEVICE_ENABLE_GET_STRING_WITH_ZERO_LANGUAGE_ID + + /* Check if the language ID is zero. */ + if (request_index == 0) + { + + /* Get the first language ID in the language ID framework. */ + request_index = _ux_utility_short_get(_ux_system_slave -> ux_system_slave_language_id_framework); + } +#endif /* The host wants a specific string index returned. Get the string framework pointer and length. */ diff --git a/common/core/src/ux_system_initialize.c b/common/core/src/ux_system_initialize.c index f6f7202..06fc65e 100644 --- a/common/core/src/ux_system_initialize.c +++ b/common/core/src/ux_system_initialize.c @@ -69,7 +69,7 @@ UCHAR _ux_system_container_id_descriptor_structure[] = {1,1 /* FUNCTION RELEASE */ /* */ /* _ux_system_initialize PORTABLE C */ -/* 6.1.10 */ +/* 6.x */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -115,6 +115,10 @@ UCHAR _ux_system_container_id_descriptor_structure[] = {1,1 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */ /* added standalone support, */ /* resulting in version 6.1.10 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* added UX_ASSERT check for */ +/* STD descriptor parse size, */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ UINT _ux_system_initialize(VOID *regular_memory_pool_start, ULONG regular_memory_size, @@ -313,6 +317,19 @@ UINT _uxe_system_initialize(VOID *regular_memory_pool_start, ULONG regular_memo VOID *cache_safe_memory_pool_start, ULONG cache_safe_memory_size) { + /* Compiling option check of descriptors structs. */ + UX_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_endpoint_descriptor_structure, UX_ENDPOINT_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_ENDPOINT_DESCRIPTOR)); + UX_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_device_descriptor_structure, UX_DEVICE_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_DEVICE_DESCRIPTOR)); + UX_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_configuration_descriptor_structure, UX_CONFIGURATION_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_CONFIGURATION_DESCRIPTOR)); + UX_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_interface_descriptor_structure, UX_INTERFACE_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_INTERFACE_DESCRIPTOR)); + UX_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_interface_association_descriptor_structure, UX_INTERFACE_ASSOCIATION_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_INTERFACE_ASSOCIATION_DESCRIPTOR)); + UX_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_string_descriptor_structure, UX_STRING_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_STRING_DESCRIPTOR)); + UX_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_dfu_functional_descriptor_structure, UX_DFU_FUNCTIONAL_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_DFU_FUNCTIONAL_DESCRIPTOR)); + UX_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_bos_descriptor_structure, UX_BOS_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_BOS_DESCRIPTOR)); + UX_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_usb_2_0_extension_descriptor_structure, UX_USB_2_0_EXTENSION_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_USB_2_0_EXTENSION_DESCRIPTOR)); + UX_ASSERT((_ux_utility_descriptor_parse_size(_ux_system_container_id_descriptor_structure, UX_CONTAINER_ID_DESCRIPTOR_ENTRIES, 0x3u)) == sizeof(UX_CONTAINER_ID_DESCRIPTOR)); + + /* Sanity check. */ if ((regular_memory_pool_start == UX_NULL) || (regular_memory_size == 0)) return(UX_INVALID_PARAMETER); diff --git a/common/core/src/ux_utility_descriptor_pack.c b/common/core/src/ux_utility_descriptor_pack.c index 574c56c..bc85c55 100644 --- a/common/core/src/ux_utility_descriptor_pack.c +++ b/common/core/src/ux_utility_descriptor_pack.c @@ -12,8 +12,8 @@ /**************************************************************************/ /**************************************************************************/ -/** */ -/** USBX Component */ +/** */ +/** USBX Component */ /** */ /** Utility */ /** */ @@ -28,50 +28,53 @@ #include "ux_api.h" -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _ux_utility_descriptor_pack PORTABLE C */ -/* 6.1 */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_utility_descriptor_pack PORTABLE C */ +/* 6.x */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ +/* */ /* This function will pack an application structure into a USB */ -/* descriptor. */ -/* */ -/* INPUT */ -/* */ -/* descriptor Pointer to the unpacked */ +/* descriptor. */ +/* */ +/* INPUT */ +/* */ +/* descriptor Pointer to the unpacked */ /* descriptor */ /* descriptor_structure Components of the descriptor */ -/* descriptor_entries Number of entries in the */ +/* descriptor_entries Number of entries in the */ /* descriptor */ /* raw_descriptor Pointer to packed descriptor */ -/* */ -/* OUTPUT */ -/* */ +/* */ +/* OUTPUT */ +/* */ /* None */ -/* */ -/* CALLS */ -/* */ +/* */ +/* CALLS */ +/* */ /* _ux_utility_long_put Put 32-bit value */ /* _ux_utility_short_put Put 16-bit value */ -/* */ -/* CALLED BY */ -/* */ -/* USBX Components */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* */ +/* CALLED BY */ +/* */ +/* USBX Components */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* optimized USB descriptors, */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ VOID _ux_utility_descriptor_pack(UCHAR * descriptor, UCHAR * descriptor_structure, @@ -90,27 +93,37 @@ VOID _ux_utility_descriptor_pack(UCHAR * descriptor, UCHAR * descriptor_structu insert it into the target descriptor. */ case 4: + /* Increase address so it's aligned. */ + while((ALIGN_TYPE)descriptor & 3u) + descriptor++; + + /* Put the DW. */ _ux_utility_long_put(raw_descriptor, *((ULONG *) descriptor)); raw_descriptor += 4; - break; + descriptor += 4; + break; case 2: - _ux_utility_short_put(raw_descriptor, (USHORT)*((ULONG *) descriptor)); + /* Increase address so it's aligned. */ + while((ALIGN_TYPE)descriptor & 1u) + descriptor++; + + /* Put the Word. */ + _ux_utility_short_put(raw_descriptor, (USHORT)*((USHORT *) descriptor)); raw_descriptor += 2; - break; + descriptor += 2; + break; default: - *raw_descriptor = (UCHAR) *((ULONG *) descriptor); + /* Put the byte. */ + *raw_descriptor = (UCHAR) *((UCHAR *) descriptor); raw_descriptor++; + descriptor++; } - - /* Add the size of the component to the destination. */ - descriptor += 4; } /* Return to caller. */ return; } - diff --git a/common/core/src/ux_utility_descriptor_parse.c b/common/core/src/ux_utility_descriptor_parse.c index ff23559..86bbd85 100644 --- a/common/core/src/ux_utility_descriptor_parse.c +++ b/common/core/src/ux_utility_descriptor_parse.c @@ -12,8 +12,8 @@ /**************************************************************************/ /**************************************************************************/ -/** */ -/** USBX Component */ +/** */ +/** USBX Component */ /** */ /** Utility */ /** */ @@ -28,50 +28,53 @@ #include "ux_api.h" -/**************************************************************************/ -/* */ -/* FUNCTION RELEASE */ -/* */ -/* _ux_utility_descriptor_parse PORTABLE C */ -/* 6.1 */ +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_utility_descriptor_parse PORTABLE C */ +/* 6.x */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ /* */ /* DESCRIPTION */ -/* */ +/* */ /* This function will unpack a USB descriptor from the bus into a */ -/* memory aligned structure. */ -/* */ -/* INPUT */ -/* */ +/* memory aligned structure. */ +/* */ +/* INPUT */ +/* */ /* raw_descriptor Pointer to packed descriptor */ /* descriptor_structure Components of the descriptor */ -/* descriptor_entries Number of entries in the */ +/* descriptor_entries Number of entries in the */ /* descriptor */ -/* descriptor Pointer to the unpacked */ +/* descriptor Pointer to the unpacked */ /* descriptor */ -/* */ -/* OUTPUT */ -/* */ +/* */ +/* OUTPUT */ +/* */ /* None */ -/* */ -/* CALLS */ -/* */ +/* */ +/* CALLS */ +/* */ /* _ux_utility_long_get Get 32-bit value */ /* _ux_utility_short_get Get 16-bit value */ -/* */ -/* CALLED BY */ -/* */ -/* USBX Components */ -/* */ -/* RELEASE HISTORY */ -/* */ -/* DATE NAME DESCRIPTION */ -/* */ +/* */ +/* CALLED BY */ +/* */ +/* USBX Components */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ /* resulting in version 6.1 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* optimized USB descriptors, */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ VOID _ux_utility_descriptor_parse(UCHAR * raw_descriptor, UCHAR * descriptor_structure, @@ -90,27 +93,126 @@ VOID _ux_utility_descriptor_parse(UCHAR * raw_descriptor, UCHAR * descriptor_st insert it into the target descriptor. */ case 4: + /* Padding zeros so address is aligned. */ + while((ALIGN_TYPE) descriptor & 3u) + *descriptor++ = 0; + + /* Save the DW. */ *((ULONG *) descriptor) = _ux_utility_long_get(raw_descriptor); raw_descriptor += 4; - break; + descriptor += 4; + break; case 2: - *((ULONG *) descriptor) = (ULONG) _ux_utility_short_get(raw_descriptor); + /* Padding zeros so address is aligned. */ + while((ALIGN_TYPE) descriptor & 1u) + *descriptor++ = 0; + + /* Save the word. */ + *((USHORT *) descriptor) = (USHORT) _ux_utility_short_get(raw_descriptor); raw_descriptor += 2; - break; + descriptor += 2; + break; default: - *((ULONG *) descriptor) = (ULONG) *raw_descriptor; + /* Save the byte. */ + *((UCHAR *) descriptor) = (UCHAR) *raw_descriptor; raw_descriptor++; + descriptor ++; } - - /* Add the size of the component to the destination. */ - descriptor += 4; } /* Return to caller. */ return; } +/**************************************************************************/ +/* */ +/* FUNCTION RELEASE */ +/* */ +/* _ux_utility_descriptor_parse_size PORTABLE C */ +/* 6.x */ +/* AUTHOR */ +/* */ +/* Chaoqiong Xiao, Microsoft Corporation */ +/* */ +/* DESCRIPTION */ +/* */ +/* This function will calculate the size of a parsed USB descriptor. */ +/* */ +/* INPUT */ +/* */ +/* descriptor_structure Components of the descriptor */ +/* descriptor_entries Number of entries in the */ +/* descriptor */ +/* size_align_mask Size alignment mask */ +/* */ +/* OUTPUT */ +/* */ +/* size Size of the parsed descriptor */ +/* */ +/* CALLS */ +/* */ +/* None */ +/* */ +/* CALLED BY */ +/* */ +/* USBX Components */ +/* */ +/* RELEASE HISTORY */ +/* */ +/* DATE NAME DESCRIPTION */ +/* */ +/* xx-xx-xxxx Chaoqiong Xiao Initial Version 6.x */ +/* */ +/**************************************************************************/ +ULONG _ux_utility_descriptor_parse_size(UCHAR * descriptor_structure, UINT descriptor_entries, UINT size_align_mask) +{ + +ULONG size = 0; +ULONG entry_size; + + /* Loop on all the entries in this descriptor. */ + while(descriptor_entries--) + { + + /* Get entry size. */ + entry_size = (ULONG)*descriptor_structure ++; + + /* Check the size then build the component from the source and + insert it into the target descriptor. */ + switch(entry_size) + { + + case 4: /* Fall through. */ + case 2: + + /* Padding zeros so address is aligned. */ + while(size & (entry_size - 1)) + size++; + + /* Add to the size. */ + size += entry_size; + break; + + case 1: + + /* Add to the size. */ + size += 1; + break; + + default: + + /* Invalid entry size. */ + return(0); + } + } + + /* Align the size. */ + size = (size + size_align_mask) & (~size_align_mask); + + /* Return the size. */ + return(size); +} diff --git a/common/core/src/ux_utility_memory_allocate.c b/common/core/src/ux_utility_memory_allocate.c index 48d8620..547b03d 100644 --- a/common/core/src/ux_utility_memory_allocate.c +++ b/common/core/src/ux_utility_memory_allocate.c @@ -33,7 +33,7 @@ /* FUNCTION RELEASE */ /* */ /* _ux_utility_memory_allocate PORTABLE C */ -/* 6.1.11 */ +/* 6.x */ /* AUTHOR */ /* */ /* Chaoqiong Xiao, Microsoft Corporation */ @@ -77,6 +77,9 @@ /* 04-25-2022 Chaoqiong Xiao Modified comment(s), */ /* internal clean up, */ /* resulting in version 6.1.11 */ +/* xx-xx-xxxx Chaoqiong Xiao Modified comment(s), */ +/* fixed issue in 64-bit env, */ +/* resulting in version 6.x */ /* */ /**************************************************************************/ VOID *_ux_utility_memory_allocate(ULONG memory_alignment, ULONG memory_cache_flag, @@ -306,7 +309,7 @@ ALIGN_TYPE int_memory_buffer; { /* Setup the leftover memory block. */ - leftover_memory_block = (UX_MEMORY_BLOCK *) (((ALIGN_TYPE) new_memory_block + sizeof(UX_MEMORY_BLOCK) + memory_size_requested) & 0xFFFFFFFFu); + leftover_memory_block = (UX_MEMORY_BLOCK *) (((ALIGN_TYPE) new_memory_block + sizeof(UX_MEMORY_BLOCK) + memory_size_requested)); leftover_memory_block -> ux_memory_block_next = new_memory_block -> ux_memory_block_next; leftover_memory_block -> ux_memory_block_previous = new_memory_block; leftover_memory_block -> ux_memory_block_size = leftover - (ULONG)sizeof(UX_MEMORY_BLOCK); |
