2 * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
3 * By downloading, copying, installing or using the software you agree
4 * to this license. If you do not agree to this license, do not
5 * download, install, copy or use the software.
7 * Intel License Agreement
9 * Copyright (c) 2000, Intel Corporation
10 * All rights reserved.
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
16 * -Redistributions of source code must retain the above copyright
17 * notice, this list of conditions and the following disclaimer.
19 * -Redistributions in binary form must reproduce the above copyright
20 * notice, this list of conditions and the following disclaimer in the
21 * documentation and/or other materials provided with the
24 * -The name of Intel Corporation may not be used to endorse or
25 * promote products derived from this software without specific prior
28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
31 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL
32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
35 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
36 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
37 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
38 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
44 #include "iscsiutil.h"
50 #define ISCSI_VENDOR "NetBSD"
51 #define ISCSI_PRODUCT "NetBSD iSCSI"
52 #define ISCSI_VERSION 0
58 #define ISCSI_IMMEDIATE_DATA_DFLT 1
59 #define ISCSI_INITIAL_R2T_DFLT 1
60 #define ISCSI_USE_PHASE_COLLAPSED_READ_DFLT 0
61 #define ISCSI_HEADER_LEN 48
62 #define ISCSI_PORT 3260 /* Default port */
63 #define ISCSI_OPCODE(HEADER) (HEADER[0] & 0x3f)
65 #define ISCSI_FIRST_BURST (ISCSI_FIRST_BURST_DFLT)
66 #define ISCSI_DATA_PDU_LENGTH (ISCSI_DATA_PDU_LENGTH_DFLT)
73 ISCSI_SCSI_CMD
= 0x01,
74 ISCSI_TASK_CMD
= 0x02,
75 ISCSI_LOGIN_CMD
= 0x03,
76 ISCSI_TEXT_CMD
= 0x04,
77 ISCSI_WRITE_DATA
= 0x05,
78 ISCSI_LOGOUT_CMD
= 0x06,
79 ISCSI_SNACK
= 0x10, /* not implemented */
81 ISCSI_SCSI_RSP
= 0x21,
82 ISCSI_TASK_RSP
= 0x22,
83 ISCSI_LOGIN_RSP
= 0x23,
84 ISCSI_TEXT_RSP
= 0x24,
85 ISCSI_READ_DATA
= 0x25,
86 ISCSI_LOGOUT_RSP
= 0x26,
93 ISCSI_AHS_EXTENDED_CDB
= 0x01,
94 ISCSI_AHS_BIDI_READ
= 0x02
101 ISCSI_LOGIN_STATUS_SUCCESS
= 0,
102 ISCSI_LOGIN_STATUS_REDIRECTION
= 1,
103 ISCSI_LOGIN_STATUS_INITIATOR_ERROR
= 2,
104 ISCSI_LOGIN_STATUS_TARGET_ERROR
= 3,
106 ISCSI_LOGIN_STAGE_SECURITY
= 0,
107 ISCSI_LOGIN_STAGE_NEGOTIATE
= 1,
108 ISCSI_LOGIN_STAGE_FULL_FEATURE
= 3
111 /* detailed return codes for login phase */
113 ISCSI_LOGIN_DETAIL_SUCCESS
= 0x0,
114 ISCSI_LOGIN_DETAIL_INIT_AUTH_FAILURE
= 0x01,
115 ISCSI_LOGIN_DETAIL_VERSION_NOT_SUPPORTED
= 0x05,
116 ISCSI_LOGIN_DETAIL_NOT_LOGGED_IN
= 0x0b
124 ISCSI_LOGOUT_CLOSE_SESSION
= 0,
125 ISCSI_LOGOUT_CLOSE_CONNECTION
= 1,
126 ISCSI_LOGOUT_CLOSE_RECOVERY
= 2,
128 ISCSI_LOGOUT_STATUS_SUCCESS
= 0,
129 ISCSI_LOGOUT_STATUS_NO_CID
= 1,
130 ISCSI_LOGOUT_STATUS_NO_RECOVERY
= 2,
131 ISCSI_LOGOUT_STATUS_FAILURE
= 3
139 ISCSI_TASK_CMD_ABORT_TASK
= 1,
140 ISCSI_TASK_CMD_ABORT_TASK_SET
= 2,
141 ISCSI_TASK_CMD_CLEAR_ACA
= 3,
142 ISCSI_TASK_CMD_CLEAR_TASK_SET
= 4,
143 ISCSI_TASK_CMD_LOGICAL_UNIT_RESET
= 5,
144 ISCSI_TASK_CMD_TARGET_WARM_RESET
= 6,
145 ISCSI_TASK_CMD_TARGET_COLD_RESET
= 7,
146 ISCSI_TASK_CMD_TARGET_REASSIGN
= 8
149 typedef struct iscsi_task_cmd_t
{
161 int iscsi_task_cmd_encap(uint8_t *header
, iscsi_task_cmd_t
* cmd
);
162 int iscsi_task_cmd_decap(uint8_t *header
, iscsi_task_cmd_t
* cmd
);
169 ISCSI_TASK_RSP_FUNCTION_COMPLETE
= 0,
170 ISCSI_TASK_RSP_NO_SUCH_TASK
= 1,
171 ISCSI_TASK_RSP_NO_SUCH_LUN
= 2,
172 ISCSI_TASK_RSP_STILL_ALLEGIANT
= 3,
173 ISCSI_TASK_RSP_NO_FAILOVER
= 4,
174 ISCSI_TASK_RSP_NO_SUPPORT
= 5,
175 ISCSI_TASK_RSP_AUTHORIZED_FAILED
= 6,
177 ISCSI_TASK_RSP_REJECTED
= 255,
179 ISCSI_TASK_QUAL_FUNCTION_EXECUTED
= 0,
180 ISCSI_TASK_QUAL_NOT_AUTHORIZED
= 1
183 typedef struct iscsi_task_rsp_t
{
192 int iscsi_task_rsp_encap(uint8_t *header
, iscsi_task_rsp_t
* rsp
);
193 int iscsi_task_rsp_decap(uint8_t *header
, iscsi_task_rsp_t
* rsp
);
201 typedef struct iscsi_nop_out_args_t
{
206 uint32_t transfer_tag
;
210 } iscsi_nop_out_args_t
;
212 int iscsi_nop_out_encap(uint8_t *header
, iscsi_nop_out_args_t
* cmd
);
213 int iscsi_nop_out_decap(uint8_t *header
, iscsi_nop_out_args_t
* cmd
);
221 typedef struct iscsi_nop_in_args_t
{
225 uint32_t transfer_tag
;
229 } iscsi_nop_in_args_t
;
231 int iscsi_nop_in_encap(uint8_t *header
, iscsi_nop_in_args_t
* cmd
);
232 int iscsi_nop_in_decap(uint8_t *header
, iscsi_nop_in_args_t
* cmd
);
240 typedef struct iscsi_text_cmd_args_t
{
247 uint32_t transfer_tag
;
251 } iscsi_text_cmd_args_t
;
253 int iscsi_text_cmd_encap(uint8_t *header
, iscsi_text_cmd_args_t
* cmd
);
254 int iscsi_text_cmd_decap(uint8_t *header
, iscsi_text_cmd_args_t
* cmd
);
262 typedef struct iscsi_text_rsp_args_t
{
268 uint32_t transfer_tag
;
272 } iscsi_text_rsp_args_t
;
274 int iscsi_text_rsp_encap(uint8_t *header
, iscsi_text_rsp_args_t
* rsp
);
275 int iscsi_text_rsp_decap(uint8_t *header
, iscsi_text_rsp_args_t
* rsp
);
283 typedef struct iscsi_login_cmd_args_t
{
299 } iscsi_login_cmd_args_t
;
301 int iscsi_login_cmd_encap(uint8_t *header
, iscsi_login_cmd_args_t
* cmd
);
302 int iscsi_login_cmd_decap(uint8_t *header
, iscsi_login_cmd_args_t
* cmd
);
310 typedef struct iscsi_login_rsp_args_t
{
316 int8_t version_active
;
325 uint8_t status_class
;
326 uint8_t status_detail
;
327 } iscsi_login_rsp_args_t
;
329 int iscsi_login_rsp_encap(uint8_t *header
, iscsi_login_rsp_args_t
* rsp
);
330 int iscsi_login_rsp_decap(uint8_t *header
, iscsi_login_rsp_args_t
* rsp
);
338 typedef struct iscsi_logout_cmd_args_t
{
345 } iscsi_logout_cmd_args_t
;
347 int iscsi_logout_cmd_encap(uint8_t *header
, iscsi_logout_cmd_args_t
* cmd
);
348 int iscsi_logout_cmd_decap(uint8_t *header
, iscsi_logout_cmd_args_t
* cmd
);
356 typedef struct iscsi_logout_rsp_args_t
{
364 uint16_t Time2Retain
;
365 } iscsi_logout_rsp_args_t
;
367 int iscsi_logout_rsp_encap(uint8_t *header
, iscsi_logout_rsp_args_t
* rsp
);
368 int iscsi_logout_rsp_decap(uint8_t *header
, iscsi_logout_rsp_args_t
* rsp
);
376 typedef struct iscsi_scsi_cmd_args_t
{
386 uint32_t bidi_trans_len
;
400 } iscsi_scsi_cmd_args_t
;
402 int iscsi_scsi_cmd_encap(uint8_t *header
, iscsi_scsi_cmd_args_t
* cmd
);
403 int iscsi_scsi_cmd_decap(uint8_t *header
, iscsi_scsi_cmd_args_t
* cmd
);
411 typedef struct iscsi_scsi_rsp_args_t
{
412 int32_t bidi_overflow
;
413 int32_t bidi_underflow
;
427 uint32_t bidi_res_cnt
;
428 uint32_t basic_res_cnt
;
431 int iscsi_scsi_rsp_encap(uint8_t *header
, iscsi_scsi_rsp_t
* rsp
);
432 int iscsi_scsi_rsp_decap(uint8_t *header
, iscsi_scsi_rsp_t
* rsp
);
436 * Ready To Transfer (R2T)
440 typedef struct iscsi_r2t_args_t
{
444 uint32_t transfer_tag
;
453 int iscsi_r2t_encap(uint8_t *header
, iscsi_r2t_t
* cmd
);
454 int iscsi_r2t_decap(uint8_t *header
, iscsi_r2t_t
* cmd
);
462 typedef struct iscsi_write_data_args_t
{
467 uint32_t transfer_tag
;
471 } iscsi_write_data_t
;
473 int iscsi_write_data_encap(uint8_t *header
, iscsi_write_data_t
* cmd
);
474 int iscsi_write_data_decap(uint8_t *header
, iscsi_write_data_t
* cmd
);
482 typedef struct iscsi_read_data_args_t
{
492 uint32_t transfer_tag
;
501 int iscsi_read_data_encap(uint8_t *header
, iscsi_read_data_t
* cmd
);
502 int iscsi_read_data_decap(uint8_t *header
, iscsi_read_data_t
* cmd
);
509 typedef struct iscsi_reject_args_t
{
520 int iscsi_reject_encap(uint8_t *header
, iscsi_reject_t
* cmd
);
521 int iscsi_reject_decap(uint8_t *header
, iscsi_reject_t
* cmd
);
527 typedef struct iscsi_async_msg_args_t
{
538 int iscsi_amsg_decap(uint8_t *header
, iscsi_async_msg_t
* msg
);
541 #define SOL_TCP IPPROTO_TCP