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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
|
/* $OpenBSD: iscsi.h,v 1.6 2009/08/27 14:12:27 claudio Exp $ */
/*
* Copyright (c) 2008 David Gwynne <dlg@openbsd.org>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#ifndef _SYS_SCSI_ISCSI_H
#define _SYS_SCSI_ISCSI_H
struct iscsi_pdu {
u_int8_t opcode;
u_int8_t flags;
u_int8_t _reserved1[2];
u_int8_t ahslen;
u_int8_t datalen[3];
u_int8_t lun[8];
u_int32_t itt;
u_int8_t _reserved2[4];
u_int32_t cmdsn;
u_int32_t expstatsn;
u_int8_t _reserved3[16];
} __packed;
/*
* Initiator opcodes
*/
#define ISCSI_OP_I_NOP 0x00
#define ISCSI_OP_SCSI_REQUEST 0x01
#define ISCSI_OP_TASK_REQUEST 0x02
#define ISCSI_OP_LOGIN_REQUEST 0x03
#define ISCSI_OP_TEXT_REQUEST 0x04
#define ISCSI_OP_DATA_OUT 0x05
#define ISCSI_OP_LOGOUT_REQUEST 0x06
#define ISCSI_OP_SNACK_REQUEST 0x10
/*
* Target opcodes
*/
#define ISCSI_OP_T_NOP 0x20
#define ISCSI_OP_SCSI_RESPONSE 0x21
#define ISCSI_OP_TASK_RESPONSE 0x22
#define ISCSI_OP_LOGIN_RESPONSE 0x23
#define ISCSI_OP_TEXT_RESPONSE 0x24
#define ISCSI_OP_DATA_IN 0x25
#define ISCSI_OP_LOGOUT_RESPONSE 0x26
#define ISCSI_OP_R2T 0x31
#define ISCSI_OP_ASYNC 0x32
#define ISCSI_OP_REJECT 0x3f
#define ISCSI_PDU_OPCODE(_o) ((_o) & 0x3f)
#define ISCSI_PDU_I(_h) ((_h)->opcode & 0x40)
#define ISCSI_PDU_F(_h) ((_h)->flags & 0x80)
#define ISCSI_OP_F_IMMEDIATE 0x40
/*
* various other flags and values
*/
#define ISCSI_ISID_OUI 0x00000000
#define ISCSI_ISID_EN 0x40000000
#define ISCSI_ISID_RAND 0x80000000
struct iscsi_pdu_scsi_request {
u_int8_t opcode;
u_int8_t flags;
u_int8_t _reserved[2];
u_int8_t ahslen;
u_int8_t datalen[3];
u_int8_t lun[8];
u_int32_t itt;
u_int32_t bytes;
u_int32_t cmdsn;
u_int32_t expstatsn;
u_int8_t cdb[16];
} __packed;
struct iscsi_pdu_scsi_response {
u_int8_t opcode;
u_int8_t flags;
u_int8_t response;
u_int8_t status;
u_int8_t ahslen;
u_int8_t datalen[3];
u_int8_t _reserved[8];
u_int32_t itt;
u_int32_t snack;
u_int32_t statsn;
u_int32_t expcmdsn;
u_int32_t maxcmdsn;
u_int32_t expdatasn;
} __packed;
#define ISCSI_SCSI_F_F 0x80
#define ISCSI_SCSI_F_R 0x40
#define ISCSI_SCSI_F_W 0x20
#define ISCSI_SCSI_ATTR_UNTAGGED 0
#define ISCSI_SCSI_ATTR_SIMPLE 1
#define ISCSI_SCSI_ATTR_ORDERED 2
#define ISCSI_SCSI_ATTR_HEAD_OF_Q 3
#define ISCSI_SCSI_ATTR_ACA 4
#define ISCSI_SCSI_STAT_GOOD 0x00
#define ISCSI_SCSI_STAT_CHCK_COND 0x02
/* we don't care about the type of the other error conditions */
struct iscsi_pdu_task_request {
u_int8_t opcode;
u_int8_t flags;
u_int8_t reserved[2];
u_int8_t ahslen;
u_int8_t datalen[3];
u_int8_t lun[8];
u_int32_t itt;
u_int32_t tag;
u_int32_t cmdsn;
u_int32_t expstatsn;
u_int32_t refcmdsn;
u_int32_t expdatasn;
u_int8_t _reserved[8];
} __packed;
struct iscsi_pdu_task_response {
u_int8_t opcode;
u_int8_t flags;
u_int8_t response;
u_int8_t _reserved1;
u_int8_t ahslen;
u_int8_t datalen[3];
u_int8_t _reserved2[4];
u_int32_t statsn;
u_int32_t expcmdsn;
u_int32_t maxcmdsn;
u_int8_t _reserved3[12];
} __packed;
struct iscsi_pdu_data_out {
u_int8_t opcode;
u_int8_t flags;
u_int8_t _reserved1[2];
u_int8_t ahslen;
u_int8_t datalen[3];
u_int8_t lun[8];
u_int32_t itt;
u_int32_t ttt;
u_int8_t _reserved2[4];
u_int32_t expstatsn;
u_int8_t _reserved3[4];
u_int32_t datasn;
u_int32_t buffer_offs;
u_int8_t _reserved4[4];
} __packed;
struct iscsi_pdu_data_in {
u_int8_t opcode;
u_int8_t flags;
u_int8_t _reserved;
u_int8_t status;
u_int8_t ahslen;
u_int8_t datalen[3];
u_int8_t lun[8];
u_int32_t itt;
u_int32_t ttt;
u_int32_t statsn;
u_int32_t expcmdsn;
u_int32_t maxcmdsn;
u_int32_t datasn;
u_int32_t buffer_offs;
u_int32_t residual;
} __packed;
struct iscsi_pdu_rt2 {
u_int8_t opcode;
u_int8_t flags;
u_int8_t _reserved1[2];
u_int8_t ahslen;
u_int8_t datalen[3];
u_int8_t lun[8];
u_int32_t itt;
u_int32_t ttt;
u_int32_t statsn;
u_int32_t expcmdsn;
u_int32_t maxcmdsn;
u_int32_t r2tsn;
u_int32_t buffer_offs;
u_int32_t desired_datalen;
} __packed;
struct iscsi_pdu_async {
u_int8_t opcode;
u_int8_t flags;
u_int8_t _reserved1[2];
u_int8_t ahslen;
u_int8_t datalen[3];
u_int8_t lun[8];
u_int32_t ffffffff;
u_int8_t _reserved2[4];
u_int32_t statsn;
u_int32_t expstatsn;
u_int32_t maxstatsn;
u_int8_t event;
u_int8_t vcode;
u_int32_t param[3];
u_int8_t _reserved3[4];
} __packed;
struct iscsi_pdu_text_request {
u_int8_t opcode;
u_int8_t flags;
u_int8_t _reserved1[2];
u_int8_t ahslen;
u_int8_t datalen[3];
u_int8_t lun[8];
u_int32_t itt;
u_int32_t ttt;
u_int32_t cmdsn;
u_int32_t expstatsn;
u_int8_t _reserved2[16];
} __packed;
struct iscsi_pdu_text_response {
u_int8_t opcode;
u_int8_t flags;
u_int8_t _reserved1[2];
u_int8_t ahslen;
u_int8_t datalen[3];
u_int8_t lun[8];
u_int32_t itt;
u_int32_t ttt;
u_int32_t cmdsn;
u_int32_t expcmdsn;
u_int32_t maxcmdsn;
u_int8_t _reserved2[12];
} __packed;
#define ISCSI_TEXT_F_F 0x80
#define ISCSI_TEXT_F_C 0x40
struct iscsi_pdu_login_request {
u_int8_t opcode;
u_int8_t flags;
u_int8_t version_max;
u_int8_t version_min;
u_int8_t ahslen;
u_int8_t datalen[3];
u_int32_t isid_base;
u_int16_t isid_qual;
u_int16_t tsih;
u_int32_t itt;
u_int16_t cid;
u_int8_t _reserved1[2];
u_int32_t cmdsn;
u_int32_t expstatsn;
u_int8_t _reserved2[16];
} __packed;
#define ISCSI_LOGIN_F_T 0x80
#define ISCSI_LOGIN_F_C 0x40
#define ISCSI_LOGIN_F_CSG(x) (((x) & 0x3) << 2)
#define ISCSI_LOGIN_F_NSG(x) ((x) & 0x3)
#define ISCSI_LOGIN_STG_SECNEG 0
#define ISCSI_LOGIN_STG_OPNEG 1
#define ISCSI_LOGIN_STG_FULL 3
struct iscsi_pdu_login_response {
u_int8_t opcode;
u_int8_t flags;
u_int8_t version_max;
u_int8_t version_active;
u_int8_t ahslen;
u_int8_t datalen[3];
u_int32_t isid_base;
u_int16_t isid_qual;
u_int16_t tsih;
u_int32_t itt;
u_int8_t _reserved1[4];
u_int32_t statsn;
u_int32_t expcmdsn;
u_int32_t maxcmdsn;
u_int8_t status_class;
u_int8_t status_detail;
u_int8_t _reserved2[10];
} __packed;
struct iscsi_pdu_logout_request {
u_int8_t opcode;
u_int8_t flags;
u_int8_t _reserved1[2];
u_int8_t ahslen;
u_int8_t datalen[3];
u_int8_t _reserved2[8];
u_int32_t itt;
u_int16_t cid;
u_int8_t _reserved3[2];
u_int32_t cmdsn;
u_int32_t expstatsn;
u_int8_t _reserved4[16];
} __packed;
struct iscsi_pdu_logout_response {
u_int8_t opcode;
u_int8_t flags;
u_int8_t _reserved1[2];
u_int8_t ahslen;
u_int8_t datalen[3];
u_int8_t _reserved2[8];
u_int32_t itt;
u_int8_t _reserved3[4];
u_int32_t statsn;
u_int32_t expcmdsn;
u_int32_t maxcmdsn;
u_int8_t _reserved4[4];
u_int16_t time2wait;
u_int16_t time2retain;
u_int8_t _reserved5[4];
} __packed;
struct iscsi_pdu_snack_request {
u_int8_t opcode;
u_int8_t flags;
u_int8_t _reserved1[2];
u_int8_t ahslen;
u_int8_t datalen[3];
u_int8_t lun[8];
u_int32_t itt;
u_int32_t ttt;
u_int8_t _reserved2[4];
u_int32_t expstatsn;
u_int8_t _reserved3[8];
u_int32_t begrun;
u_int32_t runlength;
} __packed;
struct iscsi_pdu_reject {
u_int8_t opcode;
u_int8_t flags;
u_int8_t reason;
u_int8_t _reserved1;
u_int8_t ahslen;
u_int8_t datalen[3];
u_int8_t _reserved2[8];
u_int32_t ffffffff;
u_int8_t _reserved3[4];
u_int32_t statsn;
u_int32_t expcmdsn;
u_int32_t maxcmdsn;
u_int32_t datasn_r2tsn;
u_int8_t _reserved4[8];
} __packed;
struct iscsi_pdu_nop_out {
u_int8_t opcode;
u_int8_t flags;
u_int8_t _reserved1[2];
u_int8_t ahslen;
u_int8_t datalen[3];
u_int8_t lun[8];
u_int32_t itt;
u_int32_t ttt;
u_int32_t cmdsn;
u_int32_t expstatsn;
u_int8_t _reserved2[16];
} __packed;
struct iscsi_pdu_nop_in {
u_int8_t opcode;
u_int8_t flags;
u_int8_t _reserved1[2];
u_int8_t ahslen;
u_int8_t datalen[3];
u_int8_t lun[8];
u_int32_t itt;
u_int32_t ttt;
u_int32_t statsn;
u_int32_t expcmdsn;
u_int32_t maxcmdsn;
u_int8_t _reserved2[12];
} __packed;
#endif /* _SYS_SCSI_ISCSI_H */
|