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
27#ifndef	_ISNS_H
28#define	_ISNS_H
29
30#define	ISNS_VERSION		0x0001
31
32#define	ISNS_FUNC_DEVATTRREG	0x0001
33#define	ISNS_FUNC_DEVATTRQRY	0x0002
34#define	ISNS_FUNC_DEVGETNEXT	0x0003
35#define	ISNS_FUNC_DEVDEREG	0x0004
36#define	ISNS_FUNC_SCNREG	0x0005
37#define	ISNS_FUNC_SCNDEREG	0x0006
38#define	ISNS_FUNC_SCNEVENT	0x0007
39#define	ISNS_FUNC_SCN		0x0008
40#define	ISNS_FUNC_DDREG		0x0009
41#define	ISNS_FUNC_DDDEREG	0x000a
42#define	ISNS_FUNC_DDSREG	0x000b
43#define	ISNS_FUNC_DDSDEREG	0x000c
44#define	ISNS_FUNC_ESI		0x000d
45#define	ISNS_FUNC_HEARTBEAT	0x000e
46#define	ISNS_FUNC_RESPONSE	0x8000
47
48#define	ISNS_FLAG_CLIENT	0x8000
49#define	ISNS_FLAG_SERVER	0x4000
50#define	ISNS_FLAG_AUTH		0x2000
51#define	ISNS_FLAG_REPLACE	0x1000
52#define	ISNS_FLAG_LAST		0x0800
53#define	ISNS_FLAG_FIRST		0x0400
54
55struct isns_hdr {
56	uint8_t	ih_version[2];
57	uint8_t	ih_function[2];
58	uint8_t	ih_length[2];
59	uint8_t	ih_flags[2];
60	uint8_t	ih_transaction[2];
61	uint8_t	ih_sequence[2];
62};
63
64struct isns_tlv {
65	uint8_t	it_tag[4];
66	uint8_t	it_length[4];
67	uint8_t	it_value[];
68};
69
70struct isns_req {
71	u_int	ir_buflen;
72	u_int	ir_usedlen;
73	uint8_t	*ir_buf;
74};
75
76struct isns_req * isns_req_alloc(void);
77struct isns_req * isns_req_create(uint16_t func, uint16_t flags);
78void isns_req_free(struct isns_req *req);
79void isns_req_add(struct isns_req *req, uint32_t tag, uint32_t len,
80    const void *value);
81void isns_req_add_delim(struct isns_req *req);
82void isns_req_add_str(struct isns_req *req, uint32_t tag, const char *value);
83void isns_req_add_32(struct isns_req *req, uint32_t tag, uint32_t value);
84void isns_req_add_addr(struct isns_req *req, uint32_t tag, struct addrinfo *ai);
85void isns_req_add_port(struct isns_req *req, uint32_t tag, struct addrinfo *ai);
86int isns_req_send(int s, struct isns_req *req);
87int isns_req_receive(int s, struct isns_req *req);
88uint32_t isns_req_get_status(struct isns_req *req);
89
90#endif /* _ISNS_H */
91