12f245829Sagc /* 2b6364952Sagc * IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 3b6364952Sagc * By downloading, copying, installing or using the software you agree 4b6364952Sagc * to this license. If you do not agree to this license, do not 5b6364952Sagc * download, install, copy or use the software. 62f245829Sagc * 72f245829Sagc * Intel License Agreement 82f245829Sagc * 92f245829Sagc * Copyright (c) 2000, Intel Corporation 102f245829Sagc * All rights reserved. 112f245829Sagc * 12b6364952Sagc * Redistribution and use in source and binary forms, with or without 13b6364952Sagc * modification, are permitted provided that the following conditions 14b6364952Sagc * are met: 152f245829Sagc * 16b6364952Sagc * -Redistributions of source code must retain the above copyright 17b6364952Sagc * notice, this list of conditions and the following disclaimer. 182f245829Sagc * 19b6364952Sagc * -Redistributions in binary form must reproduce the above copyright 20b6364952Sagc * notice, this list of conditions and the following disclaimer in the 21b6364952Sagc * documentation and/or other materials provided with the 22b6364952Sagc * distribution. 232f245829Sagc * 24b6364952Sagc * -The name of Intel Corporation may not be used to endorse or 25b6364952Sagc * promote products derived from this software without specific prior 26b6364952Sagc * written permission. 272f245829Sagc * 28b6364952Sagc * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 29b6364952Sagc * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 30b6364952Sagc * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 31b6364952Sagc * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL INTEL 32b6364952Sagc * OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 33b6364952Sagc * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 34b6364952Sagc * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 35b6364952Sagc * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 36b6364952Sagc * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 37b6364952Sagc * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT 38b6364952Sagc * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 39b6364952Sagc * SUCH DAMAGE. 402f245829Sagc */ 412f245829Sagc #ifndef _PARAMETERS_H_ 422f245829Sagc #define _PARAMETERS_H_ 432f245829Sagc 442f245829Sagc typedef struct MD5Context MD5Context_t; 452f245829Sagc 462f245829Sagc 472f245829Sagc #define ISCSI_PARAM_MAX_LEN 256 482f245829Sagc #define ISCSI_PARAM_KEY_LEN 64 492f245829Sagc 502f245829Sagc /* Parameter Type */ 512f245829Sagc 522f245829Sagc #define ISCSI_PARAM_TYPE_DECLARATIVE 1 532f245829Sagc #define ISCSI_PARAM_TYPE_DECLARE_MULTI 2 /* for TargetName and 542f245829Sagc * TargetAddress */ 552f245829Sagc #define ISCSI_PARAM_TYPE_NUMERICAL 3 562f245829Sagc #define ISCSI_PARAM_TYPE_NUMERICAL_Z 4 /* zero represents no limit */ 572f245829Sagc #define ISCSI_PARAM_TYPE_BINARY_OR 5 582f245829Sagc #define ISCSI_PARAM_TYPE_BINARY_AND 6 592f245829Sagc #define ISCSI_PARAM_TYPE_LIST 7 602f245829Sagc 612f245829Sagc #define ISCSI_CHAP_DATA_LENGTH 16 622f245829Sagc #define ISCSI_CHAP_STRING_LENGTH 256 632f245829Sagc 642f245829Sagc #define ISCSI_PARAM_STATUS_AUTH_FAILED -2 652f245829Sagc #define ISCSI_PARAM_STATUS_FAILED -1 662f245829Sagc 672f245829Sagc /* types of authentication which the initiator can select */ 682f245829Sagc enum { 692f245829Sagc AuthNone, 702f245829Sagc AuthCHAP, 712f245829Sagc AuthKerberos, 722f245829Sagc AuthSRP 732f245829Sagc }; 742f245829Sagc 752f245829Sagc /* types of digest which the initiator can select */ 762f245829Sagc enum { 772f245829Sagc DigestNone = 0x0, 782f245829Sagc DigestHeader = 0x01, 792f245829Sagc DigestData = 0x02 802f245829Sagc /* these are bit masks, extend accordingly */ 812f245829Sagc }; 822f245829Sagc 832f245829Sagc typedef struct iscsi_parameter_item_t { 842f245829Sagc char value[ISCSI_PARAM_MAX_LEN]; 852f245829Sagc struct iscsi_parameter_item_t *next; 862f245829Sagc } iscsi_parameter_value_t; 872f245829Sagc 882f245829Sagc /* this struct defines the credentials a user has */ 892f245829Sagc typedef struct iscsi_cred_t { 902f245829Sagc char *user; /* user's name */ 912f245829Sagc char *auth_type; /* preferred authentication type */ 92*5e01dafbSagc char *shared_secret; /* the shared secret */ 932f245829Sagc } iscsi_cred_t; 942f245829Sagc 952f245829Sagc /* 962f245829Sagc * Structure for storing negotiated parameters that are frequently accessed 972f245829Sagc * on an active session 982f245829Sagc */ 992f245829Sagc typedef struct iscsi_sess_param_t { 1002f245829Sagc uint32_t max_burst_length; 1012f245829Sagc uint32_t first_burst_length; 102*5e01dafbSagc uint32_t max_dataseg_len; 1032f245829Sagc iscsi_cred_t cred; 1042f245829Sagc uint8_t initial_r2t; 1052f245829Sagc uint8_t immediate_data; 1062f245829Sagc uint8_t header_digest; 1072f245829Sagc uint8_t data_digest; 1082f245829Sagc uint8_t auth_type; 1092f245829Sagc uint8_t mutual_auth; 1102f245829Sagc uint8_t digest_wanted; 1112f245829Sagc } iscsi_sess_param_t; 1122f245829Sagc 1132f245829Sagc typedef struct iscsi_parameter_t { 1142f245829Sagc char key[ISCSI_PARAM_KEY_LEN]; /* key */ 1152f245829Sagc int type; /* type of parameter */ 1162f245829Sagc char valid[ISCSI_PARAM_MAX_LEN]; /* list of valid values */ 1172f245829Sagc char dflt[ISCSI_PARAM_MAX_LEN]; /* default value */ 1182f245829Sagc iscsi_parameter_value_t *value_l; /* value list */ 1192f245829Sagc char offer_rx[ISCSI_PARAM_MAX_LEN]; /* outgoing offer */ 1202f245829Sagc char offer_tx[ISCSI_PARAM_MAX_LEN]; /* incoming offer */ 1212f245829Sagc char answer_tx[ISCSI_PARAM_MAX_LEN]; /* outgoing answer */ 1222f245829Sagc char answer_rx[ISCSI_PARAM_MAX_LEN]; /* incoming answer */ 1232f245829Sagc char negotiated[ISCSI_PARAM_MAX_LEN]; /* negotiated value */ 1242f245829Sagc int tx_offer; /* sent offer */ 1252f245829Sagc int rx_offer; /* received offer */ 1262f245829Sagc int tx_answer; /* sent answer */ 1272f245829Sagc int rx_answer; /* received answer */ 1282f245829Sagc int reset; /* reset value_l */ 1292f245829Sagc struct iscsi_parameter_t *next; 1302f245829Sagc } iscsi_parameter_t; 1312f245829Sagc 1322f245829Sagc int param_list_add(iscsi_parameter_t ** , int , const char *, const char *, const char *); 1332f245829Sagc int param_list_print(iscsi_parameter_t * ); 1342f245829Sagc int param_list_destroy(iscsi_parameter_t * ); 1352f245829Sagc int param_text_add(iscsi_parameter_t *, const char *, const char *, char *, int *, int, int ); 1362f245829Sagc int param_text_parse(iscsi_parameter_t *, iscsi_cred_t *, char *, int , char *, int *, int, int); 1372f245829Sagc int param_text_print(char *, uint32_t ); 1382f245829Sagc int param_num_vals(iscsi_parameter_t * , char *); 1392f245829Sagc int param_val_reset(iscsi_parameter_t * , const char *); 1402f245829Sagc char *param_val(iscsi_parameter_t * , const char *); 1412f245829Sagc char *param_val_which(iscsi_parameter_t * , const char *, int ); 1422f245829Sagc char *param_offer(iscsi_parameter_t * , char *); 1432f245829Sagc char *param_answer(iscsi_parameter_t * , char *); 1442f245829Sagc iscsi_parameter_t *param_get(iscsi_parameter_t * , const char *); 1452f245829Sagc int driver_atoi(const char *); 1462f245829Sagc int param_atoi(iscsi_parameter_t * , const char *); 1472f245829Sagc int param_equiv(iscsi_parameter_t * , const char *, const char *); 1482f245829Sagc int param_commit(iscsi_parameter_t * ); 1492f245829Sagc void set_session_parameters(iscsi_parameter_t * , iscsi_sess_param_t * ); 1502f245829Sagc 1512f245829Sagc /* 1522f245829Sagc * Macros 1532f245829Sagc */ 1542f245829Sagc 1552f245829Sagc #define PARAM_LIST_DESTROY(LIST, ELSE) \ 1562f245829Sagc if (param_list_destroy(LIST)!=0) { \ 157*5e01dafbSagc iscsi_err(__FILE__, __LINE__, "param_list_destroy() failed\n"); \ 1582f245829Sagc ELSE; \ 1592f245829Sagc } 1602f245829Sagc 1612f245829Sagc #define PARAM_LIST_ADD(LIST, TYPE, KEY, DFLT, VALID, ELSE) \ 1622f245829Sagc if (param_list_add(LIST, TYPE, KEY, DFLT, VALID)!=0) { \ 163*5e01dafbSagc iscsi_err(__FILE__, __LINE__, "param_list_add() failed\n"); \ 1642f245829Sagc ELSE; \ 1652f245829Sagc } 1662f245829Sagc 1672f245829Sagc #define PARAM_TEXT_ADD(LIST, KEY, VAL, TEXT, LEN, SIZE, OFFER, ELSE ) \ 1682f245829Sagc if (param_text_add(LIST, KEY, VAL, TEXT, LEN, SIZE, OFFER)!=0) { \ 169*5e01dafbSagc iscsi_err(__FILE__, __LINE__, "param_text_add() failed\n"); \ 1702f245829Sagc ELSE; \ 1712f245829Sagc } 1722f245829Sagc 1732f245829Sagc #define PARAM_TEXT_PARSE(LIST, CRED, TEXT, LEN, TEXT_OUT, LEN_OUT, SIZE, OFFER, ELSE ) \ 1742f245829Sagc if (param_text_parse(LIST, CRED, TEXT, LEN, TEXT_OUT, LEN_OUT, SIZE, OFFER)!=0) { \ 175*5e01dafbSagc iscsi_err(__FILE__, __LINE__, "param_text_parse_offer() failed\n"); \ 1762f245829Sagc ELSE; \ 1772f245829Sagc } 1782f245829Sagc #endif 179