isns_pdu.h revision 1.1 1 1.1 agc /* $NetBSD: isns_pdu.h,v 1.1 2011/01/16 01:22:50 agc Exp $ */
2 1.1 agc
3 1.1 agc /*-
4 1.1 agc * Copyright (c) 2004,2009 The NetBSD Foundation, Inc.
5 1.1 agc * All rights reserved.
6 1.1 agc *
7 1.1 agc * This code is derived from software contributed to The NetBSD Foundation
8 1.1 agc * by Wasabi Systems, Inc.
9 1.1 agc *
10 1.1 agc * Redistribution and use in source and binary forms, with or without
11 1.1 agc * modification, are permitted provided that the following conditions
12 1.1 agc * are met:
13 1.1 agc * 1. Redistributions of source code must retain the above copyright
14 1.1 agc * notice, this list of conditions and the following disclaimer.
15 1.1 agc * 2. Redistributions in binary form must reproduce the above copyright
16 1.1 agc * notice, this list of conditions and the following disclaimer in the
17 1.1 agc * documentation and/or other materials provided with the distribution.
18 1.1 agc *
19 1.1 agc * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 1.1 agc * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 agc * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 agc * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 1.1 agc * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 agc * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 agc * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 agc * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 agc * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 agc * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 agc * POSSIBILITY OF SUCH DAMAGE.
30 1.1 agc */
31 1.1 agc
32 1.1 agc /*
33 1.1 agc * isns_pdu.h
34 1.1 agc */
35 1.1 agc
36 1.1 agc #ifndef _ISNS_PDU_H_
37 1.1 agc #define _ISNS_PDU_H_
38 1.1 agc
39 1.1 agc #include <pthread.h>
40 1.1 agc
41 1.1 agc #include "isns_defs.h"
42 1.1 agc
43 1.1 agc #define ISNSP_VERSION (0x0001)
44 1.1 agc
45 1.1 agc /*
46 1.1 agc * Max PDU payload length (MUST be <= 65532 and a multiple of 4).
47 1.1 agc */
48 1.1 agc #define ISNS_MAX_PDU_PAYLOAD 65532
49 1.1 agc
50 1.1 agc /*
51 1.1 agc * ISNS buffer pool defines.
52 1.1 agc */
53 1.1 agc #define ISNS_BUF_SIZE 1024
54 1.1 agc #define ISNS_BUF_COUNT 32
55 1.1 agc
56 1.1 agc #define ISNS_SMALL_BUF_SIZE \
57 1.1 agc (/* CONSTCOND */MAX(sizeof(struct isns_task_s), sizeof(struct isns_trans_s)))
58 1.1 agc #define ISNS_SMALL_BUF_COUNT 32
59 1.1 agc
60 1.1 agc #define ISNS_BUF_POOL 1
61 1.1 agc #define ISNS_BUF_MALLOC 2
62 1.1 agc #define ISNS_BUF_STATIC 3
63 1.1 agc
64 1.1 agc /*
65 1.1 agc * ISNS_INIT_BUFFER - initialize buffer (pointer) provided as an isns_buffer_s,
66 1.1 agc * setting the length and type specified, and initializing
67 1.1 agc * other members to appropriate values.
68 1.1 agc */
69 1.1 agc #define ISNS_INIT_BUFFER(_bufp, _len, _type) \
70 1.1 agc do if ((_bufp) != NULL) { \
71 1.1 agc ((struct isns_buffer_s *)(_bufp))->cur_len = 0; \
72 1.1 agc ((struct isns_buffer_s *)(_bufp))->alloc_len = (_len); \
73 1.1 agc ((struct isns_buffer_s *)(_bufp))->alloc_len &= ~0x03; \
74 1.1 agc ((struct isns_buffer_s *)(_bufp))->buf_type = (_type); \
75 1.1 agc ((struct isns_buffer_s *)(_bufp))->next = NULL; \
76 1.1 agc } while (/* CONSTCOND */0)
77 1.1 agc
78 1.1 agc
79 1.1 agc /*
80 1.1 agc * ISNS buffer struct - used for trans, pdu, payload allocations in libisns.
81 1.1 agc */
82 1.1 agc struct isns_buffer_s {
83 1.1 agc uint32_t cur_len;
84 1.1 agc uint32_t alloc_len;
85 1.1 agc int buf_type;
86 1.1 agc
87 1.1 agc struct isns_buffer_s *next;
88 1.1 agc };
89 1.1 agc
90 1.1 agc #define isns_buffer_data(_bufp, _ofs) \
91 1.1 agc (void *)(((uint8_t *)(void *)(_bufp+1))+(_ofs))
92 1.1 agc
93 1.1 agc void isns_init_buffer_pool(void);
94 1.1 agc int isns_add_buffer_pool(int, int);
95 1.1 agc void isns_destroy_buffer_pool(void);
96 1.1 agc struct isns_buffer_s *isns_new_buffer(int);
97 1.1 agc void isns_free_buffer(struct isns_buffer_s *);
98 1.1 agc
99 1.1 agc
100 1.1 agc
101 1.1 agc /*
102 1.1 agc * TLV buffer access/manipulation-related macros.
103 1.1 agc */
104 1.1 agc #define ISNS_TLV_HDR_SIZE 8
105 1.1 agc
106 1.1 agc #define ISNS_PAD4_LEN(n) (uint32_t)(((n)+3) & ~0x03)
107 1.1 agc #define ISNS_PAD4_BYTES(n) ((4 - ((n) & 0x03)) & 0x03)
108 1.1 agc
109 1.1 agc #define ISNS_TLV_TAG_REF(_buf) \
110 1.1 agc (*(uint32_t *)(void *)(_buf))
111 1.1 agc #define ISNS_TLV_GET_TAG(_buf) \
112 1.1 agc isns_ntohl(ISNS_TLV_TAG_REF(_buf))
113 1.1 agc #define ISNS_TLV_SET_TAG(_buf, _tag) \
114 1.1 agc do { \
115 1.1 agc ISNS_TLV_TAG_REF(_buf) = isns_htonl(_tag); \
116 1.1 agc } while (/* CONSTCOND */0)
117 1.1 agc
118 1.1 agc #define ISNS_TLV_LEN_REF(_buf) \
119 1.1 agc (*(uint32_t *)(void *)((uint8_t *)(_buf)+4))
120 1.1 agc #define ISNS_TLV_GET_LEN(_buf) \
121 1.1 agc isns_ntohl(ISNS_TLV_LEN_REF(_buf))
122 1.1 agc #define ISNS_TLV_SET_LEN(_buf, _len) \
123 1.1 agc do { \
124 1.1 agc ISNS_TLV_LEN_REF(_buf) = isns_htonl(_len); \
125 1.1 agc } while (/* CONSTCOND */0)
126 1.1 agc
127 1.1 agc #define ISNS_TLV_DATA_PTR(_buf) \
128 1.1 agc ((void *)((uint8_t *)(_buf)+8))
129 1.1 agc
130 1.1 agc
131 1.1 agc /*
132 1.1 agc * ISNS transaction and PDU structs.
133 1.1 agc */
134 1.1 agc
135 1.1 agc #define ISNS_TRANSF_COMPLETE 0x000000001
136 1.1 agc #define ISNS_TRANSF_FREE_WHEN_COMPLETE 0x000000002
137 1.1 agc
138 1.1 agc
139 1.1 agc struct isns_refresh_s {
140 1.1 agc char node[225];
141 1.1 agc int interval;
142 1.1 agc
143 1.1 agc struct isns_trans_s *trans_p;
144 1.1 agc };
145 1.1 agc
146 1.1 agc struct isns_get_tlv_info_s {
147 1.1 agc struct isns_pdu_s *pdu_p;
148 1.1 agc struct isns_buffer_s *buf_p;
149 1.1 agc struct isns_buffer_s *extra_buf_list;
150 1.1 agc int buf_ofs;
151 1.1 agc };
152 1.1 agc
153 1.1 agc struct isns_trans_s {
154 1.1 agc uint16_t id;
155 1.1 agc uint16_t func_id;
156 1.1 agc uint32_t flags;
157 1.1 agc struct isns_config_s *cfg_p;
158 1.1 agc
159 1.1 agc struct isns_get_tlv_info_s get_tlv_info;
160 1.1 agc
161 1.1 agc struct isns_pdu_s *pdu_req_list;
162 1.1 agc struct isns_pdu_s *pdu_rsp_list;
163 1.1 agc
164 1.1 agc uint16_t disconnect_cnt;
165 1.1 agc };
166 1.1 agc
167 1.1 agc struct isns_pdu_hdr_s {
168 1.1 agc uint16_t isnsp_version __attribute__ ((packed));
169 1.1 agc uint16_t func_id __attribute__ ((packed));
170 1.1 agc uint16_t payload_len __attribute__ ((packed));
171 1.1 agc uint16_t flags __attribute__ ((packed));
172 1.1 agc uint16_t trans_id __attribute__ ((packed));
173 1.1 agc uint16_t seq_id __attribute__ ((packed));
174 1.1 agc };
175 1.1 agc
176 1.1 agc struct isns_pdu_s {
177 1.1 agc struct isns_config_s *cfg_p;
178 1.1 agc struct isns_pdu_hdr_s hdr;
179 1.1 agc int byteorder_host;
180 1.1 agc struct isns_buffer_s *payload_p;
181 1.1 agc struct isns_pdu_s *next;
182 1.1 agc };
183 1.1 agc
184 1.1 agc
185 1.1 agc #define isns_get_pdu_request(_trans) \
186 1.1 agc (((_trans) == ISNS_INVALID_TRANS) \
187 1.1 agc ? NULL : ((struct isns_trans_s *)(_trans))->pdu_req_list)
188 1.1 agc
189 1.1 agc #define isns_get_pdu_response(_trans) \
190 1.1 agc (((_trans) == ISNS_INVALID_TRANS) \
191 1.1 agc ? NULL : ((struct isns_trans_s *)(_trans))->pdu_rsp_list)
192 1.1 agc
193 1.1 agc #define isns_get_next_pdu(_pdu) \
194 1.1 agc (((_pdu) == NULL) ? NULL : ((struct isns_pdu_s *)(_pdu))->next)
195 1.1 agc
196 1.1 agc #define isns_get_trans_flags(_trans) \
197 1.1 agc isns_set_trans_flags((_trans), 0)
198 1.1 agc
199 1.1 agc
200 1.1 agc void isns_complete_trans(struct isns_trans_s *);
201 1.1 agc int isns_abort_trans(struct isns_config_s *, uint16_t);
202 1.1 agc
203 1.1 agc uint32_t isns_set_trans_flags(struct isns_trans_s *, uint32_t);
204 1.1 agc void isns_add_pdu_request(struct isns_trans_s *, struct isns_pdu_s *);
205 1.1 agc void isns_add_pdu_response(struct isns_trans_s *, struct isns_pdu_s *);
206 1.1 agc struct isns_pdu_s *isns_get_pdu_request_tail(struct isns_trans_s *);
207 1.1 agc int isns_get_pdu_response_status(struct isns_trans_s *, uint32_t *);
208 1.1 agc
209 1.1 agc struct isns_pdu_s *isns_new_pdu(struct isns_config_s *, uint16_t, uint16_t,
210 1.1 agc uint16_t);
211 1.1 agc void isns_free_pdu(struct isns_pdu_s *);
212 1.1 agc int isns_send_pdu(ISNS_TRANS, struct isns_pdu_s *, const struct timespec *);
213 1.1 agc
214 1.1 agc #ifdef ISNS_DEBUG
215 1.1 agc #define DUMP_PDU(_pdu) isns_dump_pdu(_pdu)
216 1.1 agc void isns_dump_pdu(struct isns_pdu_s *);
217 1.1 agc #else
218 1.1 agc #define DUMP_PDU(_pdu)
219 1.1 agc #endif
220 1.1 agc
221 1.1 agc
222 1.1 agc #endif /* !_ISNS_PDU_H_ */
223