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 Storage 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_storage.h"
30 #include "ux_device_stack.h"
31
32 #define USBX_DEVICE_CLASS_STORAGE_DISK_INFORMATION_LENGTH 34
33 #if UX_SLAVE_REQUEST_DATA_MAX_LENGTH < USBX_DEVICE_CLASS_STORAGE_DISK_INFORMATION_LENGTH
34 #error UX_SLAVE_REQUEST_DATA_MAX_LENGTH is too small, please check
35 #endif
36 UCHAR usbx_device_class_storage_disk_information[] = {
37
38 0x00, 0x00, /* Entire length of disk_information */
39 0x0e, /* Erasable/state of last session/disk status ...*/
40 0x01, /* Number of first track on disk. */
41 0x01, /* Number of sessions. */
42 0x01, /* First track number in last session. */
43 0x01, /* Last track number in last session. */
44
45 0x00, /* DID_V, DBC_V, URU .... */
46 0x00, /* Disk type */
47 0x00, /* Number of sessions */
48 0x00, /* First Track Number in last session */
49 0x00, /* Last Track Number in last session */
50
51 0x00, 0x00, 0x00, 0x00, /* Disk Identification */
52 0xff, 0xff, 0xff, 0xff, /* Last session lead in start time */
53 0xff, 0xff, 0xff, 0xff, /* Last possible start time for SOLO */
54 0x00, 0x00, 0x00, 0x00, /* Disk Bar Code */
55 0x00, /* Reserved */
56 0x00, /* Number of OPC table entries. */
57 0x00, 0x00, 0x00, 0x00, /* Some padding ? */
58 0x00, 0x00 /* */
59
60 };
61
62 /**************************************************************************/
63 /* */
64 /* FUNCTION RELEASE */
65 /* */
66 /* _ux_device_class_storage_read_disk_information PORTABLE C */
67 /* 6.1.10 */
68 /* AUTHOR */
69 /* */
70 /* Chaoqiong Xiao, Microsoft Corporation */
71 /* */
72 /* DESCRIPTION */
73 /* */
74 /* This function performs a READ_DISK_INFORMATION command. */
75 /* */
76 /* INPUT */
77 /* */
78 /* storage Pointer to storage class */
79 /* endpoint_in Pointer to IN endpoint */
80 /* endpoint_out Pointer to OUT endpoint */
81 /* cbwcb Pointer to CBWCB */
82 /* */
83 /* OUTPUT */
84 /* */
85 /* Completion Status */
86 /* */
87 /* CALLS */
88 /* */
89 /* _ux_device_class_storage_csw_send Send CSW */
90 /* _ux_device_stack_transfer_request Transfer request */
91 /* _ux_utility_short_put_big_endian Put 16-bit big endian */
92 /* _ux_utility_memory_copy Copy memory */
93 /* */
94 /* CALLED BY */
95 /* */
96 /* Device Storage Class */
97 /* */
98 /* RELEASE HISTORY */
99 /* */
100 /* DATE NAME DESCRIPTION */
101 /* */
102 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
103 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
104 /* optimized command logic, */
105 /* verified memset and memcpy */
106 /* cases, */
107 /* resulting in version 6.1 */
108 /* 01-31-2022 Chaoqiong Xiao Modified comment(s), */
109 /* added standalone support, */
110 /* resulting in version 6.1.10 */
111 /* */
112 /**************************************************************************/
_ux_device_class_storage_read_disk_information(UX_SLAVE_CLASS_STORAGE * storage,ULONG lun,UX_SLAVE_ENDPOINT * endpoint_in,UX_SLAVE_ENDPOINT * endpoint_out,UCHAR * cbwcb)113 UINT _ux_device_class_storage_read_disk_information(UX_SLAVE_CLASS_STORAGE *storage, ULONG lun,
114 UX_SLAVE_ENDPOINT *endpoint_in,
115 UX_SLAVE_ENDPOINT *endpoint_out, UCHAR * cbwcb)
116 {
117
118 UINT status;
119 UX_SLAVE_TRANSFER *transfer_request;
120 ULONG allocation_length;
121
122 UX_PARAMETER_NOT_USED(endpoint_out);
123
124 /* If trace is enabled, insert this event into the trace buffer. */
125 UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_STORAGE_GET_CONFIGURATION, storage, lun, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0)
126
127 /* Initialize the length of the disk information field. */
128 _ux_utility_short_put_big_endian(usbx_device_class_storage_disk_information, (USBX_DEVICE_CLASS_STORAGE_DISK_INFORMATION_LENGTH - 2));
129
130 /* Clean the disk status. */
131 usbx_device_class_storage_disk_information[2] &= (UCHAR)~3;
132
133 /* Update the disk status. */
134 usbx_device_class_storage_disk_information[2] = (UCHAR)(usbx_device_class_storage_disk_information[2] | (storage -> ux_slave_class_storage_lun[lun].ux_slave_class_storage_disk_status & 3));
135
136 /* Clean the last session state. */
137 usbx_device_class_storage_disk_information[2] &= (UCHAR)~0x0c;
138
139 /* Update the last session state. */
140 usbx_device_class_storage_disk_information[2] = (UCHAR)(usbx_device_class_storage_disk_information[2] | ((storage -> ux_slave_class_storage_lun[lun].ux_slave_class_storage_last_session_state << 2) & 0x0c));
141
142 /* Obtain the pointer to the transfer request. */
143 transfer_request = &endpoint_in -> ux_slave_endpoint_transfer_request;
144
145 /* Get the allocation length. */
146 allocation_length = _ux_utility_short_get_big_endian(cbwcb + UX_SLAVE_CLASS_STORAGE_READ_DISK_INFORMATION_ALLOCATION_LENGTH);
147
148 /* Can we send all the disk information ? */
149 if (allocation_length > USBX_DEVICE_CLASS_STORAGE_DISK_INFORMATION_LENGTH)
150
151 /* Yes, so send only the disk information profile. */
152 allocation_length = USBX_DEVICE_CLASS_STORAGE_DISK_INFORMATION_LENGTH;
153
154 /* Copy the CSW into the transfer request memory. */
155 _ux_utility_memory_copy(transfer_request -> ux_slave_transfer_request_data_pointer,
156 usbx_device_class_storage_disk_information,
157 allocation_length); /* Use case of memcpy is verified. */
158
159 #if defined(UX_DEVICE_STANDALONE)
160
161 /* Next: Transfer (DATA). */
162 storage -> ux_device_class_storage_state = UX_DEVICE_CLASS_STORAGE_STATE_TRANS_START;
163 storage -> ux_device_class_storage_cmd_state = UX_DEVICE_CLASS_STORAGE_CMD_READ;
164
165 storage -> ux_device_class_storage_transfer = transfer_request;
166 storage -> ux_device_class_storage_device_length = allocation_length;
167 storage -> ux_device_class_storage_data_length = allocation_length;
168 storage -> ux_device_class_storage_data_count = 0;
169 UX_SLAVE_TRANSFER_STATE_RESET(storage -> ux_device_class_storage_transfer);
170
171 #else
172
173 /* Send a data payload with the read_capacity response buffer. */
174 _ux_device_stack_transfer_request(transfer_request,
175 allocation_length,
176 allocation_length);
177 #endif
178
179 /* Now we set the CSW with success. */
180 storage -> ux_slave_class_storage_csw_status = UX_SLAVE_CLASS_STORAGE_CSW_PASSED;
181 status = UX_SUCCESS;
182
183 /* Return completion status. */
184 return(status);
185 }
186
187