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 /**   VIDEO Class                                                         */
18 /**                                                                       */
19 /**************************************************************************/
20 /**************************************************************************/
21 
22 
23 /* Include necessary system files.  */
24 
25 #define UX_SOURCE_CODE
26 
27 #include "ux_api.h"
28 #include "ux_host_class_video.h"
29 #include "ux_host_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_host_class_video_ioctl                          PORTABLE C      */
37 /*                                                           6.3.0        */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function is the ioctl entry point for the application to       */
45 /*    configure the video class based device.                             */
46 /*                                                                        */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    video                                 Pointer to video class        */
51 /*    ioctl_function                        Ioctl function                */
52 /*    parameter                             Pointer to structure          */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    Completion Status                                                   */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    _ux_host_class_video_format_data_get  Get video format data.        */
61 /*    _ux_host_class_video_frame_data_get   Get video frame data          */
62 /*    _ux_host_class_video_frame_interval_get                             */
63 /*                                          Get video frame internal data.*/
64 /*    _ux_host_class_video_channel_start    Start the video.              */
65 /*    _ux_host_class_video_stop             Stop the video.               */
66 /*    _ux_host_stack_endpoint_transfer_abort                              */
67 /*                                          Abort the transfer            */
68 /*    _ux_system_error_handler              Log system error              */
69 /*                                                                        */
70 /*  CALLED BY                                                             */
71 /*                                                                        */
72 /*    Application                                                         */
73 /*                                                                        */
74 /*  RELEASE HISTORY                                                       */
75 /*                                                                        */
76 /*    DATE              NAME                      DESCRIPTION             */
77 /*                                                                        */
78 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
79 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
80 /*                                            resulting in version 6.1    */
81 /*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
82 /*                                            reset indexes of requests   */
83 /*                                            ring when it is aborted,    */
84 /*                                            resulting in version 6.1.12 */
85 /*  10-31-2023     Yajun xia                Modified comment(s),          */
86 /*                                            resulting in version 6.3.0  */
87 /*                                                                        */
88 /**************************************************************************/
_ux_host_class_video_ioctl(UX_HOST_CLASS_VIDEO * video,ULONG ioctl_function,VOID * parameter)89 UINT  _ux_host_class_video_ioctl(UX_HOST_CLASS_VIDEO *video, ULONG ioctl_function,
90                                  VOID *parameter)
91 {
92 
93 UINT                                            status;
94 UX_HOST_CLASS_VIDEO_PARAMETER_INPUT_TERMINAL    *input_terminal;
95 UX_HOST_CLASS_VIDEO_PARAMETER_NUMBER_FORMATS    *number_formats;
96 UX_HOST_CLASS_VIDEO_PARAMETER_FORMAT_DATA       *format_parameter;
97 UX_HOST_CLASS_VIDEO_PARAMETER_FRAME_DATA        *frame_parameter;
98 UX_HOST_CLASS_VIDEO_PARAMETER_CHANNEL           *channel_parameter;
99 UX_HOST_CLASS_VIDEO_PARAMETER_FRAME_INTERVAL    *interval_parameter;
100 
101     /* Ensure the instance is valid.  */
102     if ((video -> ux_host_class_video_state !=  UX_HOST_CLASS_INSTANCE_LIVE) &&
103         (video -> ux_host_class_video_state !=  UX_HOST_CLASS_INSTANCE_MOUNTING))
104     {
105 
106         /* If trace is enabled, insert this event into the trace buffer.  */
107         //UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, video, 0, 0, UX_TRACE_ERRORS, 0, 0)
108 
109         return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
110     }
111 
112     /* The command request will tell us what we need to do here.  */
113     switch (ioctl_function)
114     {
115 
116     case UX_HOST_CLASS_VIDEO_IOCTL_GET_INPUT_TERMINAL:
117 
118         /* Set status to error by default.  */
119         status = UX_ERROR;
120 
121         /* Is the video terminal defined ? */
122         if (video -> ux_host_class_video_terminal_id != 0)
123         {
124 
125             /* Cast answer.  */
126             input_terminal = (UX_HOST_CLASS_VIDEO_PARAMETER_INPUT_TERMINAL *) parameter;
127 
128             /* Return input terminal id.  */
129             input_terminal -> ux_host_class_video_parameter_input_terminal_id = video -> ux_host_class_video_terminal_id;
130 
131             /* Return input terminal type.  */
132             input_terminal -> ux_host_class_video_parameter_input_terminal_type = video -> ux_host_class_video_terminal_type;
133 
134             /* Status ok.  */
135             status = UX_SUCCESS;
136         }
137 
138         break;
139 
140     case UX_HOST_CLASS_VIDEO_IOCTL_GET_FORMAT_NUMBER:
141 
142         /* Cast answer.  */
143         number_formats = (UX_HOST_CLASS_VIDEO_PARAMETER_NUMBER_FORMATS *) parameter;
144 
145         /* Save the number of formats.  */
146         number_formats -> ux_host_class_video_parameter_number_formats = video -> ux_host_class_video_number_formats;
147 
148         /* Status ok.  */
149         status = UX_SUCCESS;
150 
151         break;
152 
153     case UX_HOST_CLASS_VIDEO_IOCTL_GET_FORMAT_DATA:
154 
155         /* Cast answer.  */
156         format_parameter = (UX_HOST_CLASS_VIDEO_PARAMETER_FORMAT_DATA *) parameter;
157 
158         /* Get the format data for the format index requested.  */
159         status = _ux_host_class_video_format_data_get(video, format_parameter);
160         break;
161 
162     case UX_HOST_CLASS_VIDEO_IOCTL_GET_FRAME_DATA:
163 
164         /* Cast answer.  */
165         frame_parameter = (UX_HOST_CLASS_VIDEO_PARAMETER_FRAME_DATA *) parameter;
166 
167         /* Get the frame data for the frame index requested.  */
168         status = _ux_host_class_video_frame_data_get(video, frame_parameter);
169         break;
170 
171     case UX_HOST_CLASS_VIDEO_IOCTL_GET_FRAME_INTERVAL:
172 
173         /* Cast answer.  */
174         interval_parameter = (UX_HOST_CLASS_VIDEO_PARAMETER_FRAME_INTERVAL *) parameter;
175 
176         /* Get the frame intervals for the frame index requested.  */
177         status = _ux_host_class_video_frame_interval_get(video, interval_parameter);
178         break;
179 
180     case UX_HOST_CLASS_VIDEO_IOCTL_CHANNEL_START:
181 
182         /* Cast answer.  */
183         channel_parameter = (UX_HOST_CLASS_VIDEO_PARAMETER_CHANNEL *) parameter;
184 
185         /* Start the channel for reading video input.  */
186         status = _ux_host_class_video_channel_start(video, channel_parameter);
187         break;
188 
189     case UX_HOST_CLASS_VIDEO_IOCTL_CHANNEL_STOP:
190 
191         /* Stop the channel.  */
192         status = _ux_host_class_video_stop(video);
193         break;
194 
195 
196     case UX_HOST_CLASS_VIDEO_IOCTL_ABORT_IN_PIPE :
197 
198         /* If trace is enabled, insert this event into the trace buffer.  */
199         //UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_CLASS_VIDEO_IOCTL_ABORT_IN_PIPE, video, video -> ux_host_class_video_isochronous_endpoint, 0, 0, UX_TRACE_HOST_CLASS_EVENTS, 0, 0)
200 
201         /* We need to abort transactions on the bulk In pipe.  */
202         _ux_host_stack_endpoint_transfer_abort(video -> ux_host_class_video_isochronous_endpoint);
203 
204         /* All linked requests are aborted, reset indexes.  */
205         video -> ux_host_class_video_transfer_request_start_index = 0;
206         video -> ux_host_class_video_transfer_request_end_index = 0;
207 
208         /* Status is successful.  */
209         status = UX_SUCCESS;
210         break;
211 
212     default:
213 
214         /* Error trap. */
215         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_FUNCTION_NOT_SUPPORTED);
216 
217         /* If trace is enabled, insert this event into the trace buffer.  */
218         //UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
219 
220         /* Function not supported. Return an error.  */
221         status =  UX_FUNCTION_NOT_SUPPORTED;
222     }
223 
224     /* Return status to caller.  */
225     return(status);
226 }
227 
228 /**************************************************************************/
229 /*                                                                        */
230 /*  FUNCTION                                               RELEASE        */
231 /*                                                                        */
232 /*    _uxe_host_class_video_ioctl                         PORTABLE C      */
233 /*                                                           6.3.0        */
234 /*  AUTHOR                                                                */
235 /*                                                                        */
236 /*    Yajun Xia, Microsoft Corporation                                    */
237 /*                                                                        */
238 /*  DESCRIPTION                                                           */
239 /*                                                                        */
240 /*    This function checks errors in video ioctl function call.           */
241 /*                                                                        */
242 /*  INPUT                                                                 */
243 /*                                                                        */
244 /*    video                                 Pointer to video class        */
245 /*    ioctl_function                        Ioctl function                */
246 /*    parameter                             Pointer to structure          */
247 /*                                                                        */
248 /*  OUTPUT                                                                */
249 /*                                                                        */
250 /*    Completion Status                                                   */
251 /*                                                                        */
252 /*  CALLS                                                                 */
253 /*                                                                        */
254 /*    _ux_host_class_video_ioctl            Video ioctl                   */
255 /*                                                                        */
256 /*  CALLED BY                                                             */
257 /*                                                                        */
258 /*    Application                                                         */
259 /*                                                                        */
260 /*  RELEASE HISTORY                                                       */
261 /*                                                                        */
262 /*    DATE              NAME                      DESCRIPTION             */
263 /*                                                                        */
264 /*  10-31-2023        Yajun xia             Initial Version 6.3.0         */
265 /*                                                                        */
266 /**************************************************************************/
_uxe_host_class_video_ioctl(UX_HOST_CLASS_VIDEO * video,ULONG ioctl_function,VOID * parameter)267 UINT  _uxe_host_class_video_ioctl(UX_HOST_CLASS_VIDEO *video, ULONG ioctl_function,
268                                  VOID *parameter)
269 {
270 
271     /* Sanity checks.  */
272     if (video == UX_NULL)
273         return(UX_INVALID_PARAMETER);
274 
275     /* Call the actual video ioctl function.  */
276     return(_ux_host_class_video_ioctl(video, ioctl_function, parameter));
277 }