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 Stack */
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_stack.h"
29
30
31 /**************************************************************************/
32 /* */
33 /* FUNCTION RELEASE */
34 /* */
35 /* _ux_host_stack_device_configuration_get PORTABLE C */
36 /* 6.1 */
37 /* AUTHOR */
38 /* */
39 /* Chaoqiong Xiao, Microsoft Corporation */
40 /* */
41 /* DESCRIPTION */
42 /* */
43 /* This function returns a configuration container based on a device */
44 /* handle and a configuration index. */
45 /* */
46 /* INPUT */
47 /* */
48 /* device Pointer to device */
49 /* configuration_index Index of configuration */
50 /* configuration Pointer to configuration */
51 /* destination */
52 /* */
53 /* OUTPUT */
54 /* */
55 /* Completion Status */
56 /* */
57 /* CALLS */
58 /* */
59 /* None */
60 /* */
61 /* CALLED BY */
62 /* */
63 /* Application */
64 /* USBX Components */
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 /* */
74 /**************************************************************************/
_ux_host_stack_device_configuration_get(UX_DEVICE * device,UINT configuration_index,UX_CONFIGURATION ** configuration)75 UINT _ux_host_stack_device_configuration_get(UX_DEVICE *device, UINT configuration_index,
76 UX_CONFIGURATION **configuration)
77 {
78
79 UINT current_configuration_index;
80 UX_CONFIGURATION *current_configuration;
81
82 /* Do a sanity check on the device handle. */
83 if (device -> ux_device_handle != (ULONG) (ALIGN_TYPE) device)
84 {
85
86 /* Error trap. */
87 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_DEVICE_HANDLE_UNKNOWN);
88
89 /* If trace is enabled, insert this event into the trace buffer. */
90 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_DEVICE_HANDLE_UNKNOWN, device, 0, 0, UX_TRACE_ERRORS, 0, 0)
91
92 return(UX_DEVICE_HANDLE_UNKNOWN);
93 }
94
95 /* Start with the configuration attached to the device. */
96 current_configuration = device -> ux_device_first_configuration;
97
98 /* The first configuration has the index 0. */
99 current_configuration_index = 0;
100
101 /* Traverse the list of the configurations until we found the right one. */
102 while (current_configuration != UX_NULL)
103 {
104
105 /* Check if the configuration index matches the current one. */
106 if (configuration_index == current_configuration_index)
107 {
108
109 /* Return the configuration pointer. */
110 *configuration = current_configuration;
111
112 /* If trace is enabled, insert this event into the trace buffer. */
113 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_DEVICE_CONFIGURATION_GET, device, current_configuration, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
114
115 /* Return successful completion. */
116 return(UX_SUCCESS);
117 }
118
119 /* Move to the next configuration. */
120 current_configuration = current_configuration -> ux_configuration_next_configuration;
121
122 /* Move to the next index. */
123 current_configuration_index++;
124 }
125
126 /* Error trap. */
127 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_CONFIGURATION_HANDLE_UNKNOWN);
128
129 /* If trace is enabled, insert this event into the trace buffer. */
130 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_CONFIGURATION_HANDLE_UNKNOWN, configuration, 0, 0, UX_TRACE_ERRORS, 0, 0)
131
132 /* Return an error. */
133 return(UX_CONFIGURATION_HANDLE_UNKNOWN);
134 }
135
136
137 /**************************************************************************/
138 /* */
139 /* FUNCTION RELEASE */
140 /* */
141 /* _uxe_host_stack_device_configuration_get PORTABLE C */
142 /* 6.3.0 */
143 /* AUTHOR */
144 /* */
145 /* Chaoqiong Xiao, Microsoft Corporation */
146 /* */
147 /* DESCRIPTION */
148 /* */
149 /* This function checks errors in host stack config get function call. */
150 /* */
151 /* INPUT */
152 /* */
153 /* device Pointer to device */
154 /* configuration_index Index of configuration */
155 /* configuration Pointer to configuration */
156 /* destination */
157 /* */
158 /* OUTPUT */
159 /* */
160 /* None */
161 /* */
162 /* CALLS */
163 /* */
164 /* _ux_host_stack_device_configuration_get */
165 /* Host configuration get */
166 /* */
167 /* CALLED BY */
168 /* */
169 /* Application */
170 /* */
171 /* RELEASE HISTORY */
172 /* */
173 /* DATE NAME DESCRIPTION */
174 /* */
175 /* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */
176 /* */
177 /**************************************************************************/
_uxe_host_stack_device_configuration_get(UX_DEVICE * device,UINT configuration_index,UX_CONFIGURATION ** configuration)178 UINT _uxe_host_stack_device_configuration_get(UX_DEVICE *device, UINT configuration_index,
179 UX_CONFIGURATION **configuration)
180 {
181
182 /* Sanity checks. */
183 if ((device == UX_NULL) || (configuration == UX_NULL))
184 return(UX_INVALID_PARAMETER);
185
186 /* Invoke configuration get function. */
187 return(_ux_host_stack_device_configuration_get(device, configuration_index, configuration));
188 }
189