Lines Matching refs:header
73 iscsi_task_cmd_encap(uint8_t *header, iscsi_task_cmd_t * cmd)
85 (void) memset(header, 0x0, ISCSI_HEADER_LEN);
87 header[0] |= ISCSI_TASK_CMD; /* Opcode */
89 header[0] |= 0x40; /* Immediate bit */
91 header[1] = cmd->function & 0x80; /* Function */
92 *((uint64_t *) (void *) (header + 8)) = ISCSI_HTONLL(cmd->lun); /* LUN */
93 *((uint32_t *) (void *) (header + 16)) = ISCSI_HTONL(cmd->tag); /* Tag */
94 *((uint32_t *) (void *) (header + 20)) = ISCSI_HTONL(cmd->ref_tag); /* Reference Tag */
95 *((uint32_t *) (void *) (header + 24)) = ISCSI_HTONL(cmd->CmdSN); /* CmdSN */
96 *((uint32_t *) (void *) (header + 28)) = ISCSI_HTONL(cmd->ExpStatSN); /* ExpStatSN */
97 *((uint32_t *) (void *) (header + 32)) = ISCSI_HTONL(cmd->RefCmdSN); /* RefCmdSN */
98 *((uint32_t *) (void *) (header + 36)) = ISCSI_HTONL(cmd->ExpDataSN); /* ExpDataSN */
104 iscsi_task_cmd_decap(uint8_t *header, iscsi_task_cmd_t * cmd)
109 if (ISCSI_OPCODE(header) != ISCSI_TASK_CMD) {
113 cmd->immediate = ((header[0] & 0x40) == 0x40);
114 cmd->function = header[1] & 0x80;
115 cmd->lun = ISCSI_NTOHLL(*((uint64_t *) (void *) (header + 8)));
116 cmd->tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 16)));
117 cmd->ref_tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 20)));
118 cmd->CmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 24)));
119 cmd->ExpStatSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 28)));
120 cmd->RefCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 32)));
121 cmd->ExpDataSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 36)));
125 if ((header[1] & 0x80) != 0x80) {
127 } else if (header[2] != 0) {
129 } else if (header[3] != 0) {
131 } else if (memcmp(header + 4, zeros, 4) != 0) {
133 } else if (memcmp(header + 40, zeros, 8) != 0) {
159 iscsi_task_rsp_encap(uint8_t *header, iscsi_task_rsp_t * rsp)
170 (void) memset(header, 0x0, ISCSI_HEADER_LEN);
172 header[0] |= ISCSI_TASK_RSP; /* Opcode */
173 header[1] |= 0x80; /* Byte 1 bit 0 */
174 header[2] = rsp->response; /* Response */
176 *((uint32_t *) (void *) (header + 4)) = ISCSI_HTONL(length);
177 *((uint32_t *) (void *) (header + 16)) = ISCSI_HTONL(rsp->tag);
178 *((uint32_t *) (void *) (header + 24)) = ISCSI_HTONL(rsp->StatSN);
179 *((uint32_t *) (void *) (header + 28)) = ISCSI_HTONL(rsp->ExpCmdSN);
180 *((uint32_t *) (void *) (header + 32)) = ISCSI_HTONL(rsp->MaxCmdSN);
185 iscsi_task_rsp_decap(uint8_t *header, iscsi_task_rsp_t * rsp)
190 if (ISCSI_OPCODE(header) != ISCSI_TASK_RSP) {
194 rsp->response = header[2];
195 rsp->tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 16)));
196 rsp->StatSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 24)));
197 rsp->ExpCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 28)));
198 rsp->MaxCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 32)));
201 if ((header[0] & 0x00) != 0x00) {
203 } else if ((header[1] & 0x80) != 0x80) {
205 } else if (header[3] != 0) {
207 } else if (memcmp(header + 4, zeros, 12) != 0) {
209 } else if (memcmp(header + 20, zeros, 4) != 0) {
211 } else if (memcmp(header + 36, zeros, 12) != 0) {
232 iscsi_nop_out_encap(uint8_t *header, iscsi_nop_out_args_t * cmd)
245 (void) memset(header, 0x0, ISCSI_HEADER_LEN);
247 header[0] = ISCSI_NOP_OUT; /* Opcode */
249 header[0] |= 0x40; /* Immediate bit */
251 header[1] |= 0x80; /* Byte 1 bit 0 and Reserved */
253 *((uint32_t *) (void *) (header + 4)) = ISCSI_HTONL(length); /* Length */
254 *((uint64_t *) (void *) (header + 8)) = ISCSI_HTONLL(cmd->lun); /* LUN */
255 *((uint32_t *) (void *) (header + 16)) = ISCSI_HTONL(cmd->tag); /* Tag */
256 *((uint32_t *) (void *) (header + 20)) = ISCSI_HTONL(cmd->transfer_tag); /* Target Transfer Tag */
257 *((uint32_t *) (void *) (header + 24)) = ISCSI_HTONL(cmd->CmdSN); /* CmdSN */
258 *((uint32_t *) (void *) (header + 28)) = ISCSI_HTONL(cmd->ExpStatSN); /* ExpStatSN */
264 iscsi_nop_out_decap(uint8_t *header, iscsi_nop_out_args_t * cmd)
269 if (ISCSI_OPCODE(header) != ISCSI_NOP_OUT) {
273 cmd->immediate = ((header[0] & 0x40) == 0x40); /* Immediate bit */
274 cmd->length = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 4))); /* Length */
275 cmd->lun = ISCSI_NTOHLL(*((uint64_t *) (void *) (header + 8))); /* LUN */
276 cmd->tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 16))); /* Tag */
277 cmd->transfer_tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 20))); /* Target Tranfer Tag */
278 cmd->CmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 24))); /* CmdSN */
279 cmd->ExpStatSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 28))); /* ExpStatSN */
283 if (header[1] != 0x80) {
285 } else if (memcmp(header + 2, zeros, 3) != 0) {
287 } else if (memcmp(header + 32, zeros, 16) != 0) {
310 iscsi_nop_in_encap(uint8_t *header, iscsi_nop_in_args_t * cmd)
322 (void) memset(header, 0x0, ISCSI_HEADER_LEN);
324 header[0] = 0x00 | ISCSI_NOP_IN; /* Opcode */
325 header[1] |= 0x80; /* Reserved */
327 *((uint32_t *) (void *) (header + 4)) = ISCSI_HTONL(length); /* Length */
328 *((uint64_t *) (void *) (header + 8)) = ISCSI_HTONLL(cmd->lun); /* LUN */
329 *((uint32_t *) (void *) (header + 16)) = ISCSI_HTONL(cmd->tag); /* Tag */
330 *((uint32_t *) (void *) (header + 20)) = ISCSI_HTONL(cmd->transfer_tag); /* Target Transfer Tag */
331 *((uint32_t *) (void *) (header + 24)) = ISCSI_HTONL(cmd->StatSN); /* StatSN */
332 *((uint32_t *) (void *) (header + 28)) = ISCSI_HTONL(cmd->ExpCmdSN); /* ExpCmdSN */
333 *((uint32_t *) (void *) (header + 32)) = ISCSI_HTONL(cmd->MaxCmdSN); /* MaxCmdSN */
339 iscsi_nop_in_decap(uint8_t *header, iscsi_nop_in_args_t * cmd)
344 if (ISCSI_OPCODE(header) != ISCSI_NOP_IN) {
348 cmd->length = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 4))); /* Length */
349 cmd->lun = ISCSI_NTOHLL(*((uint64_t *) (void *) (header + 8))); /* LUN */
350 cmd->tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 16))); /* Tag */
351 cmd->transfer_tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 20))); /* Target Transfer Tag */
352 cmd->StatSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 24))); /* StatSN */
353 cmd->ExpCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 28))); /* ExpCmdSN */
354 cmd->MaxCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 32))); /* MaxCmdSN */
358 if ((header[0] & 0xc0) != 0x00) {
360 } else if (header[1] != 0x80) {
362 } else if (memcmp(header + 2, zeros, 3) != 0) {
364 } else if (memcmp(header + 36, zeros, 12) != 0) {
387 iscsi_text_cmd_encap(uint8_t *header, iscsi_text_cmd_args_t * cmd)
401 (void) memset(header, 0x0, ISCSI_HEADER_LEN);
403 header[0] |= ISCSI_TEXT_CMD; /* Opcode */
405 header[0] |= 0x40; /* Immediate bit */
408 header[1] |= 0x80; /* Final bit */
411 header[1] |= 0x40; /* Continue bit */
414 *((uint32_t *) (void *) (header + 4)) = ISCSI_HTONL(length); /* Length */
415 *((uint64_t *) (void *) (header + 8)) = ISCSI_HTONLL(cmd->lun); /* LUN */
416 *((uint32_t *) (void *) (header + 16)) = ISCSI_HTONL(cmd->tag); /* Tag */
417 *((uint32_t *) (void *) (header + 20)) = ISCSI_HTONL(cmd->transfer_tag); /* Transfer Tag */
418 *((uint32_t *) (void *) (header + 24)) = ISCSI_HTONL(cmd->CmdSN); /* CmdSN */
419 *((uint32_t *) (void *) (header + 28)) = ISCSI_HTONL(cmd->ExpStatSN); /* ExpStatSN */
425 iscsi_text_cmd_decap(uint8_t *header, iscsi_text_cmd_args_t * cmd)
430 if (ISCSI_OPCODE(header) != ISCSI_TEXT_CMD) {
434 cmd->immediate = ((header[0] & 0x40) == 0x40); /* Immediate bit */
435 cmd->final = ((header[1] & 0x80) == 0x80); /* Final bit */
436 cmd->cont = ((header[1] & 0x40) == 0x40); /* Continue bit */
437 cmd->length = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 4))); /* Length */
438 cmd->lun = ISCSI_NTOHLL(*((uint64_t *) (void *) (header + 8))); /* LUN */
439 cmd->tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 16))); /* Tag */
440 cmd->transfer_tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 20))); /* Transfer Tag */
441 cmd->CmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 24))); /* CmdSN */
442 cmd->ExpStatSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 28))); /* ExpStatSN */
446 if ((header[1] & 0x00) != 0x00) {
448 } else if (memcmp(header + 2, zeros, 3) != 0) {
450 } else if (memcmp(header + 8, zeros, 8) != 0) {
452 } else if (memcmp(header + 32, zeros, 16) != 0) {
478 iscsi_text_rsp_encap(uint8_t *header, iscsi_text_rsp_args_t * rsp)
492 (void) memset(header, 0x0, ISCSI_HEADER_LEN);
493 header[0] |= 0x00 | ISCSI_TEXT_RSP; /* Opcode */
495 header[1] |= 0x80; /* Final bit */
498 header[1] |= 0x40; /* Continue */
501 *((uint32_t *) (void *) (header + 4)) = ISCSI_HTONL(length); /* Length */
502 *((uint64_t *) (void *) (header + 8)) = ISCSI_HTONLL(rsp->lun); /* LUN */
503 *((uint32_t *) (void *) (header + 16)) = ISCSI_HTONL(rsp->tag); /* Tag */
504 *((uint32_t *) (void *) (header + 20)) = ISCSI_HTONL(rsp->transfer_tag); /* Transfer Tag */
505 *((uint32_t *) (void *) (header + 24)) = ISCSI_HTONL(rsp->StatSN); /* StatSN */
506 *((uint32_t *) (void *) (header + 28)) = ISCSI_HTONL(rsp->ExpCmdSN); /* ExpCmdSN */
507 *((uint32_t *) (void *) (header + 32)) = ISCSI_HTONL(rsp->MaxCmdSN); /* MaxCmdSN */
513 iscsi_text_rsp_decap(uint8_t *header, iscsi_text_rsp_args_t * rsp)
518 if (ISCSI_OPCODE(header) != ISCSI_TEXT_RSP) {
522 rsp->final = ((header[1] & 0x80) == 0x80); /* Final bit */
523 rsp->cont = ((header[1] & 0x40) == 0x40); /* Continue bit */
524 rsp->length = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 4))); /* Length */
525 rsp->lun = ISCSI_NTOHLL(*((uint64_t *) (void *) (header + 8))); /* LUN */
526 rsp->tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 16))); /* Tag */
527 rsp->transfer_tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 20))); /* Transfer Tag */
528 rsp->StatSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 24))); /* StatSN */
529 rsp->ExpCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 28))); /* ExpCmdSN */
530 rsp->MaxCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 32))); /* MaxCmdSN */
534 if ((header[1] & 0x3f) != 0x00) {
536 } else if (memcmp(header + 2, zeros, 3) != 0) {
538 } else if (memcmp(header + 8, zeros, 8) != 0) {
540 } else if (memcmp(header + 36, zeros, 12) != 0) {
566 iscsi_login_cmd_encap(uint8_t *header, iscsi_login_cmd_args_t * cmd)
585 (void) memset(header, 0x0, ISCSI_HEADER_LEN);
587 header[0] |= 0x40 | ISCSI_LOGIN_CMD; /* Opcode */
589 header[1] |= 0x80; /* Transit */
592 header[1] |= 0x40; /* Continue */
594 header[1] |= ((cmd->csg) << 2) & 0x0c; /* CSG */
595 header[1] |= (cmd->nsg) & 0x03; /* NSG */
596 header[2] = cmd->version_max; /* Version-Max */
597 header[3] = cmd->version_min; /* Version-Min */
598 header[4] = cmd->AHSlength; /* TotalAHSLength */
600 *((uint32_t *) (void *) (header + 4)) = ISCSI_HTONL(length); /* Length */
601 *((uint64_t *) (void *) (header + 8)) = ISCSI_HTONLL(cmd->isid << 16); /* ISID */
602 *((uint16_t *) (void *) (header + 14)) = ISCSI_HTONS(cmd->tsih); /* TSIH */
603 *((uint32_t *) (void *) (header + 16)) = ISCSI_HTONL(cmd->tag); /* Task Tag */
604 *((uint16_t *) (void *) (header + 20)) = ISCSI_HTONS(cmd->cid); /* CID */
605 *((uint32_t *) (void *) (header + 24)) = ISCSI_HTONL(cmd->CmdSN); /* CmdSN */
606 *((uint32_t *) (void *) (header + 28)) = ISCSI_HTONL(cmd->ExpStatSN); /* ExpStatSN */
612 iscsi_login_cmd_decap(uint8_t *header, iscsi_login_cmd_args_t * cmd)
617 if (ISCSI_OPCODE(header) != ISCSI_LOGIN_CMD) {
621 cmd->transit = (header[1] & 0x80) ? 1 : 0; /* Transit */
622 cmd->cont = (header[1] & 0x40) ? 1 : 0; /* Continue */
623 cmd->csg = (header[1] & 0x0cU) >> 2; /* CSG */
624 cmd->nsg = header[1] & 0x03; /* NSG */
625 cmd->version_max = header[2]; /* Version-Max */
626 cmd->version_min = header[3]; /* Version-Min */
627 cmd->AHSlength = header[4]; /* TotalAHSLength */
628 cmd->length = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 4))); /* Length */
629 cmd->isid = ISCSI_NTOHLL(*((uint64_t *) (void *) (header + 8))) >> 16; /* ISID */
630 cmd->tsih = ISCSI_NTOHS(*((uint16_t *) (void *) (header + 14))); /* TSIH */
631 cmd->tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 16))); /* Task Tag */
632 cmd->cid = ISCSI_NTOHS(*((uint16_t *) (void *) (header + 20))); /* CID */
633 cmd->CmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 24))); /* CmdSN */
634 cmd->ExpStatSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 28))); /* ExpStatSN */
653 if (((header[1] & 0x30U) >> 4U) != 0x0) {
655 } else if (memcmp(header + 22, zeros, 2) != 0) {
657 } else if (memcmp(header + 32, zeros, 16) != 0) {
681 iscsi_login_rsp_encap(uint8_t *header, iscsi_login_rsp_args_t * rsp)
701 (void) memset(header, 0x0, ISCSI_HEADER_LEN);
703 header[0] |= 0x00 | ISCSI_LOGIN_RSP; /* Opcode */
705 header[1] |= 0x80; /* Transit */
708 header[1] |= 0x40; /* Continue */
710 header[1] |= ((rsp->csg) << 2) & 0x0c; /* CSG */
712 header[1] |= (rsp->nsg) & 0x03; /* NSG */
714 header[2] = rsp->version_max; /* Version-max */
715 header[3] = rsp->version_active; /* Version-active */
716 header[4] = rsp->AHSlength; /* TotalAHSLength */
717 *((uint32_t *) (void *) (header + 4)) = ISCSI_HTONL(rsp->length); /* Length */
718 *((uint64_t *) (void *) (header + 8)) = ISCSI_HTONLL(rsp->isid << 16); /* ISID */
719 *((uint16_t *) (void *) (header + 14)) = ISCSI_HTONS(rsp->tsih); /* TSIH */
720 *((uint32_t *) (void *) (header + 16)) = ISCSI_HTONL(rsp->tag); /* Tag */
721 *((uint32_t *) (void *) (header + 24)) = ISCSI_HTONL(rsp->StatSN); /* StatRn */
722 *((uint32_t *) (void *) (header + 28)) = ISCSI_HTONL(rsp->ExpCmdSN); /* ExpCmdSN */
723 *((uint32_t *) (void *) (header + 32)) = ISCSI_HTONL(rsp->MaxCmdSN); /* MaxCmdSN */
724 header[36] = rsp->status_class; /* Status-Class */
725 header[37] = rsp->status_detail; /* Status-Detail */
731 iscsi_login_rsp_decap(uint8_t *header, iscsi_login_rsp_args_t * rsp)
736 if (ISCSI_OPCODE(header) != ISCSI_LOGIN_RSP) {
740 rsp->transit = (header[1] & 0x80U) >> 7; /* Transit */
741 rsp->cont = (header[1] & 0x40U) >> 6; /* Continue */
742 rsp->csg = (header[1] & 0x0cU) >> 2; /* CSG */
743 rsp->nsg = header[1] & 0x03; /* NSG */
744 rsp->version_max = header[2]; /* Version-max */
745 rsp->version_active = header[3]; /* Version-active */
746 rsp->AHSlength = header[4]; /* TotalAHSLength */
747 rsp->length = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 4))); /* Length */
748 rsp->isid = ISCSI_NTOHLL(*((uint64_t *) (void *) (header + 8))) >> 16; /* ISID */
749 rsp->tsih = ISCSI_NTOHS(*((uint16_t *) (void *) (header + 14))); /* TSIH */
751 rsp->tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 16))); /* Tag */
752 rsp->StatSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 24))); /* StatSN */
753 rsp->ExpCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 28))); /* ExpCmdSN */
754 rsp->MaxCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 32))); /* MaxCmdSN */
755 rsp->status_class = header[36]; /* Status-Class */
756 rsp->status_detail = header[37]; /* Status-Detail */
777 if (((header[1] & 0x30U) >> 4U) != 0x0) {
779 } else if (memcmp(header + 20, zeros, 4) != 0) {
781 } else if (memcmp(header + 38, zeros, 2) != 0) {
783 } else if (memcmp(header + 40, zeros, 8) != 0) {
799 iscsi_logout_cmd_encap(uint8_t *header, iscsi_logout_cmd_args_t * cmd)
809 (void) memset(header, 0x0, ISCSI_HEADER_LEN);
811 header[0] = ISCSI_LOGOUT_CMD; /* Opcode */
813 header[0] |= 0x40; /* Immediate */
815 header[1] = cmd->reason | 0x80; /* Reason */
816 *((uint32_t *) (void *) (header + 16)) = ISCSI_HTONL(cmd->tag); /* Tag */
817 *((uint16_t *) (void *) (header + 20)) = ISCSI_HTONS(cmd->cid); /* CID */
818 *((uint32_t *) (void *) (header + 24)) = ISCSI_HTONL(cmd->CmdSN); /* CmdSN */
819 *((uint32_t *) (void *) (header + 28)) = ISCSI_HTONL(cmd->ExpStatSN); /* ExpStatSN */
825 iscsi_logout_cmd_decap(uint8_t *header, iscsi_logout_cmd_args_t * cmd)
830 if (ISCSI_OPCODE(header) != ISCSI_LOGOUT_CMD) {
834 cmd->immediate = (header[0] & 0x40) ? 1 : 0; /* Immediate */
835 cmd->reason = header[1] & 0x7f; /* Reason */
836 cmd->tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 16))); /* Tag */
837 cmd->cid = ISCSI_NTOHS(*((uint16_t *) (void *) (header + 20))); /* CID */
838 cmd->CmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 24))); /* CmdSN */
839 cmd->ExpStatSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 28))); /* ExpStatSN */
850 if ((unsigned)(header[0]) >> 0x7U != 0) {
852 } else if ((unsigned)(header[1]) >> 7U != 1) {
854 } else if (header[2] != 0) {
856 } else if (header[3] != 0) {
858 } else if (memcmp(header + 4, zeros, 12) != 0) {
860 } else if (memcmp(header + 22, zeros, 2) != 0) {
862 } else if (memcmp(header + 32, zeros, 16) != 0) {
878 iscsi_logout_rsp_encap(uint8_t *header, iscsi_logout_rsp_args_t * rsp)
891 (void) memset(header, 0x0, ISCSI_HEADER_LEN);
893 header[0] |= 0x00 | ISCSI_LOGOUT_RSP; /* Opcode */
894 header[1] |= 0x80; /* Reserved */
895 header[2] = rsp->response; /* Response */
896 *((uint32_t *) (void *) (header + 4)) = ISCSI_HTONL(rsp->length); /* Length */
897 *((uint32_t *) (void *) (header + 16)) = ISCSI_HTONL(rsp->tag); /* Tag */
898 *((uint32_t *) (void *) (header + 24)) = ISCSI_HTONL(rsp->StatSN); /* StatSN */
899 *((uint32_t *) (void *) (header + 28)) = ISCSI_HTONL(rsp->ExpCmdSN); /* ExpCmdSN */
900 *((uint32_t *) (void *) (header + 32)) = ISCSI_HTONL(rsp->MaxCmdSN); /* MaxCmdSN */
901 *((uint16_t *) (void *) (header + 40)) = ISCSI_HTONS(rsp->Time2Wait); /* Time2Wait */
902 *((uint16_t *) (void *) (header + 42)) = ISCSI_HTONS(rsp->Time2Retain); /* Time2Retain */
908 iscsi_logout_rsp_decap(uint8_t *header, iscsi_logout_rsp_args_t * rsp)
913 if (ISCSI_OPCODE(header) != ISCSI_LOGOUT_RSP) {
917 rsp->response = header[2]; /* Response */
918 rsp->length = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 4))); /* Length */
919 rsp->tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 16))); /* Tag */
920 rsp->StatSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 24))); /* StatSN */
921 rsp->ExpCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 28))); /* ExpCmdSN */
922 rsp->MaxCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 32))); /* MaxCmdSN */
923 rsp->Time2Wait = ISCSI_NTOHS(*((uint16_t *) (void *) (header + 40))); /* Time2Wait */
924 rsp->Time2Retain = ISCSI_NTOHS(*((uint16_t *) (void *) (header + 42))); /* Time2Retain */
928 if ((header[0] & 0x20) != 0x20) {
930 } else if ((header[1] & 0x80) != 0x80) {
932 } else if (header[3] != 0) {
934 } else if (memcmp(header + 4, zeros, 12) != 0) {
936 } else if (memcmp(header + 20, zeros, 4) != 0) {
938 } else if (memcmp(header + 36, zeros, 4) != 0) {
940 } else if (memcmp(header + 44, zeros, 4) != 0) {
965 iscsi_scsi_cmd_encap(uint8_t *header, iscsi_scsi_cmd_args_t * cmd)
982 (void) memset(header, 0x0, ISCSI_HEADER_LEN);
984 header[0] |= ISCSI_SCSI_CMD; /* Opcode */
986 header[0] |= 0x40; /* Immediate */
989 header[1] |= 0x80; /* Final */
992 header[1] |= 0x40; /* Input bit */
995 header[1] |= 0x20; /* Output bit */
997 header[1] |= cmd->attr & 0x07; /* ATTR */
998 *((uint32_t *) (void *) (header + 4)) = ISCSI_HTONL(cmd->length); /* DataSegmentLength */
999 header[4] = cmd->ahs_len; /* TotalAHSLength */
1000 *((uint64_t *) (void *) (header + 8)) = ISCSI_HTONLL(cmd->lun); /* LUN */
1001 *((uint32_t *) (void *) (header + 16)) = ISCSI_HTONL(cmd->tag); /* Task Tag */
1002 *((uint32_t *) (void *) (header + 20)) = ISCSI_HTONL(cmd->trans_len); /* Expected Transfer
1004 *((uint32_t *) (void *) (header + 24)) = ISCSI_HTONL(cmd->CmdSN); /* CmdSN */
1005 *((uint32_t *) (void *) (header + 28)) = ISCSI_HTONL(cmd->ExpStatSN); /* ExpStatSN */
1006 memcpy(header + 32, cmd->cdb, 16); /* CDB */
1012 iscsi_scsi_cmd_decap(uint8_t *header, iscsi_scsi_cmd_args_t * cmd)
1016 if (ISCSI_OPCODE(header) != ISCSI_SCSI_CMD) {
1020 cmd->immediate = (header[0] & 0x40) ? 1 : 0; /* Immediate */
1021 cmd->final = (header[1] & 0x80) ? 1 : 0; /* Final */
1022 cmd->input = (header[1] & 0x40) ? 1 : 0; /* Input */
1023 cmd->output = (header[1] & 0x20) ? 1 : 0; /* Output */
1024 cmd->attr = header[1] & 0x07; /* ATTR */
1025 cmd->ahs_len = header[4];
1026 header[4] = 0x00;
1027 cmd->length = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 4))); /* DataSegmentLength */
1028 cmd->lun = ISCSI_NTOHLL(*((uint64_t *) (void *) (header + 8))); /* LUN */
1029 cmd->tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 16))); /* Task Tag */
1030 cmd->trans_len = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 20))); /* Expected Transfer
1032 cmd->CmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 24))); /* CmdSN */
1033 cmd->ExpStatSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 28))); /* ExpStatSN */
1034 cmd->cdb = header + 32; /* CDB */
1037 if ((header[1] & 0x18) != 0x0) {
1039 } else if (header[2] != 0) {
1041 } else if (header[3] != 0) {
1071 iscsi_scsi_rsp_encap(uint8_t *header, iscsi_scsi_rsp_t * rsp)
1089 (void) memset(header, 0x0, ISCSI_HEADER_LEN);
1091 header[0] |= 0x00 | ISCSI_SCSI_RSP; /* Opcode */
1092 header[1] |= 0x80; /* Byte 1 bit 7 */
1094 header[1] |= 0x10; /* Bidi overflow */
1097 header[1] |= 0x08; /* Bidi underflow */
1100 header[1] |= 0x04; /* Overflow */
1103 header[1] |= 0x02; /* Underflow */
1105 header[2] = rsp->response; /* iSCSI Response */
1106 header[3] = rsp->status;/* SCSI Status */
1107 header[4] = rsp->ahs_len; /* TotalAHSLength */
1108 *((uint32_t *) (void *) (header + 4)) = ISCSI_HTONL(rsp->length); /* DataSegmentLength */
1109 *((uint32_t *) (void *) (header + 16)) = ISCSI_HTONL(rsp->tag); /* Task Tag */
1110 *((uint32_t *) (void *) (header + 24)) = ISCSI_HTONL(rsp->StatSN); /* StatSN */
1111 *((uint32_t *) (void *) (header + 28)) = ISCSI_HTONL(rsp->ExpCmdSN); /* ExpCmdSN */
1112 *((uint32_t *) (void *) (header + 32)) = ISCSI_HTONL(rsp->MaxCmdSN); /* MaxCmdSN */
1113 *((uint32_t *) (void *) (header + 36)) = ISCSI_HTONL(rsp->ExpDataSN); /* ExpDataSN */
1114 *((uint32_t *) (void *) (header + 40)) = ISCSI_HTONL(rsp->bidi_res_cnt); /* Bidi Residual Count */
1115 *((uint32_t *) (void *) (header + 44)) = ISCSI_HTONL(rsp->basic_res_cnt); /* Residual Count */
1121 iscsi_scsi_rsp_decap(uint8_t *header, iscsi_scsi_rsp_t * rsp)
1125 if (ISCSI_OPCODE(header) != ISCSI_SCSI_RSP) {
1129 rsp->bidi_overflow = (header[1] & 0x10) ? 1 : 0; /* Bidi overflow */
1130 rsp->bidi_underflow = (header[1] & 0x08) ? 1 : 0; /* Bidi underflow */
1131 rsp->overflow = (header[1] & 0x04) ? 1 : 0; /* Overflow */
1132 rsp->underflow = (header[1] & 0x02) ? 1 : 0; /* Underflow */
1134 rsp->response = header[2]; /* iSCSI Response */
1135 rsp->status = header[3];/* SCSI Status */
1136 rsp->ahs_len = header[4]; /* TotalAHSLength */
1137 rsp->length = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 4))); /* DataSegmentLength */
1138 rsp->tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 16))); /* Task Tag */
1139 rsp->StatSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 24))); /* StatSN */
1140 rsp->ExpCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 28))); /* ExpCmdSN */
1141 rsp->MaxCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 32))); /* MaxCmdSN */
1142 rsp->ExpDataSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 36))); /* ExpDataSN */
1143 rsp->bidi_res_cnt = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 40))); /* Bidi Residual Count */
1144 rsp->basic_res_cnt = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 44))); /* Residual Count */
1147 if ((header[0] & 0xc0) != 0x0) {
1149 } else if ((header[1] & 0x80) != 0x80) {
1189 iscsi_r2t_encap(uint8_t *header, iscsi_r2t_t * cmd)
1204 (void) memset(header, 0x0, ISCSI_HEADER_LEN);
1206 header[0] |= 0x00 | ISCSI_R2T; /* Opcode */
1207 header[1] |= 0x80;
1209 *((uint32_t *) (void *) (header + 4)) = ISCSI_HTONL(length); /* AHSLength */
1210 *((uint64_t *) (void *) (header + 8)) = ISCSI_HTONLL(cmd->lun); /* LUN */
1211 *((uint32_t *) (void *) (header + 16)) = ISCSI_HTONL(cmd->tag); /* Tag */
1212 *((uint32_t *) (void *) (header + 20)) = ISCSI_HTONL(cmd->transfer_tag); /* Transfer Tag */
1213 *((uint32_t *) (void *) (header + 24)) = ISCSI_HTONL(cmd->StatSN); /* StatSN */
1214 *((uint32_t *) (void *) (header + 28)) = ISCSI_HTONL(cmd->ExpCmdSN); /* ExpCmdSN */
1215 *((uint32_t *) (void *) (header + 32)) = ISCSI_HTONL(cmd->MaxCmdSN); /* MaxCmdSN */
1216 *((uint32_t *) (void *) (header + 36)) = ISCSI_HTONL(cmd->R2TSN); /* R2TSN */
1217 *((uint32_t *) (void *) (header + 40)) = ISCSI_HTONL(cmd->offset); /* Buffer Offset */
1218 *((uint32_t *) (void *) (header + 44)) = ISCSI_HTONL(cmd->length); /* Transfer Length */
1224 iscsi_r2t_decap(uint8_t *header, iscsi_r2t_t * cmd)
1229 if (ISCSI_OPCODE(header) != ISCSI_R2T) {
1233 cmd->AHSlength = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 4))); /* TotalAHSLength */
1234 cmd->lun = ISCSI_NTOHLL(*((uint64_t *) (void *) (header + 8))); /* LUN */
1235 cmd->tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 16)));
1236 cmd->transfer_tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 20)));
1237 cmd->StatSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 24)));
1238 cmd->ExpCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 28)));
1239 cmd->MaxCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 32)));
1240 cmd->R2TSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 36)));
1241 cmd->offset = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 40)));
1242 cmd->length = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 44)));
1246 if ((header[1] & 0x7f) != 0x0) {
1248 } else if (header[2] != 0) {
1250 } else if (header[3] != 0) {
1252 } else if (memcmp(header + 4, zeros, 12) != 0) {
1278 iscsi_write_data_encap(uint8_t *header, iscsi_write_data_t * cmd)
1290 (void) memset(header, 0x0, ISCSI_HEADER_LEN);
1291 header[0] = 0x00 | ISCSI_WRITE_DATA; /* Opcode */
1293 header[1] |= 0x80; /* Final */
1295 *((uint32_t *) (void *) (header + 4)) = ISCSI_HTONL(cmd->length); /* Length */
1296 *((uint64_t *) (void *) (header + 8)) = ISCSI_HTONLL(cmd->lun); /* LUN */
1297 *((uint32_t *) (void *) (header + 16)) = ISCSI_HTONL(cmd->tag); /* Tag */
1298 *((uint32_t *) (void *) (header + 20)) = ISCSI_HTONL(cmd->transfer_tag); /* Transfer Tag */
1299 *((uint32_t *) (void *) (header + 28)) = ISCSI_HTONL(cmd->ExpStatSN); /* ExpStatSN */
1300 *((uint32_t *) (void *) (header + 36)) = ISCSI_HTONL(cmd->DataSN); /* DataSN */
1301 *((uint32_t *) (void *) (header + 40)) = ISCSI_HTONL(cmd->offset); /* Buffer Offset */
1307 iscsi_write_data_decap(uint8_t *header, iscsi_write_data_t * cmd)
1312 if (ISCSI_OPCODE(header) != ISCSI_WRITE_DATA) {
1316 cmd->final = (header[1] & 0x80) ? 1 : 0; /* Final */
1317 cmd->length = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 4))); /* Length */
1318 cmd->lun = ISCSI_NTOHLL(*((uint64_t *) (void *) (header + 8))); /* LUN */
1319 cmd->tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 16))); /* Tag */
1320 cmd->transfer_tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 20))); /* Transfer Tag */
1321 cmd->ExpStatSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 28))); /* ExpStatSN */
1322 cmd->DataSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 36))); /* DataSN */
1323 cmd->offset = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 40))); /* Buffer Offset */
1327 if ((header[1] & 0x7f) != 0x0) {
1329 } else if (header[2] != 0) {
1331 } else if (header[3] != 0) {
1333 } else if (header[4] != 0) {
1335 } else if (memcmp(header + 24, zeros, 4) != 0) {
1337 } else if (memcmp(header + 32, zeros, 4) != 0) {
1339 } else if (memcmp(header + 44, zeros, 4) != 0) {
1364 iscsi_read_data_encap(uint8_t *header, iscsi_read_data_t * cmd)
1384 (void) memset(header, 0x0, ISCSI_HEADER_LEN);
1386 header[0] = 0x00 | ISCSI_READ_DATA; /* Opcode */
1388 header[1] |= 0x80; /* Final */
1391 header[1] |= 0x40; /* ACK */
1394 header[1] |= 0x04; /* Overflow */
1397 header[1] |= 0x02; /* Underflow */
1400 header[1] |= 0x01; /* S Bit */
1403 header[3] = cmd->status; /* Status */
1405 *((uint32_t *) (void *) (header + 4)) = ISCSI_HTONL(cmd->length); /* Length */
1406 *((uint64_t *) (void *) (header + 8)) = ISCSI_HTONLL(cmd->lun); /* LUN */
1407 *((uint32_t *) (void *) (header + 16)) = ISCSI_HTONL(cmd->task_tag); /* Task Tag */
1408 *((uint32_t *) (void *) (header + 20)) = ISCSI_HTONL(cmd->transfer_tag); /* Transfer Tag */
1410 *((uint32_t *) (void *) (header + 24)) = ISCSI_HTONL(cmd->StatSN); /* StatSN */
1412 *((uint32_t *) (void *) (header + 28)) = ISCSI_HTONL(cmd->ExpCmdSN); /* ExpCmdSN */
1413 *((uint32_t *) (void *) (header + 32)) = ISCSI_HTONL(cmd->MaxCmdSN); /* MaxCmdSN */
1414 *((uint32_t *) (void *) (header + 36)) = ISCSI_HTONL(cmd->DataSN); /* DataSN */
1415 *((uint32_t *) (void *) (header + 40)) = ISCSI_HTONL(cmd->offset); /* Buffer Offset */
1417 *((uint32_t *) (void *) (header + 44)) = ISCSI_HTONL(cmd->res_count); /* Residual Count */
1424 iscsi_read_data_decap(uint8_t *header, iscsi_read_data_t * cmd)
1429 if (ISCSI_OPCODE(header) != ISCSI_READ_DATA) {
1433 cmd->final = (header[1] & 0x80) ? 1 : 0; /* Final */
1434 cmd->ack = (header[1] & 0x40) ? 1 : 0; /* Acknowledge */
1435 cmd->overflow = (header[1] & 0x04) ? 1 : 0; /* Overflow */
1436 cmd->underflow = (header[1] & 0x02) ? 1 : 0; /* Underflow */
1437 cmd->S_bit = (header[1] & 0x01) ? 1 : 0; /* S Bit */
1438 cmd->status = header[3];/* Status */
1439 cmd->length = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 4))); /* Length */
1440 cmd->lun = ISCSI_NTOHLL(*((uint64_t *) (void *) (header + 8))); /* LUN */
1441 cmd->task_tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 16))); /* Task Tag */
1442 cmd->transfer_tag = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 20))); /* Transfer Tag */
1443 cmd->StatSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 24))); /* StatSN */
1444 cmd->ExpCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 28))); /* ExpCmdSN */
1445 cmd->MaxCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 32))); /* MaxCmdSN */
1446 cmd->DataSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 36))); /* DataSN */
1447 cmd->offset = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 40))); /* Buffer Offset */
1448 cmd->res_count = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 44))); /* Residual Count */
1451 if ((header[0] & 0xc0) != 0x0) {
1453 } else if ((header[1] & 0x38) != 0x0) {
1455 } else if (header[2] != 0) {
1457 } else if (header[4] != 0) {
1459 } else if (memcmp(header + 8, zeros, 8) != 0) {
1461 } else if (!cmd->underflow && memcmp(header + 44, zeros, 4) != 0) {
1491 iscsi_reject_encap(uint8_t *header, iscsi_reject_t * cmd)
1501 (void) memset(header, 0x0, ISCSI_HEADER_LEN);
1503 header[0] |= 0x00 | ISCSI_REJECT; /* Opcode */
1504 header[1] |= 0x80;
1505 header[2] = cmd->reason;/* Reason */
1506 *((uint32_t *) (void *) (header + 4)) = ISCSI_HTONL(cmd->length); /* Length */
1507 *((uint32_t *) (void *) (header + 24)) = ISCSI_HTONL(cmd->StatSN); /* StatSN */
1508 *((uint32_t *) (void *) (header + 28)) = ISCSI_HTONL(cmd->ExpCmdSN); /* ExpCmdSN */
1509 *((uint32_t *) (void *) (header + 32)) = ISCSI_HTONL(cmd->MaxCmdSN); /* MaxCmdSN */
1510 *((uint32_t *) (void *) (header + 36)) = ISCSI_HTONL(cmd->DataSN); /* DataSN */
1516 iscsi_reject_decap(uint8_t *header, iscsi_reject_t * cmd)
1521 if (ISCSI_OPCODE(header) != ISCSI_REJECT) {
1525 cmd->reason = header[2];/* Reason */
1526 cmd->length = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 4))); /* Length */
1527 cmd->StatSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 24))); /* StatSN */
1528 cmd->ExpCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 28))); /* ExpCmdSN */
1529 cmd->MaxCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 32))); /* MaxCmdSN */
1530 cmd->DataSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 36))); /* DataSN */
1534 if ((header[0] & 0xc0) != 0x0) {
1536 } else if ((header[1] & 0x7f) != 0x0) {
1538 } else if (header[3] != 0) {
1540 } else if (header[4] != 0) {
1542 } else if (memcmp(header + 8, zeros, 8) != 0) {
1544 } else if (memcmp(header + 20, zeros, 4) != 0) {
1546 } else if (memcmp(header + 40, zeros, 8) != 0) {
1564 iscsi_amsg_decap(uint8_t *header, iscsi_async_msg_t * msg)
1567 if (ISCSI_OPCODE(header) != ISCSI_ASYNC) {
1571 msg->AHSlength = header[4]; /* TotalAHSLength */
1572 msg->length = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 4))); /* Length */
1573 msg->lun = ISCSI_NTOHLL(*((uint64_t *) (void *) (header + 8))); /* LUN */
1574 msg->StatSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 24))); /* StatSN */
1575 msg->ExpCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 28))); /* ExpCmdSN */
1576 msg->MaxCmdSN = ISCSI_NTOHL(*((uint32_t *) (void *) (header + 32))); /* MaxCmdSN */
1577 msg->AsyncEvent = header[36]; /* Async Event */
1578 msg->AsyncVCode = header[37]; /* Async Vendor Code */