1 /* $NetBSD: iscsic_globals.h,v 1.6 2020/04/03 18:39:15 joerg Exp $ */ 2 3 /*- 4 * Copyright (c) 2005,2006,2011 The NetBSD Foundation, Inc. 5 * All rights reserved. 6 * 7 * This code is derived from software contributed to The NetBSD Foundation 8 * by Wasabi Systems, Inc. 9 * 10 * Redistribution and use in source and binary forms, with or without 11 * modification, are permitted provided that the following conditions 12 * are met: 13 * 1. Redistributions of source code must retain the above copyright 14 * notice, this list of conditions and the following disclaimer. 15 * 2. Redistributions in binary form must reproduce the above copyright 16 * notice, this list of conditions and the following disclaimer in the 17 * documentation and/or other materials provided with the distribution. 18 * 19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 29 * POSSIBILITY OF SUCH DAMAGE. 30 */ 31 32 33 #ifndef _ISCSIC_GLOBALS_H 34 #define _ISCSIC_GLOBALS_H 35 36 #include <sys/types.h> 37 38 #include <stdio.h> 39 #include <stdlib.h> 40 #include <string.h> 41 #include <unistd.h> 42 #include <sys/scsiio.h> 43 44 /* iSCSI daemon ioctl interface */ 45 #include <iscsid.h> 46 47 #include <iscsi_ioctl.h> 48 49 /* ------------------------- Global Constants ----------------------------- */ 50 51 /* Version information */ 52 53 #define VERSION_MAJOR 3 54 #define VERSION_MINOR 1 55 #define VERSION_STRING "NetBSD iSCSI Software Initiator CLI 20110407 " 56 57 58 #define TRUE 1 59 #define FALSE 0 60 61 #define BUF_SIZE 8192 62 63 /* --------------------------- Global Types ------------------------------- */ 64 65 typedef int (*cmdproc_t) (int, char **); 66 67 typedef struct { 68 const char *cmd; 69 cmdproc_t proc; 70 } command_t; 71 72 73 /* ------------------------- Global Variables ----------------------------- */ 74 75 extern int driver; /* handle to driver (for ioctls) */ 76 extern uint8_t buf[BUF_SIZE]; /* buffer for daemon comm and driver I/O */ 77 78 /* ------------------------- Global Functions ----------------------------- */ 79 80 #define min(a,b) ((a < b) ? a : b) 81 82 #define STATIC static 83 84 /* 85 * Convert uint64 to 6-byte string in network byte order (for ISID field) 86 */ 87 static __inline void 88 hton6(uint8_t * d, uint64_t x) 89 { 90 #if BYTE_ORDER == LITTLE_ENDIAN 91 uint8_t *s = ((uint8_t *)(void *)&x) + 5; 92 *d++ = *s--; 93 *d++ = *s--; 94 *d++ = *s--; 95 *d++ = *s--; 96 *d++ = *s--; 97 *d = *s; 98 #else 99 memcpy(d, &((uint8_t *)&x)[2], 6); 100 #endif 101 } 102 103 /* 104 * Convert uint64 from network byte order (for LUN field) 105 */ 106 static __inline uint64_t 107 ntohq(uint64_t x) 108 { 109 #if BYTE_ORDER == LITTLE_ENDIAN 110 uint8_t *s = (uint8_t *)(void *)&x; 111 112 return (uint64_t) ((uint64_t) s[0] << 56 | (uint64_t) s[1] << 48 | 113 (uint64_t) s[2] << 40 | (uint64_t) s[3] << 32 | 114 (uint64_t) s[4] << 24 | (uint64_t) s[5] << 16 | 115 (uint64_t) s[6] << 8 | (uint64_t) s[7]); 116 #else 117 return x; 118 #endif 119 } 120 121 #define htonq(x) ntohq(x) 122 123 124 /* we usually have to get the id out of a message */ 125 #define GET_SYM_ID(x, y) do { \ 126 iscsid_sym_id_t *__param; \ 127 __param = (iscsid_sym_id_t *)(void *)(y); \ 128 (void) memcpy(&x, &__param->id, sizeof(x)); \ 129 } while (/*CONSTCOND*/0) 130 131 132 /* Check whether ID is present */ 133 #define NO_ID(sid) (!(sid)->id && !(sid)->name[0]) 134 135 /* iscsic_main.c */ 136 137 void arg_error(char *, const char *, ...) __printflike(2, 3) __dead; 138 void arg_missing(const char *) __dead; 139 void io_error(const char *, ...) __printflike(1, 2) __dead; 140 void gen_error(const char *, ...) __printflike(1, 2) __dead; 141 void check_extra_args(int, char **); 142 void status_error(unsigned) __dead; 143 void status_error_slist(unsigned) __dead; 144 145 void send_request(unsigned, size_t, void *); 146 iscsid_response_t *get_response(int); 147 void free_response(iscsid_response_t *); 148 149 /* iscsic_daemonif.c */ 150 151 int add_target(int, char **); 152 int add_portal(int, char **); 153 int remove_target(int, char **); 154 int slp_find_targets(int, char **); 155 int refresh_targets(int, char **); 156 int list_targets(int, char **); 157 int add_send_target(int, char **); 158 int remove_send_target(int, char **); 159 int list_send_targets(int, char **); 160 int add_isns_server(int, char **); 161 int remove_isns_server(int, char **); 162 int find_isns_servers(int, char **); 163 int list_isns_servers(int, char **); 164 int refresh_isns(int, char **); 165 int login(int, char **); 166 int logout(int, char **); 167 int add_connection(int, char **); 168 int remove_connection(int, char **); 169 int add_initiator(int, char **); 170 int remove_initiator(int, char **); 171 int list_initiators(int, char **); 172 int list_sessions(int, char **); 173 int get_version(int, char **); 174 175 /* iscsic_driverif.c */ 176 177 uint32_t get_sessid(int, char **, int); 178 void dump_data(const char *, const void *, size_t); 179 int do_ioctl(iscsi_iocommand_parameters_t *, int); 180 int set_node_name(int, char **); 181 int inquiry(int, char **); 182 int test_unit_ready(int, char **); 183 int read_capacity(int, char **); 184 int report_luns(int, char **); 185 186 /* iscsic_parse.c */ 187 188 int cl_get_target(iscsid_add_target_req_t **, int, char **, int); 189 int cl_get_portal(iscsid_add_portal_req_t *, int, char **); 190 int cl_get_isns(iscsid_add_isns_server_req_t *, int, char **); 191 int cl_get_send_targets(iscsid_add_target_req_t *, int, char **); 192 int cl_get_auth_opts(iscsid_set_target_authentication_req_t *, int, char **); 193 int cl_get_target_opts(iscsid_get_set_target_options_t *, int, char **); 194 int cl_get_id(char, iscsid_sym_id_t *, int, char **); 195 int cl_get_symname(uint8_t *, int, char **); 196 int cl_get_string(char, char *, int, char **); 197 int cl_get_opt(char, int, char **); 198 char cl_get_char(char, int, char **); 199 int cl_get_int(char, int, char **); 200 int cl_get_uint(char, int, char **); 201 uint64_t cl_get_longlong(char, int, char **); 202 203 #endif /* !_ISCSIC_GLOBALS_H */ 204