2 * Copyright 2010, Andreas Färber <andreas.faerber@web.de>
3 * All rights reserved. Distributed under the terms of the MIT License.
12 // TODO Add Little Endian support by introducing more macros
13 #if __BYTE_ORDER != __BIG_ENDIAN
14 #error Only Big Endian systems supported yet.
18 // iSCSI Basic Header Segment (BHS) (RFC 3720 10.2.1)
20 #define ISCSI_BHS_BYTE0 \
22 bool immediateDelivery : 1; \
25 // TODO This macro is LE-incompatible
26 #define ISCSI_BHS_START \
30 #define ISCSI_BHS_LENGTHS \
31 uint8 totalAHSLength; \
32 uint32 dataSegmentLength : 24;
34 #define ISCSI_BHS_TASK_TAG \
35 uint32 initiatorTaskTag;
37 #define ISCSI_BHS_TAGS \
39 uint32 targetTransferTag;
41 struct iscsi_basic_header_segment
{
43 uint32 opcodeSpecific
: 23;
47 uint8 opcodeSpecific2
[28];
51 #define ISCSI_OPCODE_NOP_OUT 0x00
52 #define ISCSI_OPCODE_SCSI_COMMAND 0x01
53 #define ISCSI_OPCODE_LOGIN_REQUEST 0x03
54 #define ISCSI_OPCODE_TEXT_REQUEST 0x04
55 #define ISCSI_OPCODE_LOGOUT_REQUEST 0x06
57 #define ISCSI_OPCODE_NOP_IN 0x20
58 #define ISCSI_OPCODE_SCSI_RESPONSE 0x21
59 #define ISCSI_OPCODE_LOGIN_RESPONSE 0x23
60 #define ISCSI_OPCODE_TEXT_RESPONSE 0x24
61 #define ISCSI_OPCODE_SCSI_DATA_IN 0x25
62 #define ISCSI_OPCODE_LOGOUT_RESPONSE 0x26
64 // SCSI Command (RFC 3720 10.3)
65 struct iscsi_scsi_command
{
69 opcode(ISCSI_OPCODE_SCSI_COMMAND
),
83 uint32 expectedDataTransferLength
;
89 // SCSI Response (RFC 3720 10.4)
90 struct iscsi_scsi_response
{
108 uint32 bidirectionalReadResidualCount
;
109 uint32 residualCount
;
112 // SCSI Data-In (RFC 3270 10.7)
113 struct iscsi_scsi_data_in
{
115 bool acknowledge
: 1;
130 uint32 residualCount
;
133 // Text Request (RFC 3720 10.10)
134 struct iscsi_text_request
{
138 opcode(ISCSI_OPCODE_TEXT_REQUEST
),
147 bool c
: 1; // continue
148 uint32 reserved2
: 22;
157 // Text Response (RFC 3720 10.11)
158 struct iscsi_text_response
{
160 bool c
: 1; // continue
161 uint32 reserved2
: 22;
179 // Login Request (RFC 3720 10.12)
180 struct iscsi_login_request
{
181 iscsi_login_request()
184 immediateDelivery(1),
185 opcode(ISCSI_OPCODE_LOGIN_REQUEST
),
189 memset(reserved4
, 0, sizeof(reserved4
));
194 bool c
: 1; // continue
196 uint8 currentStage
: 2;
211 #define ISCSI_SESSION_STAGE_SECURITY_NEGOTIATION 0
212 #define ISCSI_SESSION_STAGE_LOGIN_OPERATIONAL_NEGOTIATION 1
213 #define ISCSI_SESSION_STAGE_FULL_FEATURE_PHASE 3
215 #define ISCSI_VERSION 0x00
217 #define ISCSI_ISID_OUI 0
218 #define ISCSI_ISID_EN 1
219 #define ISCSI_ISID_RANDOM 2
221 // Login Response (RFC 3720 10.13)
222 struct iscsi_login_response
{
225 bool c
: 1; // continue
227 uint8 currentStage
: 2;
245 // Logout Request (RFC 3720 10.14)
246 struct iscsi_logout_request
{
247 iscsi_logout_request()
250 opcode(ISCSI_OPCODE_LOGOUT_REQUEST
),
263 uint8 reasonCode
: 7;
275 #define ISCSI_LOGOUT_REASON_CLOSE_SESSION 0
276 #define ISCSI_LOGOUT_REASON_CLOSE_CONNECTION 1
277 #define ISCSI_LOGOUT_REASON_REMOVE_CONNECTION 2
279 // Logout Response (RFC 3720 10.15)
280 struct iscsi_logout_response
{
298 // NOP-Out (RFC 3270, 10.18)
299 struct iscsi_nop_out
{
303 opcode(ISCSI_OPCODE_NOP_OUT
),
313 uint32 reserved2
: 23;
322 // NOP-In (RFC 3270, 10.19)
323 struct iscsi_nop_in
{
325 uint32 reserved2
: 23;