1 /* 2 * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 3 * By downloading, copying, installing or using the software you agree 4 * to this license. If you do not agree to this license, do not 5 * download, install, copy or use the software. 6 * 7 * Intel License Agreement 8 * 9 * Copyright (c) 2000, Intel Corporation 10 * All rights reserved. 11 * 12 * Redistribution and use in source and binary forms, with or without 13 * modification, are permitted provided that the following conditions 14 * are met: 15 * 16 * -Redistributions of source code must retain the above copyright 17 * notice, this list of conditions and the following disclaimer. 18 * 19 * -Redistributions in binary form must reproduce the above copyright 20 * notice, this list of conditions and the following disclaimer in the 21 * documentation and/or other materials provided with the 22 * distribution. 23 * 24 * -The name of Intel Corporation may not be used to endorse or 25 * promote products derived from this software without specific prior 26 * written permission. 27 * 28 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 31 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL 32 * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 35 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 36 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 37 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 38 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39 * SUCH DAMAGE. 40 */ 41 #ifndef _PARAMETERS_H_ 42 #define _PARAMETERS_H_ 43 44 typedef struct MD5Context MD5Context_t; 45 46 47 #define ISCSI_PARAM_MAX_LEN 256 48 #define ISCSI_PARAM_KEY_LEN 64 49 50 /* Parameter Type */ 51 52 #define ISCSI_PARAM_TYPE_DECLARATIVE 1 53 #define ISCSI_PARAM_TYPE_DECLARE_MULTI 2 /* for TargetName and 54 * TargetAddress */ 55 #define ISCSI_PARAM_TYPE_NUMERICAL 3 56 #define ISCSI_PARAM_TYPE_NUMERICAL_Z 4 /* zero represents no limit */ 57 #define ISCSI_PARAM_TYPE_BINARY_OR 5 58 #define ISCSI_PARAM_TYPE_BINARY_AND 6 59 #define ISCSI_PARAM_TYPE_LIST 7 60 61 #define ISCSI_CHAP_DATA_LENGTH 16 62 #define ISCSI_CHAP_STRING_LENGTH 256 63 64 #define ISCSI_PARAM_STATUS_AUTH_FAILED -2 65 #define ISCSI_PARAM_STATUS_FAILED -1 66 67 /* types of authentication which the initiator can select */ 68 enum { 69 AuthNone, 70 AuthCHAP, 71 AuthKerberos, 72 AuthSRP 73 }; 74 75 /* types of digest which the initiator can select */ 76 enum { 77 DigestNone = 0x0, 78 DigestHeader = 0x01, 79 DigestData = 0x02 80 /* these are bit masks, extend accordingly */ 81 }; 82 83 typedef struct iscsi_parameter_item_t { 84 char value[ISCSI_PARAM_MAX_LEN]; 85 struct iscsi_parameter_item_t *next; 86 } iscsi_parameter_value_t; 87 88 /* this struct defines the credentials a user has */ 89 typedef struct iscsi_cred_t { 90 char *user; /* user's name */ 91 char *auth_type; /* preferred authentication type */ 92 char *shared_secret; /* the shared secret */ 93 } iscsi_cred_t; 94 95 /* 96 * Structure for storing negotiated parameters that are frequently accessed 97 * on an active session 98 */ 99 typedef struct iscsi_sess_param_t { 100 uint32_t max_burst_length; 101 uint32_t first_burst_length; 102 uint32_t max_dataseg_len; 103 iscsi_cred_t cred; 104 uint8_t initial_r2t; 105 uint8_t immediate_data; 106 uint8_t header_digest; 107 uint8_t data_digest; 108 uint8_t auth_type; 109 uint8_t mutual_auth; 110 uint8_t digest_wanted; 111 } iscsi_sess_param_t; 112 113 typedef struct iscsi_parameter_t { 114 char key[ISCSI_PARAM_KEY_LEN]; /* key */ 115 int type; /* type of parameter */ 116 char valid[ISCSI_PARAM_MAX_LEN]; /* list of valid values */ 117 char dflt[ISCSI_PARAM_MAX_LEN]; /* default value */ 118 iscsi_parameter_value_t *value_l; /* value list */ 119 char offer_rx[ISCSI_PARAM_MAX_LEN]; /* outgoing offer */ 120 char offer_tx[ISCSI_PARAM_MAX_LEN]; /* incoming offer */ 121 char answer_tx[ISCSI_PARAM_MAX_LEN]; /* outgoing answer */ 122 char answer_rx[ISCSI_PARAM_MAX_LEN]; /* incoming answer */ 123 char negotiated[ISCSI_PARAM_MAX_LEN]; /* negotiated value */ 124 int tx_offer; /* sent offer */ 125 int rx_offer; /* received offer */ 126 int tx_answer; /* sent answer */ 127 int rx_answer; /* received answer */ 128 int reset; /* reset value_l */ 129 struct iscsi_parameter_t *next; 130 } iscsi_parameter_t; 131 132 int param_list_add(iscsi_parameter_t ** , int , const char *, const char *, const char *); 133 int param_list_print(iscsi_parameter_t * ); 134 int param_list_destroy(iscsi_parameter_t * ); 135 int param_text_add(iscsi_parameter_t *, const char *, const char *, char *, int *, int, int ); 136 int param_text_parse(iscsi_parameter_t *, iscsi_cred_t *, char *, int , char *, int *, int, int); 137 int param_text_print(char *, uint32_t ); 138 int param_num_vals(iscsi_parameter_t * , char *); 139 int param_val_reset(iscsi_parameter_t * , const char *); 140 char *param_val(iscsi_parameter_t * , const char *); 141 char *param_val_which(iscsi_parameter_t * , const char *, int ); 142 char *param_offer(iscsi_parameter_t * , char *); 143 char *param_answer(iscsi_parameter_t * , char *); 144 iscsi_parameter_t *param_get(iscsi_parameter_t * , const char *); 145 int driver_atoi(const char *); 146 int param_atoi(iscsi_parameter_t * , const char *); 147 int param_equiv(iscsi_parameter_t * , const char *, const char *); 148 int param_commit(iscsi_parameter_t * ); 149 void set_session_parameters(iscsi_parameter_t * , iscsi_sess_param_t * ); 150 151 /* 152 * Macros 153 */ 154 155 #define PARAM_LIST_DESTROY(LIST, ELSE) \ 156 if (param_list_destroy(LIST)!=0) { \ 157 iscsi_err(__FILE__, __LINE__, "param_list_destroy() failed\n"); \ 158 ELSE; \ 159 } 160 161 #define PARAM_LIST_ADD(LIST, TYPE, KEY, DFLT, VALID, ELSE) \ 162 if (param_list_add(LIST, TYPE, KEY, DFLT, VALID)!=0) { \ 163 iscsi_err(__FILE__, __LINE__, "param_list_add() failed\n"); \ 164 ELSE; \ 165 } 166 167 #define PARAM_TEXT_ADD(LIST, KEY, VAL, TEXT, LEN, SIZE, OFFER, ELSE ) \ 168 if (param_text_add(LIST, KEY, VAL, TEXT, LEN, SIZE, OFFER)!=0) { \ 169 iscsi_err(__FILE__, __LINE__, "param_text_add() failed\n"); \ 170 ELSE; \ 171 } 172 173 #define PARAM_TEXT_PARSE(LIST, CRED, TEXT, LEN, TEXT_OUT, LEN_OUT, SIZE, OFFER, ELSE ) \ 174 if (param_text_parse(LIST, CRED, TEXT, LEN, TEXT_OUT, LEN_OUT, SIZE, OFFER)!=0) { \ 175 iscsi_err(__FILE__, __LINE__, "param_text_parse_offer() failed\n"); \ 176 ELSE; \ 177 } 178 #endif 179