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 /**   Host Data Pump 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_dpump.h"
29 #include "ux_host_stack.h"
30 
31 
32 /**************************************************************************/
33 /*                                                                        */
34 /*  FUNCTION                                               RELEASE        */
35 /*                                                                        */
36 /*    _ux_host_class_dpump_ioctl                          PORTABLE C      */
37 /*                                                           6.1.12       */
38 /*  AUTHOR                                                                */
39 /*                                                                        */
40 /*    Chaoqiong Xiao, Microsoft Corporation                               */
41 /*                                                                        */
42 /*  DESCRIPTION                                                           */
43 /*                                                                        */
44 /*    This function is called by the application to change the alternate  */
45 /*    setting of the dpump class.                                         */
46 /*                                                                        */
47 /*  INPUT                                                                 */
48 /*                                                                        */
49 /*    dpump                                 Pointer to the dpump class    */
50 /*    ioctl_function                        ioctl function                */
51 /*    parameter                             pointer to structure          */
52 /*                                                                        */
53 /*                                                                        */
54 /*  OUTPUT                                                                */
55 /*                                                                        */
56 /*    Completion Status                                                   */
57 /*                                                                        */
58 /*  CALLS                                                                 */
59 /*                                                                        */
60 /*    _ux_host_stack_interface_setting_select                             */
61 /*                                          Select alternate setting      */
62 /*                                                                        */
63 /*  CALLED BY                                                             */
64 /*                                                                        */
65 /*                                                                        */
66 /*  RELEASE HISTORY                                                       */
67 /*                                                                        */
68 /*    DATE              NAME                      DESCRIPTION             */
69 /*                                                                        */
70 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
71 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
72 /*                                            resulting in version 6.1    */
73 /*  07-29-2022     Chaoqiong Xiao           Modified comment(s),          */
74 /*                                            fixed parameter/variable    */
75 /*                                            names conflict C++ keyword, */
76 /*                                            resulting in version 6.1.12 */
77 /*                                                                        */
78 /**************************************************************************/
_ux_host_class_dpump_ioctl(UX_HOST_CLASS_DPUMP * dpump,ULONG ioctl_function,VOID * parameter)79 UINT  _ux_host_class_dpump_ioctl(UX_HOST_CLASS_DPUMP *dpump, ULONG ioctl_function,
80                                     VOID *parameter)
81 {
82 
83 UX_CONFIGURATION            *configuration;
84 UX_INTERFACE                *interface_ptr;
85 UINT                           status;
86 
87     /* Ensure the instance is valid.  */
88     if ((dpump -> ux_host_class_dpump_state !=  UX_HOST_CLASS_INSTANCE_LIVE) &&
89         (dpump -> ux_host_class_dpump_state !=  UX_HOST_CLASS_INSTANCE_MOUNTING))
90     {
91 
92         /* Error trap. */
93         _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
94 
95         /* If trace is enabled, insert this event into the trace buffer.  */
96         UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_INSTANCE_UNKNOWN, dpump, 0, 0, UX_TRACE_ERRORS, 0, 0)
97 
98         return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
99     }
100 
101     /* The command request will tell us we need to do here.  */
102     switch (ioctl_function)
103     {
104 
105         case UX_HOST_CLASS_DPUMP_SELECT_ALTERNATE_SETTING:
106 
107 
108             /* The parameter value has the alternate setting number.
109                We need to scan the entire device framework.  Only one configuration for data pump device framework.  */
110             interface_ptr = dpump -> ux_host_class_dpump_interface;
111             configuration = interface_ptr -> ux_interface_configuration;
112 
113             /* Do some verification just in case !  */
114             if (configuration == UX_NULL)
115             {
116 
117             /* Error trap. */
118             _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_HOST_CLASS_INSTANCE_UNKNOWN);
119 
120                 return(UX_HOST_CLASS_INSTANCE_UNKNOWN);
121             }
122 
123             /* Point to the first interface.  */
124             interface_ptr =  configuration -> ux_configuration_first_interface;
125 
126             /* Loop on all interfaces and alternate settings for this device in search of the right alternate setting.  */
127             while (interface_ptr != UX_NULL)
128             {
129 
130                 /* Check the alternate setting.  */
131                 if (interface_ptr -> ux_interface_descriptor.bAlternateSetting == (ULONG) (ALIGN_TYPE) parameter)
132                 {
133 
134                     /* We have found the alternate setting. Select it now.  */
135                     status =  _ux_host_stack_interface_setting_select(interface_ptr);
136 
137                     /* We are done here.  */
138                     return(status);
139                 }
140 
141                 /* Next interface.  */
142                 interface_ptr = interface_ptr -> ux_interface_next_interface;
143             }
144 
145             /* We come here when the alternate setting was not found.  */
146             status = UX_INTERFACE_HANDLE_UNKNOWN;
147 
148             /* Error trap. */
149             _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, status);
150 
151             break;
152 
153         default:
154 
155             /* If trace is enabled, insert this event into the trace buffer.  */
156             UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_FUNCTION_NOT_SUPPORTED, 0, 0, 0, UX_TRACE_ERRORS, 0, 0)
157 
158             /* Function not supported. Return an error.  */
159             status =  UX_FUNCTION_NOT_SUPPORTED;
160 
161             /* Error trap. */
162             _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, status);
163 
164     }
165 
166     /* Return status to caller.  */
167     return(status);
168 }
169 
170