Home | History | Annotate | Line # | Download | only in iscsictl
iscsic_globals.h revision 1.3
      1 /*	$NetBSD: iscsic_globals.h,v 1.3 2011/10/30 18:40:06 christos 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 int driver;						/* handle to driver (for ioctls) */
     76 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 /* Debugging stuff */
     83 
     84 #ifdef ISCSI_DEBUG
     85 
     86 int debug_level;				/* How much info to display */
     87 
     88 #define DEBOUT(x) printf x
     89 #define DEB(lev,x) {if (debug_level >= lev) printf x ;}
     90 
     91 #define STATIC static
     92 
     93 #else
     94 
     95 #define DEBOUT(x)
     96 #define DEB(lev,x)
     97 
     98 #define STATIC static
     99 
    100 #endif
    101 
    102 /*
    103  * Convert uint64 to 6-byte string in network byte order (for ISID field)
    104 */
    105 static __inline void
    106 hton6(uint8_t * d, uint64_t x)
    107 {
    108 #if BYTE_ORDER == LITTLE_ENDIAN
    109 	uint8_t *s = ((uint8_t *)(void *)&x) + 5;
    110 	*d++ = *s--;
    111 	*d++ = *s--;
    112 	*d++ = *s--;
    113 	*d++ = *s--;
    114 	*d++ = *s--;
    115 	*d = *s;
    116 #else
    117 	memcpy(d, &((uint8_t *)&x)[2], 6);
    118 #endif
    119 }
    120 
    121 /*
    122  * Convert uint64 from network byte order (for LUN field)
    123 */
    124 static __inline uint64_t
    125 ntohq(uint64_t x)
    126 {
    127 #if BYTE_ORDER == LITTLE_ENDIAN
    128 	uint8_t *s = (uint8_t *)(void *)&x;
    129 
    130 	return (uint64_t) ((uint64_t) s[0] << 56 | (uint64_t) s[1] << 48 |
    131 			(uint64_t) s[2] << 40 | (uint64_t) s[3] << 32 |
    132 			(uint64_t) s[4] << 24 | (uint64_t) s[5] << 16 |
    133 			(uint64_t) s[6] <<  8 | (uint64_t) s[7]);
    134 #else
    135 	return x;
    136 #endif
    137 }
    138 
    139 #define htonq(x)  ntohq(x)
    140 
    141 
    142 /* we usually have to get the id out of a message */
    143 #define GET_SYM_ID(x, y)	do {					\
    144 	iscsid_sym_id_t	*__param;					\
    145 	__param = (iscsid_sym_id_t *)(void *)(y);			\
    146 	(void) memcpy(&x, &__param->id, sizeof(x));			\
    147 } while (/*CONSTCOND*/0)
    148 
    149 
    150 /* Check whether ID is present */
    151 #define NO_ID(sid) (!(sid)->id && !(sid)->name[0])
    152 
    153 /* iscsic_main.c */
    154 
    155 void arg_error(char *, const char *, ...) __printflike(2, 3);
    156 void arg_missing(const char *);
    157 void io_error(const char *, ...) __printflike(1, 2);
    158 void gen_error(const char *, ...) __printflike(1, 2);
    159 void check_extra_args(int, char **);
    160 void status_error(unsigned);
    161 void status_error_slist(unsigned);
    162 
    163 void send_request(unsigned, size_t, void *);
    164 iscsid_response_t *get_response(int);
    165 void free_response(iscsid_response_t *);
    166 
    167 /* iscsic_daemonif.c */
    168 
    169 int add_target(int, char **);
    170 int add_portal(int, char **);
    171 int remove_target(int, char **);
    172 int slp_find_targets(int, char **);
    173 int refresh_targets(int, char **);
    174 int list_targets(int, char **);
    175 int add_send_target(int, char **);
    176 int remove_send_target(int, char **);
    177 int list_send_targets(int, char **);
    178 int add_isns_server(int, char **);
    179 int remove_isns_server(int, char **);
    180 int find_isns_servers(int, char **);
    181 int list_isns_servers(int, char **);
    182 int refresh_isns(int, char **);
    183 int login(int, char **);
    184 int logout(int, char **);
    185 int add_connection(int, char **);
    186 int remove_connection(int, char **);
    187 int add_initiator(int, char **);
    188 int remove_initiator(int, char **);
    189 int list_initiators(int, char **);
    190 int list_sessions(int, char **);
    191 int get_version(int, char **);
    192 #ifdef ISCSI_DEBUG
    193 int kill_daemon(int, char **);
    194 #endif
    195 
    196 /* iscsic_driverif.c */
    197 
    198 uint32_t get_sessid(int, char **, int);
    199 void dump_data(const char *, const void *, size_t);
    200 int do_ioctl(iscsi_iocommand_parameters_t *, int);
    201 int set_node_name(int, char **);
    202 int inquiry(int, char **);
    203 int test_unit_ready(int, char **);
    204 int read_capacity(int, char **);
    205 int report_luns(int, char **);
    206 
    207 /* iscsic_parse.c */
    208 
    209 int cl_get_target(iscsid_add_target_req_t **, int, char **, int);
    210 int cl_get_portal(iscsid_add_portal_req_t *, int, char **);
    211 int cl_get_isns(iscsid_add_isns_server_req_t *, int, char **);
    212 int cl_get_send_targets(iscsid_add_target_req_t *, int, char **);
    213 int cl_get_auth_opts(iscsid_set_target_authentication_req_t *, int, char **);
    214 int cl_get_target_opts(iscsid_get_set_target_options_t *, int, char **);
    215 int cl_get_id(char, iscsid_sym_id_t *, int, char **);
    216 int cl_get_symname(uint8_t *, int, char **);
    217 int cl_get_string(char, char *, int, char **);
    218 int cl_get_opt(char, int, char **);
    219 char cl_get_char(char, int, char **);
    220 int cl_get_int(char, int, char **);
    221 int cl_get_uint(char, int, char **);
    222 uint64_t cl_get_longlong(char, int, char **);
    223 
    224 #ifdef ISCSI_TEST_MODE
    225 int test(int, char **);
    226 #endif
    227 
    228 
    229 #endif /* !_ISCSIC_GLOBALS_H */
    230