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 /** USBX Component */
15 /** */
16 /** Device Printer Class */
17 /** */
18 /**************************************************************************/
19 /**************************************************************************/
20
21 #define UX_SOURCE_CODE
22
23
24 /* Include necessary system files. */
25
26 #include "ux_api.h"
27 #include "ux_device_class_printer.h"
28 #include "ux_device_stack.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _ux_device_class_printer_ioctl PORTABLE C */
36 /* 6.2.1 */
37 /* AUTHOR */
38 /* */
39 /* Chaoqiong Xiao, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function performs certain functions on the printer instance */
44 /* */
45 /* INPUT */
46 /* */
47 /* printer Address of printer class */
48 /* instance */
49 /* ioctl_function Ioctl function */
50 /* Parameter Parameter of ioctl function */
51 /* */
52 /* OUTPUT */
53 /* */
54 /* Status */
55 /* */
56 /* CALLS */
57 /* */
58 /* None */
59 /* */
60 /* CALLED BY */
61 /* */
62 /* Application */
63 /* */
64 /* RELEASE HISTORY */
65 /* */
66 /* DATE NAME DESCRIPTION */
67 /* */
68 /* 01-31-2022 Chaoqiong Xiao Initial Version 6.1.10 */
69 /* 03-08-2023 Yajun Xia Modified comment(s), */
70 /* resulting in version 6.2.1 */
71 /* */
72 /**************************************************************************/
_ux_device_class_printer_ioctl(UX_DEVICE_CLASS_PRINTER * printer,ULONG ioctl_function,VOID * parameter)73 UINT _ux_device_class_printer_ioctl(UX_DEVICE_CLASS_PRINTER *printer, ULONG ioctl_function,
74 VOID *parameter)
75 {
76
77 UINT status;
78 UX_SLAVE_ENDPOINT *endpoint;
79 UX_SLAVE_TRANSFER *transfer;
80
81
82 /* Default to success. */
83 status = UX_SUCCESS;
84
85 /* The command request will tell us what we need to do here. */
86 switch (ioctl_function)
87 {
88 case UX_DEVICE_CLASS_PRINTER_IOCTL_PORT_STATUS_SET:
89
90 /* Set port status. */
91 printer -> ux_device_class_printer_port_status = (ULONG)(UCHAR)(ALIGN_TYPE)parameter;
92 break;
93
94 case UX_DEVICE_CLASS_PRINTER_IOCTL_READ_TIMEOUT_SET:
95
96 /* Set endpoint transfer timeout. */
97 endpoint = printer -> ux_device_class_printer_endpoint_out;
98 transfer = &endpoint -> ux_slave_endpoint_transfer_request;
99 transfer -> ux_slave_transfer_request_timeout = (ULONG)(ALIGN_TYPE)parameter;
100 break;
101
102 case UX_DEVICE_CLASS_PRINTER_IOCTL_WRITE_TIMEOUT_SET:
103
104 /* Set endpoint transfer timeout (if exist). */
105 endpoint = printer -> ux_device_class_printer_endpoint_in;
106 if (endpoint != UX_NULL)
107 {
108 transfer = &endpoint -> ux_slave_endpoint_transfer_request;
109 transfer -> ux_slave_transfer_request_timeout = (ULONG)(ALIGN_TYPE)parameter;
110 }
111 break;
112
113 default:
114
115 /* Error trap. */
116 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED);
117
118 /* If trace is enabled, insert this event into the trace buffer. */
119 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
120
121 /* Function not supported. Return an error. */
122 status = UX_FUNCTION_NOT_SUPPORTED;
123 break;
124 }
125
126 /* Return status to caller. */
127 return(status);
128
129 }
130
131 /**************************************************************************/
132 /* */
133 /* FUNCTION RELEASE */
134 /* */
135 /* _uxe_device_class_printer_ioctl PORTABLE C */
136 /* 6.2.1 */
137 /* AUTHOR */
138 /* */
139 /* Yajun Xia, Microsoft Corporation */
140 /* */
141 /* DESCRIPTION */
142 /* */
143 /* This function checks errors in printer class ioctl function */
144 /* */
145 /* INPUT */
146 /* */
147 /* printer Address of printer class */
148 /* instance */
149 /* ioctl_function Ioctl function */
150 /* Parameter Parameter of ioctl function */
151 /* */
152 /* OUTPUT */
153 /* */
154 /* Status */
155 /* */
156 /* CALLS */
157 /* */
158 /* _ux_device_class_printer_ioctl Printer class ioctl function */
159 /* */
160 /* CALLED BY */
161 /* */
162 /* Application */
163 /* */
164 /* RELEASE HISTORY */
165 /* */
166 /* DATE NAME DESCRIPTION */
167 /* */
168 /* 03-08-2023 Yajun Xia Initial Version 6.2.1 */
169 /* */
170 /**************************************************************************/
_uxe_device_class_printer_ioctl(UX_DEVICE_CLASS_PRINTER * printer,ULONG ioctl_function,VOID * parameter)171 UINT _uxe_device_class_printer_ioctl(UX_DEVICE_CLASS_PRINTER *printer, ULONG ioctl_function,
172 VOID *parameter)
173 {
174
175 /* Sanity checks. */
176 if (printer == UX_NULL)
177 {
178 return (UX_INVALID_PARAMETER);
179 }
180
181 return (_ux_device_class_printer_ioctl(printer, ioctl_function, parameter));
182 }