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 Stack */
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_stack.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _ux_host_stack_interface_endpoint_get PORTABLE C */
37 /* 6.1.12 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function returns an endpoint container based on the interface */
45 /* handle and an endpoint index. */
46 /* */
47 /* INPUT */
48 /* */
49 /* interface Pointer to interface */
50 /* endpoint_index Index of endpoint to get */
51 /* endpoint Destination for endpoint */
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 /* 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_stack_interface_endpoint_get(UX_INTERFACE * interface_ptr,UINT endpoint_index,UX_ENDPOINT ** endpoint)79 UINT _ux_host_stack_interface_endpoint_get(UX_INTERFACE *interface_ptr, UINT endpoint_index, UX_ENDPOINT **endpoint)
80 {
81
82 UINT current_endpoint_index;
83 UX_ENDPOINT *current_endpoint;
84
85 /* If trace is enabled, insert this event into the trace buffer. */
86 UX_TRACE_IN_LINE_INSERT(UX_TRACE_HOST_STACK_INTERFACE_ENDPOINT_GET, interface_ptr, endpoint_index, 0, 0, UX_TRACE_HOST_STACK_EVENTS, 0, 0)
87
88 /* Do a sanity check on the interface handle. */
89 if (interface_ptr -> ux_interface_handle != (ULONG) (ALIGN_TYPE) interface_ptr)
90 {
91
92 /* Error trap. */
93 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_INTERFACE_HANDLE_UNKNOWN);
94
95 /* If trace is enabled, insert this event into the trace buffer. */
96 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_INTERFACE_HANDLE_UNKNOWN, interface_ptr, 0, 0, UX_TRACE_ERRORS, 0, 0)
97
98 return(UX_INTERFACE_HANDLE_UNKNOWN);
99 }
100
101 /* Start with the endpoint attached to the interface. */
102 current_endpoint = interface_ptr -> ux_interface_first_endpoint;
103
104 /* The first endpoint has the index 0. */
105 current_endpoint_index = 0;
106
107 /* Traverse the list of the endpoints until we found the right one. */
108 while (current_endpoint != UX_NULL)
109 {
110
111 /* Check if the endpoint index matches the current one. */
112 if (endpoint_index == current_endpoint_index)
113 {
114
115 /* Setup the return endpoint pointer. */
116 *endpoint=current_endpoint;
117
118 /* Return success to the caller. */
119 return(UX_SUCCESS);
120 }
121
122 /* Move to the next endpoint. */
123 current_endpoint = current_endpoint -> ux_endpoint_next_endpoint;
124
125 /* Move to the next index. */
126 current_endpoint_index++;
127 }
128
129 /* Error trap. */
130 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_ENUMERATOR, UX_ENDPOINT_HANDLE_UNKNOWN);
131
132 /* If trace is enabled, insert this event into the trace buffer. */
133 UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_ENDPOINT_HANDLE_UNKNOWN, endpoint, 0, 0, UX_TRACE_ERRORS, 0, 0)
134
135 /* Return an error! */
136 return(UX_ENDPOINT_HANDLE_UNKNOWN);
137 }
138
139
140 /**************************************************************************/
141 /* */
142 /* FUNCTION RELEASE */
143 /* */
144 /* _uxe_host_stack_interface_endpoint_get PORTABLE C */
145 /* 6.3.0 */
146 /* AUTHOR */
147 /* */
148 /* Chaoqiong Xiao, Microsoft Corporation */
149 /* */
150 /* DESCRIPTION */
151 /* */
152 /* This function checks errors in host stack endpoint get function */
153 /* call. */
154 /* */
155 /* INPUT */
156 /* */
157 /* interface_ptr Pointer to interface */
158 /* endpoint_index Index of endpoint to get */
159 /* endpoint Destination for endpoint */
160 /* */
161 /* OUTPUT */
162 /* */
163 /* None */
164 /* */
165 /* CALLS */
166 /* */
167 /* _ux_host_stack_interface_endpoint_get Endpoint get */
168 /* */
169 /* CALLED BY */
170 /* */
171 /* Application */
172 /* */
173 /* RELEASE HISTORY */
174 /* */
175 /* DATE NAME DESCRIPTION */
176 /* */
177 /* 10-31-2023 Chaoqiong Xiao Initial Version 6.3.0 */
178 /* */
179 /**************************************************************************/
_uxe_host_stack_interface_endpoint_get(UX_INTERFACE * interface_ptr,UINT endpoint_index,UX_ENDPOINT ** endpoint)180 UINT _uxe_host_stack_interface_endpoint_get(UX_INTERFACE *interface_ptr, UINT endpoint_index, UX_ENDPOINT **endpoint)
181 {
182
183 /* Sanity checks. */
184 if ((interface_ptr == UX_NULL) || (endpoint == UX_NULL))
185 return(UX_INVALID_PARAMETER);
186
187 /* Invoke endpoint get function. */
188 return(_ux_host_stack_interface_endpoint_get(interface_ptr, endpoint_index, endpoint));
189 }
190