-
Notifications
You must be signed in to change notification settings - Fork 1
/
scsi_cmd.h
245 lines (220 loc) · 6.75 KB
/
scsi_cmd.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*
*
* Copyright 2018 The wookey project team <wookey@ssi.gouv.fr>
* - Ryad Benadjila
* - Arnauld Michelizza
* - Mathieu Renard
* - Philippe Thierry
* - Philippe Trebuchet
*
* This package is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* the Free Software Foundation; either version 2.1 of the License, or (at
* ur option) any later version.
*
* This package is distributed in the hope that it will be useful, but WITHOUT ANY
* WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
* PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License along
* with this package; if not, write to the Free Software Foundation, Inc., 51
* Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
*/
#ifndef SCSI_CMD_H_
#define SCSI_CMD_H_
#include "usbmsc_framac_private.h"
/* SCSI commands list */
typedef enum {
SCSI_CMD_FORMAT_UNIT = 0x04, // Mandatory
SCSI_CMD_INQUIRY = 0x12, // Mandatory
SCSI_CMD_MODE_SELECT_6 = 0x15,
SCSI_CMD_MODE_SELECT_10 = 0x55,
SCSI_CMD_MODE_SENSE_10 = 0x5a, // Requiered for some bootable devices
SCSI_CMD_MODE_SENSE_6 = 0x1a, // Requiered for some bootable devices
SCSI_CMD_PREVENT_ALLOW_MEDIUM_REMOVAL = 0x1e,
SCSI_CMD_READ_6 = 0x08, // Mandatory for olders
SCSI_CMD_READ_10 = 0x28, // Mandatory
SCSI_CMD_READ_CAPACITY_10 = 0x25, // Mandatory
SCSI_CMD_READ_FORMAT_CAPACITIES = 0x23,
SCSI_CMD_REPORT_LUNS = 0xa0, // Mandatory
SCSI_CMD_REQUEST_SENSE = 0x03, // Mandatory
SCSI_CMD_SEND_DIAGNOSTIC = 0x1d, // Mandatory
SCSI_CMD_START_STOP_UNIT = 0x1b,
SCSI_CMD_SYNCHRONIZE_CACHE_10 = 0x35,
SCSI_CMD_TEST_UNIT_READY = 0x00, // Mandatory
SCSI_CMD_VERIFY_10 = 0x2f,
SCSI_CMD_WRITE_6 = 0x0a, // Mandatory for olders
SCSI_CMD_WRITE_10 = 0x2a, // Mandatory
SCSI_CMD_READ_CAPACITY_16 = 0x9e,
} scsi_operation_code_t;
#ifndef __FRAMAC__
/***************************
* about SCSI commands
*
* All commands here are defined as packed structure
* *without* the starting operation byte.
*
* All commands start with the same field (the operation byte)
* which is used to segregate commands.
*
* This byte is added to the cdb_t structure, associating
* this byte to an union associating all supported commands
* (see bellow)
**************************/
/* MODE SENSE 10 */
typedef struct __attribute__((packed)) {
uint8_t reserved1:3;
uint8_t LLBAA:2;
uint8_t DBD:2;
uint8_t reserved2:1;
uint8_t PC:2;
uint8_t page_code:6;
uint8_t sub_page_code;
uint16_t reserved3;
uint16_t allocation_length;
uint8_t control;
} cdb10_mode_sense_t;
/* PREVENT ALLOW REMOVAL */
typedef struct __attribute__((packed)) {
uint16_t reserved1;
uint8_t reserved2:6;
uint8_t prevent:2;
uint8_t control;
} cdb10_prevent_allow_removal_t;
/* REQUEST SENSE 10 */
typedef struct __attribute__((packed)) {
uint8_t reserved1:7;
uint8_t desc:1;
uint16_t reserved;
uint8_t allocation_length;
} cdb10_request_sense_t;
/* READ FORMAT CAPACITIES */
typedef struct __attribute__((packed)) {
uint8_t lun:3;
uint8_t reserved_1:5;
uint32_t reserved_2;
uint8_t reserved_3;
uint8_t allocation_length_msb;
uint8_t allocation_length_lsb;
uint16_t reserved_4;
uint8_t reserved_5;
} cdb12_read_format_capacities_t;
/* READ 6 / WRITE 6 */
typedef struct __attribute__((packed)) {
uint32_t reserved:3;
uint32_t logical_block:21;
uint8_t transfer_blocks;
uint8_t control;
} cdb6_t;
/* READ 10 / WRITE 10 */
typedef struct __attribute__((packed)) {
uint8_t misc1:3;
uint8_t service_action:5;
uint32_t logical_block;
uint8_t misc2;
uint16_t transfer_blocks;
uint8_t control;
} cdb10_t;
/* MODE SENSE 6 */
typedef struct __attribute__((packed)) {
uint8_t LUN:3;
uint8_t reserved4:1;
uint8_t DBD:1;
uint8_t reserved3:3;
uint8_t PC:2;
uint8_t page_code:6;
uint8_t reserved2;
uint8_t allocation_length;
uint8_t vendor_specific:2;
uint8_t reserved1:4;
uint8_t flag:1;
uint8_t link:1;
} cdb6_mode_sense_t;
/* MODE SELECT 6 */
typedef struct __attribute__((packed)) {
uint8_t reserved3:3;
uint8_t PF:1;
uint8_t reserved2:2;
uint8_t RTD:1;
uint8_t SP:1;
uint16_t reserved1;
uint8_t parameter_list_length;
uint8_t control;
} cdb6_mode_select_t;
/* INQUIRY 6 */
typedef struct __attribute__((packed)) {
uint8_t reserved:6;
uint8_t CMDDT:1; /* obsolete */
uint8_t EVPD:1;
uint8_t page_code;
uint16_t allocation_length;
uint8_t control;
} cdb6_inquiry_t;
/* MODE SELECT 10 */
typedef struct __attribute__((packed)) {
uint8_t reserved3:3;
uint8_t PF:1;
uint8_t reserved2:3;
uint8_t SP:1;
uint8_t reserved1_bis;
uint32_t reserved1;
uint16_t parameter_list_length;
uint8_t control;
} cdb10_mode_select_t;
/* REPORT LUNS */
typedef struct __attribute__((packed)) {
uint8_t reserved3;
uint8_t selected_report;
uint16_t reserved2_2;
uint8_t reserved2_1;
uint32_t allocation_length;
uint8_t reserved1;
uint8_t control;
} cdb12_report_luns_t;
/* READ CAPACITY 16 */
typedef struct __attribute__((packed)) {
uint8_t Reserved2:3;
uint8_t service_action:5;
uint64_t logical_block_address;
uint32_t allocation_length;
uint8_t Reserved1:7;
uint8_t PMI:1;
uint8_t control;
} cdb16_read_capacity_16_t;
/*
* polymorphic SCSI command content, using a C union
* type.
* Each command is identified by an operation attribute before
* the command content used as segregation field:
*
* [cmd id][type-variable, length variable cmd content]
*/
typedef union {
/* CDB 6 bytes length */
cdb6_t cdb6; /* read and write */
cdb6_mode_sense_t cdb6_mode_sense;
cdb6_mode_select_t cdb6_mode_select;
cdb6_inquiry_t cdb6_inquiry;
/* CDB 10 bytes length */
cdb10_t cdb10; /* read and write */
cdb10_mode_sense_t cdb10_mode_sense;
cdb10_mode_select_t cdb10_mode_select;
cdb10_prevent_allow_removal_t cdb10_prevent_allow_removal;
cdb10_request_sense_t cdb10_request_sense;
/* CDB 12 bytes length */
cdb12_report_luns_t cdb12_report_luns;
cdb12_read_format_capacities_t cdb12_read_format_capacities;
/* CDB 16 bytes length */
cdb16_read_capacity_16_t cdb16_read_capacity;
} u_cdb_payload;
/*
* SCSI command storage area, associating the operation byte
* and the union field in a packed content
*/
typedef struct __attribute__((packed)) {
uint8_t operation;
u_cdb_payload payload;
} cdb_t;
#endif/*__FRAMAC__*/
#endif /*!SCSI_CMD_H_ */