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