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 |
|
|
/** Device Storage Class */ |
18 |
|
|
/** */ |
19 |
|
|
/**************************************************************************/ |
20 |
|
|
/**************************************************************************/ |
21 |
|
|
|
22 |
|
|
#define UX_SOURCE_CODE |
23 |
|
|
|
24 |
|
|
|
25 |
|
|
/* Include necessary system files. */ |
26 |
|
|
|
27 |
|
|
#include "ux_api.h" |
28 |
|
|
#include "ux_device_class_storage.h" |
29 |
|
|
#include "ux_device_stack.h" |
30 |
|
|
|
31 |
|
|
|
32 |
|
|
#if UX_SLAVE_CLASS_STORAGE_BUFFER_SIZE < UX_SLAVE_CLASS_STORAGE_READ_FORMAT_CAPACITY_RESPONSE_LENGTH |
33 |
|
|
/* #error UX_SLAVE_CLASS_STORAGE_BUFFER_SIZE too small, please check */ |
34 |
|
|
/* Build option checked runtime by UX_ASSERT */ |
35 |
|
|
#endif |
36 |
|
|
|
37 |
|
|
/**************************************************************************/ |
38 |
|
|
/* */ |
39 |
|
|
/* FUNCTION RELEASE */ |
40 |
|
|
/* */ |
41 |
|
|
/* _ux_device_class_storage_read_format_capacity PORTABLE C */ |
42 |
|
|
/* 6.3.0 */ |
43 |
|
|
/* AUTHOR */ |
44 |
|
|
/* */ |
45 |
|
|
/* Chaoqiong Xiao, Microsoft Corporation */ |
46 |
|
|
/* */ |
47 |
|
|
/* DESCRIPTION */ |
48 |
|
|
/* */ |
49 |
|
|
/* This function performs a READ_FORMAT_CAPACITY command. */ |
50 |
|
|
/* */ |
51 |
|
|
/* INPUT */ |
52 |
|
|
/* */ |
53 |
|
|
/* storage Pointer to storage class */ |
54 |
|
|
/* endpoint_in Pointer to IN endpoint */ |
55 |
|
|
/* endpoint_out Pointer to OUT endpoint */ |
56 |
|
|
/* cbwcb Pointer to CBWCB */ |
57 |
|
|
/* */ |
58 |
|
|
/* OUTPUT */ |
59 |
|
|
/* */ |
60 |
|
|
/* Completion Status */ |
61 |
|
|
/* */ |
62 |
|
|
/* CALLS */ |
63 |
|
|
/* */ |
64 |
|
|
/* _ux_device_class_storage_csw_send Send CSW */ |
65 |
|
|
/* _ux_device_stack_transfer_request Transfer request */ |
66 |
|
|
/* _ux_utility_memory_set Set memory */ |
67 |
|
|
/* _ux_utility_long_put_big_endian Put 32-bit big endian */ |
68 |
|
|
/* _ux_utility_memory_copy Copy memory */ |
69 |
|
|
/* */ |
70 |
|
|
/* CALLED BY */ |
71 |
|
|
/* */ |
72 |
|
|
/* Device Storage Class */ |
73 |
|
|
/* */ |
74 |
|
|
/* RELEASE HISTORY */ |
75 |
|
|
/* */ |
76 |
|
|
/* DATE NAME DESCRIPTION */ |
77 |
|
|
/* */ |
78 |
|
|
/* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */ |
79 |
|
|
/* 09-30-2020 Chaoqiong Xiao Modified comment(s), */ |
80 |
|
|
/* optimized command logic, */ |
81 |
|
|
/* verified memset and memcpy */ |
82 |
|
|
/* cases, */ |
83 |
|
|
/* resulting in version 6.1 */ |
84 |
|
|
/* 01-31-2022 Chaoqiong Xiao Modified comment(s), */ |
85 |
|
|
/* added standalone support, */ |
86 |
|
|
/* resulting in version 6.1.10 */ |
87 |
|
|
/* 10-31-2023 Chaoqiong Xiao Modified comment(s), */ |
88 |
|
|
/* checked compiling options */ |
89 |
|
|
/* by runtime UX_ASSERT, */ |
90 |
|
|
/* resulting in version 6.3.0 */ |
91 |
|
|
/* */ |
92 |
|
|
/**************************************************************************/ |
93 |
|
353 |
UINT _ux_device_class_storage_read_format_capacity(UX_SLAVE_CLASS_STORAGE *storage, ULONG lun, |
94 |
|
|
UX_SLAVE_ENDPOINT *endpoint_in, |
95 |
|
|
UX_SLAVE_ENDPOINT *endpoint_out, UCHAR * cbwcb) |
96 |
|
|
{ |
97 |
|
|
|
98 |
|
|
UINT status; |
99 |
|
|
UX_SLAVE_TRANSFER *transfer_request; |
100 |
|
|
UCHAR *read_format_capacity_buffer; |
101 |
|
|
|
102 |
|
|
UX_PARAMETER_NOT_USED(cbwcb); |
103 |
|
|
UX_PARAMETER_NOT_USED(endpoint_out); |
104 |
|
|
|
105 |
|
|
/* Build option check. */ |
106 |
|
|
UX_ASSERT(UX_SLAVE_CLASS_STORAGE_BUFFER_SIZE >= UX_SLAVE_CLASS_STORAGE_READ_FORMAT_CAPACITY_RESPONSE_LENGTH); |
107 |
|
|
|
108 |
|
|
/* If trace is enabled, insert this event into the trace buffer. */ |
109 |
|
|
UX_TRACE_IN_LINE_INSERT(UX_TRACE_DEVICE_CLASS_STORAGE_READ_FORMAT_CAPACITY, storage, lun, 0, 0, UX_TRACE_DEVICE_CLASS_EVENTS, 0, 0) |
110 |
|
|
|
111 |
|
|
/* Obtain the pointer to the transfer request. */ |
112 |
|
353 |
transfer_request = &endpoint_in -> ux_slave_endpoint_transfer_request; |
113 |
|
|
|
114 |
|
|
/* Get read format capacity response buffer. */ |
115 |
|
353 |
read_format_capacity_buffer = transfer_request -> ux_slave_transfer_request_data_pointer; |
116 |
|
|
|
117 |
|
|
/* Ensure it is cleaned. */ |
118 |
|
353 |
_ux_utility_memory_set(read_format_capacity_buffer, 0, UX_SLAVE_CLASS_STORAGE_READ_FORMAT_CAPACITY_RESPONSE_LENGTH); /* Use case of memset is verified. */ |
119 |
|
|
|
120 |
|
|
/* Insert the size of the response block. */ |
121 |
|
353 |
_ux_utility_long_put_big_endian(&read_format_capacity_buffer[UX_SLAVE_CLASS_STORAGE_READ_FORMAT_CAPACITY_RESPONSE_SIZE], 8); |
122 |
|
|
|
123 |
|
|
/* Insert the last LBA address in the response. */ |
124 |
|
353 |
_ux_utility_long_put_big_endian(&read_format_capacity_buffer[UX_SLAVE_CLASS_STORAGE_READ_FORMAT_CAPACITY_RESPONSE_LAST_LBA], |
125 |
|
|
storage -> ux_slave_class_storage_lun[lun].ux_slave_class_storage_media_last_lba); |
126 |
|
|
|
127 |
|
|
/* Insert the block length in the response. This is in 3 bytes. */ |
128 |
|
353 |
_ux_utility_long_put_big_endian(&read_format_capacity_buffer[UX_SLAVE_CLASS_STORAGE_READ_FORMAT_CAPACITY_RESPONSE_BLOCK_SIZE], |
129 |
|
|
storage -> ux_slave_class_storage_lun[lun].ux_slave_class_storage_media_block_length); |
130 |
|
|
|
131 |
|
|
/* Insert the response code : always 2. */ |
132 |
|
353 |
read_format_capacity_buffer[UX_SLAVE_CLASS_STORAGE_READ_FORMAT_CAPACITY_RESPONSE_DESC_CODE] = 2; |
133 |
|
|
|
134 |
|
|
#if defined(UX_DEVICE_STANDALONE) |
135 |
|
|
|
136 |
|
|
/* Next: Transfer (DATA). */ |
137 |
|
|
storage -> ux_device_class_storage_state = UX_DEVICE_CLASS_STORAGE_STATE_TRANS_START; |
138 |
|
|
storage -> ux_device_class_storage_cmd_state = UX_DEVICE_CLASS_STORAGE_CMD_READ; |
139 |
|
|
|
140 |
|
|
storage -> ux_device_class_storage_transfer = transfer_request; |
141 |
|
|
storage -> ux_device_class_storage_device_length = |
142 |
|
|
UX_SLAVE_CLASS_STORAGE_READ_FORMAT_CAPACITY_RESPONSE_LENGTH; |
143 |
|
|
storage -> ux_device_class_storage_data_length = |
144 |
|
|
UX_SLAVE_CLASS_STORAGE_READ_FORMAT_CAPACITY_RESPONSE_LENGTH; |
145 |
|
|
storage -> ux_device_class_storage_data_count = 0; |
146 |
|
|
UX_SLAVE_TRANSFER_STATE_RESET(storage -> ux_device_class_storage_transfer); |
147 |
|
|
|
148 |
|
|
#else |
149 |
|
|
|
150 |
|
|
/* Send a data payload with the read_capacity response buffer. */ |
151 |
|
353 |
_ux_device_stack_transfer_request(transfer_request, |
152 |
|
|
UX_SLAVE_CLASS_STORAGE_READ_FORMAT_CAPACITY_RESPONSE_LENGTH, |
153 |
|
|
UX_SLAVE_CLASS_STORAGE_READ_FORMAT_CAPACITY_RESPONSE_LENGTH); |
154 |
|
|
#endif |
155 |
|
|
|
156 |
|
|
/* Now we set the CSW with success. */ |
157 |
|
353 |
storage -> ux_slave_class_storage_csw_status = UX_SLAVE_CLASS_STORAGE_CSW_PASSED; |
158 |
|
353 |
status = UX_SUCCESS; |
159 |
|
|
|
160 |
|
|
/* Return completion status. */ |
161 |
|
353 |
return(status); |
162 |
|
|
} |
163 |
|
|
|