1273635Smav/*-
2273635Smav * Copyright (c) 2014 Alexander Motin <mav@FreeBSD.org>
3273635Smav * All rights reserved.
4273635Smav *
5273635Smav * Redistribution and use in source and binary forms, with or without
6273635Smav * modification, are permitted provided that the following conditions
7273635Smav * are met:
8273635Smav * 1. Redistributions of source code must retain the above copyright
9273635Smav *    notice, this list of conditions and the following disclaimer.
10273635Smav * 2. Redistributions in binary form must reproduce the above copyright
11273635Smav *    notice, this list of conditions and the following disclaimer in the
12273635Smav *    documentation and/or other materials provided with the distribution.
13273635Smav *
14273635Smav * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15273635Smav * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16273635Smav * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17273635Smav * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18273635Smav * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19273635Smav * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20273635Smav * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21273635Smav * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22273635Smav * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23273635Smav * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24273635Smav * SUCH DAMAGE.
25273635Smav *
26273635Smav * $FreeBSD$
27273635Smav */
28273635Smav
29273635Smav#ifndef	_ISNS_H
30273635Smav#define	_ISNS_H
31273635Smav
32273635Smav#define	ISNS_VERSION		0x0001
33273635Smav
34273635Smav#define	ISNS_FUNC_DEVATTRREG	0x0001
35273635Smav#define	ISNS_FUNC_DEVATTRQRY	0x0002
36273635Smav#define	ISNS_FUNC_DEVGETNEXT	0x0003
37273635Smav#define	ISNS_FUNC_DEVDEREG	0x0004
38273635Smav#define	ISNS_FUNC_SCNREG	0x0005
39273635Smav#define	ISNS_FUNC_SCNDEREG	0x0006
40273635Smav#define	ISNS_FUNC_SCNEVENT	0x0007
41273635Smav#define	ISNS_FUNC_SCN		0x0008
42273635Smav#define	ISNS_FUNC_DDREG		0x0009
43273635Smav#define	ISNS_FUNC_DDDEREG	0x000a
44273635Smav#define	ISNS_FUNC_DDSREG	0x000b
45273635Smav#define	ISNS_FUNC_DDSDEREG	0x000c
46273635Smav#define	ISNS_FUNC_ESI		0x000d
47273635Smav#define	ISNS_FUNC_HEARTBEAT	0x000e
48273635Smav#define	ISNS_FUNC_RESPONSE	0x8000
49273635Smav
50273635Smav#define	ISNS_FLAG_CLIENT	0x8000
51273635Smav#define	ISNS_FLAG_SERVER	0x4000
52273635Smav#define	ISNS_FLAG_AUTH		0x2000
53273635Smav#define	ISNS_FLAG_REPLACE	0x1000
54273635Smav#define	ISNS_FLAG_LAST		0x0800
55273635Smav#define	ISNS_FLAG_FIRST		0x0400
56273635Smav
57273635Smavstruct isns_hdr {
58273635Smav	uint8_t	ih_version[2];
59273635Smav	uint8_t	ih_function[2];
60273635Smav	uint8_t	ih_length[2];
61273635Smav	uint8_t	ih_flags[2];
62273635Smav	uint8_t	ih_transaction[2];
63273635Smav	uint8_t	ih_sequence[2];
64273635Smav};
65273635Smav
66273635Smavstruct isns_tlv {
67273635Smav	uint8_t	it_tag[4];
68273635Smav	uint8_t	it_length[4];
69273635Smav	uint8_t	it_value[];
70273635Smav};
71273635Smav
72273635Smavstruct isns_req {
73273635Smav	u_int	ir_buflen;
74273635Smav	u_int	ir_usedlen;
75273635Smav	uint8_t	*ir_buf;
76273635Smav};
77273635Smav
78273635Smavstruct isns_req * isns_req_alloc(void);
79273635Smavstruct isns_req * isns_req_create(uint16_t func, uint16_t flags);
80273635Smavvoid isns_req_free(struct isns_req *req);
81273635Smavvoid isns_req_add(struct isns_req *req, uint32_t tag, uint32_t len,
82273635Smav    const void *value);
83273635Smavvoid isns_req_add_delim(struct isns_req *req);
84273635Smavvoid isns_req_add_str(struct isns_req *req, uint32_t tag, const char *value);
85273635Smavvoid isns_req_add_32(struct isns_req *req, uint32_t tag, uint32_t value);
86273635Smavvoid isns_req_add_addr(struct isns_req *req, uint32_t tag, struct addrinfo *ai);
87273635Smavvoid isns_req_add_port(struct isns_req *req, uint32_t tag, struct addrinfo *ai);
88273635Smavint isns_req_send(int s, struct isns_req *req);
89273635Smavint isns_req_receive(int s, struct isns_req *req);
90273635Smavuint32_t isns_req_get_status(struct isns_req *req);
91273635Smav
92273635Smav#endif /* _ISNS_H */
93