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_storage_info_get PORTABLE C */
38 /* 6.1.12 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function returns the storage info structure to the host. */
46 /* */
47 /* INPUT */
48 /* */
49 /* pima Pointer to pima class */
50 /* */
51 /* OUTPUT */
52 /* */
53 /* Completion Status */
54 /* */
55 /* CALLS */
56 /* */
57 /* _ux_device_stack_transfer_request Transfer request */
58 /* _ux_utility_long_put Put 32-bit value */
59 /* _ux_utility_short_put Put 32-bit value */
60 /* _ux_utility_string_to_unicode Ascii string to unicode */
61 /* _ux_device_class_pima_response_send Send PIMA response */
62 /* */
63 /* CALLED BY */
64 /* */
65 /* Device Storage Class */
66 /* */
67 /* RELEASE HISTORY */
68 /* */
69 /* DATE NAME DESCRIPTION */
70 /* */
71 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
72 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
73 /* resulting in version 6.1 */
74 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
75 /* improved sanity checks, */
76 /* resulting in version 6.1.10 */
77 /* 07-29-2022 Chaoqiong Xiao Modified comment(s), */
78 /* added no-callback handling, */
79 /* resulting in version 6.1.12 */
80 /* */
81 /**************************************************************************/
_ux_device_class_pima_storage_info_get(UX_SLAVE_CLASS_PIMA * pima,ULONG storage_id)82 UINT _ux_device_class_pima_storage_info_get(UX_SLAVE_CLASS_PIMA *pima, ULONG storage_id)
83 {
84
85 UINT status;
86 UX_SLAVE_TRANSFER *transfer_request;
87 ULONG storage_info_length;
88 UCHAR *storage_info;
89 UCHAR *storage_info_pointer;
90
91 /* If trace is enabled, insert this event into the trace buffer. */
92 UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_PIMA_STORAGE_INFO_SEND, pima, 0, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
93
94 /* Obtain the pointer to the transfer request. */
95 transfer_request = &pima -> ux_device_class_pima_bulk_in_endpoint -> ux_slave_endpoint_transfer_request;
96
97 /* Obtain memory for this object info. Use the transfer request pre-allocated memory. */
98 storage_info = transfer_request -> ux_slave_transfer_request_data_pointer;
99
100 /* Update the storage information. We get the volatile parameters from the application. */
101 if (pima -> ux_device_class_pima_storage_info_get)
102 status = pima -> ux_device_class_pima_storage_info_get(pima, storage_id);
103 else
104 {
105 if (storage_id == pima -> ux_device_class_pima_storage_id)
106 status = UX_SUCCESS;
107 else
108 status = UX_DEVICE_CLASS_PIMA_RC_INVALID_STORAGE_ID;
109 }
110
111 /* Check for error. */
112 if (status != UX_SUCCESS)
113
114 /* We return an error. */
115 _ux_device_class_pima_response_send(pima, status, 0, 0, 0, 0);
116
117 else
118 {
119
120 /* Fill in the data container type. */
121 _ux_utility_short_put(storage_info + UX_DEVICE_CLASS_PIMA_DATA_HEADER_TYPE,
122 UX_DEVICE_CLASS_PIMA_CT_DATA_BLOCK);
123
124 /* Fill in the data code. */
125 _ux_utility_short_put(storage_info + UX_DEVICE_CLASS_PIMA_DATA_HEADER_CODE,
126 UX_DEVICE_CLASS_PIMA_OC_GET_STORAGE_INFO);
127
128 /* Fill in the Transaction ID. */
129 _ux_utility_long_put(storage_info + UX_DEVICE_CLASS_PIMA_DATA_HEADER_TRANSACTION_ID,
130 pima -> ux_device_class_pima_transaction_id);
131
132 /* Allocate the device info pointer to the beginning of the dynamic storage info field. */
133 storage_info_pointer = storage_info + UX_DEVICE_CLASS_PIMA_STORAGE_FREE_STORAGE_DESCRIPTION;
134
135 /* Fill in the storage type. */
136 _ux_utility_short_put(storage_info + UX_DEVICE_CLASS_PIMA_STORAGE_TYPE,
137 (USHORT)pima -> ux_device_class_pima_storage_type);
138
139 /* Fill in the file system type. */
140 _ux_utility_short_put(storage_info + UX_DEVICE_CLASS_PIMA_STORAGE_FILE_SYSTEM_TYPE,
141 (USHORT)pima -> ux_device_class_pima_storage_file_system_type);
142
143 /* Fill in the access capability. */
144 _ux_utility_short_put(storage_info + UX_DEVICE_CLASS_PIMA_STORAGE_ACCESS_CAPABILITY,
145 (USHORT)pima -> ux_device_class_pima_storage_access_capability);
146
147 /* Fill in the low dword of max capacity. */
148 _ux_utility_long_put(storage_info + UX_DEVICE_CLASS_PIMA_STORAGE_MAX_CAPACITY_LOW,
149 pima -> ux_device_class_pima_storage_max_capacity_low);
150
151 /* Fill in the high dword of max capacity. */
152 _ux_utility_long_put(storage_info + UX_DEVICE_CLASS_PIMA_STORAGE_MAX_CAPACITY_HIGH,
153 pima -> ux_device_class_pima_storage_max_capacity_high);
154
155 /* Fill in the low dword of free space. */
156 _ux_utility_long_put(storage_info + UX_DEVICE_CLASS_PIMA_STORAGE_FREE_SPACE_LOW,
157 pima -> ux_device_class_pima_storage_free_space_low);
158
159 /* Fill in the high dword of free space. */
160 _ux_utility_long_put(storage_info + UX_DEVICE_CLASS_PIMA_STORAGE_FREE_SPACE_HIGH,
161 pima -> ux_device_class_pima_storage_free_space_high);
162
163 /* Fill in the free space in image. */
164 _ux_utility_long_put(storage_info + UX_DEVICE_CLASS_PIMA_STORAGE_FREE_SPACE_IMAGE,
165 pima -> ux_device_class_pima_storage_free_space_image);
166
167 /* Sanity check for buffer length. */
168 UX_ASSERT(UX_DEVICE_CLASS_PIMA_STORAGE_FREE_STORAGE_DESCRIPTION + 2 +
169 _ux_utility_string_length_get(pima -> ux_device_class_pima_storage_description) * 2 +
170 _ux_utility_string_length_get(pima -> ux_device_class_pima_storage_volume_label) * 2);
171
172 /* Fill in the storage description string. */
173 _ux_utility_string_to_unicode(pima -> ux_device_class_pima_storage_description, storage_info_pointer);
174
175 /* Update the storage info pointer. */
176 storage_info_pointer += (ULONG) (*storage_info_pointer * 2) + 1;
177
178 /* Fill in the volume label string. */
179 _ux_utility_string_to_unicode(pima -> ux_device_class_pima_storage_volume_label, storage_info_pointer);
180
181 /* Update the storage info pointer. */
182 storage_info_pointer += (ULONG) (*storage_info_pointer* 2) + 1;
183
184 /* Compute the overall length of the storage info structure. */
185 storage_info_length = (ULONG) ((ALIGN_TYPE) storage_info_pointer - (ALIGN_TYPE) storage_info);
186
187 /* Fill in the size of the response header. */
188 _ux_utility_long_put(storage_info + UX_DEVICE_CLASS_PIMA_DATA_HEADER_LENGTH,
189 storage_info_length);
190
191 /* Send a data payload with the storage info data set. */
192 status = _ux_device_stack_transfer_request(transfer_request, storage_info_length, 0);
193
194 /* Now we return a response with success. */
195 _ux_device_class_pima_response_send(pima, UX_DEVICE_CLASS_PIMA_RC_OK, 0, 0, 0, 0);
196 }
197
198 /* Return completion status. */
199 return(status);
200 }
201