2 Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "iscsi-private.h"
22 int iscsi_nop_out_async(struct iscsi_context *iscsi, iscsi_command_cb cb, unsigned char *data, int len, void *private_data)
24 struct iscsi_pdu *pdu;
27 printf("trying to send nop-out on NULL context\n");
31 if (iscsi->is_loggedin == 0) {
32 printf("trying send nop-out while not logged in\n");
36 pdu = iscsi_allocate_pdu(iscsi, ISCSI_PDU_NOP_OUT, ISCSI_PDU_NOP_IN);
38 printf("Failed to allocate nop-out pdu\n");
43 iscsi_pdu_set_immediate(pdu);
46 iscsi_pdu_set_pduflags(pdu, 0x80);
49 iscsi_pdu_set_ttt(pdu, 0xffffffff);
52 iscsi_pdu_set_lun(pdu, 2);
54 /* cmdsn is not increased if Immediate delivery*/
55 iscsi_pdu_set_cmdsn(pdu, iscsi->cmdsn);
56 pdu->cmdsn = iscsi->cmdsn;
60 pdu->private_data = private_data;
62 if (iscsi_pdu_add_data(iscsi, pdu, data, len) != 0) {
63 printf("Failed to add outdata to nop-out\n");
64 iscsi_free_pdu(iscsi, pdu);
69 if (iscsi_queue_pdu(iscsi, pdu) != 0) {
70 printf("failed to queue iscsi nop-out pdu\n");
71 iscsi_free_pdu(iscsi, pdu);
78 int iscsi_process_nop_out_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size)
80 struct iscsi_data data;
85 if (size > ISCSI_HEADER_SIZE) {
86 data.data = discard_const(&hdr[ISCSI_HEADER_SIZE]);
87 data.size = size - ISCSI_HEADER_SIZE;
89 pdu->callback(iscsi, ISCSI_STATUS_GOOD, &data, pdu->private_data);