1 /***************************************************************************
2 * Copyright (c) 2024 Microsoft Corporation
3 *
4 * This program and the accompanying materials are made available under the
5 * terms of the MIT License which is available at
6 * https://opensource.org/licenses/MIT.
7 *
8 * SPDX-License-Identifier: MIT
9 **************************************************************************/
10
11
12 /**************************************************************************/
13 /**************************************************************************/
14 /** */
15 /** USBX Component */
16 /** */
17 /** Pictbridge Application */
18 /** */
19 /**************************************************************************/
20 /**************************************************************************/
21
22
23 /* Include necessary system files. */
24
25 #define UX_SOURCE_CODE
26
27 #include "ux_api.h"
28 #include "ux_pictbridge.h"
29 #include "ux_device_class_pima.h"
30
31
32 /**************************************************************************/
33 /* */
34 /* FUNCTION RELEASE */
35 /* */
36 /* _ux_pictbridge_dpsclient_object_data_send PORTABLE C */
37 /* 6.1.12 */
38 /* AUTHOR */
39 /* */
40 /* Chaoqiong Xiao, Microsoft Corporation */
41 /* */
42 /* DESCRIPTION */
43 /* */
44 /* This function accepts the data of the object. */
45 /* */
46 /* INPUT */
47 /* */
48 /* pima Pima instance associated */
49 /* */
50 /* OUTPUT */
51 /* */
52 /* Completion Status */
53 /* */
54 /* CALLS */
55 /* */
56 /* */
57 /* CALLED BY */
58 /* */
59 /* user application */
60 /* */
61 /* RELEASE HISTORY */
62 /* */
63 /* DATE NAME DESCRIPTION */
64 /* */
65 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
66 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
67 /* verified memset and memcpy */
68 /* cases, used UX prefix to */
69 /* refer to TX symbols instead */
70 /* of using them directly, */
71 /* resulting in version 6.1 */
72 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
73 /* used macros for RTOS calls, */
74 /* resulting in version 6.1.12 */
75 /* */
76 /**************************************************************************/
_ux_pictbridge_dpsclient_object_data_send(UX_SLAVE_CLASS_PIMA * pima,ULONG object_handle,ULONG phase,UCHAR * object_buffer,ULONG object_offset,ULONG object_length)77 UINT _ux_pictbridge_dpsclient_object_data_send(UX_SLAVE_CLASS_PIMA *pima, ULONG object_handle,
78 ULONG phase,
79 UCHAR *object_buffer,
80 ULONG object_offset,
81 ULONG object_length)
82 {
83 UINT status;
84 UX_PICTBRIDGE *pictbridge;
85 UX_SLAVE_CLASS_PIMA_OBJECT *object_info;
86 ULONG event_flag = 0;
87 UCHAR *pima_object_buffer;
88
89
90 /* Get the pointer to the Pictbridge instance. */
91 pictbridge = (UX_PICTBRIDGE *)pima -> ux_device_class_pima_application;
92
93 /* Get the pointer to the pima object. */
94 object_info = (UX_SLAVE_CLASS_PIMA_OBJECT *) pictbridge -> ux_pictbridge_object_host;
95
96 /* Is this the correct handle ? */
97 if (object_info -> ux_device_class_pima_object_handle_id == object_handle)
98 {
99
100 /* Get the pointer to the object buffer. */
101 pima_object_buffer = object_info -> ux_device_class_pima_object_buffer;
102
103 /* Check the phase. We should wait for the object to be completed and the response sent back
104 before parsing the object. */
105 if (phase == UX_DEVICE_CLASS_PIMA_OBJECT_TRANSFER_PHASE_ACTIVE)
106 {
107
108 /* Check if it will fit in our buffer. */
109 if (object_offset + object_length > UX_PICTBRIDGE_MAX_PIMA_OBJECT_BUFFER)
110 return(UX_MEMORY_INSUFFICIENT);
111
112 /* Copy the demanded object data portion. */
113 _ux_utility_memory_copy(pima_object_buffer + object_offset, object_buffer, object_length); /* Use case of memcpy is verified. */
114
115 /* Save the length of this object. */
116 object_info -> ux_device_class_pima_object_length = object_length;
117
118 /* We are not done yet. */
119 return(UX_SUCCESS);
120 }
121
122 /* We now have the entire script into memory. Parse the object and execute the script. */
123 status = _ux_pictbridge_object_parse(pictbridge, pima_object_buffer,
124 object_info -> ux_device_class_pima_object_compressed_size);
125
126 /* Analyze the status from the parsing and determine the result code to be sent back. */
127 switch (status)
128 {
129 case UX_SUCCESS :
130
131 /* Set the result code to OK. */
132 pictbridge -> ux_pictbridge_operation_result = UX_PICTBRIDGE_ACTION_RESULT_OK;
133 break;
134
135 case UX_PICTBRIDGE_ERROR_SCRIPT_SYNTAX_ERROR :
136
137 /* Set the result code to Error. */
138 pictbridge -> ux_pictbridge_operation_result = UX_PICTBRIDGE_ACTION_RESULT_NOT_SUPPORTED_IP;
139 break;
140
141 case UX_PICTBRIDGE_ERROR_PARAMETER_UNKNOWN :
142
143 /* Set the result code to Error. */
144 pictbridge -> ux_pictbridge_operation_result = UX_PICTBRIDGE_ACTION_RESULT_NOT_SUPPORTED_UP;
145 break;
146
147 case UX_PICTBRIDGE_ERROR_PARAMETER_MISSING :
148
149 /* Set the result code to Error. */
150 pictbridge -> ux_pictbridge_operation_result = UX_PICTBRIDGE_ACTION_RESULT_NOT_SUPPORTED_MP;
151 break;
152
153 default :
154
155 /* Set the result code to Error. */
156 pictbridge -> ux_pictbridge_operation_result = UX_PICTBRIDGE_ACTION_RESULT_NOT_SUPPORTED_DEFAULT;
157 break;
158 }
159
160 /* We may have a complete event. We only raise the event flag if the completion was successful. */
161 if (pictbridge -> ux_pictbridge_operation_result == UX_PICTBRIDGE_ACTION_RESULT_OK)
162 {
163
164 /* Check what command we got back from the host. */
165 switch (pictbridge -> ux_pictbridge_input_request)
166 {
167
168 case UX_PICTBRIDGE_IR_CONFIGURE_PRINT_SERVICE :
169
170 /* Set event to configure print service. */
171 event_flag = UX_PICTBRIDGE_EVENT_FLAG_CONFIGURE_PRINT_SERVICE;
172 break;
173
174 case UX_PICTBRIDGE_IR_GET_CAPABILITY :
175
176 /* Set event to capability. */
177 event_flag = UX_PICTBRIDGE_EVENT_FLAG_CAPABILITY;
178 break;
179
180 case UX_PICTBRIDGE_IR_GET_JOB_STATUS :
181
182 /* Set event to capability. */
183 event_flag = UX_PICTBRIDGE_EVENT_FLAG_JOB_STATUS;
184 break;
185
186 case UX_PICTBRIDGE_IR_GET_DEVICE_STATUS :
187
188 /* Set event to device status. */
189 event_flag = UX_PICTBRIDGE_EVENT_FLAG_DEVICE_STATUS;
190 break;
191
192 case UX_PICTBRIDGE_IR_START_JOB :
193
194 /* Set event to start job . */
195 event_flag = UX_PICTBRIDGE_EVENT_FLAG_START_JOB;
196 break;
197
198 case UX_PICTBRIDGE_IR_ABORT_JOB :
199
200 /* Set event to abort job. */
201 event_flag = UX_PICTBRIDGE_EVENT_FLAG_ABORT_JOB;
202 break;
203
204 case UX_PICTBRIDGE_IR_CONTINUE_JOB :
205
206 /* Set event to continue job. */
207 event_flag = UX_PICTBRIDGE_EVENT_FLAG_CONTINUE_JOB;
208 break;
209
210 case UX_PICTBRIDGE_IR_NOTIFY_JOB_STATUS :
211
212 /* Set event to notify job status. */
213 event_flag = UX_PICTBRIDGE_EVENT_FLAG_NOTIFY_JOB_STATUS;
214 break;
215
216 case UX_PICTBRIDGE_IR_NOTIFY_DEVICE_STATUS :
217
218 /* Set event to notify device status. */
219 event_flag = UX_PICTBRIDGE_EVENT_FLAG_NOTIFY_DEVICE_STATUS;
220 break;
221
222
223 default :
224 /* Function not yet supported. */
225 break;
226 }
227
228 /* Send event to the application. */
229 _ux_system_event_flags_set(&pictbridge -> ux_pictbridge_event_flags_group, event_flag, UX_OR);
230
231
232 }
233 else
234 {
235
236 /* We have an error of some kind. Wake up the application with error event. */
237 _ux_system_event_flags_set(&pictbridge -> ux_pictbridge_event_flags_group, UX_PICTBRIDGE_EVENT_FLAG_ERROR, UX_OR);
238
239 }
240
241 /* What cycle are we in ? */
242 if (pictbridge -> ux_pictbridge_host_client_state_machine & UX_PICTBRIDGE_STATE_MACHINE_CLIENT_REQUEST)
243 {
244
245 /* Since we are in client request, this indicates we are done with the cycle. */
246 pictbridge -> ux_pictbridge_host_client_state_machine = UX_PICTBRIDGE_STATE_MACHINE_IDLE;
247
248 }
249
250 /* We have executed the script. */
251 return(UX_SUCCESS);
252
253 }
254
255 /* Could not find the handle. */
256 return(UX_DEVICE_CLASS_PIMA_RC_INVALID_OBJECT_HANDLE);
257 }
258
259