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
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
|
/***************************************************************************
* 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_input_object_send PORTABLE C */
/* 6.1.12 */
/* AUTHOR */
/* */
/* Chaoqiong Xiao, Microsoft Corporation */
/* */
/* DESCRIPTION */
/* */
/* This function creates an input report for the dpshost */
/* */
/* INPUT */
/* */
/* pictbridge Pictbridge instance */
/* input_function input tag */
/* */
/* OUTPUT */
/* */
/* Completion Status */
/* */
/* CALLS */
/* */
/* */
/* CALLED BY */
/* */
/* */
/* */
/**************************************************************************/
UINT _ux_pictbridge_dpshost_input_object_send(UX_PICTBRIDGE *pictbridge, ULONG input_function)
{
UINT status;
ULONG object_length;
UCHAR *pima_object_buffer;
UX_HOST_CLASS_PIMA *pima;
UX_HOST_CLASS_PIMA_SESSION *pima_session;
UX_HOST_CLASS_PIMA_OBJECT *pima_object;
ULONG requested_length;
ULONG object_handle;
ULONG actual_flags;
/* Check the state machine. */
if (pictbridge -> ux_pictbridge_host_client_state_machine != UX_PICTBRIDGE_STATE_MACHINE_IDLE)
{
/* Set the state machine to Host Request pending. */
pictbridge -> ux_pictbridge_host_client_state_machine |= UX_PICTBRIDGE_STATE_MACHINE_HOST_REQUEST_PENDING;
/* Wait for the client event pending request to be completed. */
status = _ux_system_event_flags_get(&pictbridge -> ux_pictbridge_event_flags_group,
UX_PICTBRIDGE_EVENT_FLAG_STATE_MACHINE_READY,
UX_AND_CLEAR, &actual_flags, UX_PICTBRIDGE_EVENT_TIMEOUT);
/* Reset the state machine to not Host Request pending. */
pictbridge -> ux_pictbridge_host_client_state_machine &= (UINT)~UX_PICTBRIDGE_STATE_MACHINE_HOST_REQUEST_PENDING;
/* Check status. */
if (status != UX_SUCCESS)
return(UX_ERROR);
/* Status good means flag match, no need to check variable again, mark it unused. */
(void)actual_flags;
}
/* Change state machine to host request pending. */
pictbridge -> ux_pictbridge_host_client_state_machine |= UX_PICTBRIDGE_STATE_MACHINE_HOST_REQUEST;
/* 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;
/* Get the object buffer address. */
pima_object_buffer = pima_object -> ux_host_class_pima_object_buffer;
/* Reset the object length. */
object_length = 0;
/* Clear the object memory buffer. */
_ux_utility_memory_set(pima_object_buffer, 0, UX_PICTBRIDGE_MAX_PIMA_OBJECT_BUFFER); /* Use case of memset is verified. */
/* Add the line <?xml version="1.0"?> */
status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_xmlversion,
UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_LF,
UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
if (status != UX_SUCCESS)
return(status);
/* Add the line <dps xmlns="http://www.cipa.jp/dps/schema/"> */
status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_dpsxmlns,
UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_LF,
UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
/* Add the line <input> */
if (status == UX_SUCCESS)
{
status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_input,
UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_LF,
UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
}
/* Look into the tag code from the input object and proceed to individual functions. */
if (status == UX_SUCCESS)
{
switch (input_function)
{
case UX_PICTBRIDGE_IR_NOTIFY_JOB_STATUS :
/* Insert the notifyJobStatus tag lines. */
status = _ux_pictbridge_dpshost_input_object_notify_job_status(pictbridge, pima_object_buffer, object_length, &pima_object_buffer, &object_length);
break;
case UX_PICTBRIDGE_IR_NOTIFY_DEVICE_STATUS :
/* Insert the notifyDeviceStatus tag lines. */
status = _ux_pictbridge_dpshost_input_object_notify_device_status(pictbridge, pima_object_buffer, object_length, &pima_object_buffer, &object_length);
break;
default :
/* Function not yet supported. We should never come here anyway. */
status = UX_ERROR;
}
}
/* Add the line </input> */
if (status == UX_SUCCESS)
{
status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_input,
UX_PICTBRIDGE_TAG_FLAG_END,
UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
}
/* Add the line </dps> */
if (status == UX_SUCCESS)
{
status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_dps,
UX_PICTBRIDGE_TAG_FLAG_END,
UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
}
/* Handle error. */
if (status != UX_SUCCESS)
{
/* Do we have a pending client event ? */
if (pictbridge -> ux_pictbridge_host_client_state_machine & UX_PICTBRIDGE_STATE_MACHINE_CLIENT_REQUEST_PENDING)
{
/* Yes, so we need to set the event that advertise the completion of the host request. */
_ux_system_event_flags_set(&pictbridge -> ux_pictbridge_event_flags_group,
UX_PICTBRIDGE_EVENT_FLAG_STATE_MACHINE_READY,
UX_AND);
}
/* Change state machine to idle. */
pictbridge -> ux_pictbridge_host_client_state_machine &= (UINT)~UX_PICTBRIDGE_STATE_MACHINE_HOST_REQUEST;
return(UX_ERROR);
}
/* Store the length of the new object waiting to be sent out.
We do not store the length into the object itself since this function is
host\client agnostic. */
pima_object -> ux_host_class_pima_object_length = object_length;
/* Get the length of the object and store it into the object data set. */
pima_object -> ux_host_class_pima_object_compressed_size = object_length;
/* We need to change the file name to HREQUEST.DPS. Encode the file name from ascii format into Unicode. */
_ux_utility_string_to_unicode(_ux_pictbridge_hrequest_name, pima_object -> ux_host_class_pima_object_filename);
/* Set the object handle. */
object_handle = 1;
/* Send a script info. */
status = _ux_host_class_pima_object_info_send(pima, pima_session, 0, 0, pima_object);
if (status != UX_SUCCESS)
{
/* Do we have a pending client event ? */
if (pictbridge -> ux_pictbridge_host_client_state_machine & UX_PICTBRIDGE_STATE_MACHINE_CLIENT_REQUEST_PENDING)
{
/* Yes, so we need to set the event that advertise the completion of the host request. */
_ux_system_event_flags_set(&pictbridge -> ux_pictbridge_event_flags_group,
UX_PICTBRIDGE_EVENT_FLAG_STATE_MACHINE_READY,
UX_AND);
}
/* Change state machine to idle. */
pictbridge -> ux_pictbridge_host_client_state_machine &= (UINT)~UX_PICTBRIDGE_STATE_MACHINE_HOST_REQUEST;
/* Return status. */
return(status);
}
/* Open the object. */
status = _ux_host_class_pima_object_open(pima, pima_session,
object_handle,
pima_object);
if (status != UX_SUCCESS)
{
/* Do we have a pending client event ? */
if (pictbridge -> ux_pictbridge_host_client_state_machine & UX_PICTBRIDGE_STATE_MACHINE_CLIENT_REQUEST_PENDING)
{
/* Yes, so we need to set the event that advertise the completion of the host request. */
_ux_system_event_flags_set(&pictbridge -> ux_pictbridge_event_flags_group,
UX_PICTBRIDGE_EVENT_FLAG_STATE_MACHINE_READY,
UX_AND);
}
/* Change state machine to idle. */
pictbridge -> ux_pictbridge_host_client_state_machine &= (UINT)~UX_PICTBRIDGE_STATE_MACHINE_HOST_REQUEST;
/* Return status. */
return(status);
}
/* Get the object length. */
object_length = pima_object -> ux_host_class_pima_object_compressed_size;
/* Recall the object buffer address. */
pima_object_buffer = pima_object -> ux_host_class_pima_object_buffer;
/* Send 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;
/* Send the object data. */
status = _ux_host_class_pima_object_send(pima, pima_session, pima_object,
pima_object_buffer, requested_length);
if (status != UX_SUCCESS)
{
/* Abort the transfer. */
_ux_host_class_pima_object_transfer_abort(pima, pima_session, object_handle, pima_object);
/* Do we have a pending client event ? */
if (pictbridge -> ux_pictbridge_host_client_state_machine & UX_PICTBRIDGE_STATE_MACHINE_CLIENT_REQUEST_PENDING)
{
/* Yes, so we need to set the event that advertise the completion of the host request. */
_ux_system_event_flags_set(&pictbridge -> ux_pictbridge_event_flags_group,
UX_PICTBRIDGE_EVENT_FLAG_STATE_MACHINE_READY,
UX_AND);
}
/* Change state machine to idle. */
pictbridge -> ux_pictbridge_host_client_state_machine &= (UINT)~UX_PICTBRIDGE_STATE_MACHINE_HOST_REQUEST;
/* Return status. */
return(status);
}
/* We have sent some data, update the length remaining. */
object_length -= requested_length;
}
/* Close the object. */
status = _ux_host_class_pima_object_close(pima, pima_session, object_handle, pima_object);
/* Check the status. */
if (status != UX_SUCCESS)
{
/* Do we have a pending client event ? */
if (pictbridge -> ux_pictbridge_host_client_state_machine & UX_PICTBRIDGE_STATE_MACHINE_CLIENT_REQUEST_PENDING)
{
/* Yes, so we need to set the event that advertise the completion of the host request. */
_ux_system_event_flags_set(&pictbridge -> ux_pictbridge_event_flags_group,
UX_PICTBRIDGE_EVENT_FLAG_STATE_MACHINE_READY,
UX_AND);
}
/* Change state machine to idle. */
pictbridge -> ux_pictbridge_host_client_state_machine &= (UINT)~UX_PICTBRIDGE_STATE_MACHINE_HOST_REQUEST;
/* Return status. */
return(status);
}
/* Wait for the response from the device. */
status = _ux_pictbridge_dpshost_response_get(pictbridge);
/* Do we have a pending client event ? */
if (pictbridge -> ux_pictbridge_host_client_state_machine & UX_PICTBRIDGE_STATE_MACHINE_CLIENT_REQUEST_PENDING)
{
/* Yes, so we need to set the event that advertise the completion of the host request. */
_ux_system_event_flags_set(&pictbridge -> ux_pictbridge_event_flags_group,
UX_PICTBRIDGE_EVENT_FLAG_STATE_MACHINE_READY,
UX_AND);
}
/* Change state machine to idle. */
pictbridge -> ux_pictbridge_host_client_state_machine &= (UINT)~UX_PICTBRIDGE_STATE_MACHINE_HOST_REQUEST;
/* Return status. */
return(status);
}
|