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