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_input_object_prepare PORTABLE C */
38 /* 6.1.12 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function prepares a client input object to be sent. */
46 /* This function puts a interrupt notification for the host to issue */
47 /* a get object request. */
48 /* */
49 /* INPUT */
50 /* */
51 /* pictbridge Pictbridge instance */
52 /* input_function input function */
53 /* */
54 /* OUTPUT */
55 /* */
56 /* Completion Status */
57 /* */
58 /* CALLS */
59 /* */
60 /* */
61 /* CALLED BY */
62 /* */
63 /* */
64 /* */
65 /* RELEASE HISTORY */
66 /* */
67 /* DATE NAME DESCRIPTION */
68 /* */
69 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
70 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
71 /* verified memset and memcpy */
72 /* cases, used UX prefix to */
73 /* refer to TX symbols instead */
74 /* of using them directly, */
75 /* resulting in version 6.1 */
76 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
77 /* cleared compile warning, */
78 /* used macros for RTOS calls, */
79 /* resulting in version 6.1.12 */
80 /* */
81 /**************************************************************************/
_ux_pictbridge_dpsclient_input_object_prepare(UX_PICTBRIDGE * pictbridge,ULONG input_function,ULONG input_subfunction,ULONG input_parameter)82 UINT _ux_pictbridge_dpsclient_input_object_prepare(UX_PICTBRIDGE *pictbridge,
83 ULONG input_function,
84 ULONG input_subfunction,
85 ULONG input_parameter)
86 {
87 UINT status;
88 ULONG object_length;
89 UCHAR *pima_object_buffer;
90 UX_SLAVE_CLASS_PIMA *pima;
91 UX_SLAVE_CLASS_PIMA_OBJECT *pima_object;
92 ULONG actual_flags;
93
94
95 /* Check the status of pictbridge, if we are in a host request cycle, cannot add object now. */
96 if (pictbridge -> ux_pictbridge_host_client_state_machine & UX_PICTBRIDGE_STATE_MACHINE_HOST_REQUEST)
97 {
98
99 /* Add to the state machine the client pending request. */
100 pictbridge -> ux_pictbridge_host_client_state_machine |= UX_PICTBRIDGE_STATE_MACHINE_CLIENT_REQUEST_PENDING;
101
102 /* We should wait for the state machine to allow our operation. */
103 status = _ux_system_event_flags_get(&pictbridge -> ux_pictbridge_event_flags_group, UX_PICTBRIDGE_EVENT_FLAG_STATE_MACHINE_READY,
104 UX_AND_CLEAR, &actual_flags, UX_PICTBRIDGE_EVENT_TIMEOUT);
105
106 /* Check status. */
107 if (status != UX_SUCCESS)
108 return(UX_EVENT_ERROR);
109
110 /* Status good means flag match, no need to check variable again, mark it unused. */
111 (void)actual_flags;
112 }
113
114 /* Change the state machine to client request. */
115 pictbridge -> ux_pictbridge_host_client_state_machine |= UX_PICTBRIDGE_STATE_MACHINE_CLIENT_REQUEST;
116
117 /* Get the pima instance from the pictbridge container. */
118 pima = (UX_SLAVE_CLASS_PIMA *) pictbridge -> ux_pictbridge_pima;
119
120 /* Get the address of the object container. We choose the client container. */
121 pima_object = pictbridge -> ux_pictbridge_object_client;
122
123 /* Get the object buffer address. */
124 pima_object_buffer = pima_object -> ux_device_class_pima_object_buffer;
125
126 /* Reset the object length. */
127 object_length = 0;
128
129 /* Clear the object memory buffer. */
130 _ux_utility_memory_set(pima_object_buffer, 0, UX_PICTBRIDGE_MAX_PIMA_OBJECT_BUFFER); /* Use case of memset is verified. */
131
132 /* Add the line <?xml version="1.0"?> */
133 status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_xmlversion,
134 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_LF,
135 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
136 if (status != UX_SUCCESS)
137 return(status);
138
139 /* Add the line <dps xmlns="http://www.cipa.jp/dps/schema/"> */
140 status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_dpsxmlns,
141 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_LF,
142 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
143 if (status != UX_SUCCESS)
144 return(status);
145
146 /* Add the line <input> */
147 status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_input,
148 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_LF,
149 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
150 if (status != UX_SUCCESS)
151 return(status);
152
153 /* Look into the tag code from the input object and proceed to individual functions. */
154 switch (input_function)
155 {
156
157
158 case UX_PICTBRIDGE_OR_CONFIGURE_PRINT_SERVICE :
159
160 status = _ux_pictbridge_dpsclient_input_object_configure_print_service(pictbridge, pima_object_buffer, object_length,
161 &pima_object_buffer, &object_length);
162 break;
163
164 case UX_PICTBRIDGE_OR_GET_CAPABILITY :
165
166 status = _ux_pictbridge_dpsclient_input_object_get_capability(pictbridge, input_subfunction, input_parameter, pima_object_buffer, object_length,
167 &pima_object_buffer, &object_length);
168 break;
169
170 case UX_PICTBRIDGE_OR_START_JOB :
171
172 status = _ux_pictbridge_dpsclient_input_object_startjob(pictbridge, input_subfunction, input_parameter, pima_object_buffer, object_length,
173 &pima_object_buffer, &object_length);
174 break;
175
176 case UX_PICTBRIDGE_OR_ABORT_JOB :
177
178 status = _ux_pictbridge_dpsclient_input_object_abortjob(pictbridge, input_subfunction, input_parameter, pima_object_buffer, object_length,
179 &pima_object_buffer, &object_length);
180 break;
181
182 case UX_PICTBRIDGE_OR_CONTINUE_JOB :
183
184 status = _ux_pictbridge_dpsclient_input_object_continuejob(pictbridge, input_subfunction, input_parameter, pima_object_buffer, object_length,
185 &pima_object_buffer, &object_length);
186 break;
187
188 case UX_PICTBRIDGE_OR_GET_DEVICE_STATUS :
189
190 /* Add the line <getDeviceStatus/> */
191 status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_getdevicestatus,
192 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_SLASH_AT_END,
193 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
194
195 break;
196
197 default :
198
199 /* Function not yet supported. We should never come here anyway. */
200 status = (UX_ERROR);
201 }
202 if (status != UX_SUCCESS)
203 return(status);
204
205 /* Add the line </input> */
206 status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_input,
207 UX_PICTBRIDGE_TAG_FLAG_END,
208 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
209 if (status != UX_SUCCESS)
210 return(status);
211
212 /* Add the line </dps> */
213 status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_dps,
214 UX_PICTBRIDGE_TAG_FLAG_END,
215 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
216 if (status != UX_SUCCESS)
217 return(status);
218
219 /* Get the length of the object and store it into the object data set. */
220 pima_object -> ux_device_class_pima_object_length = object_length;
221 pima_object -> ux_device_class_pima_object_compressed_size = object_length;
222
223 /* Save the handle for this object. */
224 pima_object -> ux_device_class_pima_object_handle_id = UX_PICTBRIDGE_OBJECT_HANDLE_CLIENT_REQUEST;
225
226 /* We need to change the file name to DREQUEST.DPS. Encode the file name from ascii format into Unicode. */
227 _ux_utility_string_to_unicode(_ux_pictbridge_drequest_name, pima_object -> ux_device_class_pima_object_filename);
228
229 /* Send the notification to the host that an object has been added. */
230 status = _ux_device_class_pima_object_add(pima, UX_PICTBRIDGE_OBJECT_HANDLE_CLIENT_REQUEST);
231
232 /* Return completion status. */
233 return(status);
234 }
235
236