1272234Sgjb/*-
2272234Sgjb * Copyright (c) 2014 Alexander Motin <mav@FreeBSD.org>
3278505Sgjb * All rights reserved.
4272234Sgjb *
5272234Sgjb * Redistribution and use in source and binary forms, with or without
6272234Sgjb * modification, are permitted provided that the following conditions
7272234Sgjb * are met:
8272234Sgjb * 1. Redistributions of source code must retain the above copyright
9272234Sgjb *    notice, this list of conditions and the following disclaimer.
10272234Sgjb * 2. Redistributions in binary form must reproduce the above copyright
11272234Sgjb *    notice, this list of conditions and the following disclaimer in the
12272234Sgjb *    documentation and/or other materials provided with the distribution.
13272234Sgjb *
14272234Sgjb * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15272234Sgjb * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16272234Sgjb * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17272234Sgjb * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18272234Sgjb * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19272234Sgjb * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20272234Sgjb * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21272234Sgjb * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22272234Sgjb * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23272234Sgjb * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24272234Sgjb * SUCH DAMAGE.
25272234Sgjb *
26272234Sgjb * $FreeBSD: releng/10.3/usr.sbin/ctld/isns.h 274939 2014-11-24 00:47:04Z mav $
27272234Sgjb */
28272234Sgjb
29272234Sgjb#ifndef	_ISNS_H
30272234Sgjb#define	_ISNS_H
31272234Sgjb
32272234Sgjb#define	ISNS_VERSION		0x0001
33272234Sgjb
34272234Sgjb#define	ISNS_FUNC_DEVATTRREG	0x0001
35277458Sgjb#define	ISNS_FUNC_DEVATTRQRY	0x0002
36277458Sgjb#define	ISNS_FUNC_DEVGETNEXT	0x0003
37277458Sgjb#define	ISNS_FUNC_DEVDEREG	0x0004
38277458Sgjb#define	ISNS_FUNC_SCNREG	0x0005
39277458Sgjb#define	ISNS_FUNC_SCNDEREG	0x0006
40277458Sgjb#define	ISNS_FUNC_SCNEVENT	0x0007
41274134Sgjb#define	ISNS_FUNC_SCN		0x0008
42274134Sgjb#define	ISNS_FUNC_DDREG		0x0009
43278502Sgjb#define	ISNS_FUNC_DDDEREG	0x000a
44274134Sgjb#define	ISNS_FUNC_DDSREG	0x000b
45274134Sgjb#define	ISNS_FUNC_DDSDEREG	0x000c
46274134Sgjb#define	ISNS_FUNC_ESI		0x000d
47274134Sgjb#define	ISNS_FUNC_HEARTBEAT	0x000e
48274134Sgjb#define	ISNS_FUNC_RESPONSE	0x8000
49274134Sgjb
50274134Sgjb#define	ISNS_FLAG_CLIENT	0x8000
51274134Sgjb#define	ISNS_FLAG_SERVER	0x4000
52274134Sgjb#define	ISNS_FLAG_AUTH		0x2000
53274134Sgjb#define	ISNS_FLAG_REPLACE	0x1000
54274134Sgjb#define	ISNS_FLAG_LAST		0x0800
55274134Sgjb#define	ISNS_FLAG_FIRST		0x0400
56274134Sgjb
57274134Sgjbstruct isns_hdr {
58274134Sgjb	uint8_t	ih_version[2];
59277458Sgjb	uint8_t	ih_function[2];
60274134Sgjb	uint8_t	ih_length[2];
61274134Sgjb	uint8_t	ih_flags[2];
62274134Sgjb	uint8_t	ih_transaction[2];
63274134Sgjb	uint8_t	ih_sequence[2];
64274134Sgjb};
65274134Sgjb
66274134Sgjbstruct isns_tlv {
67274134Sgjb	uint8_t	it_tag[4];
68274134Sgjb	uint8_t	it_length[4];
69274134Sgjb	uint8_t	it_value[];
70274134Sgjb};
71274134Sgjb
72274134Sgjbstruct isns_req {
73272234Sgjb	u_int	ir_buflen;
74274134Sgjb	u_int	ir_usedlen;
75272234Sgjb	uint8_t	*ir_buf;
76274134Sgjb};
77274134Sgjb
78274134Sgjbstruct isns_req * isns_req_alloc(void);
79274134Sgjbstruct isns_req * isns_req_create(uint16_t func, uint16_t flags);
80278502Sgjbvoid isns_req_free(struct isns_req *req);
81274134Sgjbvoid isns_req_add(struct isns_req *req, uint32_t tag, uint32_t len,
82278502Sgjb    const void *value);
83272380Sgjbvoid isns_req_add_delim(struct isns_req *req);
84272380Sgjbvoid isns_req_add_str(struct isns_req *req, uint32_t tag, const char *value);
85274134Sgjbvoid isns_req_add_32(struct isns_req *req, uint32_t tag, uint32_t value);
86274134Sgjbvoid isns_req_add_addr(struct isns_req *req, uint32_t tag, struct addrinfo *ai);
87274134Sgjbvoid isns_req_add_port(struct isns_req *req, uint32_t tag, struct addrinfo *ai);
88272234Sgjbint isns_req_send(int s, struct isns_req *req);
89272234Sgjbint isns_req_receive(int s, struct isns_req *req);
90274134Sgjbuint32_t isns_req_get_status(struct isns_req *req);
91274134Sgjb
92278502Sgjb#endif /* _ISNS_H */
93274134Sgjb