summaryrefslogtreecommitdiff
path: root/external/bsd/iscsi/dist/include/parameters.h
blob: c3e8e1e87bfb54be023469c592194ed3007d597c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
/*
 * IMPORTANT:  READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 
 * By downloading, copying, installing or using the software you agree
 * to this license.  If you do not agree to this license, do not
 * download, install, copy or use the software.
 *
 * Intel License Agreement
 *
 * Copyright (c) 2000, Intel Corporation
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * -Redistributions of source code must retain the above copyright
 *  notice, this list of conditions and the following disclaimer.
 *
 * -Redistributions in binary form must reproduce the above copyright
 *  notice, this list of conditions and the following disclaimer in the
 *  documentation and/or other materials provided with the
 *  distribution.
 *
 * -The name of Intel Corporation may not be used to endorse or
 *  promote products derived from this software without specific prior
 *  written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL INTEL
 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 */
#ifndef _PARAMETERS_H_
#define _PARAMETERS_H_

typedef struct MD5Context MD5Context_t;


#define ISCSI_PARAM_MAX_LEN 256
#define ISCSI_PARAM_KEY_LEN 64

/* Parameter Type */

#define ISCSI_PARAM_TYPE_DECLARATIVE    1
#define ISCSI_PARAM_TYPE_DECLARE_MULTI  2	/* for TargetName and
						 * TargetAddress */
#define ISCSI_PARAM_TYPE_NUMERICAL      3
#define ISCSI_PARAM_TYPE_NUMERICAL_Z    4	/* zero represents no limit */
#define ISCSI_PARAM_TYPE_BINARY_OR      5
#define ISCSI_PARAM_TYPE_BINARY_AND     6
#define ISCSI_PARAM_TYPE_LIST           7

#define ISCSI_CHAP_DATA_LENGTH          16
#define ISCSI_CHAP_STRING_LENGTH        256

#define ISCSI_PARAM_STATUS_AUTH_FAILED	-2
#define ISCSI_PARAM_STATUS_FAILED	-1

/* types of authentication which the initiator can select */
enum {
	AuthNone,
	AuthCHAP,
	AuthKerberos,
	AuthSRP
};

/* types of digest which the initiator can select */
enum {
	DigestNone	= 0x0,
	DigestHeader	= 0x01,
	DigestData	= 0x02
	/* these are bit masks, extend accordingly */
};

typedef struct iscsi_parameter_item_t {
	char				 value[ISCSI_PARAM_MAX_LEN];
	struct iscsi_parameter_item_t	*next;
} iscsi_parameter_value_t;

/* this struct defines the credentials a user has */
typedef struct iscsi_cred_t {
	char		*user;		/* user's name */
	char		*auth_type;	/* preferred authentication type */
	char		*shared_secret;	/* the shared secret */
} iscsi_cred_t;

/*
 * Structure for storing negotiated parameters that are frequently accessed
 * on an active session
 */
typedef struct iscsi_sess_param_t {
	uint32_t        max_burst_length;
	uint32_t        first_burst_length;
	uint32_t        max_dataseg_len;
	iscsi_cred_t	cred;
	uint8_t         initial_r2t;
	uint8_t         immediate_data;
	uint8_t		header_digest;
	uint8_t		data_digest;
	uint8_t		auth_type;
	uint8_t		mutual_auth;
	uint8_t		digest_wanted;
} iscsi_sess_param_t;

typedef struct iscsi_parameter_t {
	char            key[ISCSI_PARAM_KEY_LEN];	/* key */
	int             type;	/* type of parameter */
	char            valid[ISCSI_PARAM_MAX_LEN];	/* list of valid values */
	char            dflt[ISCSI_PARAM_MAX_LEN];	/* default value */
	iscsi_parameter_value_t *value_l;	/* value list */
	char            offer_rx[ISCSI_PARAM_MAX_LEN];	/* outgoing offer */
	char            offer_tx[ISCSI_PARAM_MAX_LEN];	/* incoming offer */
	char            answer_tx[ISCSI_PARAM_MAX_LEN];	/* outgoing answer */
	char            answer_rx[ISCSI_PARAM_MAX_LEN];	/* incoming answer */
	char            negotiated[ISCSI_PARAM_MAX_LEN];	/* negotiated value */
	int             tx_offer;	/* sent offer  */
	int             rx_offer;	/* received offer  */
	int             tx_answer;	/* sent answer */
	int             rx_answer;	/* received answer */
	int             reset;	/* reset value_l */
	struct iscsi_parameter_t *next;
} iscsi_parameter_t;

int             param_list_add(iscsi_parameter_t ** , int , const char *, const char *, const char *);
int             param_list_print(iscsi_parameter_t * );
int             param_list_destroy(iscsi_parameter_t * );
int             param_text_add(iscsi_parameter_t *, const char *, const char *, char *, int *, int, int );
int             param_text_parse(iscsi_parameter_t *, iscsi_cred_t *, char *, int , char *, int *, int, int);
int             param_text_print(char *, uint32_t );
int             param_num_vals(iscsi_parameter_t * , char *);
int             param_val_reset(iscsi_parameter_t * , const char *);
char           *param_val(iscsi_parameter_t * , const char *);
char           *param_val_which(iscsi_parameter_t * , const char *, int );
char           *param_offer(iscsi_parameter_t * , char *);
char           *param_answer(iscsi_parameter_t * , char *);
iscsi_parameter_t *param_get(iscsi_parameter_t * , const char *);
int		driver_atoi(const char *);
int             param_atoi(iscsi_parameter_t * , const char *);
int             param_equiv(iscsi_parameter_t * , const char *, const char *);
int             param_commit(iscsi_parameter_t * );
void            set_session_parameters(iscsi_parameter_t * , iscsi_sess_param_t * );

/*
 * Macros
 */

#define PARAM_LIST_DESTROY(LIST, ELSE)                    \
if (param_list_destroy(LIST)!=0) {                             \
  iscsi_err(__FILE__, __LINE__, "param_list_destroy() failed\n");                \
  ELSE;                                                        \
}

#define PARAM_LIST_ADD(LIST, TYPE, KEY, DFLT, VALID, ELSE)   \
if (param_list_add(LIST, TYPE, KEY, DFLT, VALID)!=0) {            \
  iscsi_err(__FILE__, __LINE__, "param_list_add() failed\n");                       \
  ELSE;                                                           \
}

#define PARAM_TEXT_ADD(LIST, KEY, VAL, TEXT, LEN, SIZE, OFFER, ELSE )  \
if (param_text_add(LIST, KEY, VAL, TEXT, LEN, SIZE, OFFER)!=0) {            \
  iscsi_err(__FILE__, __LINE__, "param_text_add() failed\n");                           \
  ELSE;                                                               \
}

#define PARAM_TEXT_PARSE(LIST, CRED, TEXT, LEN, TEXT_OUT, LEN_OUT, SIZE, OFFER, ELSE )   \
if (param_text_parse(LIST, CRED, TEXT, LEN, TEXT_OUT, LEN_OUT, SIZE, OFFER)!=0) {             \
  iscsi_err(__FILE__, __LINE__, "param_text_parse_offer() failed\n");                               \
  ELSE;                                                                           \
}
#endif