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 /** Storage Class */
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_host_class_storage.h"
30 #include "ux_host_stack.h"
31
32
33 /**************************************************************************/
34 /* */
35 /* FUNCTION RELEASE */
36 /* */
37 /* _ux_host_class_storage_cbw_initialize PORTABLE C */
38 /* 6.1.3 */
39 /* AUTHOR */
40 /* */
41 /* Chaoqiong Xiao, Microsoft Corporation */
42 /* */
43 /* DESCRIPTION */
44 /* */
45 /* This function will initialize the Command Block Wrapper (CBW) that */
46 /* encapsulate the SCSI request to be sent to the storage device. */
47 /* The CBW is normally used only for the BO protocol. */
48 /* */
49 /* INPUT */
50 /* */
51 /* storage Pointer to storage class */
52 /* flags Flags for transfer */
53 /* data_transfer_length Length of data transfer */
54 /* command_length Length of command */
55 /* */
56 /* OUTPUT */
57 /* */
58 /* None */
59 /* */
60 /* CALLS */
61 /* */
62 /* _ux_utility_long_put Write a 32-bit value */
63 /* _ux_utility_memory_set Set memory to a value */
64 /* */
65 /* CALLED BY */
66 /* */
67 /* Storage Class */
68 /* */
69 /* RELEASE HISTORY */
70 /* */
71 /* DATE NAME DESCRIPTION */
72 /* */
73 /* 05-19-2020 Chaoqiong Xiao Initial Version 6.0 */
74 /* 09-30-2020 Chaoqiong Xiao Modified comment(s), */
75 /* verified memset and memcpy */
76 /* cases, */
77 /* resulting in version 6.1 */
78 /* 12-31-2020 Chaoqiong Xiao Modified comment(s), */
79 /* resulting in version 6.1.3 */
80 /* */
81 /**************************************************************************/
_ux_host_class_storage_cbw_initialize(UX_HOST_CLASS_STORAGE * storage,UINT flags,ULONG data_transfer_length,UINT command_length)82 VOID _ux_host_class_storage_cbw_initialize(UX_HOST_CLASS_STORAGE *storage, UINT flags,
83 ULONG data_transfer_length, UINT command_length)
84 {
85
86 UCHAR *cbw;
87
88
89 /* Use a pointer for the cbw, easier to manipulate. */
90 cbw = (UCHAR *) storage -> ux_host_class_storage_cbw;
91
92 /* Store the signature of the CBW. */
93 _ux_utility_long_put(cbw, UX_HOST_CLASS_STORAGE_CBW_SIGNATURE_MASK);
94
95 /* Set the Tag, this value is simply an arbitrary number that is echoed by
96 the device in the CSW. */
97 _ux_utility_long_put(cbw + UX_HOST_CLASS_STORAGE_CBW_TAG, UX_HOST_CLASS_STORAGE_CBW_TAG_MASK);
98
99 /* Store the Data Transfer Length expected for the data payload. */
100 _ux_utility_long_put(cbw + UX_HOST_CLASS_STORAGE_CBW_DATA_LENGTH, data_transfer_length);
101
102 /* Store the CBW Flag field that contains the transfer flags. */
103 *(cbw + UX_HOST_CLASS_STORAGE_CBW_FLAGS) = (UCHAR)flags;
104
105 /* Store the LUN value. */
106 *(cbw + UX_HOST_CLASS_STORAGE_CBW_LUN) = (UCHAR)storage -> ux_host_class_storage_lun;
107
108 /* Store the size of the SCSI command block that follows. */
109 *(cbw + UX_HOST_CLASS_STORAGE_CBW_CB_LENGTH) = (UCHAR)command_length;
110
111 /* Reset the SCSI command block. */
112 _ux_utility_memory_set(cbw + UX_HOST_CLASS_STORAGE_CBW_CB, 0, (ULONG) command_length); /* Use case of memset is verified. */
113
114 /* Return to caller. */
115 return;
116 }
117
118