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_input_get_capability                       */
37 /*                                                        PORTABLE C      */
38 /*                                                           6.1          */
39 /*                                                                        */
40 /*  AUTHOR                                                                */
41 /*                                                                        */
42 /*    Chaoqiong Xiao, Microsoft Corporation                               */
43 /*                                                                        */
44 /*  DESCRIPTION                                                           */
45 /*                                                                        */
46 /*    This function creates the tag lines of the capability               */
47 /*    request.                                                            */
48 /*                                                                        */
49 /*  INPUT                                                                 */
50 /*                                                                        */
51 /*    pictbridge                            Pictbridge instance           */
52 /*    pima_object_buffer                    Pointer to object buffer      */
53 /*    object_length                         Length of the object          */
54 /*    pima_object_buffer_updated            Updated Address of the object */
55 /*    object_length_updated                 Updated length                */
56 /*                                                                        */
57 /*                                                                        */
58 /*  OUTPUT                                                                */
59 /*                                                                        */
60 /*    Completion Status                                                   */
61 /*                                                                        */
62 /*  CALLS                                                                 */
63 /*                                                                        */
64 /*                                                                        */
65 /*  CALLED BY                                                             */
66 /*                                                                        */
67 /*    _ux_pictbridge_dpsclient_input_object_prepare                       */
68 /*                                                                        */
69 /*  RELEASE HISTORY                                                       */
70 /*                                                                        */
71 /*    DATE              NAME                      DESCRIPTION             */
72 /*                                                                        */
73 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
74 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
75 /*                                            resulting in version 6.1    */
76 /*                                                                        */
77 /**************************************************************************/
_ux_pictbridge_dpsclient_input_object_get_capability(UX_PICTBRIDGE * pictbridge,ULONG input_subcode,ULONG input_parameter,UCHAR * pima_object_buffer,ULONG object_length,UCHAR ** pima_object_buffer_updated,ULONG * object_length_updated)78 UINT _ux_pictbridge_dpsclient_input_object_get_capability(UX_PICTBRIDGE *pictbridge,
79                                                             ULONG input_subcode,
80                                                             ULONG input_parameter,
81                                                             UCHAR *pima_object_buffer,
82                                                             ULONG object_length,
83                                                             UCHAR **pima_object_buffer_updated,
84                                                             ULONG *object_length_updated)
85 {
86 
87 UINT                status;
88 
89 
90     /* Add the line <getcapability>  */
91     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_getcapability,
92                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_LF,
93                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
94     if (status != UX_SUCCESS)
95         return(status);
96 
97     /* Add the line <capability>  */
98     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_capability,
99                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_LF,
100                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
101     if (status != UX_SUCCESS)
102         return(status);
103 
104     /* Check was subcode we need to for this request. The API might be sending one or multiple requests.  */
105     if (input_subcode & UX_PICTBRIDGE_API_QUALITIES)
106     {
107         /* Add the line <qualities/> */
108         status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_qualities,
109                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_SLASH_AT_END,
110                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
111         if (status != UX_SUCCESS)
112             return(status);
113     }
114 
115     /* Check was subcode we need to for this request. The API might be sending one or multiple requests.  */
116     if (input_subcode & UX_PICTBRIDGE_API_PAPER_SIZES)
117     {
118         /* Add the line <paperSizes/> */
119         status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_papersizes,
120                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_SLASH_AT_END,
121                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
122         if (status != UX_SUCCESS)
123             return(status);
124     }
125 
126     /* Check was subcode we need to for this request. The API might be sending one or multiple requests.  */
127     if (input_subcode & UX_PICTBRIDGE_API_PAPER_SIZES)
128     {
129 
130         /* Check if we had a paper size value specified in the input report.  */
131         if (input_parameter != 0)
132         {
133             /* Add the line <paperTypes paperSize = "xxxxxxxx"/> */
134             status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_papertypes,
135                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_SLASH_AT_END | UX_PICTBRIDGE_TAG_FLAG_VARIABLE_HEXA,
136                                                 _ux_pictbridge_xml_variable_papersize,
137                                                 input_parameter,
138                                                 UX_NULL, &pima_object_buffer, &object_length);
139             if (status != UX_SUCCESS)
140                 return(status);
141         }
142         else
143         {
144             /* Add the line <paperTypes/> */
145             status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_papertypes,
146                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_SLASH_AT_END,
147                                                 UX_NULL, 0,
148                                                 (VOID *) &pictbridge -> ux_pictbridge_dpslocal.ux_pictbridge_devinfo_papertypes, &pima_object_buffer, &object_length);
149             if (status != UX_SUCCESS)
150                 return(status);
151         }
152     }
153 
154     /* Parse the tag code that was memorized during the input.  */
155     if (input_subcode & UX_PICTBRIDGE_API_FILE_TYPES)
156     {
157         /* Add the line <fileTypes/> */
158         _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_filetypes,
159                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_SLASH_AT_END,
160                                                 UX_NULL, 0, UX_NULL , &pima_object_buffer, &object_length);
161         if (status != UX_SUCCESS)
162             return(status);
163     }
164 
165     /* Parse the tag code that was memorized during the input.  */
166     if (input_subcode & UX_PICTBRIDGE_API_DATE_PRINTS)
167     {
168         /* Add the line <datePrints/> */
169         _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_dateprints,
170                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_SLASH_AT_END,
171                                                 UX_NULL, 0, UX_NULL , &pima_object_buffer, &object_length);
172         if (status != UX_SUCCESS)
173             return(status);
174     }
175 
176     /* Parse the tag code that was memorized during the input.  */
177     if (input_subcode & UX_PICTBRIDGE_API_FILE_NAME_PRINTS)
178     {
179         /* Add the line <namePrints/> */
180         status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_filenameprints,
181                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_SLASH_AT_END,
182                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
183         if (status != UX_SUCCESS)
184             return(status);
185     }
186 
187     /* Parse the tag code that was memorized during the input.  */
188     if (input_subcode & UX_PICTBRIDGE_API_IMAGE_OPTIMIZES)
189     {
190         /* Add the line <imageOptimizes/> */
191         status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_imageoptimizes,
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         if (status != UX_SUCCESS)
195             return(status);
196     }
197 
198     /* Parse the tag code that was memorized during the input.  */
199     if (input_subcode & UX_PICTBRIDGE_API_LAYOUTS)
200     {
201 
202         /* Check if we had a paper size value specified in the input report.  */
203         if (input_parameter != 0)
204         {
205             /* Add the line <layouts paperSize = "xxxxxxxx"/> */
206             status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_layouts,
207                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_SLASH_AT_END | UX_PICTBRIDGE_TAG_FLAG_VARIABLE_HEXA,
208                                                 _ux_pictbridge_xml_variable_papersize,
209                                                 input_parameter,
210                                                 UX_NULL, &pima_object_buffer, &object_length);
211             if (status != UX_SUCCESS)
212                 return(status);
213         }
214         else
215         {
216             /* Add the line <layouts/> */
217             status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_layouts,
218                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_SLASH_AT_END,
219                                                 UX_NULL, 0,
220                                                 UX_NULL, &pima_object_buffer, &object_length);
221             if (status != UX_SUCCESS)
222                 return(status);
223         }
224     }
225 
226     /* Parse the tag code that was memorized during the input.  */
227     if (input_subcode & UX_PICTBRIDGE_API_FIXED_SIZES)
228     {
229         /* Add the line <fixedSizes/> */
230         status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_fixedsizes,
231                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_SLASH_AT_END,
232                                                 UX_NULL, 0,
233                                                 UX_NULL, &pima_object_buffer, &object_length);
234         if (status != UX_SUCCESS)
235             return(status);
236     }
237 
238     /* Parse the tag code that was memorized during the input.  */
239     if (input_subcode & UX_PICTBRIDGE_API_CROPPINGS)
240     {
241         /* Add the line <croppings/> */
242         status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_croppings,
243                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_SLASH_AT_END,
244                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
245         if (status != UX_SUCCESS)
246             return(status);
247     }
248 
249     /* Parse the tag code that was memorized during the input.  */
250     if (input_subcode & UX_PICTBRIDGE_API_CHAR_REPERTOIRES)
251     {
252         /* Add the line <charRepertoires/> */
253         status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_charrepertoires,
254                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_SLASH_AT_END,
255                                                 UX_NULL, 0,
256                                                 UX_NULL, &pima_object_buffer, &object_length);
257         if (status != UX_SUCCESS)
258             return(status);
259     }
260 
261     /* Add the line </capability>  */
262     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_capability,
263                                                 UX_PICTBRIDGE_TAG_FLAG_END,
264                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
265     if (status != UX_SUCCESS)
266         return(status);
267 
268     /* Add the line </getcapability>  */
269     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_getcapability,
270                                                 UX_PICTBRIDGE_TAG_FLAG_END,
271                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
272     if (status != UX_SUCCESS)
273         return(status);
274 
275     /* Update the caller's object position.  */
276     *pima_object_buffer_updated = pima_object_buffer;
277 
278     /* Update the caller's object length .  */
279     *object_length_updated = object_length;
280 
281     /* Return completion status.  */
282     return(UX_SUCCESS);
283 }
284 
285