134e8d664SJohn Baldwin /*- 234e8d664SJohn Baldwin * Copyright (c) 2014 Alexander Motin <mav@FreeBSD.org> 334e8d664SJohn Baldwin * All rights reserved. 434e8d664SJohn Baldwin * 534e8d664SJohn Baldwin * Redistribution and use in source and binary forms, with or without 634e8d664SJohn Baldwin * modification, are permitted provided that the following conditions 734e8d664SJohn Baldwin * are met: 834e8d664SJohn Baldwin * 1. Redistributions of source code must retain the above copyright 934e8d664SJohn Baldwin * notice, this list of conditions and the following disclaimer. 1034e8d664SJohn Baldwin * 2. Redistributions in binary form must reproduce the above copyright 1134e8d664SJohn Baldwin * notice, this list of conditions and the following disclaimer in the 1234e8d664SJohn Baldwin * documentation and/or other materials provided with the distribution. 1334e8d664SJohn Baldwin * 1434e8d664SJohn Baldwin * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1534e8d664SJohn Baldwin * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1634e8d664SJohn Baldwin * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1734e8d664SJohn Baldwin * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 1834e8d664SJohn Baldwin * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 1934e8d664SJohn Baldwin * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2034e8d664SJohn Baldwin * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2134e8d664SJohn Baldwin * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2234e8d664SJohn Baldwin * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2334e8d664SJohn Baldwin * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2434e8d664SJohn Baldwin * SUCH DAMAGE. 2534e8d664SJohn Baldwin */ 2634e8d664SJohn Baldwin 2734e8d664SJohn Baldwin #ifndef __ISNS_HH__ 2834e8d664SJohn Baldwin #define __ISNS_HH__ 2934e8d664SJohn Baldwin 301ee9931dSJohn Baldwin #include <vector> 311ee9931dSJohn Baldwin 3234e8d664SJohn Baldwin #define ISNS_VERSION 0x0001 3334e8d664SJohn Baldwin 3434e8d664SJohn Baldwin #define ISNS_FUNC_DEVATTRREG 0x0001 3534e8d664SJohn Baldwin #define ISNS_FUNC_DEVATTRQRY 0x0002 3634e8d664SJohn Baldwin #define ISNS_FUNC_DEVGETNEXT 0x0003 3734e8d664SJohn Baldwin #define ISNS_FUNC_DEVDEREG 0x0004 3834e8d664SJohn Baldwin #define ISNS_FUNC_SCNREG 0x0005 3934e8d664SJohn Baldwin #define ISNS_FUNC_SCNDEREG 0x0006 4034e8d664SJohn Baldwin #define ISNS_FUNC_SCNEVENT 0x0007 4134e8d664SJohn Baldwin #define ISNS_FUNC_SCN 0x0008 4234e8d664SJohn Baldwin #define ISNS_FUNC_DDREG 0x0009 4334e8d664SJohn Baldwin #define ISNS_FUNC_DDDEREG 0x000a 4434e8d664SJohn Baldwin #define ISNS_FUNC_DDSREG 0x000b 4534e8d664SJohn Baldwin #define ISNS_FUNC_DDSDEREG 0x000c 4634e8d664SJohn Baldwin #define ISNS_FUNC_ESI 0x000d 4734e8d664SJohn Baldwin #define ISNS_FUNC_HEARTBEAT 0x000e 4834e8d664SJohn Baldwin #define ISNS_FUNC_RESPONSE 0x8000 4934e8d664SJohn Baldwin 5034e8d664SJohn Baldwin #define ISNS_FLAG_CLIENT 0x8000 5134e8d664SJohn Baldwin #define ISNS_FLAG_SERVER 0x4000 5234e8d664SJohn Baldwin #define ISNS_FLAG_AUTH 0x2000 5334e8d664SJohn Baldwin #define ISNS_FLAG_REPLACE 0x1000 5434e8d664SJohn Baldwin #define ISNS_FLAG_LAST 0x0800 5534e8d664SJohn Baldwin #define ISNS_FLAG_FIRST 0x0400 5634e8d664SJohn Baldwin 5734e8d664SJohn Baldwin struct isns_hdr { 5834e8d664SJohn Baldwin uint8_t ih_version[2]; 5934e8d664SJohn Baldwin uint8_t ih_function[2]; 6034e8d664SJohn Baldwin uint8_t ih_length[2]; 6134e8d664SJohn Baldwin uint8_t ih_flags[2]; 6234e8d664SJohn Baldwin uint8_t ih_transaction[2]; 6334e8d664SJohn Baldwin uint8_t ih_sequence[2]; 6434e8d664SJohn Baldwin }; 6534e8d664SJohn Baldwin 6634e8d664SJohn Baldwin struct isns_tlv { 6734e8d664SJohn Baldwin uint8_t it_tag[4]; 6834e8d664SJohn Baldwin uint8_t it_length[4]; 6934e8d664SJohn Baldwin uint8_t it_value[]; 7034e8d664SJohn Baldwin }; 7134e8d664SJohn Baldwin 7234e8d664SJohn Baldwin struct isns_req { isns_reqisns_req731ee9931dSJohn Baldwin isns_req() {} 74*0aa09b7aSJohn Baldwin isns_req(uint16_t func, uint16_t flags, const char *descr); 75*0aa09b7aSJohn Baldwin descrisns_req76*0aa09b7aSJohn Baldwin const char *descr() const { return ir_descr; } 7734e8d664SJohn Baldwin 781ee9931dSJohn Baldwin void add(uint32_t tag, uint32_t len, const void *value); 791ee9931dSJohn Baldwin void add_delim(); 801ee9931dSJohn Baldwin void add_str(uint32_t tag, const char *value); 811ee9931dSJohn Baldwin void add_32(uint32_t tag, uint32_t value); 821ee9931dSJohn Baldwin void add_addr(uint32_t tag, const struct addrinfo *ai); 831ee9931dSJohn Baldwin void add_port(uint32_t tag, const struct addrinfo *ai); 841ee9931dSJohn Baldwin bool send(int s); 851ee9931dSJohn Baldwin bool receive(int s); 861ee9931dSJohn Baldwin uint32_t get_status(); 871ee9931dSJohn Baldwin private: 881ee9931dSJohn Baldwin void getspace(uint32_t len); 891ee9931dSJohn Baldwin void append(const void *buf, size_t len); 901ee9931dSJohn Baldwin 911ee9931dSJohn Baldwin std::vector<char> ir_buf; 92*0aa09b7aSJohn Baldwin const char *ir_descr; 931ee9931dSJohn Baldwin }; 9434e8d664SJohn Baldwin 9534e8d664SJohn Baldwin #endif /* __ISNS_HH__ */ 96