[PATCH] LSM: remove BSD secure level security module
[usb.git] / include / scsi / iscsi_proto.h
blob02f6e4b9e6932c407481d7c6ae5814b3ac4187f9
1 /*
2 * RFC 3720 (iSCSI) protocol data types
4 * Copyright (C) 2005 Dmitry Yusupov
5 * Copyright (C) 2005 Alex Aizman
6 * maintained by open-iscsi@googlegroups.com
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published
10 * by the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 * See the file COPYING included with this distribution for more details.
21 #ifndef ISCSI_PROTO_H
22 #define ISCSI_PROTO_H
24 #define ISCSI_DRAFT20_VERSION 0x00
26 /* default iSCSI listen port for incoming connections */
27 #define ISCSI_LISTEN_PORT 3260
29 /* Padding word length */
30 #define PAD_WORD_LEN 4
33 * useful common(control and data pathes) macro
35 #define ntoh24(p) (((p)[0] << 16) | ((p)[1] << 8) | ((p)[2]))
36 #define hton24(p, v) { \
37 p[0] = (((v) >> 16) & 0xFF); \
38 p[1] = (((v) >> 8) & 0xFF); \
39 p[2] = ((v) & 0xFF); \
41 #define zero_data(p) {p[0]=0;p[1]=0;p[2]=0;}
44 * iSCSI Template Message Header
46 struct iscsi_hdr {
47 uint8_t opcode;
48 uint8_t flags; /* Final bit */
49 uint8_t rsvd2[2];
50 uint8_t hlength; /* AHSs total length */
51 uint8_t dlength[3]; /* Data length */
52 uint8_t lun[8];
53 __be32 itt; /* Initiator Task Tag */
54 __be32 ttt; /* Target Task Tag */
55 __be32 statsn;
56 __be32 exp_statsn;
57 __be32 max_statsn;
58 uint8_t other[12];
61 /************************* RFC 3720 Begin *****************************/
63 #define ISCSI_RESERVED_TAG 0xffffffff
65 /* Opcode encoding bits */
66 #define ISCSI_OP_RETRY 0x80
67 #define ISCSI_OP_IMMEDIATE 0x40
68 #define ISCSI_OPCODE_MASK 0x3F
70 /* Initiator Opcode values */
71 #define ISCSI_OP_NOOP_OUT 0x00
72 #define ISCSI_OP_SCSI_CMD 0x01
73 #define ISCSI_OP_SCSI_TMFUNC 0x02
74 #define ISCSI_OP_LOGIN 0x03
75 #define ISCSI_OP_TEXT 0x04
76 #define ISCSI_OP_SCSI_DATA_OUT 0x05
77 #define ISCSI_OP_LOGOUT 0x06
78 #define ISCSI_OP_SNACK 0x10
80 #define ISCSI_OP_VENDOR1_CMD 0x1c
81 #define ISCSI_OP_VENDOR2_CMD 0x1d
82 #define ISCSI_OP_VENDOR3_CMD 0x1e
83 #define ISCSI_OP_VENDOR4_CMD 0x1f
85 /* Target Opcode values */
86 #define ISCSI_OP_NOOP_IN 0x20
87 #define ISCSI_OP_SCSI_CMD_RSP 0x21
88 #define ISCSI_OP_SCSI_TMFUNC_RSP 0x22
89 #define ISCSI_OP_LOGIN_RSP 0x23
90 #define ISCSI_OP_TEXT_RSP 0x24
91 #define ISCSI_OP_SCSI_DATA_IN 0x25
92 #define ISCSI_OP_LOGOUT_RSP 0x26
93 #define ISCSI_OP_R2T 0x31
94 #define ISCSI_OP_ASYNC_EVENT 0x32
95 #define ISCSI_OP_REJECT 0x3f
97 struct iscsi_ahs_hdr {
98 __be16 ahslength;
99 uint8_t ahstype;
100 uint8_t ahspec[5];
103 #define ISCSI_AHSTYPE_CDB 1
104 #define ISCSI_AHSTYPE_RLENGTH 2
106 /* iSCSI PDU Header */
107 struct iscsi_cmd {
108 uint8_t opcode;
109 uint8_t flags;
110 __be16 rsvd2;
111 uint8_t hlength;
112 uint8_t dlength[3];
113 uint8_t lun[8];
114 __be32 itt; /* Initiator Task Tag */
115 __be32 data_length;
116 __be32 cmdsn;
117 __be32 exp_statsn;
118 uint8_t cdb[16]; /* SCSI Command Block */
119 /* Additional Data (Command Dependent) */
122 /* Command PDU flags */
123 #define ISCSI_FLAG_CMD_FINAL 0x80
124 #define ISCSI_FLAG_CMD_READ 0x40
125 #define ISCSI_FLAG_CMD_WRITE 0x20
126 #define ISCSI_FLAG_CMD_ATTR_MASK 0x07 /* 3 bits */
128 /* SCSI Command Attribute values */
129 #define ISCSI_ATTR_UNTAGGED 0
130 #define ISCSI_ATTR_SIMPLE 1
131 #define ISCSI_ATTR_ORDERED 2
132 #define ISCSI_ATTR_HEAD_OF_QUEUE 3
133 #define ISCSI_ATTR_ACA 4
135 struct iscsi_rlength_ahdr {
136 __be16 ahslength;
137 uint8_t ahstype;
138 uint8_t reserved;
139 __be32 read_length;
142 /* SCSI Response Header */
143 struct iscsi_cmd_rsp {
144 uint8_t opcode;
145 uint8_t flags;
146 uint8_t response;
147 uint8_t cmd_status;
148 uint8_t hlength;
149 uint8_t dlength[3];
150 uint8_t rsvd[8];
151 __be32 itt; /* Initiator Task Tag */
152 __be32 rsvd1;
153 __be32 statsn;
154 __be32 exp_cmdsn;
155 __be32 max_cmdsn;
156 __be32 exp_datasn;
157 __be32 bi_residual_count;
158 __be32 residual_count;
159 /* Response or Sense Data (optional) */
162 /* Command Response PDU flags */
163 #define ISCSI_FLAG_CMD_BIDI_OVERFLOW 0x10
164 #define ISCSI_FLAG_CMD_BIDI_UNDERFLOW 0x08
165 #define ISCSI_FLAG_CMD_OVERFLOW 0x04
166 #define ISCSI_FLAG_CMD_UNDERFLOW 0x02
168 /* iSCSI Status values. Valid if Rsp Selector bit is not set */
169 #define ISCSI_STATUS_CMD_COMPLETED 0
170 #define ISCSI_STATUS_TARGET_FAILURE 1
171 #define ISCSI_STATUS_SUBSYS_FAILURE 2
173 /* Asynchronous Event Header */
174 struct iscsi_async {
175 uint8_t opcode;
176 uint8_t flags;
177 uint8_t rsvd2[2];
178 uint8_t rsvd3;
179 uint8_t dlength[3];
180 uint8_t lun[8];
181 uint8_t rsvd4[8];
182 __be32 statsn;
183 __be32 exp_cmdsn;
184 __be32 max_cmdsn;
185 uint8_t async_event;
186 uint8_t async_vcode;
187 __be16 param1;
188 __be16 param2;
189 __be16 param3;
190 uint8_t rsvd5[4];
193 /* iSCSI Event Codes */
194 #define ISCSI_ASYNC_MSG_SCSI_EVENT 0
195 #define ISCSI_ASYNC_MSG_REQUEST_LOGOUT 1
196 #define ISCSI_ASYNC_MSG_DROPPING_CONNECTION 2
197 #define ISCSI_ASYNC_MSG_DROPPING_ALL_CONNECTIONS 3
198 #define ISCSI_ASYNC_MSG_PARAM_NEGOTIATION 4
199 #define ISCSI_ASYNC_MSG_VENDOR_SPECIFIC 255
201 /* NOP-Out Message */
202 struct iscsi_nopout {
203 uint8_t opcode;
204 uint8_t flags;
205 __be16 rsvd2;
206 uint8_t rsvd3;
207 uint8_t dlength[3];
208 uint8_t lun[8];
209 __be32 itt; /* Initiator Task Tag */
210 __be32 ttt; /* Target Transfer Tag */
211 __be32 cmdsn;
212 __be32 exp_statsn;
213 uint8_t rsvd4[16];
216 /* NOP-In Message */
217 struct iscsi_nopin {
218 uint8_t opcode;
219 uint8_t flags;
220 __be16 rsvd2;
221 uint8_t rsvd3;
222 uint8_t dlength[3];
223 uint8_t lun[8];
224 __be32 itt; /* Initiator Task Tag */
225 __be32 ttt; /* Target Transfer Tag */
226 __be32 statsn;
227 __be32 exp_cmdsn;
228 __be32 max_cmdsn;
229 uint8_t rsvd4[12];
232 /* SCSI Task Management Message Header */
233 struct iscsi_tm {
234 uint8_t opcode;
235 uint8_t flags;
236 uint8_t rsvd1[2];
237 uint8_t hlength;
238 uint8_t dlength[3];
239 uint8_t lun[8];
240 __be32 itt; /* Initiator Task Tag */
241 __be32 rtt; /* Reference Task Tag */
242 __be32 cmdsn;
243 __be32 exp_statsn;
244 __be32 refcmdsn;
245 __be32 exp_datasn;
246 uint8_t rsvd2[8];
249 #define ISCSI_FLAG_TM_FUNC_MASK 0x7F
251 /* Function values */
252 #define ISCSI_TM_FUNC_ABORT_TASK 1
253 #define ISCSI_TM_FUNC_ABORT_TASK_SET 2
254 #define ISCSI_TM_FUNC_CLEAR_ACA 3
255 #define ISCSI_TM_FUNC_CLEAR_TASK_SET 4
256 #define ISCSI_TM_FUNC_LOGICAL_UNIT_RESET 5
257 #define ISCSI_TM_FUNC_TARGET_WARM_RESET 6
258 #define ISCSI_TM_FUNC_TARGET_COLD_RESET 7
259 #define ISCSI_TM_FUNC_TASK_REASSIGN 8
261 /* SCSI Task Management Response Header */
262 struct iscsi_tm_rsp {
263 uint8_t opcode;
264 uint8_t flags;
265 uint8_t response; /* see Response values below */
266 uint8_t qualifier;
267 uint8_t hlength;
268 uint8_t dlength[3];
269 uint8_t rsvd2[8];
270 __be32 itt; /* Initiator Task Tag */
271 __be32 rtt; /* Reference Task Tag */
272 __be32 statsn;
273 __be32 exp_cmdsn;
274 __be32 max_cmdsn;
275 uint8_t rsvd3[12];
278 /* Response values */
279 #define ISCSI_TMF_RSP_COMPLETE 0x00
280 #define ISCSI_TMF_RSP_NO_TASK 0x01
281 #define ISCSI_TMF_RSP_NO_LUN 0x02
282 #define ISCSI_TMF_RSP_TASK_ALLEGIANT 0x03
283 #define ISCSI_TMF_RSP_NO_FAILOVER 0x04
284 #define ISCSI_TMF_RSP_NOT_SUPPORTED 0x05
285 #define ISCSI_TMF_RSP_AUTH_FAILED 0x06
286 #define ISCSI_TMF_RSP_REJECTED 0xff
288 /* Ready To Transfer Header */
289 struct iscsi_r2t_rsp {
290 uint8_t opcode;
291 uint8_t flags;
292 uint8_t rsvd2[2];
293 uint8_t hlength;
294 uint8_t dlength[3];
295 uint8_t lun[8];
296 __be32 itt; /* Initiator Task Tag */
297 __be32 ttt; /* Target Transfer Tag */
298 __be32 statsn;
299 __be32 exp_cmdsn;
300 __be32 max_cmdsn;
301 __be32 r2tsn;
302 __be32 data_offset;
303 __be32 data_length;
306 /* SCSI Data Hdr */
307 struct iscsi_data {
308 uint8_t opcode;
309 uint8_t flags;
310 uint8_t rsvd2[2];
311 uint8_t rsvd3;
312 uint8_t dlength[3];
313 uint8_t lun[8];
314 __be32 itt;
315 __be32 ttt;
316 __be32 rsvd4;
317 __be32 exp_statsn;
318 __be32 rsvd5;
319 __be32 datasn;
320 __be32 offset;
321 __be32 rsvd6;
322 /* Payload */
325 /* SCSI Data Response Hdr */
326 struct iscsi_data_rsp {
327 uint8_t opcode;
328 uint8_t flags;
329 uint8_t rsvd2;
330 uint8_t cmd_status;
331 uint8_t hlength;
332 uint8_t dlength[3];
333 uint8_t lun[8];
334 __be32 itt;
335 __be32 ttt;
336 __be32 statsn;
337 __be32 exp_cmdsn;
338 __be32 max_cmdsn;
339 __be32 datasn;
340 __be32 offset;
341 __be32 residual_count;
344 /* Data Response PDU flags */
345 #define ISCSI_FLAG_DATA_ACK 0x40
346 #define ISCSI_FLAG_DATA_OVERFLOW 0x04
347 #define ISCSI_FLAG_DATA_UNDERFLOW 0x02
348 #define ISCSI_FLAG_DATA_STATUS 0x01
350 /* Text Header */
351 struct iscsi_text {
352 uint8_t opcode;
353 uint8_t flags;
354 uint8_t rsvd2[2];
355 uint8_t hlength;
356 uint8_t dlength[3];
357 uint8_t rsvd4[8];
358 __be32 itt;
359 __be32 ttt;
360 __be32 cmdsn;
361 __be32 exp_statsn;
362 uint8_t rsvd5[16];
363 /* Text - key=value pairs */
366 #define ISCSI_FLAG_TEXT_CONTINUE 0x40
368 /* Text Response Header */
369 struct iscsi_text_rsp {
370 uint8_t opcode;
371 uint8_t flags;
372 uint8_t rsvd2[2];
373 uint8_t hlength;
374 uint8_t dlength[3];
375 uint8_t rsvd4[8];
376 __be32 itt;
377 __be32 ttt;
378 __be32 statsn;
379 __be32 exp_cmdsn;
380 __be32 max_cmdsn;
381 uint8_t rsvd5[12];
382 /* Text Response - key:value pairs */
385 /* Login Header */
386 struct iscsi_login {
387 uint8_t opcode;
388 uint8_t flags;
389 uint8_t max_version; /* Max. version supported */
390 uint8_t min_version; /* Min. version supported */
391 uint8_t hlength;
392 uint8_t dlength[3];
393 uint8_t isid[6]; /* Initiator Session ID */
394 __be16 tsih; /* Target Session Handle */
395 __be32 itt; /* Initiator Task Tag */
396 __be16 cid;
397 __be16 rsvd3;
398 __be32 cmdsn;
399 __be32 exp_statsn;
400 uint8_t rsvd5[16];
403 /* Login PDU flags */
404 #define ISCSI_FLAG_LOGIN_TRANSIT 0x80
405 #define ISCSI_FLAG_LOGIN_CONTINUE 0x40
406 #define ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK 0x0C /* 2 bits */
407 #define ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK 0x03 /* 2 bits */
409 #define ISCSI_LOGIN_CURRENT_STAGE(flags) \
410 ((flags & ISCSI_FLAG_LOGIN_CURRENT_STAGE_MASK) >> 2)
411 #define ISCSI_LOGIN_NEXT_STAGE(flags) \
412 (flags & ISCSI_FLAG_LOGIN_NEXT_STAGE_MASK)
414 /* Login Response Header */
415 struct iscsi_login_rsp {
416 uint8_t opcode;
417 uint8_t flags;
418 uint8_t max_version; /* Max. version supported */
419 uint8_t active_version; /* Active version */
420 uint8_t hlength;
421 uint8_t dlength[3];
422 uint8_t isid[6]; /* Initiator Session ID */
423 __be16 tsih; /* Target Session Handle */
424 __be32 itt; /* Initiator Task Tag */
425 __be32 rsvd3;
426 __be32 statsn;
427 __be32 exp_cmdsn;
428 __be32 max_cmdsn;
429 uint8_t status_class; /* see Login RSP ststus classes below */
430 uint8_t status_detail; /* see Login RSP Status details below */
431 uint8_t rsvd4[10];
434 /* Login stage (phase) codes for CSG, NSG */
435 #define ISCSI_INITIAL_LOGIN_STAGE -1
436 #define ISCSI_SECURITY_NEGOTIATION_STAGE 0
437 #define ISCSI_OP_PARMS_NEGOTIATION_STAGE 1
438 #define ISCSI_FULL_FEATURE_PHASE 3
440 /* Login Status response classes */
441 #define ISCSI_STATUS_CLS_SUCCESS 0x00
442 #define ISCSI_STATUS_CLS_REDIRECT 0x01
443 #define ISCSI_STATUS_CLS_INITIATOR_ERR 0x02
444 #define ISCSI_STATUS_CLS_TARGET_ERR 0x03
446 /* Login Status response detail codes */
447 /* Class-0 (Success) */
448 #define ISCSI_LOGIN_STATUS_ACCEPT 0x00
450 /* Class-1 (Redirection) */
451 #define ISCSI_LOGIN_STATUS_TGT_MOVED_TEMP 0x01
452 #define ISCSI_LOGIN_STATUS_TGT_MOVED_PERM 0x02
454 /* Class-2 (Initiator Error) */
455 #define ISCSI_LOGIN_STATUS_INIT_ERR 0x00
456 #define ISCSI_LOGIN_STATUS_AUTH_FAILED 0x01
457 #define ISCSI_LOGIN_STATUS_TGT_FORBIDDEN 0x02
458 #define ISCSI_LOGIN_STATUS_TGT_NOT_FOUND 0x03
459 #define ISCSI_LOGIN_STATUS_TGT_REMOVED 0x04
460 #define ISCSI_LOGIN_STATUS_NO_VERSION 0x05
461 #define ISCSI_LOGIN_STATUS_ISID_ERROR 0x06
462 #define ISCSI_LOGIN_STATUS_MISSING_FIELDS 0x07
463 #define ISCSI_LOGIN_STATUS_CONN_ADD_FAILED 0x08
464 #define ISCSI_LOGIN_STATUS_NO_SESSION_TYPE 0x09
465 #define ISCSI_LOGIN_STATUS_NO_SESSION 0x0a
466 #define ISCSI_LOGIN_STATUS_INVALID_REQUEST 0x0b
468 /* Class-3 (Target Error) */
469 #define ISCSI_LOGIN_STATUS_TARGET_ERROR 0x00
470 #define ISCSI_LOGIN_STATUS_SVC_UNAVAILABLE 0x01
471 #define ISCSI_LOGIN_STATUS_NO_RESOURCES 0x02
473 /* Logout Header */
474 struct iscsi_logout {
475 uint8_t opcode;
476 uint8_t flags;
477 uint8_t rsvd1[2];
478 uint8_t hlength;
479 uint8_t dlength[3];
480 uint8_t rsvd2[8];
481 __be32 itt; /* Initiator Task Tag */
482 __be16 cid;
483 uint8_t rsvd3[2];
484 __be32 cmdsn;
485 __be32 exp_statsn;
486 uint8_t rsvd4[16];
489 /* Logout PDU flags */
490 #define ISCSI_FLAG_LOGOUT_REASON_MASK 0x7F
492 /* logout reason_code values */
494 #define ISCSI_LOGOUT_REASON_CLOSE_SESSION 0
495 #define ISCSI_LOGOUT_REASON_CLOSE_CONNECTION 1
496 #define ISCSI_LOGOUT_REASON_RECOVERY 2
497 #define ISCSI_LOGOUT_REASON_AEN_REQUEST 3
499 /* Logout Response Header */
500 struct iscsi_logout_rsp {
501 uint8_t opcode;
502 uint8_t flags;
503 uint8_t response; /* see Logout response values below */
504 uint8_t rsvd2;
505 uint8_t hlength;
506 uint8_t dlength[3];
507 uint8_t rsvd3[8];
508 __be32 itt; /* Initiator Task Tag */
509 __be32 rsvd4;
510 __be32 statsn;
511 __be32 exp_cmdsn;
512 __be32 max_cmdsn;
513 __be32 rsvd5;
514 __be16 t2wait;
515 __be16 t2retain;
516 __be32 rsvd6;
519 /* logout response status values */
521 #define ISCSI_LOGOUT_SUCCESS 0
522 #define ISCSI_LOGOUT_CID_NOT_FOUND 1
523 #define ISCSI_LOGOUT_RECOVERY_UNSUPPORTED 2
524 #define ISCSI_LOGOUT_CLEANUP_FAILED 3
526 /* SNACK Header */
527 struct iscsi_snack {
528 uint8_t opcode;
529 uint8_t flags;
530 uint8_t rsvd2[14];
531 __be32 itt;
532 __be32 begrun;
533 __be32 runlength;
534 __be32 exp_statsn;
535 __be32 rsvd3;
536 __be32 exp_datasn;
537 uint8_t rsvd6[8];
540 /* SNACK PDU flags */
541 #define ISCSI_FLAG_SNACK_TYPE_MASK 0x0F /* 4 bits */
543 /* Reject Message Header */
544 struct iscsi_reject {
545 uint8_t opcode;
546 uint8_t flags;
547 uint8_t reason;
548 uint8_t rsvd2;
549 uint8_t hlength;
550 uint8_t dlength[3];
551 uint8_t rsvd3[8];
552 __be32 ffffffff;
553 uint8_t rsvd4[4];
554 __be32 statsn;
555 __be32 exp_cmdsn;
556 __be32 max_cmdsn;
557 __be32 datasn;
558 uint8_t rsvd5[8];
559 /* Text - Rejected hdr */
562 /* Reason for Reject */
563 #define ISCSI_REASON_CMD_BEFORE_LOGIN 1
564 #define ISCSI_REASON_DATA_DIGEST_ERROR 2
565 #define ISCSI_REASON_DATA_SNACK_REJECT 3
566 #define ISCSI_REASON_PROTOCOL_ERROR 4
567 #define ISCSI_REASON_CMD_NOT_SUPPORTED 5
568 #define ISCSI_REASON_IMM_CMD_REJECT 6
569 #define ISCSI_REASON_TASK_IN_PROGRESS 7
570 #define ISCSI_REASON_INVALID_SNACK 8
571 #define ISCSI_REASON_BOOKMARK_INVALID 9
572 #define ISCSI_REASON_BOOKMARK_NO_RESOURCES 10
573 #define ISCSI_REASON_NEGOTIATION_RESET 11
575 /* Max. number of Key=Value pairs in a text message */
576 #define MAX_KEY_VALUE_PAIRS 8192
578 /* maximum length for text keys/values */
579 #define KEY_MAXLEN 64
580 #define VALUE_MAXLEN 255
581 #define TARGET_NAME_MAXLEN VALUE_MAXLEN
583 #define DEFAULT_MAX_RECV_DATA_SEGMENT_LENGTH 8192
585 /************************* RFC 3720 End *****************************/
587 #endif /* ISCSI_PROTO_H */