1 |
|
|
/*************************************************************************** |
2 |
|
|
* Copyright (c) 2024 Microsoft Corporation |
3 |
|
|
* Copyright (c) 2026-present Eclipse ThreadX contributors |
4 |
|
|
* |
5 |
|
|
* This program and the accompanying materials are made available under the |
6 |
|
|
* terms of the MIT License which is available at |
7 |
|
|
* https://opensource.org/licenses/MIT. |
8 |
|
|
* |
9 |
|
|
* SPDX-License-Identifier: MIT |
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 |
|
|
/**************************************************************************/ |
70 |
|
2619 |
VOID _ux_host_class_storage_cbw_initialize(UX_HOST_CLASS_STORAGE *storage, UINT flags, |
71 |
|
|
ULONG data_transfer_length, UINT command_length) |
72 |
|
|
{ |
73 |
|
|
|
74 |
|
|
UCHAR *cbw; |
75 |
|
|
|
76 |
|
|
|
77 |
|
|
/* Use a pointer for the cbw, easier to manipulate. */ |
78 |
|
2619 |
cbw = (UCHAR *) storage -> ux_host_class_storage_cbw; |
79 |
|
|
|
80 |
|
|
/* Store the signature of the CBW. */ |
81 |
|
2619 |
_ux_utility_long_put(cbw, UX_HOST_CLASS_STORAGE_CBW_SIGNATURE_MASK); |
82 |
|
|
|
83 |
|
|
/* Set the Tag, this value is simply an arbitrary number that is echoed by |
84 |
|
|
the device in the CSW. */ |
85 |
|
2619 |
_ux_utility_long_put(cbw + UX_HOST_CLASS_STORAGE_CBW_TAG, UX_HOST_CLASS_STORAGE_CBW_TAG_MASK); |
86 |
|
|
|
87 |
|
|
/* Store the Data Transfer Length expected for the data payload. */ |
88 |
|
2619 |
_ux_utility_long_put(cbw + UX_HOST_CLASS_STORAGE_CBW_DATA_LENGTH, data_transfer_length); |
89 |
|
|
|
90 |
|
|
/* Store the CBW Flag field that contains the transfer flags. */ |
91 |
|
2619 |
*(cbw + UX_HOST_CLASS_STORAGE_CBW_FLAGS) = (UCHAR)flags; |
92 |
|
|
|
93 |
|
|
/* Store the LUN value. */ |
94 |
|
2619 |
*(cbw + UX_HOST_CLASS_STORAGE_CBW_LUN) = (UCHAR)storage -> ux_host_class_storage_lun; |
95 |
|
|
|
96 |
|
|
/* Store the size of the SCSI command block that follows. */ |
97 |
|
2619 |
*(cbw + UX_HOST_CLASS_STORAGE_CBW_CB_LENGTH) = (UCHAR)command_length; |
98 |
|
|
|
99 |
|
|
/* Reset the SCSI command block. */ |
100 |
|
2619 |
_ux_utility_memory_set(cbw + UX_HOST_CLASS_STORAGE_CBW_CB, 0, (ULONG) command_length); /* Use case of memset is verified. */ |
101 |
|
|
|
102 |
|
|
/* Return to caller. */ |
103 |
|
2619 |
return; |
104 |
|
|
} |
105 |
|
|
|