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 /** Device Pima Class */
19 /** */
20 /**************************************************************************/
21 /**************************************************************************/
22
23 #define UX_SOURCE_CODE
24
25
26 /* Include necessary system files. */
27
28 #include "ux_api.h"
29 #include "ux_device_class_pima.h"
30 #include "ux_device_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_device_class_pima_object_prop_desc_get PORTABLE C */
38 /* 6.1.10 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* Return an Object Property Description dataset for a format code and */
46 /* a specific object property. */
47 /* */
48 /* INPUT */
49 /* */
50 /* pima Pointer to pima class */
51 /* object_property Object Property */
52 /* object_format_code Object format for which the */
53 /* properties supported are. */
54 /* */
55 /* OUTPUT */
56 /* */
57 /* Completion Status */
58 /* */
59 /* CALLS */
60 /* */
61 /* _ux_device_stack_transfer_request Transfer request */
62 /* _ux_utility_long_put Put 32-bit value */
63 /* _ux_utility_short_put Put 32-bit value */
64 /* _ux_utility_memory_copy Copy memory */
65 /* _ux_device_class_pima_response_send Send PIMA response */
66 /* */
67 /* CALLED BY */
68 /* */
69 /* Device Pima Class */
70 /* */
71 /* RELEASE HISTORY */
72 /* */
73 /* DATE NAME DESCRIPTION */
74 /* */
75 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
76 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
77 /* verified memset and memcpy */
78 /* cases, */
79 /* resulting in version 6.1 */
80 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
81 /* updated status handling, */
82 /* passed max length to app, */
83 /* resulting in version 6.1.10 */
84 /* */
85 /**************************************************************************/
_ux_device_class_pima_object_prop_desc_get(UX_SLAVE_CLASS_PIMA * pima,ULONG object_property,ULONG object_format_code)86 UINT _ux_device_class_pima_object_prop_desc_get(UX_SLAVE_CLASS_PIMA *pima,
87 ULONG object_property,
88 ULONG object_format_code)
89 {
90
91 UINT status;
92 UX_SLAVE_TRANSFER *transfer_request;
93 UCHAR *object_prop_dataset;
94 ULONG object_prop_dataset_length;
95 UCHAR *object_props_desc;
96 UCHAR *object_props_desc_end;
97
98 /* If trace is enabled, insert this event into the trace buffer. */
99 UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_PIMA_GET_OBJECT_PROP_DESC, pima, object_property, object_format_code, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
100
101 /* Obtain the pointer to the transfer request. */
102 transfer_request = &pima -> ux_device_class_pima_bulk_in_endpoint -> ux_slave_endpoint_transfer_request;
103
104 /* Obtain memory for this object info. Use the transfer request pre-allocated memory. */
105 object_props_desc = transfer_request -> ux_slave_transfer_request_data_pointer;
106
107 /* Save the end of the object info. */
108 object_props_desc_end = object_props_desc + UX_SLAVE_REQUEST_DATA_MAX_LENGTH;
109
110 /* Fill in the data container type. */
111 _ux_utility_short_put(object_props_desc + UX_DEVICE_CLASS_PIMA_DATA_HEADER_TYPE,
112 UX_DEVICE_CLASS_PIMA_CT_DATA_BLOCK);
113
114 /* Fill in the data code. */
115 _ux_utility_short_put(object_props_desc + UX_DEVICE_CLASS_PIMA_DATA_HEADER_CODE,
116 UX_DEVICE_CLASS_PIMA_OC_GET_OBJECT_PROP_DESC);
117
118 /* Fill in the Transaction ID. */
119 _ux_utility_long_put(object_props_desc + UX_DEVICE_CLASS_PIMA_DATA_HEADER_TRANSACTION_ID,
120 pima -> ux_device_class_pima_transaction_id);
121
122 /* Call the application to retrieve the property description dataset. */
123 object_prop_dataset_length = UX_DEVICE_CLASS_PIMA_MAX_PAYLOAD;
124 status = pima -> ux_device_class_pima_object_prop_desc_get(pima, object_property, object_format_code, &object_prop_dataset, &object_prop_dataset_length);
125
126 /* See if we have the right format code and object property. */
127 if (status == UX_SUCCESS)
128 {
129
130 /* We have found the object property for the format code requested, retrieve the dataset. */
131
132 /* Do we have enough space? */
133 if (object_props_desc + UX_DEVICE_CLASS_PIMA_DATA_HEADER_SIZE + object_prop_dataset_length <= object_props_desc_end)
134 {
135
136 /* Copy the object property array. */
137 _ux_utility_memory_copy(object_props_desc + UX_DEVICE_CLASS_PIMA_DATA_HEADER_SIZE,
138 object_prop_dataset, object_prop_dataset_length); /* Use case of memcpy is verified. */
139
140 /* Add the header size. */
141 object_prop_dataset_length += UX_DEVICE_CLASS_PIMA_DATA_HEADER_SIZE;
142
143 /* Fill in the size of the response header. */
144 _ux_utility_long_put(object_props_desc + UX_DEVICE_CLASS_PIMA_DATA_HEADER_LENGTH,
145 object_prop_dataset_length);
146
147 /* Send a data payload with the object props array. */
148 status = _ux_device_stack_transfer_request(transfer_request, object_prop_dataset_length, 0);
149
150 /* Now we return a response with success. */
151 _ux_device_class_pima_response_send(pima, UX_DEVICE_CLASS_PIMA_RC_OK, 0, 0, 0, 0);
152
153 /* Return status. */
154 return(status);
155 }
156 else
157 {
158
159 /* The dataset is too large for our buffer. */
160
161 /* Report the error to the application. */
162 _ux_system_error_handler(UX_SYSTEM_LEVEL_THREAD, UX_SYSTEM_CONTEXT_CLASS, UX_MEMORY_INSUFFICIENT);
163
164 /* Report the error. */
165 status = UX_DEVICE_CLASS_PIMA_RC_GENERAL_ERROR;
166 }
167 }
168
169 /* We get here when we did not find the object format code or the dataset was too large. */
170
171 /* Now we return a response with error code. */
172 _ux_device_class_pima_response_send(pima, status, 0, 0, 0, 0);
173
174 /* Return completion status. */
175 return(status);
176 }
177
178
179