1/*-
2 * Copyright (c) 2014 Alexander Motin <mav@FreeBSD.org>
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
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.
13 *
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
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: releng/10.3/usr.sbin/ctld/isns.h 274939 2014-11-24 00:47:04Z mav $
27 */
28
29#ifndef	_ISNS_H
30#define	_ISNS_H
31
32#define	ISNS_VERSION		0x0001
33
34#define	ISNS_FUNC_DEVATTRREG	0x0001
35#define	ISNS_FUNC_DEVATTRQRY	0x0002
36#define	ISNS_FUNC_DEVGETNEXT	0x0003
37#define	ISNS_FUNC_DEVDEREG	0x0004
38#define	ISNS_FUNC_SCNREG	0x0005
39#define	ISNS_FUNC_SCNDEREG	0x0006
40#define	ISNS_FUNC_SCNEVENT	0x0007
41#define	ISNS_FUNC_SCN		0x0008
42#define	ISNS_FUNC_DDREG		0x0009
43#define	ISNS_FUNC_DDDEREG	0x000a
44#define	ISNS_FUNC_DDSREG	0x000b
45#define	ISNS_FUNC_DDSDEREG	0x000c
46#define	ISNS_FUNC_ESI		0x000d
47#define	ISNS_FUNC_HEARTBEAT	0x000e
48#define	ISNS_FUNC_RESPONSE	0x8000
49
50#define	ISNS_FLAG_CLIENT	0x8000
51#define	ISNS_FLAG_SERVER	0x4000
52#define	ISNS_FLAG_AUTH		0x2000
53#define	ISNS_FLAG_REPLACE	0x1000
54#define	ISNS_FLAG_LAST		0x0800
55#define	ISNS_FLAG_FIRST		0x0400
56
57struct isns_hdr {
58	uint8_t	ih_version[2];
59	uint8_t	ih_function[2];
60	uint8_t	ih_length[2];
61	uint8_t	ih_flags[2];
62	uint8_t	ih_transaction[2];
63	uint8_t	ih_sequence[2];
64};
65
66struct isns_tlv {
67	uint8_t	it_tag[4];
68	uint8_t	it_length[4];
69	uint8_t	it_value[];
70};
71
72struct isns_req {
73	u_int	ir_buflen;
74	u_int	ir_usedlen;
75	uint8_t	*ir_buf;
76};
77
78struct isns_req * isns_req_alloc(void);
79struct isns_req * isns_req_create(uint16_t func, uint16_t flags);
80void isns_req_free(struct isns_req *req);
81void isns_req_add(struct isns_req *req, uint32_t tag, uint32_t len,
82    const void *value);
83void isns_req_add_delim(struct isns_req *req);
84void isns_req_add_str(struct isns_req *req, uint32_t tag, const char *value);
85void isns_req_add_32(struct isns_req *req, uint32_t tag, uint32_t value);
86void isns_req_add_addr(struct isns_req *req, uint32_t tag, struct addrinfo *ai);
87void isns_req_add_port(struct isns_req *req, uint32_t tag, struct addrinfo *ai);
88int isns_req_send(int s, struct isns_req *req);
89int isns_req_receive(int s, struct isns_req *req);
90uint32_t isns_req_get_status(struct isns_req *req);
91
92#endif /* _ISNS_H */
93