1 /**************************************************************************/
2 /* */
3 /* Copyright (c) Microsoft Corporation. All rights reserved. */
4 /* */
5 /* This software is licensed under the Microsoft Software License */
6 /* Terms for Microsoft Azure RTOS. Full text of the license can be */
7 /* found in the LICENSE file at https://aka.ms/AzureRTOS_EULA */
8 /* and in the root directory of this software. */
9 /* */
10 /**************************************************************************/
11
12
13 /**************************************************************************/
14 /**************************************************************************/
15 /** */
16 /** USBX Component */
17 /** */
18 /** Utility */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23
24 /* Include necessary system files. */
25
26 #define UX_SOURCE_CODE
27
28 #include "ux_api.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _ux_utility_descriptor_parse PORTABLE C */
36 /* 6.1 */
37 /* AUTHOR */
38 /* */
39 /* Chaoqiong Xiao, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function will unpack a USB descriptor from the bus into a */
44 /* memory aligned structure. */
45 /* */
46 /* INPUT */
47 /* */
48 /* raw_descriptor Pointer to packed descriptor */
49 /* descriptor_structure Components of the descriptor */
50 /* descriptor_entries Number of entries in the */
51 /* descriptor */
52 /* descriptor Pointer to the unpacked */
53 /* descriptor */
54 /* */
55 /* OUTPUT */
56 /* */
57 /* None */
58 /* */
59 /* CALLS */
60 /* */
61 /* _ux_utility_long_get Get 32-bit value */
62 /* _ux_utility_short_get Get 16-bit value */
63 /* */
64 /* CALLED BY */
65 /* */
66 /* USBX Components */
67 /* */
68 /* RELEASE HISTORY */
69 /* */
70 /* DATE NAME DESCRIPTION */
71 /* */
72 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
73 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
74 /* resulting in version 6.1 */
75 /* */
76 /**************************************************************************/
_ux_utility_descriptor_parse(UCHAR * raw_descriptor,UCHAR * descriptor_structure,UINT descriptor_entries,UCHAR * descriptor)77 VOID _ux_utility_descriptor_parse(UCHAR * raw_descriptor, UCHAR * descriptor_structure,
78 UINT descriptor_entries, UCHAR * descriptor)
79 {
80
81 /* Loop on all the entries in this descriptor. */
82 while(descriptor_entries--)
83 {
84
85 /* Get the length of that component. */
86 switch(*descriptor_structure++)
87 {
88
89 /* Check the size then build the component from the source and
90 insert it into the target descriptor. */
91 case 4:
92
93 *((ULONG *) descriptor) = _ux_utility_long_get(raw_descriptor);
94 raw_descriptor += 4;
95 break;
96
97 case 2:
98
99 *((ULONG *) descriptor) = (ULONG) _ux_utility_short_get(raw_descriptor);
100 raw_descriptor += 2;
101 break;
102
103 default:
104
105 *((ULONG *) descriptor) = (ULONG) *raw_descriptor;
106 raw_descriptor++;
107 }
108
109 /* Add the size of the component to the destination. */
110 descriptor += 4;
111 }
112
113 /* Return to caller. */
114 return;
115 }
116
117