]> git.ozlabs.org Git - ccan/blob - ccan/iscsi/nop.c
base64: fix for unsigned chars (e.g. ARM).
[ccan] / ccan / iscsi / nop.c
1 /*
2    Copyright (C) 2010 by Ronnie Sahlberg <ronniesahlberg@gmail.com>
3    
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.
8    
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.
13    
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/>.
16 */
17
18 #include <stdio.h>
19 #include "iscsi.h"
20 #include "iscsi-private.h"
21
22 int iscsi_nop_out_async(struct iscsi_context *iscsi, iscsi_command_cb cb, unsigned char *data, int len, void *private_data)
23 {
24         struct iscsi_pdu *pdu;
25
26         if (iscsi == NULL) {
27                 printf("trying to send nop-out on NULL context\n");
28                 return -1;
29         }
30
31         if (iscsi->is_loggedin == 0) {
32                 printf("trying send nop-out while not logged in\n");
33                 return -2;
34         }
35
36         pdu = iscsi_allocate_pdu(iscsi, ISCSI_PDU_NOP_OUT, ISCSI_PDU_NOP_IN);
37         if (pdu == NULL) {
38                 printf("Failed to allocate nop-out pdu\n");
39                 return -3;
40         }
41
42         /* immediate flag */
43         iscsi_pdu_set_immediate(pdu);
44
45         /* flags */
46         iscsi_pdu_set_pduflags(pdu, 0x80);
47
48         /* ttt */
49         iscsi_pdu_set_ttt(pdu, 0xffffffff);
50
51         /* lun */
52         iscsi_pdu_set_lun(pdu, 2);
53
54         /* cmdsn is not increased if Immediate delivery*/
55         iscsi_pdu_set_cmdsn(pdu, iscsi->cmdsn);
56         pdu->cmdsn = iscsi->cmdsn;
57 //      iscsi->cmdsn++;
58
59         pdu->callback     = cb;
60         pdu->private_data = private_data;
61
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);
65                 return -4;
66         }
67
68
69         if (iscsi_queue_pdu(iscsi, pdu) != 0) {
70                 printf("failed to queue iscsi nop-out pdu\n");
71                 iscsi_free_pdu(iscsi, pdu);
72                 return -5;
73         }
74
75         return 0;
76 }
77
78 int iscsi_process_nop_out_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size)
79 {
80         struct iscsi_data data;
81
82         data.data = NULL;
83         data.size = 0;
84
85         if (size > ISCSI_HEADER_SIZE) {
86                 data.data = discard_const(&hdr[ISCSI_HEADER_SIZE]);
87                 data.size = size - ISCSI_HEADER_SIZE;
88         }
89         pdu->callback(iscsi, ISCSI_STATUS_GOOD, &data, pdu->private_data);
90
91         return 0;
92 }