]> git.ozlabs.org Git - ccan/blob - ccan/iscsi/iscsi-private.h
iscsi: fix warnings with -Wwrite-strings
[ccan] / ccan / iscsi / iscsi-private.h
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 #ifndef CCAN_ISCSI_PRIVATE_H
18 #define CCAN_ISCSI_PRIVATE_H
19
20 #include <stdint.h>
21
22 #ifndef discard_const
23 #define discard_const(ptr) ((void *)((intptr_t)(ptr)))
24 #endif
25
26 struct iscsi_context {
27        const char *initiator_name;
28        const char *target_name;
29        const char *alias;
30        enum iscsi_session_type session_type;
31        unsigned char isid[6];
32        uint32_t itt;
33        uint32_t cmdsn;
34        uint32_t statsn;
35
36        int fd;
37        int is_connected;
38        int is_loggedin;
39
40        iscsi_command_cb connect_cb;
41        void *connect_data;
42
43        struct iscsi_pdu *outqueue;
44        struct iscsi_pdu *waitpdu;
45
46        int insize;
47        int inpos;
48        unsigned char *inbuf;
49 };
50
51 #define ISCSI_HEADER_SIZE                       48
52
53 #define ISCSI_PDU_IMMEDIATE                    0x40
54
55 #define ISCSI_PDU_TEXT_FINAL                   0x80
56 #define ISCSI_PDU_TEXT_CONTINUE                0x40
57
58 #define ISCSI_PDU_LOGIN_TRANSIT                0x80
59 #define ISCSI_PDU_LOGIN_CONTINUE               0x40
60 #define ISCSI_PDU_LOGIN_CSG_SECNEG             0x00
61 #define ISCSI_PDU_LOGIN_CSG_OPNEG              0x04
62 #define ISCSI_PDU_LOGIN_CSG_FF                 0x0c
63 #define ISCSI_PDU_LOGIN_NSG_SECNEG             0x00
64 #define ISCSI_PDU_LOGIN_NSG_OPNEG              0x01
65 #define ISCSI_PDU_LOGIN_NSG_FF                 0x03
66
67
68 #define ISCSI_PDU_SCSI_FINAL                   0x80
69 #define ISCSI_PDU_SCSI_READ                    0x40
70 #define ISCSI_PDU_SCSI_WRITE                   0x20
71 #define ISCSI_PDU_SCSI_ATTR_UNTAGGED           0x00
72 #define ISCSI_PDU_SCSI_ATTR_SIMPLE             0x01
73 #define ISCSI_PDU_SCSI_ATTR_ORDERED            0x02
74 #define ISCSI_PDU_SCSI_ATTR_HEADOFQUEUE        0x03
75 #define ISCSI_PDU_SCSI_ATTR_ACA                0x04
76
77 #define ISCSI_PDU_DATA_FINAL                   0x80
78 #define ISCSI_PDU_DATA_ACK_REQUESTED           0x40
79 #define ISCSI_PDU_DATA_BIDIR_OVERFLOW          0x10
80 #define ISCSI_PDU_DATA_BIDIR_UNDERFLOW         0x08
81 #define ISCSI_PDU_DATA_RESIDUAL_OVERFLOW       0x04
82 #define ISCSI_PDU_DATA_RESIDUAL_UNDERFLOW      0x02
83 #define ISCSI_PDU_DATA_CONTAINS_STATUS         0x01
84
85 enum iscsi_opcode {ISCSI_PDU_NOP_OUT=0x00,
86                   ISCSI_PDU_SCSI_REQUEST=0x01,
87                   ISCSI_PDU_LOGIN_REQUEST=0x03,
88                   ISCSI_PDU_TEXT_REQUEST=0x04,
89                   ISCSI_PDU_LOGOUT_REQUEST=0x06,
90                   ISCSI_PDU_NOP_IN=0x20,
91                   ISCSI_PDU_SCSI_RESPONSE=0x21,
92                   ISCSI_PDU_LOGIN_RESPONSE=0x23,
93                   ISCSI_PDU_TEXT_RESPONSE=0x24,
94                   ISCSI_PDU_DATA_IN=0x25,
95                   ISCSI_PDU_LOGOUT_RESPONSE=0x26};
96
97 struct iscsi_pdu {
98        struct iscsi_pdu *prev, *next;
99
100        uint32_t itt;
101        uint32_t cmdsn;
102        enum iscsi_opcode response_opcode;
103
104        iscsi_command_cb callback;
105        void *private_data;
106
107        int written;
108        struct iscsi_data outdata;
109        struct iscsi_data indata;
110
111        struct iscsi_scsi_cbdata *scsi_cbdata;
112 };
113
114 void iscsi_free_scsi_cbdata(struct iscsi_scsi_cbdata *scsi_cbdata);
115
116 struct iscsi_pdu *iscsi_allocate_pdu(struct iscsi_context *iscsi, enum iscsi_opcode opcode, enum iscsi_opcode response_opcode);
117 void iscsi_free_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu);
118 void iscsi_pdu_set_pduflags(struct iscsi_pdu *pdu, unsigned char flags);
119 void iscsi_pdu_set_immediate(struct iscsi_pdu *pdu);
120 void iscsi_pdu_set_ttt(struct iscsi_pdu *pdu, uint32_t ttt);
121 void iscsi_pdu_set_cmdsn(struct iscsi_pdu *pdu, uint32_t cmdsn);
122 void iscsi_pdu_set_lun(struct iscsi_pdu *pdu, uint32_t lun);
123 void iscsi_pdu_set_expstatsn(struct iscsi_pdu *pdu, uint32_t expstatsnsn);
124 void iscsi_pdu_set_expxferlen(struct iscsi_pdu *pdu, uint32_t expxferlen);
125 int iscsi_pdu_add_data(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *dptr, int dsize);
126 int iscsi_queue_pdu(struct iscsi_context *iscsi, struct iscsi_pdu *pdu);
127 int iscsi_add_data(struct iscsi_data *data, const unsigned char *dptr, int dsize, int pdualignment);
128 int iscsi_set_random_isid(struct iscsi_context *iscsi);
129
130 struct scsi_task;
131 void iscsi_pdu_set_cdb(struct iscsi_pdu *pdu, struct scsi_task *task);
132
133 int iscsi_get_pdu_size(const unsigned char *hdr);
134 int iscsi_process_pdu(struct iscsi_context *iscsi, const unsigned char *hdr, int size);
135
136 int iscsi_process_login_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size);
137 int iscsi_process_text_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size);
138 int iscsi_process_logout_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size);
139 int iscsi_process_scsi_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size);
140 int iscsi_process_scsi_data_in(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size, int *is_finished);
141 int iscsi_process_nop_out_reply(struct iscsi_context *iscsi, struct iscsi_pdu *pdu, const unsigned char *hdr, int size);
142
143 #endif /* CCAN_ISCSI_PRIVATE_H */