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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
|
/***************************************************************************
* 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 */
/** */
/** Pictbridge Application */
/** */
/**************************************************************************/
/**************************************************************************/
/* Include necessary system files. */
#define UX_SOURCE_CODE
#include "ux_api.h"
#include "ux_pictbridge.h"
#include "ux_host_class_pima.h"
/**************************************************************************/
/* */
/* FUNCTION RELEASE */
/* */
/* _ux_pictbridge_dpshost_response_get PORTABLE C */
/* 6.1.12 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function obtains a response. */
/* */
/* INPUT */
/* */
/* pictbridge Pictbridge instance */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* */
/* CALLED BY */
/* */
/* _ux_pictbridge_dpshost_thread */
/* */
/**************************************************************************/
UINT _ux_pictbridge_dpshost_response_get(UX_PICTBRIDGE *pictbridge)
{
UINT status;
UX_HOST_CLASS_PIMA *pima;
UX_HOST_CLASS_PIMA_SESSION *pima_session;
UX_HOST_CLASS_PIMA_OBJECT *pima_object;
ULONG object_length;
ULONG requested_length;
ULONG actual_length;
UCHAR *object_buffer;
UCHAR object_file_name[UX_PICTBRIDGE_MAX_FILE_NAME_SIZE + 1]; /* +1 for null-terminator */
ULONG object_handle;
UX_PICTBRIDGE_EVENT *pictbridge_event;
UINT length, length1;
/* Get the pima instance from the pictbridge container. */
pima = (UX_HOST_CLASS_PIMA *) pictbridge -> ux_pictbridge_pima;
/* And now the session since we use it. */
pima_session = (UX_HOST_CLASS_PIMA_SESSION *) pictbridge -> ux_pictbridge_session;
/* Get the address of the object container. */
pima_object = (UX_HOST_CLASS_PIMA_OBJECT *) pictbridge -> ux_pictbridge_object_host;
/* Wait for the semaphore to be put by the root hub or a regular hub. */
_ux_system_semaphore_get_norc(&pictbridge -> ux_pictbridge_notification_semaphore, UX_WAIT_FOREVER);
/* Check if there is an event. Normally there should be at least one since we got awaken. */
if (pictbridge -> ux_pictbridge_event_array_tail != pictbridge -> ux_pictbridge_event_array_head)
{
/* Get the current event tail. */
pictbridge_event = pictbridge -> ux_pictbridge_event_array_tail;
/* Analyze the event type. */
switch (pictbridge_event -> ux_pictbridge_event_code)
{
/* The DSC client is informing us that an object is ready. */
case UX_PICTBRIDGE_EC_OBJECT_ADDED :
case UX_PICTBRIDGE_EC_REQUEST_OBJECT_TRANSFER :
/* Obtain the object handle. */
object_handle = pictbridge_event -> ux_pictbridge_event_parameter_1;
break;
default :
return(UX_ERROR);
}
/* Compute the next entry in the event array. */
if ((pictbridge -> ux_pictbridge_event_array_tail + 1) == pictbridge -> ux_pictbridge_event_array_end)
/* Start at the beginning of the list. */
pictbridge_event = pictbridge -> ux_pictbridge_event_array;
else
/* Point to the next entry in the event array. */
pictbridge_event = pictbridge -> ux_pictbridge_event_array_tail + 1;
/* Now, store the new event tail. */
pictbridge -> ux_pictbridge_event_array_tail = pictbridge_event;
}
else
/* We have an error. Got awaken for nothing ! */
return(UX_ERROR);
/* Get the object info structure. */
status = _ux_host_class_pima_object_info_get(pima, pima_session,
object_handle, pima_object);
if (status != UX_SUCCESS)
{
/* Return an error. */
return(UX_PICTBRIDGE_ERROR_INVALID_OBJECT_HANDLE);
}
/* Check if this is a script. If the object is not a script or does not contain the
File Name we expect, we ignore it. */
if (pima_object -> ux_host_class_pima_object_format == UX_HOST_CLASS_PIMA_OFC_SCRIPT)
{
/* Yes this is a script. We need to search for the DRSPONSE.DPS file name.
Get the file name length (with null-terminator). */
length1 = (UINT)(*pima_object -> ux_host_class_pima_object_filename);
/* Check the file name from this script. It should be in the form DRSPONSE.DPS. */
if (length1 <= UX_PICTBRIDGE_MAX_FILE_NAME_SIZE)
{
/* Invalidate length, on error it's untouched. */
length = UX_PICTBRIDGE_MAX_FILE_NAME_SIZE + 1;
_ux_utility_string_length_check(_ux_pictbridge_drsponse_name, &length, UX_PICTBRIDGE_MAX_FILE_NAME_SIZE);
if ((length + 1) == length1)
{
/* Get the file name in a ascii format (with null-terminator). */
_ux_utility_unicode_to_string(pima_object -> ux_host_class_pima_object_filename, object_file_name);
/* So far, the length of name of the files are the same.
Compare names now (since length is same just compare without null-terminator). */
if (_ux_utility_memory_compare(_ux_pictbridge_drsponse_name, object_file_name,
length) == UX_SUCCESS)
{
/* Yes this is a script. Get the entire object in memory. */
/* Get script length from the object info. */
object_length = pima_object -> ux_host_class_pima_object_compressed_size;
/* Check for overflow. */
if (object_length > UX_PICTBRIDGE_MAX_PIMA_OBJECT_BUFFER)
return(UX_PICTBRIDGE_ERROR_SCRIPT_BUFFER_OVERFLOW);
/* Open the object. */
status = _ux_host_class_pima_object_open(pima, pima_session, object_handle, pima_object);
/* Check status. */
if (status != UX_SUCCESS)
return(status);
/* Set the object buffer pointer. */
object_buffer = pima_object -> ux_host_class_pima_object_buffer;
/* Obtain all the object data. */
while(object_length != 0)
{
/* Calculate what length to request. */
if (object_length > UX_PICTBRIDGE_MAX_PIMA_OBJECT_BUFFER)
/* Request maximum length. */
requested_length = UX_PICTBRIDGE_MAX_PIMA_OBJECT_BUFFER;
else
/* Request remaining length. */
requested_length = object_length;
/* Get the object data. */
status = _ux_host_class_pima_object_get(pima, pima_session, object_handle, pima_object,
object_buffer, requested_length, &actual_length);
if (status != UX_SUCCESS)
{
/* We had a problem, abort the transfer. */
_ux_host_class_pima_object_transfer_abort(pima, pima_session, object_handle, pima_object);
/* And close the object. */
_ux_host_class_pima_object_close(pima, pima_session, object_handle, pima_object);
return(status);
}
/* We have received some data, update the length remaining. */
object_length -= actual_length;
/* Update the buffer address. */
object_buffer += actual_length;
}
/* Close the object. */
status = _ux_host_class_pima_object_close(pima, pima_session, object_handle, pima_object);
/* Check the error. */
if (status != UX_SUCCESS)
return(UX_PICTBRIDGE_ERROR_INVALID_OBJECT_HANDLE);
/* We now have the entire script into memory. Parse the object and execute the script. */
status = _ux_pictbridge_object_parse(pictbridge, pima_object -> ux_host_class_pima_object_buffer,
pima_object -> ux_host_class_pima_object_compressed_size);
/* Analyze the status from the parsing and determine the result code. */
switch (status)
{
case UX_SUCCESS :
/* Set the result code to OK. */
pictbridge -> ux_pictbridge_operation_result = UX_PICTBRIDGE_ACTION_RESULT_OK;
break;
case UX_PICTBRIDGE_ERROR_SCRIPT_SYNTAX_ERROR :
/* Set the result code to Error. */
pictbridge -> ux_pictbridge_operation_result = UX_PICTBRIDGE_ACTION_RESULT_NOT_SUPPORTED_IP;
break;
case UX_PICTBRIDGE_ERROR_PARAMETER_UNKNOWN :
/* Set the result code to Error. */
pictbridge -> ux_pictbridge_operation_result = UX_PICTBRIDGE_ACTION_RESULT_NOT_SUPPORTED_UP;
break;
case UX_PICTBRIDGE_ERROR_PARAMETER_MISSING :
/* Set the result code to Error. */
pictbridge -> ux_pictbridge_operation_result = UX_PICTBRIDGE_ACTION_RESULT_NOT_SUPPORTED_MP;
break;
default :
/* Set the result code to Error. */
pictbridge -> ux_pictbridge_operation_result = UX_PICTBRIDGE_ACTION_RESULT_NOT_SUPPORTED_DEFAULT;
break;
}
if (status != UX_SUCCESS)
return(status);
}
}
}
}
return(UX_SUCCESS);
}
|