1 /***************************************************************************
2  * Copyright (c) 2024 Microsoft Corporation
3  *
4  * This program and the accompanying materials are made available under the
5  * terms of the MIT License which is available at
6  * https://opensource.org/licenses/MIT.
7  *
8  * SPDX-License-Identifier: MIT
9  **************************************************************************/
10 
11 
12 /**************************************************************************/
13 /**************************************************************************/
14 /**                                                                       */
15 /** USBX Component                                                        */
16 /**                                                                       */
17 /**   Device Data Pump Class                                              */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 
23 /**************************************************************************/
24 /*                                                                        */
25 /*  COMPONENT DEFINITION                                   RELEASE        */
26 /*                                                                        */
27 /*    ux_device_class_dpump.h                             PORTABLE C      */
28 /*                                                           6.3.0        */
29 /*  AUTHOR                                                                */
30 /*                                                                        */
31 /*    Chaoqiong Xiao, Microsoft Corporation                               */
32 /*                                                                        */
33 /*  DESCRIPTION                                                           */
34 /*                                                                        */
35 /*    This file contains all the header and extern functions used by the  */
36 /*    USBX device dpump class.                                            */
37 /*                                                                        */
38 /*  RELEASE HISTORY                                                       */
39 /*                                                                        */
40 /*    DATE              NAME                      DESCRIPTION             */
41 /*                                                                        */
42 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
43 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
44 /*                                            resulting in version 6.1    */
45 /*  08-02-2021     Wen Wang                 Modified comment(s),          */
46 /*                                            added extern "C" keyword    */
47 /*                                            for compatibility with C++, */
48 /*                                            resulting in version 6.1.8  */
49 /*  01-31-2022     Chaoqiong Xiao           Modified comment(s),          */
50 /*                                            added standalone support,   */
51 /*                                            resulting in version 6.1.10 */
52 /*  10-31-2023     Chaoqiong Xiao           Modified comment(s),          */
53 /*                                            added a new mode to manage  */
54 /*                                            endpoint buffer in classes, */
55 /*                                            resulting in version 6.3.0  */
56 /*                                                                        */
57 /**************************************************************************/
58 
59 #ifndef UX_DEVICE_CLASS_DPUMP_H
60 #define UX_DEVICE_CLASS_DPUMP_H
61 
62 /* Determine if a C++ compiler is being used.  If so, ensure that standard
63    C is used to process the API information.  */
64 
65 #ifdef   __cplusplus
66 
67 /* Yes, C++ compiler is present.  Use standard C.  */
68 extern   "C" {
69 
70 #endif
71 
72 
73 /* Bulk out endpoint / read buffer size, must be larger than max packet size in framework, and aligned in 4-bytes.  */
74 #define UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE                  UX_SLAVE_REQUEST_DATA_MAX_LENGTH
75 
76 /* Bulk in endpoint / write buffer size, must be larger than max packet size in framework, and aligned in 4-bytes.  */
77 #define UX_DEVICE_CLASS_DPUMP_WRITE_BUFFER_SIZE                 UX_SLAVE_REQUEST_DATA_MAX_LENGTH
78 
79 
80 /* Define Storage Class USB Class constants.  */
81 
82 #define UX_SLAVE_CLASS_DPUMP_CLASS                              0x99
83 #define UX_SLAVE_CLASS_DPUMP_SUBCLASS                           0x99
84 #define UX_SLAVE_CLASS_DPUMP_PROTOCOL                           0x99
85 
86 /* Define Data Pump Class packet equivalences.  */
87 #define UX_DEVICE_CLASS_DPUMP_PACKET_SIZE                       128
88 
89 
90 /* Define Slave DPUMP Class Calling Parameter structure */
91 
92 typedef struct UX_SLAVE_CLASS_DPUMP_PARAMETER_STRUCT
93 {
94     VOID                    (*ux_slave_class_dpump_instance_activate)(VOID *);
95     VOID                    (*ux_slave_class_dpump_instance_deactivate)(VOID *);
96 
97 } UX_SLAVE_CLASS_DPUMP_PARAMETER;
98 
99 /* Define Slave Data Pump Class structure.  */
100 
101 typedef struct UX_SLAVE_CLASS_DPUMP_STRUCT
102 {
103     UX_SLAVE_INTERFACE                  *ux_slave_class_dpump_interface;
104     UX_SLAVE_CLASS_DPUMP_PARAMETER      ux_slave_class_dpump_parameter;
105     UX_SLAVE_ENDPOINT                   *ux_slave_class_dpump_bulkin_endpoint;
106     UX_SLAVE_ENDPOINT                   *ux_slave_class_dpump_bulkout_endpoint;
107 #if UX_DEVICE_ENDPOINT_BUFFER_OWNER == 1
108     UCHAR                               *ux_device_class_dpump_endpoint_buffer;
109 #endif
110     ULONG                               ux_slave_class_dpump_alternate_setting;
111 #if defined(UX_DEVICE_STANDALONE)
112     UCHAR                               *ux_device_class_dpump_write_buffer;
113     ULONG                               ux_device_class_dpump_write_requested_length;
114     ULONG                               ux_device_class_dpump_write_transfer_length;
115     ULONG                               ux_device_class_dpump_write_actual_length;
116     UINT                                ux_device_class_dpump_write_state;
117     UINT                                ux_device_class_dpump_write_status;
118     UCHAR                               *ux_device_class_dpump_read_buffer;
119     ULONG                               ux_device_class_dpump_read_requested_length;
120     ULONG                               ux_device_class_dpump_read_transfer_length;
121     ULONG                               ux_device_class_dpump_read_actual_length;
122     UINT                                ux_device_class_dpump_read_state;
123     UINT                                ux_device_class_dpump_read_status;
124 #endif
125 } UX_SLAVE_CLASS_DPUMP;
126 
127 /* Defined for endpoint buffer settings (when DPUMP owns buffer).  */
128 #define UX_DEVICE_CLASS_DPUMP_ENDPOINT_BUFFER_SIZE_CALC_OVERFLOW                \
129     (UX_OVERFLOW_CHECK_ADD_ULONG(UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE,        \
130                                  UX_DEVICE_CLASS_DPUMP_WRITE_BUFFER_SIZE))
131 #define UX_DEVICE_CLASS_DPUMP_ENDPOINT_BUFFER_SIZE  (UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE + UX_DEVICE_CLASS_DPUMP_WRITE_BUFFER_SIZE)
132 #define UX_DEVICE_CLASS_DPUMP_READ_BUFFER(dpump)    ((dpump)->ux_device_class_dpump_endpoint_buffer)
133 #define UX_DEVICE_CLASS_DPUMP_WRITE_BUFFER(dpump)   (UX_DEVICE_CLASS_DPUMP_READ_BUFFER(dpump) + UX_DEVICE_CLASS_DPUMP_READ_BUFFER_SIZE)
134 
135 
136 /* Define Device Data Pump Class prototypes.  */
137 
138 UINT    _ux_device_class_dpump_initialize(UX_SLAVE_CLASS_COMMAND *command);
139 UINT    _ux_device_class_dpump_activate(UX_SLAVE_CLASS_COMMAND *command);
140 UINT    _ux_device_class_dpump_deactivate(UX_SLAVE_CLASS_COMMAND *command);
141 UINT    _ux_device_class_dpump_entry(UX_SLAVE_CLASS_COMMAND *command);
142 UINT    _ux_device_class_dpump_read(UX_SLAVE_CLASS_DPUMP *dpump, UCHAR *buffer,
143                                 ULONG requested_length, ULONG *actual_length);
144 UINT    _ux_device_class_dpump_read_run(UX_SLAVE_CLASS_DPUMP *dpump, UCHAR *buffer,
145                                 ULONG requested_length, ULONG *actual_length);
146 UINT    _ux_device_class_dpump_write(UX_SLAVE_CLASS_DPUMP *dpump, UCHAR *buffer,
147                                 ULONG requested_length, ULONG *actual_length);
148 UINT    _ux_device_class_dpump_write_run(UX_SLAVE_CLASS_DPUMP *dpump, UCHAR *buffer,
149                                 ULONG requested_length, ULONG *actual_length);
150 UINT    _ux_device_class_dpump_change(UX_SLAVE_CLASS_COMMAND *command);
151 
152 /* Define Device DPUMP Class API prototypes.  */
153 
154 #define ux_device_class_dpump_entry                               _ux_device_class_dpump_entry
155 #define ux_device_class_dpump_read                                _ux_device_class_dpump_read
156 #define ux_device_class_dpump_read_run                            _ux_device_class_dpump_read_run
157 #define ux_device_class_dpump_write                               _ux_device_class_dpump_write
158 #define ux_device_class_dpump_write_run                           _ux_device_class_dpump_write_run
159 
160 /* Determine if a C++ compiler is being used.  If so, complete the standard
161    C conditional started above.  */
162 #ifdef __cplusplus
163 }
164 #endif
165 
166 #endif
167