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