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 /**   PROLIFIC Class                                                      */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 
23 /**************************************************************************/
24 /*                                                                        */
25 /*  COMPONENT DEFINITION                                   RELEASE        */
26 /*                                                                        */
27 /*    ux_host_class_prolific.h                            PORTABLE C      */
28 /*                                                           6.1.8        */
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 PROLIFIC 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 /*                                            used UX prefix to refer to  */
45 /*                                            TX symbols instead of using */
46 /*                                            them directly,              */
47 /*                                            resulting in version 6.1    */
48 /*  08-02-2021     Wen Wang                 Modified comment(s),          */
49 /*                                            added extern "C" keyword    */
50 /*                                            for compatibility with C++, */
51 /*                                            resulting in version 6.1.8  */
52 /*                                                                        */
53 /**************************************************************************/
54 
55 #ifndef UX_HOST_CLASS_PROLIFIC_H
56 #define UX_HOST_CLASS_PROLIFIC_H
57 
58 /* Determine if a C++ compiler is being used.  If so, ensure that standard
59    C is used to process the API information.  */
60 
61 #ifdef   __cplusplus
62 
63 /* Yes, C++ compiler is present.  Use standard C.  */
64 extern   "C" {
65 
66 #endif
67 
68 
69 /* Internal option: enable the basic USBX error checking. This define is typically used
70    while debugging application.  */
71 #if defined(UX_ENABLE_ERROR_CHECKING) && !defined(UX_HOST_CLASS_PROLIFIC_ENABLE_ERROR_CHECKING)
72 #define UX_HOST_CLASS_PROLIFIC_ENABLE_ERROR_CHECKING
73 #endif
74 
75 
76 /* Define PROLIFIC Class constants.  */
77 
78 #define UX_HOST_CLASS_PROLIFIC_DEVICE_INIT_DELAY                (1 * UX_PERIODIC_RATE)
79 #define UX_HOST_CLASS_PROLIFIC_CLASS_TRANSFER_TIMEOUT           300000
80 #define UX_HOST_CLASS_PROLIFIC_SETUP_BUFFER_SIZE                16
81 #define UX_HOST_CLASS_PROLIFIC_DEVICE_PRESENT                   1
82 #define UX_HOST_CLASS_PROLIFIC_DEVICE_NOT_PRESENT               0
83 #define UX_HOST_CLASS_PROLIFIC_DEVICE_STATE_OFFSET              8
84 #define UX_HOST_CLASS_PROLIFIC_DEVICE_STATE_MASK                0x7F
85 #define UX_HOST_CLASS_PROLIFIC_DEVICE_TYPE_0                    0
86 #define UX_HOST_CLASS_PROLIFIC_DEVICE_TYPE_1                    1
87 #define UX_HOST_CLASS_PROLIFIC_DEVICE_TYPE_HX                   2
88 #define UX_HOST_CLASS_PROLIFIC_VENDOR_READ_REQUEST              1
89 #define UX_HOST_CLASS_PROLIFIC_VENDOR_WRITE_REQUEST             1
90 
91 /* Define PROLIFIC Class descriptor subtypes in functional descriptors.  */
92 #define UX_HOST_CLASS_PROLIFIC_HEADER_DESCRIPTOR                0X00
93 #define UX_HOST_CLASS_PROLIFIC_CALL_MANAGEMENT_DESCRIPTOR       0X01
94 #define UX_HOST_CLASS_PROLIFIC_ABSTRACT_CONTROL_MGT_DESCRIPTOR  0X02
95 #define UX_HOST_CLASS_PROLIFIC_DIRECT_LINE_MGT_DESCRIPTOR       0X03
96 #define UX_HOST_CLASS_PROLIFIC_TELEPHONE_RINGER_DESCRIPTOR      0X04
97 #define UX_HOST_CLASS_PROLIFIC_REPORT_CAPABILITY_DESCRIPTOR     0X05
98 #define UX_HOST_CLASS_PROLIFIC_UNION_DESCRIPTOR                 0X06
99 #define UX_HOST_CLASS_PROLIFIC_COUNTRY_SELECTION_DESCRIPTOR     0X07
100 #define UX_HOST_CLASS_PROLIFIC_TELEPHONE_OPERATIONAL_DESCRIPTOR 0X08
101 #define UX_HOST_CLASS_PROLIFIC_USB_TERMINAL_DESCRIPTOR          0X09
102 
103 /* Define PROLIFIC Class call management descriptors.  */
104 #define UX_HOST_CLASS_PROLIFIC_CALL_MANAGEMENT_CAPABILITIES     0x03
105 #define UX_HOST_CLASS_PROLIFIC_CALL_MANAGEMENT_DCM              0x01
106 #define UX_HOST_CLASS_PROLIFIC_CALL_MANAGEMENT_DCI              0x02
107 
108 /* Define PROLIFIC command request values.  */
109 
110 #define UX_HOST_CLASS_PROLIFIC_REQ_SEND_ENCAPSULATED_COMMAND    0x00
111 #define UX_HOST_CLASS_PROLIFIC_REQ_GET_ENCAPSULATED_COMMAND     0x01
112 #define UX_HOST_CLASS_PROLIFIC_REQ_SET_COMM_FEATURE             0x02
113 #define UX_HOST_CLASS_PROLIFIC_REQ_GET_COMM_FEATURE             0x03
114 #define UX_HOST_CLASS_PROLIFIC_REQ_CLEAR_COMM_FEATURE           0x04
115 #define UX_HOST_CLASS_PROLIFIC_REQ_SET_AUX_LINE_STATE           0x10
116 #define UX_HOST_CLASS_PROLIFIC_REQ_SET_HOOK_STATE               0x11
117 #define UX_HOST_CLASS_PROLIFIC_REQ_PULSE_SETUP                  0x12
118 #define UX_HOST_CLASS_PROLIFIC_REQ_SEND_PULSE                   0x13
119 #define UX_HOST_CLASS_PROLIFIC_REQ_SET_PUSLE_TIME               0x14
120 #define UX_HOST_CLASS_PROLIFIC_REQ_RING_AUX_JACK                0x15
121 #define UX_HOST_CLASS_PROLIFIC_REQ_SET_LINE_CODING              0x20
122 #define UX_HOST_CLASS_PROLIFIC_REQ_GET_LINE_CODING              0x21
123 #define UX_HOST_CLASS_PROLIFIC_REQ_SET_LINE_STATE               0x22
124 #define UX_HOST_CLASS_PROLIFIC_REQ_SEND_BREAK                   0x23
125 #define UX_HOST_CLASS_PROLIFIC_REQ_SET_RINGER_PARMS             0x30
126 #define UX_HOST_CLASS_PROLIFIC_REQ_GET_RINGER_PARMS             0x31
127 #define UX_HOST_CLASS_PROLIFIC_REQ_SET_OPERATION_PARMS          0x32
128 #define UX_HOST_CLASS_PROLIFIC_REQ_GET_OPERATION_PARMS          0x33
129 #define UX_HOST_CLASS_PROLIFIC_REQ_SET_LINE_PARMS               0x34
130 #define UX_HOST_CLASS_PROLIFIC_REQ_GET_LINE_PARMS               0x35
131 
132 /* Define  PROLIFIC line output control values.  */
133 
134 #define UX_HOST_CLASS_PROLIFIC_CTRL_DTR                         0x01
135 #define UX_HOST_CLASS_PROLIFIC_CTRL_RTS                         0x02
136 
137 /* Define  PROLIFIC line input control values.  */
138 
139 #define UX_HOST_CLASS_PROLIFIC_CTRL_DCD                         0x01
140 #define UX_HOST_CLASS_PROLIFIC_CTRL_DSR                         0x02
141 #define UX_HOST_CLASS_PROLIFIC_CTRL_BRK                         0x04
142 #define UX_HOST_CLASS_PROLIFIC_CTRL_RI                          0x08
143 
144 #define UX_HOST_CLASS_PROLIFIC_CTRL_FRAMING                     0x10
145 #define UX_HOST_CLASS_PROLIFIC_CTRL_PARITY                      0x20
146 #define UX_HOST_CLASS_PROLIFIC_CTRL_OVERRUN                     0x40
147 
148 #define    UX_HOST_CLASS_PROLIFIC_COMMAND_EEPROM_READ           0x8484
149 #define    UX_HOST_CLASS_PROLIFIC_COMMAND_EEPROM_WRITE          0x0404
150 #define    UX_HOST_CLASS_PROLIFIC_COMMAND_EEPROM_ADDRESS        0x8383
151 #define    UX_HOST_CLASS_PROLIFIC_COMMAND_REG_CONFIGURE         0x0002
152 #define    UX_HOST_CLASS_PROLIFIC_COMMAND_PIPE1_RESET           0x0008
153 #define    UX_HOST_CLASS_PROLIFIC_COMMAND_PIPE2_RESET           0x0009
154 
155 /* Define  PROLIFIC Class packet equivalences.  */
156 
157 #define UX_HOST_CLASS_PROLIFIC_PACKET_SIZE                      128
158 
159 /* Define  PROLIFIC default values.  */
160 
161 #define UX_HOST_CLASS_PROLIFIC_LINE_CODING_DEFAULT_RATE         19200
162 #define UX_HOST_CLASS_PROLIFIC_LINE_CODING_DEFAULT_DATA_BIT     8
163 
164 /* Define  PROLIFIC line coding definitions.  */
165 
166 #define UX_HOST_CLASS_PROLIFIC_LINE_CODING_STOP_BIT_0           0
167 #define UX_HOST_CLASS_PROLIFIC_LINE_CODING_STOP_BIT_15          1
168 #define UX_HOST_CLASS_PROLIFIC_LINE_CODING_STOP_BIT_2           2
169 
170 #define UX_HOST_CLASS_PROLIFIC_LINE_CODING_PARITY_NONE          0
171 #define UX_HOST_CLASS_PROLIFIC_LINE_CODING_PARITY_ODD           1
172 #define UX_HOST_CLASS_PROLIFIC_LINE_CODING_PARITY_EVEN          2
173 #define UX_HOST_CLASS_PROLIFIC_LINE_CODING_PARITY_MARK          3
174 #define UX_HOST_CLASS_PROLIFIC_LINE_CODING_PARITY_SPACE         4
175 
176 #define UX_HOST_CLASS_PROLIFIC_LINE_CODING_LENGTH               7
177 #define UX_HOST_CLASS_PROLIFIC_LINE_CODING_RATE                 0
178 #define UX_HOST_CLASS_PROLIFIC_LINE_CODING_STOP_BIT             4
179 #define UX_HOST_CLASS_PROLIFIC_LINE_CODING_PARITY               5
180 #define UX_HOST_CLASS_PROLIFIC_LINE_CODING_DATA_BIT             6
181 
182 /* Define  PROLIFIC line state definitions.  */
183 
184 #define UX_HOST_CLASS_PROLIFIC_LINE_STATE_STOP_BIT_0            0
185 #define UX_HOST_CLASS_PROLIFIC_LINE_CODING_STOP_BIT_15          1
186 
187 /* Define  PROLIFIC IOCTL Functions. */
188 
189 #define UX_HOST_CLASS_PROLIFIC_IOCTL_SET_LINE_CODING            0
190 #define UX_HOST_CLASS_PROLIFIC_IOCTL_GET_LINE_CODING            1
191 #define UX_HOST_CLASS_PROLIFIC_IOCTL_SET_LINE_STATE             2
192 #define UX_HOST_CLASS_PROLIFIC_IOCTL_SEND_BREAK                 3
193 #define UX_HOST_CLASS_PROLIFIC_IOCTL_PURGE                      4
194 #define UX_HOST_CLASS_PROLIFIC_IOCTL_ABORT_IN_PIPE              5
195 #define UX_HOST_CLASS_PROLIFIC_IOCTL_ABORT_OUT_PIPE             6
196 #define UX_HOST_CLASS_PROLIFIC_IOCTL_REPORT_DEVICE_STATUS_CHANGE 7
197 #define UX_HOST_CLASS_PROLIFIC_IOCTL_GET_DEVICE_STATUS          8
198 
199 /* Define  PROLIFIC Reception States. */
200 
201 #define UX_HOST_CLASS_PROLIFIC_RECEPTION_STATE_STOPPED          0
202 #define UX_HOST_CLASS_PROLIFIC_RECEPTION_STATE_STARTED          1
203 #define UX_HOST_CLASS_PROLIFIC_RECEPTION_STATE_IN_TRANSFER      2
204 
205 
206 /* Define  PROLIFIC Class instance structure.  */
207 
208 typedef struct UX_HOST_CLASS_PROLIFIC_STRUCT
209 {
210     struct UX_HOST_CLASS_PROLIFIC_STRUCT
211                     *ux_host_class_prolific_next_instance;
212     UX_HOST_CLASS   *ux_host_class_prolific_class;
213     UX_DEVICE       *ux_host_class_prolific_device;
214     UX_ENDPOINT     *ux_host_class_prolific_bulk_in_endpoint;
215     UX_ENDPOINT     *ux_host_class_prolific_bulk_out_endpoint;
216     UX_ENDPOINT     *ux_host_class_prolific_interrupt_endpoint;
217     UX_INTERFACE    *ux_host_class_prolific_interface;
218     UINT            ux_host_class_prolific_instance_status;
219     UINT            ux_host_class_prolific_state;
220     UX_SEMAPHORE    ux_host_class_prolific_semaphore;
221     ULONG           ux_host_class_prolific_notification_count;
222     ULONG           ux_host_class_prolific_device_state;
223     VOID            (*ux_host_class_prolific_device_status_change_callback)(struct UX_HOST_CLASS_PROLIFIC_STRUCT *prolific,
224                                                                 ULONG  device_state);
225 
226     ULONG           ux_host_class_prolific_version;
227     UCHAR           ux_host_class_prolific_device_type;
228     struct UX_HOST_CLASS_PROLIFIC_RECEPTION_STRUCT
229                     *ux_host_class_prolific_reception;
230 
231 } UX_HOST_CLASS_PROLIFIC;
232 
233 
234 /* Define  PROLIFIC reception structure. */
235 
236 typedef struct UX_HOST_CLASS_PROLIFIC_RECEPTION_STRUCT
237 {
238 
239     ULONG            ux_host_class_prolific_reception_state;
240     ULONG            ux_host_class_prolific_reception_block_size;
241     UCHAR            *ux_host_class_prolific_reception_data_buffer;
242     ULONG            ux_host_class_prolific_reception_data_buffer_size;
243     UCHAR            *ux_host_class_prolific_reception_data_head;
244     UCHAR            *ux_host_class_prolific_reception_data_tail;
245     VOID            (*ux_host_class_prolific_reception_callback)(struct UX_HOST_CLASS_PROLIFIC_STRUCT *prolific,
246                                                                 UINT  status,
247                                                                 UCHAR *reception_buffer,
248                                                                 ULONG reception_size);
249 
250 } UX_HOST_CLASS_PROLIFIC_RECEPTION;
251 
252 /* Define  PROLIFIC Line Coding IOCTL structure.  */
253 
254 typedef struct UX_HOST_CLASS_PROLIFIC_LINE_CODING_STRUCT
255 {
256 
257     ULONG            ux_host_class_prolific_line_coding_dter;
258     ULONG            ux_host_class_prolific_line_coding_stop_bit;
259     ULONG            ux_host_class_prolific_line_coding_parity;
260     ULONG            ux_host_class_prolific_line_coding_data_bits;
261 
262 } UX_HOST_CLASS_PROLIFIC_LINE_CODING;
263 
264 /* Define  PROLIFIC Line State IOCTL structure.  */
265 
266 typedef struct UX_HOST_CLASS_PROLIFIC_LINE_STATE_STRUCT
267 {
268 
269     ULONG            ux_host_class_prolific_line_state_rts;
270     ULONG            ux_host_class_prolific_line_state_dtr;
271 
272 } UX_HOST_CLASS_PROLIFIC_LINE_STATE;
273 
274 /* Define  PROLIFIC Line break IOCTL structure.  */
275 
276 typedef struct UX_HOST_CLASS_PROLIFIC_LINE_BREAK_STRUCT
277 {
278 
279     ULONG            ux_host_class_prolific_line_break;
280 
281 } UX_HOST_CLASS_PROLIFIC_LINE_BREAK;
282 
283 
284 /* Define Prolific Class function prototypes.  */
285 
286 UINT  _ux_host_class_prolific_activate(UX_HOST_CLASS_COMMAND *command);
287 UINT  _ux_host_class_prolific_configure(UX_HOST_CLASS_PROLIFIC *prolific);
288 UINT  _ux_host_class_prolific_deactivate(UX_HOST_CLASS_COMMAND *command);
289 UINT  _ux_host_class_prolific_endpoints_get(UX_HOST_CLASS_PROLIFIC *prolific);
290 UINT  _ux_host_class_prolific_entry(UX_HOST_CLASS_COMMAND *command);
291 UINT  _ux_host_class_prolific_read (UX_HOST_CLASS_PROLIFIC *prolific, UCHAR *data_pointer,
292                                   ULONG requested_length, ULONG *actual_length);
293 UINT  _ux_host_class_prolific_write(UX_HOST_CLASS_PROLIFIC *prolific, UCHAR *data_pointer,
294                                   ULONG requested_length, ULONG *actual_length);
295 UINT  _ux_host_class_prolific_ioctl(UX_HOST_CLASS_PROLIFIC *prolific, ULONG request,
296                                   VOID *parameter);
297 UINT  _ux_host_class_prolific_command(UX_HOST_CLASS_PROLIFIC *prolific, ULONG command,
298                                     ULONG value, UCHAR *data_buffer, ULONG data_length);
299 VOID  _ux_host_class_prolific_transfer_request_completed(UX_TRANSFER *transfer_request);
300 UINT  _ux_host_class_prolific_reception_stop (UX_HOST_CLASS_PROLIFIC *prolific,
301                                     UX_HOST_CLASS_PROLIFIC_RECEPTION *prolific_reception);
302 UINT  _ux_host_class_prolific_reception_start (UX_HOST_CLASS_PROLIFIC *prolific,
303                                     UX_HOST_CLASS_PROLIFIC_RECEPTION *prolific_reception);
304 
305 VOID  _ux_host_class_prolific_reception_callback (UX_TRANSFER *transfer_request);
306 UINT  _ux_host_class_prolific_setup(UX_HOST_CLASS_PROLIFIC *prolific);
307 
308 
309 UINT  _uxe_host_class_prolific_read (UX_HOST_CLASS_PROLIFIC *prolific, UCHAR *data_pointer,
310                                   ULONG requested_length, ULONG *actual_length);
311 UINT  _uxe_host_class_prolific_write(UX_HOST_CLASS_PROLIFIC *prolific, UCHAR *data_pointer,
312                                   ULONG requested_length, ULONG *actual_length);
313 UINT  _uxe_host_class_prolific_ioctl(UX_HOST_CLASS_PROLIFIC *prolific, ULONG request,
314                                   VOID *parameter);
315 UINT  _uxe_host_class_prolific_command(UX_HOST_CLASS_PROLIFIC *prolific, ULONG command,
316                                     ULONG value, UCHAR *data_buffer, ULONG data_length);
317 UINT  _uxe_host_class_prolific_reception_stop (UX_HOST_CLASS_PROLIFIC *prolific,
318                                     UX_HOST_CLASS_PROLIFIC_RECEPTION *prolific_reception);
319 UINT  _uxe_host_class_prolific_reception_start (UX_HOST_CLASS_PROLIFIC *prolific,
320                                     UX_HOST_CLASS_PROLIFIC_RECEPTION *prolific_reception);
321 
322 
323 /* Define Prolific Class API prototypes.  */
324 
325 #define  ux_host_class_prolific_entry                           _ux_host_class_prolific_entry
326 #define  ux_host_class_prolific_setup                           _ux_host_class_prolific_setup
327 
328 #if defined(UX_HOST_CLASS_PROLIFIC_ENABLE_ERROR_CHECKING)
329 
330 #define  ux_host_class_prolific_read                            _uxe_host_class_prolific_read
331 #define  ux_host_class_prolific_write                           _uxe_host_class_prolific_write
332 #define  ux_host_class_prolific_ioctl                           _uxe_host_class_prolific_ioctl
333 #define  ux_host_class_prolific_command                         _uxe_host_class_prolific_command
334 #define  ux_host_class_prolific_reception_stop                  _uxe_host_class_prolific_reception_stop
335 #define  ux_host_class_prolific_reception_start                 _uxe_host_class_prolific_reception_start
336 
337 #else
338 
339 #define  ux_host_class_prolific_read                            _ux_host_class_prolific_read
340 #define  ux_host_class_prolific_write                           _ux_host_class_prolific_write
341 #define  ux_host_class_prolific_ioctl                           _ux_host_class_prolific_ioctl
342 #define  ux_host_class_prolific_command                         _ux_host_class_prolific_command
343 #define  ux_host_class_prolific_reception_stop                  _ux_host_class_prolific_reception_stop
344 #define  ux_host_class_prolific_reception_start                 _ux_host_class_prolific_reception_start
345 
346 #endif
347 
348 /* Determine if a C++ compiler is being used.  If so, complete the standard
349    C conditional started above.  */
350 #ifdef __cplusplus
351 }
352 #endif
353 
354 #endif
355