2 * Copyright (c) 2005-2008 Daniel Braniss <danny@cs.huji.ac.il>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 | $Id: pdu.c,v 2.2 2006/12/01 09:11:56 danny Exp danny $
31 #include <sys/cdefs.h>
33 #include <sys/types.h>
36 #include <sys/ioctl.h>
46 #include "iscontrol.h"
49 xmitpdu(isess_t
*sess
, pdu_t
*pp
)
51 if(ioctl(sess
->fd
, ISCSISEND
, pp
)) {
62 recvpdu(isess_t
*sess
, pdu_t
*pp
)
64 if(ioctl(sess
->fd
, ISCSIRECV
, pp
)) {
68 // XXX: return error if truncated via
77 sendPDU(isess_t
*sess
, pdu_t
*pp
, handler_t
*hdlr
)
84 pp
->ahs_size
= 8 * 1024;
85 if((pp
->ahs
= malloc(pp
->ahs_size
)) == NULL
) {
86 fprintf(stderr
, "out of mem!");
90 if((res
= recvpdu(sess
, pp
)) != 0) {
91 fprintf(stderr
, "recvpdu failed\n");
102 #define FUDGE (512 * 8)
104 | We use the same memory for the response
105 | so make enough room ...
106 | XXX: must find a better way.
109 addText(pdu_t
*pp
, char *fmt
, ...)
116 len
= vasprintf(&str
, fmt
, ap
) + 1;
117 if((pp
->ds_len
+ len
) > 0xffffff) {
118 printf("ds overflow\n");
123 if((pp
->ds_len
+ len
) > pp
->ds_size
) {
126 np
= realloc(pp
->ds
, pp
->ds_size
+ len
+ FUDGE
);
129 //XXX: out of memory!
133 pp
->ds_size
+= len
+ FUDGE
;
135 memcpy(pp
->ds
+ pp
->ds_len
, str
, len
);
148 bzero(&pp
->ipdu
, sizeof(union ipdu_u
));
152 pp
->ds_size
= pp
->ds_len
= 0;
156 pukeText(char *it
, pdu_t
*pp
)
163 ptr
= (char *)pp
->ds
;
164 cmd
= pp
->ipdu
.bhs
.opcode
;
166 printf("%s: cmd=0x%x len=%d\n", it
, cmd
, (int)len
);
168 printf("\t%s\n", ptr
);