1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
|
/***************************************************************************
* Copyright (c) 2024 Microsoft Corporation
* Copyright (c) 2026-present Eclipse ThreadX contributors
*
* This program and the accompanying materials are made available under the
* terms of the MIT License which is available at
* https://opensource.org/licenses/MIT.
*
* SPDX-License-Identifier: MIT
**************************************************************************/
/**************************************************************************/
/**************************************************************************/
/** */
/** USBX Component */
/** */
/** PIMA Class */
/** */
/**************************************************************************/
/**************************************************************************/
/* Include necessary system files. */
#define UX_SOURCE_CODE
#include "ux_api.h"
#include "ux_host_class_pima.h"
#include "ux_host_stack.h"
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_host_class_pima_object_handles_get PORTABLE C */
/* 6.1.12 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function gets a list if the current valid Storage IDS. There */
/* is one Storage ID for each valid logical store. */
/* */
/* INPUT */
/* */
/* pima Pointer to pima class */
/* pima_session Pointer to pima session */
/* object_handles_array Pointer to store handles */
/* object_handles_length Array length in handles */
/* object_format_code Object Format Code */
/* object_handle_association Object Handle */
/* Association */
/* */
/* The 2 last parameter are optional and should be set to 0 if not */
/* used. */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* _ux_host_class_pima_command Pima command function */
/* _ux_utility_long_get Get 32 bit value */
/* _ux_utility_memory_allocate Allocate some memory */
/* _ux_utility_memory_free Free some memory */
/* */
/* CALLED BY */
/* */
/* USB application */
/* */
/**************************************************************************/
UINT _ux_host_class_pima_object_handles_get(UX_HOST_CLASS_PIMA *pima, UX_HOST_CLASS_PIMA_SESSION *pima_session,
ULONG *object_handles_array, ULONG object_handles_length,
ULONG storage_id, ULONG object_format_code, ULONG object_handle_association)
{
UX_HOST_CLASS_PIMA_COMMAND command;
UCHAR *object_handles_array_raw;
ULONG object_handle_length_raw;
ULONG count_object_handles;
ULONG nb_object_handles;
UINT status;
/* Check if this session is valid or not. */
if (pima_session -> ux_host_class_pima_session_magic != UX_HOST_CLASS_PIMA_MAGIC_NUMBER)
return (UX_HOST_CLASS_PIMA_RC_SESSION_NOT_OPEN);
/* Check if this session is opened or not. */
if (pima_session -> ux_host_class_pima_session_state != UX_HOST_CLASS_PIMA_SESSION_STATE_OPENED)
return (UX_HOST_CLASS_PIMA_RC_SESSION_NOT_OPEN);
/* Check the number of handles and compare with the size of the array given by the user. */
if (pima_session -> ux_host_class_pima_session_nb_objects > object_handles_length)
return(UX_MEMORY_INSUFFICIENT);
/* Issue command to get the storage IDs. 3 parameters. */
command.ux_host_class_pima_command_nb_parameters = 3;
/* Parameter 1 is the Storage ID. */
command.ux_host_class_pima_command_parameter_1 = storage_id;
/* Parameter 2 is optional. It is the Object Format Code. */
command.ux_host_class_pima_command_parameter_2 = object_format_code;
/* Parameter 3 is optional. It is the object handle association. */
command.ux_host_class_pima_command_parameter_3 = object_handle_association;
/* Other parameters unused. */
command.ux_host_class_pima_command_parameter_4 = 0;
command.ux_host_class_pima_command_parameter_5 = 0;
/* Then set the command to GET_STORAGE_IDS. */
command.ux_host_class_pima_command_operation_code = UX_HOST_CLASS_PIMA_OC_GET_OBJECT_HANDLES;
/* Calculate the length the raw array. We multiply the number of handles by the size on the handle and
add a ULONG for the number of handles stored at the beginning of the array. */
status = UX_SUCCESS;
object_handle_length_raw = 0;
UX_UTILITY_ADD_SAFE(pima_session -> ux_host_class_pima_session_nb_objects, 1, object_handle_length_raw, status);
if (status != UX_SUCCESS)
return(status);
UX_UTILITY_MULC_SAFE(object_handle_length_raw, (ULONG)sizeof(ULONG), object_handle_length_raw, status);
if (status != UX_SUCCESS)
return(status);
/* Allocate some DMA safe memory for receiving the handles */
object_handles_array_raw = _ux_utility_memory_allocate(UX_SAFE_ALIGN, UX_CACHE_SAFE_MEMORY, object_handle_length_raw);
if (object_handles_array_raw == UX_NULL)
return(UX_MEMORY_INSUFFICIENT);
/* Issue the command. */
status = _ux_host_class_pima_command(pima, &command, UX_HOST_CLASS_PIMA_DATA_PHASE_IN , object_handles_array_raw,
object_handle_length_raw, object_handle_length_raw);
/* Check the result. If OK, the object handles array is returned properly. */
if (status == UX_SUCCESS)
{
/* Read the number of Object handles in the returned array. */
nb_object_handles = _ux_utility_long_get(object_handles_array_raw);
/* Save the number of object handles. */
pima_session -> ux_host_class_pima_session_nb_objects = nb_object_handles;
/* Check if the user gave us enough memory. */
if (nb_object_handles > object_handles_length)
/* No, not enough memory to store the array. */
return(UX_MEMORY_INSUFFICIENT);
/* Unpack all object handles. */
for(count_object_handles = 0; count_object_handles < nb_object_handles; count_object_handles++)
/* Unpack one object handle at a time */
*(object_handles_array + count_object_handles) = _ux_utility_long_get(object_handles_array_raw + sizeof(ULONG) +
(count_object_handles * sizeof(ULONG)));
}
/* Free the original raw array. */
_ux_utility_memory_free(object_handles_array_raw);
/* Return completion status. */
return(status);
}
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _uxe_host_class_pima_object_handles_get PORTABLE C */
/* 6.3.0 */
/* AUTHOR */
/* */
/* Yajun Xia, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function checks errors in pima object handles get function */
/* call. */
/* */
/* INPUT */
/* */
/* pima Pointer to pima class */
/* pima_session Pointer to pima session */
/* object_handles_array Pointer to store handles */
/* object_handles_length Array length in handles */
/* object_format_code Object Format Code */
/* object_handle_association Object Handle */
/* Association */
/* */
/* The 2 last parameter are optional and should be set to 0 if not */
/* used. */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* _ux_host_class_pima_object_handles_get Get object handles */
/* */
/* CALLED BY */
/* */
/* USB application */
/* */
/**************************************************************************/
UINT _uxe_host_class_pima_object_handles_get(UX_HOST_CLASS_PIMA *pima, UX_HOST_CLASS_PIMA_SESSION *pima_session,
ULONG *object_handles_array, ULONG object_handles_length,
ULONG storage_id, ULONG object_format_code, ULONG object_handle_association)
{
/* Sanity checks. */
if ((pima == UX_NULL) || (pima_session == UX_NULL) || (object_handles_array == UX_NULL) || (object_handles_length == 0))
return(UX_INVALID_PARAMETER);
/* Call the actual function. */
return(_ux_host_class_pima_object_handles_get(pima, pima_session, object_handles_array, object_handles_length,
storage_id, object_format_code, object_handle_association));
}
|