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_host_class_pima.h"
31 
32 
33 /**************************************************************************/
34 /*                                                                        */
35 /*  FUNCTION                                               RELEASE        */
36 /*                                                                        */
37 /*    _ux_pictbridge_dpshost_output_object_create         PORTABLE C      */
38 /*                                                           6.1          */
39 /*  AUTHOR                                                                */
40 /*                                                                        */
41 /*    Chaoqiong Xiao, Microsoft Corporation                               */
42 /*                                                                        */
43 /*  DESCRIPTION                                                           */
44 /*                                                                        */
45 /*    This function creates an output report based on the parsing of      */
46 /*    a previous input object.                                            */
47 /*                                                                        */
48 /*  INPUT                                                                 */
49 /*                                                                        */
50 /*    pictbridge                             Pictbridge instance          */
51 /*                                                                        */
52 /*  OUTPUT                                                                */
53 /*                                                                        */
54 /*    Completion Status                                                   */
55 /*                                                                        */
56 /*  CALLS                                                                 */
57 /*                                                                        */
58 /*                                                                        */
59 /*  CALLED BY                                                             */
60 /*                                                                        */
61 /*    _ux_pictbridge_dpshost_object_get                                   */
62 /*                                                                        */
63 /*  RELEASE HISTORY                                                       */
64 /*                                                                        */
65 /*    DATE              NAME                      DESCRIPTION             */
66 /*                                                                        */
67 /*  05-19-2020     Chaoqiong Xiao           Initial Version 6.0           */
68 /*  09-30-2020     Chaoqiong Xiao           Modified comment(s),          */
69 /*                                            verified memset and memcpy  */
70 /*                                            cases,                      */
71 /*                                            resulting in version 6.1    */
72 /*                                                                        */
73 /**************************************************************************/
_ux_pictbridge_dpshost_output_object_create(UX_PICTBRIDGE * pictbridge)74 UINT  _ux_pictbridge_dpshost_output_object_create(UX_PICTBRIDGE *pictbridge)
75 {
76 UINT                                status;
77 ULONG                               object_length;
78 UCHAR                               *pima_object_buffer;
79 UX_HOST_CLASS_PIMA_OBJECT           *pima_object;
80 
81     /* Get the address of the object container.  */
82     pima_object =  (UX_HOST_CLASS_PIMA_OBJECT *) pictbridge -> ux_pictbridge_object_host;
83 
84     /* And its buffer address.  */
85     pima_object_buffer = pima_object -> ux_host_class_pima_object_buffer;
86 
87     /* Reset the object length.  */
88     object_length =  0;
89 
90     /* Clear the object memory buffer.  */
91    _ux_utility_memory_set(pima_object_buffer, 0, UX_PICTBRIDGE_MAX_PIMA_OBJECT_BUFFER); /* Use case of memset is verified. */
92 
93 
94     /* Add the line <?xml version="1.0"?>  */
95     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_xmlversion,
96                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_LF,
97                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
98     if (status != UX_SUCCESS)
99         return(status);
100 
101     /* Add the line <dps xmlns="http://www.cipa.jp/dps/schema/">  */
102     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_dpsxmlns,
103                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_LF,
104                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
105     if (status != UX_SUCCESS)
106         return(status);
107 
108     /* Add the line <output>  */
109     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_output,
110                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_LF,
111                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
112     if (status != UX_SUCCESS)
113         return(status);
114 
115     /* Add the line <result> xxxxxxxx </result> */
116     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_result,
117                                             UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_END | UX_PICTBRIDGE_TAG_FLAG_VARIABLE_HEXA,
118                                             UX_NULL, 0, (VOID *)(ALIGN_TYPE) pictbridge -> ux_pictbridge_operation_result, &pima_object_buffer, &object_length);
119     if (status != UX_SUCCESS)
120         return(status);
121 
122     /* Look into the tag code from the input object and proceed to individual functions.  */
123     switch (pictbridge -> ux_pictbridge_input_request)
124     {
125 
126         case UX_PICTBRIDGE_IR_CONFIGURE_PRINT_SERVICE           :
127 
128             /* Insert the ConfigurePrintService tag lines.  */
129             status = _ux_pictbridge_dpshost_output_object_configure_print_service(pictbridge, pima_object_buffer, object_length, &pima_object_buffer, &object_length);
130             break;
131 
132         case UX_PICTBRIDGE_IR_GET_CAPABILITY                    :
133 
134             /* Insert the Getcapability tag lines.  */
135             status = _ux_pictbridge_dpshost_output_object_get_capability(pictbridge, pima_object_buffer, object_length, &pima_object_buffer, &object_length);
136             break;
137         case UX_PICTBRIDGE_IR_GET_JOB_STATUS                    :
138         case UX_PICTBRIDGE_IR_GET_DEVICE_STATUS                 :
139 
140             /* Insert the getDeviceStatus tag lines.  */
141             status = _ux_pictbridge_dpshost_output_object_get_device_status(pictbridge, pima_object_buffer, object_length, &pima_object_buffer, &object_length);
142             break;
143         case UX_PICTBRIDGE_IR_START_JOB                         :
144 
145             /* The Start Job adds the line </startJob> after the result. Weird syntax ! */
146             status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_startjob,
147                                                 UX_PICTBRIDGE_TAG_FLAG_BEGIN | UX_PICTBRIDGE_TAG_FLAG_FORCE_LF | UX_PICTBRIDGE_TAG_FLAG_FORCE_SLASH_AT_END,
148                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
149 
150 
151             status =  UX_SUCCESS;
152             break;
153 
154         case UX_PICTBRIDGE_IR_ABORT_JOB                         :
155         case UX_PICTBRIDGE_IR_CONTINUE_JOB                      :
156         case UX_PICTBRIDGE_IR_NOTIFY_JOB_STATUS                 :
157         case UX_PICTBRIDGE_IR_NOTIFY_DEVICE_STATUS              :
158 
159         default                                                 :
160             /* Function not yet supported.  */
161 
162             /* We have a syntax error !  */
163             status = (UX_ERROR);
164     }
165     if (status != UX_SUCCESS)
166         return(status);
167 
168     /* Add the line </output>  */
169     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_output,
170                                                 UX_PICTBRIDGE_TAG_FLAG_END,
171                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
172     if (status != UX_SUCCESS)
173         return(status);
174 
175     /* Add the line </dps>  */
176     status = _ux_pictbridge_object_tag_line_add(pima_object_buffer, object_length, _ux_pictbridge_xml_tag_line_dps,
177                                                 UX_PICTBRIDGE_TAG_FLAG_END,
178                                                 UX_NULL, 0, UX_NULL, &pima_object_buffer, &object_length);
179     if (status != UX_SUCCESS)
180         return(status);
181 
182     /* Store the length of the new object waiting to be sent out.
183        We do not store the length into the object itself since this function is
184        host\client agnostic.  */
185     pima_object -> ux_host_class_pima_object_length = object_length;
186 
187     /* Return completion status.  */
188     return(status);
189 }
190 
191