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_pack                         PORTABLE C      */
36 /*                                                           6.1          */
37 /*  AUTHOR                                                                */
38 /*                                                                        */
39 /*    Chaoqiong Xiao, Microsoft Corporation                               */
40 /*                                                                        */
41 /*  DESCRIPTION                                                           */
42 /*                                                                        */
43 /*    This function will pack an application structure into a USB         */
44 /*    descriptor.                                                         */
45 /*                                                                        */
46 /*  INPUT                                                                 */
47 /*                                                                        */
48 /*    descriptor                            Pointer to the unpacked       */
49 /*                                            descriptor                  */
50 /*    descriptor_structure                  Components of the descriptor  */
51 /*    descriptor_entries                    Number of entries in the      */
52 /*                                            descriptor                  */
53 /*    raw_descriptor                        Pointer to packed descriptor  */
54 /*                                                                        */
55 /*  OUTPUT                                                                */
56 /*                                                                        */
57 /*    None                                                                */
58 /*                                                                        */
59 /*  CALLS                                                                 */
60 /*                                                                        */
61 /*    _ux_utility_long_put                  Put 32-bit value              */
62 /*    _ux_utility_short_put                 Put 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_pack(UCHAR * descriptor,UCHAR * descriptor_structure,UINT descriptor_entries,UCHAR * raw_descriptor)77 VOID  _ux_utility_descriptor_pack(UCHAR * descriptor, UCHAR * descriptor_structure,
78                         UINT descriptor_entries, UCHAR * raw_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             _ux_utility_long_put(raw_descriptor, *((ULONG *) descriptor));
94             raw_descriptor +=  4;
95             break;
96 
97         case 2:
98 
99             _ux_utility_short_put(raw_descriptor, (USHORT)*((ULONG *) descriptor));
100             raw_descriptor += 2;
101             break;
102 
103         default:
104 
105             *raw_descriptor =  (UCHAR) *((ULONG *) 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