1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
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_class_get PORTABLE C */ |
37 |
|
|
/* 6.3.0 */ |
38 |
|
|
/* AUTHOR */ |
39 |
|
|
/* */ |
40 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
41 |
|
|
/* */ |
42 |
|
|
/* DESCRIPTION */ |
43 |
|
|
/* */ |
44 |
|
|
/* This function returns a pointer to the class container. A class */ |
45 |
|
|
/* needs to obtain its container from the USBX stack to search for */ |
46 |
|
|
/* instances when a driver or an application wants to open a device. */ |
47 |
|
|
/* */ |
48 |
|
|
/* Note: The C string of class_name must be NULL-terminated and the */ |
49 |
|
|
/* length of it (without the NULL-terminator itself) must be no larger */ |
50 |
|
|
/* than UX_MAX_CLASS_NAME_LENGTH. */ |
51 |
|
|
/* */ |
52 |
|
|
/* INPUT */ |
53 |
|
|
/* */ |
54 |
|
|
/* class_name Name of class */ |
55 |
|
|
/* host_class Class pointer */ |
56 |
|
|
/* */ |
57 |
|
|
/* OUTPUT */ |
58 |
|
|
/* */ |
59 |
|
|
/* Completion Status */ |
60 |
|
|
/* */ |
61 |
|
|
/* CALLS */ |
62 |
|
|
/* */ |
63 |
|
|
/* _ux_utility_string_length_check Check C string and return its */ |
64 |
|
|
/* length if null-terminated */ |
65 |
|
|
/* _ux_utility_memory_compare Compare memory blocks */ |
66 |
|
|
/* */ |
67 |
|
|
/* CALLED BY */ |
68 |
|
|
/* */ |
69 |
|
|
/* Application */ |
70 |
|
|
/* USBX Components */ |
71 |
|
|
/* */ |
72 |
|
|
/**************************************************************************/ |
73 |
|
6430 |
UINT _ux_host_stack_class_get(UCHAR *class_name, UX_HOST_CLASS **host_class) |
74 |
|
|
{ |
75 |
|
|
|
76 |
|
|
UX_HOST_CLASS *class_ptr; |
77 |
|
|
#if !defined(UX_NAME_REFERENCED_BY_POINTER) |
78 |
|
|
UINT status; |
79 |
|
6430 |
UINT class_name_length = 0; |
80 |
|
|
#endif |
81 |
|
|
#if UX_MAX_CLASS_DRIVER > 1 |
82 |
|
|
ULONG class_index; |
83 |
|
|
#endif |
84 |
|
|
|
85 |
|
|
#if !defined(UX_NAME_REFERENCED_BY_POINTER) |
86 |
|
|
/* Get the length of the class name (exclude null-terminator). */ |
87 |
|
6430 |
status = _ux_utility_string_length_check(class_name, &class_name_length, UX_MAX_CLASS_NAME_LENGTH); |
88 |
✓✓ |
6430 |
if (status) |
89 |
|
1 |
return(status); |
90 |
|
|
#endif |
91 |
|
|
|
92 |
|
|
/* Get first class. */ |
93 |
|
6429 |
class_ptr = _ux_system_host -> ux_system_host_class_array; |
94 |
|
|
|
95 |
|
|
#if UX_MAX_CLASS_DRIVER > 1 |
96 |
|
|
/* We need to parse the class driver table. */ |
97 |
✓✓ |
6672 |
for (class_index = 0; class_index < _ux_system_host -> ux_system_host_max_class; class_index++) |
98 |
|
|
{ |
99 |
|
|
#endif |
100 |
|
|
|
101 |
|
|
/* Check if this class is already being used. */ |
102 |
✓✓ |
6670 |
if (class_ptr -> ux_host_class_status == UX_USED) |
103 |
|
|
{ |
104 |
|
|
|
105 |
|
|
/* We have found a container. Check if this is the one we need (compare including null-terminator). */ |
106 |
✓✓ |
6655 |
if (ux_utility_name_match(class_ptr -> ux_host_class_name, class_name, class_name_length + 1)) |
107 |
|
|
{ |
108 |
|
|
|
109 |
|
|
/* The class container was found. Update the pointer to the class container for the caller. */ |
110 |
|
6427 |
*host_class = class_ptr; |
111 |
|
|
|
112 |
|
|
/* Return success. */ |
113 |
|
6427 |
return(UX_SUCCESS); |
114 |
|
|
} |
115 |
|
|
} |
116 |
|
|
|
117 |
|
|
#if UX_MAX_CLASS_DRIVER > 1 |
118 |
|
|
/* Move to the next class. */ |
119 |
|
243 |
class_ptr++; |
120 |
|
|
} |
121 |
|
|
#endif |
122 |
|
|
|
123 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
124 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_ERROR, UX_HOST_CLASS_UNKNOWN, class_name, 0, 0, UX_TRACE_ERRORS, 0, 0) |
125 |
|
|
|
126 |
|
|
/* This class does not exist, return an error. */ |
127 |
|
2 |
return(UX_HOST_CLASS_UNKNOWN); |
128 |
|
|
} |
129 |
|
|
|
130 |
|
|
|
131 |
|
|
/**************************************************************************/ |
132 |
|
|
/* */ |
133 |
|
|
/* FUNCTION RELEASE */ |
134 |
|
|
/* */ |
135 |
|
|
/* _uxe_host_stack_class_get PORTABLE C */ |
136 |
|
|
/* 6.3.0 */ |
137 |
|
|
/* AUTHOR */ |
138 |
|
|
/* */ |
139 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
140 |
|
|
/* */ |
141 |
|
|
/* DESCRIPTION */ |
142 |
|
|
/* */ |
143 |
|
|
/* This function checks errors in host stack class get function call. */ |
144 |
|
|
/* */ |
145 |
|
|
/* INPUT */ |
146 |
|
|
/* */ |
147 |
|
|
/* class_name Name of class */ |
148 |
|
|
/* host_class Class pointer */ |
149 |
|
|
/* */ |
150 |
|
|
/* OUTPUT */ |
151 |
|
|
/* */ |
152 |
|
|
/* None */ |
153 |
|
|
/* */ |
154 |
|
|
/* CALLS */ |
155 |
|
|
/* */ |
156 |
|
|
/* _ux_host_stack_class_get Host stack class get */ |
157 |
|
|
/* */ |
158 |
|
|
/* CALLED BY */ |
159 |
|
|
/* */ |
160 |
|
|
/* Application */ |
161 |
|
|
/* */ |
162 |
|
|
/**************************************************************************/ |
163 |
|
|
UINT _uxe_host_stack_class_get(UCHAR *class_name, UX_HOST_CLASS **host_class) |
164 |
|
|
{ |
165 |
|
|
|
166 |
|
|
/* Sanity checks. */ |
167 |
|
|
if ((class_name == UX_NULL) || (host_class == UX_NULL)) |
168 |
|
|
return(UX_INVALID_PARAMETER); |
169 |
|
|
|
170 |
|
|
/* Invoke class get function. */ |
171 |
|
|
return(_ux_host_stack_class_get(class_name, host_class)); |
172 |
|
|
} |