xref: /illumos-gate/usr/src/uts/common/io/fibre-channel/fca/emlxs/emlxs_dhchap.c (revision 8f23e9fa8abcb5857661066b954e63400d589b65)
1fcf3ce44SJohn Forte /*
2fcf3ce44SJohn Forte  * CDDL HEADER START
3fcf3ce44SJohn Forte  *
4fcf3ce44SJohn Forte  * The contents of this file are subject to the terms of the
5fcf3ce44SJohn Forte  * Common Development and Distribution License (the "License").
6fcf3ce44SJohn Forte  * You may not use this file except in compliance with the License.
7fcf3ce44SJohn Forte  *
8*8f23e9faSHans Rosenfeld  * You can obtain a copy of the license at
9*8f23e9faSHans Rosenfeld  * http://www.opensource.org/licenses/cddl1.txt.
10fcf3ce44SJohn Forte  * See the License for the specific language governing permissions
11fcf3ce44SJohn Forte  * and limitations under the License.
12fcf3ce44SJohn Forte  *
13fcf3ce44SJohn Forte  * When distributing Covered Code, include this CDDL HEADER in each
14fcf3ce44SJohn Forte  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15fcf3ce44SJohn Forte  * If applicable, add the following below this CDDL HEADER, with the
16fcf3ce44SJohn Forte  * fields enclosed by brackets "[]" replaced with your own identifying
17fcf3ce44SJohn Forte  * information: Portions Copyright [yyyy] [name of copyright owner]
18fcf3ce44SJohn Forte  *
19fcf3ce44SJohn Forte  * CDDL HEADER END
20fcf3ce44SJohn Forte  */
21fcf3ce44SJohn Forte 
22fcf3ce44SJohn Forte /*
23*8f23e9faSHans Rosenfeld  * Copyright (c) 2004-2011 Emulex. All rights reserved.
2482527734SSukumar Swaminathan  * Use is subject to license terms.
25fcf3ce44SJohn Forte  */
26fcf3ce44SJohn Forte 
27291a2b48SSukumar Swaminathan #include <emlxs.h>
28fcf3ce44SJohn Forte 
29fcf3ce44SJohn Forte #ifdef DHCHAP_SUPPORT
30fcf3ce44SJohn Forte 
31fcf3ce44SJohn Forte #include <md5.h>
32fcf3ce44SJohn Forte #include <sha1.h>
33fcf3ce44SJohn Forte #include <sys/sha1_consts.h>
34fcf3ce44SJohn Forte #include <bignum.h>
35fcf3ce44SJohn Forte #include <sys/time.h>
36fcf3ce44SJohn Forte 
37fcf3ce44SJohn Forte 
38fcf3ce44SJohn Forte #define	RAND
39fcf3ce44SJohn Forte 
40fcf3ce44SJohn Forte #ifndef ENABLE
41fcf3ce44SJohn Forte #define	ENABLE   1
42fcf3ce44SJohn Forte #endif	/* ENABLE */
43fcf3ce44SJohn Forte 
44fcf3ce44SJohn Forte #ifndef DISABLE
45fcf3ce44SJohn Forte #define	DISABLE   0
46fcf3ce44SJohn Forte #endif	/* DISABLE */
47fcf3ce44SJohn Forte 
48fcf3ce44SJohn Forte 
49fcf3ce44SJohn Forte /* Required for EMLXS_CONTEXT in EMLXS_MSGF calls */
50fcf3ce44SJohn Forte EMLXS_MSG_DEF(EMLXS_DHCHAP_C);
51fcf3ce44SJohn Forte 
52fcf3ce44SJohn Forte static char *emlxs_dhc_pstate_xlate(uint32_t state);
53fcf3ce44SJohn Forte static char *emlxs_dhc_nstate_xlate(uint32_t state);
54fcf3ce44SJohn Forte static uint32_t emlxs_check_dhgp(emlxs_port_t *port, NODELIST *ndlp,
55fcf3ce44SJohn Forte 	uint32_t *dh_id, uint16_t cnt, uint32_t *dhgp_id);
56fcf3ce44SJohn Forte static void emlxs_dhc_set_reauth_time(emlxs_port_t *port,
57fcf3ce44SJohn Forte 	emlxs_node_t *ndlp, uint32_t status);
58fcf3ce44SJohn Forte 
59fcf3ce44SJohn Forte static void emlxs_auth_cfg_init(emlxs_hba_t *hba);
60fcf3ce44SJohn Forte static void emlxs_auth_cfg_fini(emlxs_hba_t *hba);
61fcf3ce44SJohn Forte static void emlxs_auth_cfg_read(emlxs_hba_t *hba);
62fcf3ce44SJohn Forte static uint32_t emlxs_auth_cfg_parse(emlxs_hba_t *hba,
63fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *config, char *prop_str);
64fcf3ce44SJohn Forte static emlxs_auth_cfg_t *emlxs_auth_cfg_get(emlxs_hba_t *hba,
65fcf3ce44SJohn Forte 	uint8_t *lwwpn, uint8_t *rwwpn);
66fcf3ce44SJohn Forte static emlxs_auth_cfg_t *emlxs_auth_cfg_create(emlxs_hba_t *hba,
67fcf3ce44SJohn Forte 	uint8_t *lwwpn, uint8_t *rwwpn);
68fcf3ce44SJohn Forte static void emlxs_auth_cfg_destroy(emlxs_hba_t *hba,
69fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *auth_cfg);
70fcf3ce44SJohn Forte static void emlxs_auth_cfg_print(emlxs_hba_t *hba,
71fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *auth_cfg);
72fcf3ce44SJohn Forte 
73fcf3ce44SJohn Forte static void emlxs_auth_key_init(emlxs_hba_t *hba);
74fcf3ce44SJohn Forte static void emlxs_auth_key_fini(emlxs_hba_t *hba);
75fcf3ce44SJohn Forte static void emlxs_auth_key_read(emlxs_hba_t *hba);
76fcf3ce44SJohn Forte static uint32_t emlxs_auth_key_parse(emlxs_hba_t *hba,
77fcf3ce44SJohn Forte 	emlxs_auth_key_t *auth_key, char *prop_str);
78fcf3ce44SJohn Forte static emlxs_auth_key_t *emlxs_auth_key_get(emlxs_hba_t *hba,
79fcf3ce44SJohn Forte 	uint8_t *lwwpn, uint8_t *rwwpn);
80fcf3ce44SJohn Forte static emlxs_auth_key_t *emlxs_auth_key_create(emlxs_hba_t *hba,
81fcf3ce44SJohn Forte 	uint8_t *lwwpn, uint8_t *rwwpn);
82fcf3ce44SJohn Forte static void emlxs_auth_key_destroy(emlxs_hba_t *hba,
83fcf3ce44SJohn Forte 	emlxs_auth_key_t *auth_key);
84fcf3ce44SJohn Forte static void emlxs_auth_key_print(emlxs_hba_t *hba,
85fcf3ce44SJohn Forte 	emlxs_auth_key_t *auth_key);
86fcf3ce44SJohn Forte 
87fcf3ce44SJohn Forte static void emlxs_get_random_bytes(NODELIST *ndlp, uint8_t *rdn,
88fcf3ce44SJohn Forte 	uint32_t len);
89fcf3ce44SJohn Forte static emlxs_auth_cfg_t *emlxs_auth_cfg_find(emlxs_port_t *port,
90fcf3ce44SJohn Forte 	uint8_t *rwwpn);
91fcf3ce44SJohn Forte static emlxs_auth_key_t *emlxs_auth_key_find(emlxs_port_t *port,
92fcf3ce44SJohn Forte 	uint8_t *rwwpn);
93fcf3ce44SJohn Forte static void emlxs_dhc_auth_complete(emlxs_port_t *port,
94fcf3ce44SJohn Forte 	emlxs_node_t *ndlp, uint32_t status);
95fcf3ce44SJohn Forte static void emlxs_log_auth_event(emlxs_port_t *port, NODELIST *ndlp,
96fcf3ce44SJohn Forte 	char *subclass, char *info);
97fcf3ce44SJohn Forte static int emlxs_issue_auth_negotiate(emlxs_port_t *port,
98fcf3ce44SJohn Forte 	emlxs_node_t *ndlp, uint8_t retry);
99fcf3ce44SJohn Forte static void emlxs_cmpl_auth_negotiate_issue(fc_packet_t *pkt);
100fcf3ce44SJohn Forte static uint32_t *emlxs_hash_rsp(emlxs_port_t *port,
101fcf3ce44SJohn Forte 	emlxs_port_dhc_t *port_dhc, NODELIST *ndlp, uint32_t tran_id,
102fcf3ce44SJohn Forte 	union challenge_val un_cval, uint8_t *dhval, uint32_t dhvallen);
103fcf3ce44SJohn Forte static fc_packet_t *emlxs_prep_els_fc_pkt(emlxs_port_t *port,
104fcf3ce44SJohn Forte 	uint32_t d_id, uint32_t cmd_size, uint32_t rsp_size,
105fcf3ce44SJohn Forte 	uint32_t datalen, int32_t sleepflag);
106fcf3ce44SJohn Forte 
107fcf3ce44SJohn Forte static uint32_t *emlxs_hash_vrf(emlxs_port_t *port,
108fcf3ce44SJohn Forte 	emlxs_port_dhc_t *port_dhc, NODELIST *ndlp, uint32_t tran_id,
109fcf3ce44SJohn Forte 	union challenge_val un_cval);
110a9800bebSGarrett D'Amore 
111fcf3ce44SJohn Forte 
112fcf3ce44SJohn Forte static BIG_ERR_CODE
113fcf3ce44SJohn Forte emlxs_interm_hash(emlxs_port_t *port, emlxs_port_dhc_t *port_dhc,
114fcf3ce44SJohn Forte 	NODELIST *ndlp, void *hash_val, uint32_t tran_id,
115fcf3ce44SJohn Forte 	union challenge_val un_cval, uint8_t *dhval, uint32_t *);
116fcf3ce44SJohn Forte 
117fcf3ce44SJohn Forte static BIG_ERR_CODE
118fcf3ce44SJohn Forte emlxs_BIGNUM_get_pubkey(emlxs_port_t *port, emlxs_port_dhc_t *port_dhc,
119fcf3ce44SJohn Forte 	NODELIST *ndlp, uint8_t *dhval, uint32_t *dhvallen,
120fcf3ce44SJohn Forte 	uint32_t hash_size, uint32_t dhgp_id);
121fcf3ce44SJohn Forte static BIG_ERR_CODE
122fcf3ce44SJohn Forte emlxs_BIGNUM_get_dhval(emlxs_port_t *port, emlxs_port_dhc_t *port_dhc,
123fcf3ce44SJohn Forte 	NODELIST *ndlp, uint8_t *dhval, uint32_t *dhval_len,
124fcf3ce44SJohn Forte 	uint32_t dhgp_id, uint8_t *priv_key, uint32_t privkey_len);
125fcf3ce44SJohn Forte static uint32_t *
126fcf3ce44SJohn Forte emlxs_hash_verification(emlxs_port_t *port, emlxs_port_dhc_t *port_dhc,
127fcf3ce44SJohn Forte 	NODELIST *ndlp, uint32_t tran_id, uint8_t *dhval,
128fcf3ce44SJohn Forte 	uint32_t dhval_len, uint32_t flag, uint8_t *bi_cval);
129fcf3ce44SJohn Forte 
130fcf3ce44SJohn Forte static uint32_t *
131fcf3ce44SJohn Forte emlxs_hash_get_R2(emlxs_port_t *port, emlxs_port_dhc_t *port_dhc,
132fcf3ce44SJohn Forte 	NODELIST *ndlp, uint32_t tran_id, uint8_t *dhval,
133fcf3ce44SJohn Forte 	uint32_t dhval_len, uint32_t flag, uint8_t *bi_cval);
134fcf3ce44SJohn Forte 
135fcf3ce44SJohn Forte static uint32_t emlxs_issue_auth_reject(emlxs_port_t *port,
136fcf3ce44SJohn Forte 	NODELIST *ndlp, int retry, uint32_t *arg, uint8_t ReasonCode,
137fcf3ce44SJohn Forte 	uint8_t ReasonCodeExplanation);
138fcf3ce44SJohn Forte 
139fcf3ce44SJohn Forte static uint32_t emlxs_disc_neverdev(emlxs_port_t *port, void *arg1,
140fcf3ce44SJohn Forte 	void *arg2, void *arg3, void *arg4, uint32_t evt);
141fcf3ce44SJohn Forte static uint32_t emlxs_rcv_auth_msg_unmapped_node(emlxs_port_t *port,
142fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
143fcf3ce44SJohn Forte static uint32_t emlxs_rcv_auth_msg_npr_node(emlxs_port_t *port,
144fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
145fcf3ce44SJohn Forte static uint32_t emlxs_cmpl_auth_msg_npr_node(emlxs_port_t *port,
146fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
147fcf3ce44SJohn Forte static uint32_t emlxs_rcv_auth_msg_auth_negotiate_issue(emlxs_port_t *port,
148fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
149fcf3ce44SJohn Forte static uint32_t emlxs_cmpl_auth_msg_auth_negotiate_issue(emlxs_port_t *port,
150fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
151fcf3ce44SJohn Forte static uint32_t emlxs_rcv_auth_msg_auth_negotiate_rcv(emlxs_port_t *port,
152fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
153fcf3ce44SJohn Forte static uint32_t emlxs_cmpl_auth_msg_auth_negotiate_rcv(emlxs_port_t *port,
154fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
155fcf3ce44SJohn Forte static uint32_t
156fcf3ce44SJohn Forte emlxs_rcv_auth_msg_auth_negotiate_cmpl_wait4next(emlxs_port_t *port,
157fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
158fcf3ce44SJohn Forte static uint32_t
159fcf3ce44SJohn Forte emlxs_cmpl_auth_msg_auth_negotiate_cmpl_wait4next(emlxs_port_t *port,
160fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
161fcf3ce44SJohn Forte static uint32_t
162fcf3ce44SJohn Forte emlxs_rcv_auth_msg_dhchap_challenge_issue(emlxs_port_t *port, void *arg1,
163fcf3ce44SJohn Forte 	void *arg2, void *arg3, void *arg4, uint32_t evt);
164fcf3ce44SJohn Forte static uint32_t
165fcf3ce44SJohn Forte emlxs_cmpl_auth_msg_dhchap_challenge_issue(emlxs_port_t *port, void *arg1,
166fcf3ce44SJohn Forte 	void *arg2, void *arg3, void *arg4, uint32_t evt);
167fcf3ce44SJohn Forte static uint32_t emlxs_rcv_auth_msg_dhchap_reply_issue(emlxs_port_t *port,
168fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
169fcf3ce44SJohn Forte static uint32_t emlxs_cmpl_auth_msg_dhchap_reply_issue(emlxs_port_t *port,
170fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
171fcf3ce44SJohn Forte static uint32_t
172fcf3ce44SJohn Forte emlxs_rcv_auth_msg_dhchap_challenge_cmpl_wait4next(emlxs_port_t *port,
173fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
174fcf3ce44SJohn Forte static uint32_t
175fcf3ce44SJohn Forte emlxs_cmpl_auth_msg_dhchap_challenge_cmpl_wait4next(emlxs_port_t *port,
176fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
177fcf3ce44SJohn Forte static uint32_t
178fcf3ce44SJohn Forte emlxs_rcv_auth_msg_dhchap_reply_cmpl_wait4next(emlxs_port_t *port,
179fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
180fcf3ce44SJohn Forte static uint32_t
181fcf3ce44SJohn Forte emlxs_cmpl_auth_msg_dhchap_reply_cmpl_wait4next(emlxs_port_t *port,
182fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
183fcf3ce44SJohn Forte static uint32_t emlxs_rcv_auth_msg_dhchap_success_issue(emlxs_port_t *port,
184fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
185fcf3ce44SJohn Forte static uint32_t
186fcf3ce44SJohn Forte emlxs_cmpl_auth_msg_dhchap_success_issue(emlxs_port_t *port, void *arg1,
187fcf3ce44SJohn Forte 	void *arg2, void *arg3, void *arg4, uint32_t evt);
188fcf3ce44SJohn Forte static uint32_t
189fcf3ce44SJohn Forte emlxs_rcv_auth_msg_dhchap_success_issue_wait4next(emlxs_port_t *port,
190fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
191fcf3ce44SJohn Forte static uint32_t
192fcf3ce44SJohn Forte emlxs_cmpl_auth_msg_dhchap_success_issue_wait4next(emlxs_port_t *port,
193fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
194fcf3ce44SJohn Forte static uint32_t
195fcf3ce44SJohn Forte emlxs_rcv_auth_msg_dhchap_success_cmpl_wait4next(emlxs_port_t *port,
196fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
197fcf3ce44SJohn Forte static uint32_t
198fcf3ce44SJohn Forte emlxs_cmpl_auth_msg_dhchap_success_cmpl_wait4next(emlxs_port_t *port,
199fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
200a9800bebSGarrett D'Amore 
201a9800bebSGarrett D'Amore 
202fcf3ce44SJohn Forte static uint32_t emlxs_device_recov_unmapped_node(emlxs_port_t *port,
203fcf3ce44SJohn Forte 	void *arg1, void *arg2, void *arg3, void *arg4, uint32_t evt);
204fcf3ce44SJohn Forte static uint32_t emlxs_device_rm_npr_node(emlxs_port_t *port, void *arg1,
205fcf3ce44SJohn Forte 	void *arg2, void *arg3, void *arg4, uint32_t evt);
206fcf3ce44SJohn Forte static uint32_t emlxs_device_recov_npr_node(emlxs_port_t *port, void *arg1,
207fcf3ce44SJohn Forte 	void *arg2, void *arg3, void *arg4, uint32_t evt);
208fcf3ce44SJohn Forte static uint32_t emlxs_device_rem_auth(emlxs_port_t *port, void *arg1,
209fcf3ce44SJohn Forte 	void *arg2, void *arg3, void *arg4, uint32_t evt);
210fcf3ce44SJohn Forte static uint32_t emlxs_device_recov_auth(emlxs_port_t *port, void *arg1,
211fcf3ce44SJohn Forte 	void *arg2, void *arg3, void *arg4, uint32_t evt);
212fcf3ce44SJohn Forte 
213a9800bebSGarrett D'Amore static uint8_t emlxs_null_wwn[8] =
214a9800bebSGarrett D'Amore 	{0, 0, 0, 0, 0, 0, 0, 0};
215a9800bebSGarrett D'Amore static uint8_t emlxs_fabric_wwn[8] =
216a9800bebSGarrett D'Amore 	{0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
217fcf3ce44SJohn Forte 
218fcf3ce44SJohn Forte unsigned char dhgp1_pVal[] =
219fcf3ce44SJohn Forte {0xEE, 0xAF, 0x0A, 0xB9, 0xAD, 0xB3, 0x8D, 0xD6, 0x9C, 0x33, 0xF8, 0x0A, 0xFA,
220fcf3ce44SJohn Forte 0x8F, 0xC5, 0xE8,
221fcf3ce44SJohn Forte 0x60, 0x72, 0x61, 0x87, 0x75, 0xFF, 0x3C, 0x0B, 0x9E, 0xA2, 0x31, 0x4C, 0x9C,
222fcf3ce44SJohn Forte 0x25, 0x65, 0x76,
223fcf3ce44SJohn Forte 0xD6, 0x74, 0xDF, 0x74, 0x96, 0xEA, 0x81, 0xD3, 0x38, 0x3B, 0x48, 0x13, 0xD6,
224fcf3ce44SJohn Forte 0x92, 0xC6, 0xE0,
225fcf3ce44SJohn Forte 0xE0, 0xD5, 0xD8, 0xE2, 0x50, 0xB9, 0x8B, 0xE4, 0x8E, 0x49, 0x5C, 0x1D, 0x60,
226fcf3ce44SJohn Forte 0x89, 0xDA, 0xD1,
227fcf3ce44SJohn Forte 0x5D, 0xC7, 0xD7, 0xB4, 0x61, 0x54, 0xD6, 0xB6, 0xCE, 0x8E, 0xF4, 0xAD, 0x69,
228fcf3ce44SJohn Forte 0xB1, 0x5D, 0x49,
229fcf3ce44SJohn Forte 0x82, 0x55, 0x9B, 0x29, 0x7B, 0xCF, 0x18, 0x85, 0xC5, 0x29, 0xF5, 0x66, 0x66,
230fcf3ce44SJohn Forte 0x0E, 0x57, 0xEC,
231fcf3ce44SJohn Forte 0x68, 0xED, 0xBC, 0x3C, 0x05, 0x72, 0x6C, 0xC0, 0x2F, 0xD4, 0xCB, 0xF4, 0x97,
232fcf3ce44SJohn Forte 0x6E, 0xAA, 0x9A,
233fcf3ce44SJohn Forte 0xFD, 0x51, 0x38, 0xFE, 0x83, 0x76, 0x43, 0x5B, 0x9F, 0xC6, 0x1D, 0x2F, 0xC0,
234fcf3ce44SJohn Forte 0xEB, 0x06, 0xE3,
235fcf3ce44SJohn Forte };
236fcf3ce44SJohn Forte 
237fcf3ce44SJohn Forte unsigned char dhgp2_pVal[] =
238fcf3ce44SJohn Forte {0xD7, 0x79, 0x46, 0x82, 0x6E, 0x81, 0x19, 0x14, 0xB3, 0x94, 0x01, 0xD5, 0x6A,
239fcf3ce44SJohn Forte 0x0A, 0x78, 0x43,
240fcf3ce44SJohn Forte 0xA8, 0xE7, 0x57, 0x5D, 0x73, 0x8C, 0x67, 0x2A, 0x09, 0x0A, 0xB1, 0x18, 0x7D,
241fcf3ce44SJohn Forte 0x69, 0x0D, 0xC4,
242fcf3ce44SJohn Forte 0x38, 0x72, 0xFC, 0x06, 0xA7, 0xB6, 0xA4, 0x3F, 0x3B, 0x95, 0xBE, 0xAE, 0xC7,
243fcf3ce44SJohn Forte 0xDF, 0x04, 0xB9,
244fcf3ce44SJohn Forte 0xD2, 0x42, 0xEB, 0xDC, 0x48, 0x11, 0x11, 0x28, 0x32, 0x16, 0xCE, 0x81, 0x6E,
245fcf3ce44SJohn Forte 0x00, 0x4B, 0x78,
246fcf3ce44SJohn Forte 0x6C, 0x5F, 0xCE, 0x85, 0x67, 0x80, 0xD4, 0x18, 0x37, 0xD9, 0x5A, 0xD7, 0x87,
247fcf3ce44SJohn Forte 0xA5, 0x0B, 0xBE,
248fcf3ce44SJohn Forte 0x90, 0xBD, 0x3A, 0x9C, 0x98, 0xAC, 0x0F, 0x5F, 0xC0, 0xDE, 0x74, 0x4B, 0x1C,
249fcf3ce44SJohn Forte 0xDE, 0x18, 0x91,
250fcf3ce44SJohn Forte 0x69, 0x08, 0x94, 0xBC, 0x1F, 0x65, 0xE0, 0x0D, 0xE1, 0x5B, 0x4B, 0x2A, 0xA6,
251fcf3ce44SJohn Forte 0xD8, 0x71, 0x00,
252fcf3ce44SJohn Forte 0xC9, 0xEC, 0xC2, 0x52, 0x7E, 0x45, 0xEB, 0x84, 0x9D, 0xEB, 0x14, 0xBB, 0x20,
253fcf3ce44SJohn Forte 0x49, 0xB1, 0x63,
254fcf3ce44SJohn Forte 0xEA, 0x04, 0x18, 0x7F, 0xD2, 0x7C, 0x1B, 0xD9, 0xC7, 0x95, 0x8C, 0xD4, 0x0C,
255fcf3ce44SJohn Forte 0xE7, 0x06, 0x7A,
256fcf3ce44SJohn Forte 0x9C, 0x02, 0x4F, 0x9B, 0x7C, 0x5A, 0x0B, 0x4F, 0x50, 0x03, 0x68, 0x61, 0x61,
257fcf3ce44SJohn Forte 0xF0, 0x60, 0x5B
258fcf3ce44SJohn Forte };
259fcf3ce44SJohn Forte 
260fcf3ce44SJohn Forte unsigned char dhgp3_pVal[] =
261fcf3ce44SJohn Forte {0x9D, 0xEF, 0x3C, 0xAF, 0xB9, 0x39, 0x27, 0x7A, 0xB1, 0xF1, 0x2A, 0x86, 0x17,
262fcf3ce44SJohn Forte 0xA4, 0x7B, 0xBB,
263fcf3ce44SJohn Forte 0xDB, 0xA5, 0x1D, 0xF4, 0x99, 0xAC, 0x4C, 0x80, 0xBE, 0xEE, 0xA9, 0x61, 0x4B,
264fcf3ce44SJohn Forte 0x19, 0xCC, 0x4D,
265fcf3ce44SJohn Forte 0x5F, 0x4F, 0x5F, 0x55, 0x6E, 0x27, 0xCB, 0xDE, 0x51, 0xC6, 0xA9, 0x4B, 0xE4,
266fcf3ce44SJohn Forte 0x60, 0x7A, 0x29,
267fcf3ce44SJohn Forte 0x15, 0x58, 0x90, 0x3B, 0xA0, 0xD0, 0xF8, 0x43, 0x80, 0xB6, 0x55, 0xBB, 0x9A,
268fcf3ce44SJohn Forte 0x22, 0xE8, 0xDC,
269fcf3ce44SJohn Forte 0xDF, 0x02, 0x8A, 0x7C, 0xEC, 0x67, 0xF0, 0xD0, 0x81, 0x34, 0xB1, 0xC8, 0xB9,
270fcf3ce44SJohn Forte 0x79, 0x89, 0x14,
271fcf3ce44SJohn Forte 0x9B, 0x60, 0x9E, 0x0B, 0xE3, 0xBA, 0xB6, 0x3D, 0x47, 0x54, 0x83, 0x81, 0xDB,
272fcf3ce44SJohn Forte 0xC5, 0xB1, 0xFC,
273fcf3ce44SJohn Forte 0x76, 0x4E, 0x3F, 0x4B, 0x53, 0xDD, 0x9D, 0xA1, 0x15, 0x8B, 0xFD, 0x3E, 0x2B,
274fcf3ce44SJohn Forte 0x9C, 0x8C, 0xF5,
275fcf3ce44SJohn Forte 0x6E, 0xDF, 0x01, 0x95, 0x39, 0x34, 0x96, 0x27, 0xDB, 0x2F, 0xD5, 0x3D, 0x24,
276fcf3ce44SJohn Forte 0xB7, 0xC4, 0x86,
277fcf3ce44SJohn Forte 0x65, 0x77, 0x2E, 0x43, 0x7D, 0x6C, 0x7F, 0x8C, 0xE4, 0x42, 0x73, 0x4A, 0xF7,
278fcf3ce44SJohn Forte 0xCC, 0xB7, 0xAE,
279fcf3ce44SJohn Forte 0x83, 0x7C, 0x26, 0x4A, 0xE3, 0xA9, 0xBE, 0xB8, 0x7F, 0x8A, 0x2F, 0xE9, 0xB8,
280fcf3ce44SJohn Forte 0xB5, 0x29, 0x2E,
281fcf3ce44SJohn Forte 0x5A, 0x02, 0x1F, 0xFF, 0x5E, 0x91, 0x47, 0x9E, 0x8C, 0xE7, 0xA2, 0x8C, 0x24,
282fcf3ce44SJohn Forte 0x42, 0xC6, 0xF3,
283fcf3ce44SJohn Forte 0x15, 0x18, 0x0F, 0x93, 0x49, 0x9A, 0x23, 0x4D, 0xCF, 0x76, 0xE3, 0xFE, 0xD1,
284fcf3ce44SJohn Forte 0x35, 0xF9, 0xBB
285fcf3ce44SJohn Forte };
286fcf3ce44SJohn Forte 
287fcf3ce44SJohn Forte unsigned char dhgp4_pVal[] =
288fcf3ce44SJohn Forte {0xAC, 0x6B, 0xDB, 0x41, 0x32, 0x4A, 0x9A, 0x9B, 0xF1, 0x66, 0xDE, 0x5E, 0x13,
289fcf3ce44SJohn Forte 0x89, 0x58, 0x2F,
290fcf3ce44SJohn Forte 0xAF, 0x72, 0xB6, 0x65, 0x19, 0x87, 0xEE, 0x07, 0xFC, 0x31, 0x92, 0x94, 0x3D,
291fcf3ce44SJohn Forte 0xB5, 0x60, 0x50,
292fcf3ce44SJohn Forte 0xA3, 0x73, 0x29, 0xCB, 0xB4, 0xA0, 0x99, 0xED, 0x81, 0x93, 0xE0, 0x75, 0x77,
293fcf3ce44SJohn Forte 0x67, 0xA1, 0x3D,
294fcf3ce44SJohn Forte 0xD5, 0x23, 0x12, 0xAB, 0x4B, 0x03, 0x31, 0x0D, 0xCD, 0x7F, 0x48, 0xA9, 0xDA,
295fcf3ce44SJohn Forte 0x04, 0xFD, 0x50,
296fcf3ce44SJohn Forte 0xE8, 0x08, 0x39, 0x69, 0xED, 0xB7, 0x67, 0xB0, 0xCF, 0x60, 0x95, 0x17, 0x9A,
297fcf3ce44SJohn Forte 0x16, 0x3A, 0xB3,
298fcf3ce44SJohn Forte 0x66, 0x1A, 0x05, 0xFB, 0xD5, 0xFA, 0xAA, 0xE8, 0x29, 0x18, 0xA9, 0x96, 0x2F,
299fcf3ce44SJohn Forte 0x0B, 0x93, 0xB8,
300fcf3ce44SJohn Forte 0x55, 0xF9, 0x79, 0x93, 0xEC, 0x97, 0x5E, 0xEA, 0xA8, 0x0D, 0x74, 0x0A, 0xDB,
301fcf3ce44SJohn Forte 0xF4, 0xFF, 0x74,
302fcf3ce44SJohn Forte 0x73, 0x59, 0xD0, 0x41, 0xD5, 0xC3, 0x3E, 0xA7, 0x1D, 0x28, 0x1E, 0x44, 0x6B,
303fcf3ce44SJohn Forte 0x14, 0x77, 0x3B,
304fcf3ce44SJohn Forte 0xCA, 0x97, 0xB4, 0x3A, 0x23, 0xFB, 0x80, 0x16, 0x76, 0xBD, 0x20, 0x7A, 0x43,
305fcf3ce44SJohn Forte 0x6C, 0x64, 0x81,
306fcf3ce44SJohn Forte 0xF1, 0xD2, 0xB9, 0x07, 0x87, 0x17, 0x46, 0x1A, 0x5B, 0x9D, 0x32, 0xE6, 0x88,
307fcf3ce44SJohn Forte 0xF8, 0x77, 0x48,
308fcf3ce44SJohn Forte 0x54, 0x45, 0x23, 0xB5, 0x24, 0xB0, 0xD5, 0x7D, 0x5E, 0xA7, 0x7A, 0x27, 0x75,
309fcf3ce44SJohn Forte 0xD2, 0xEC, 0xFA,
310fcf3ce44SJohn Forte 0x03, 0x2C, 0xFB, 0xDB, 0xF5, 0x2F, 0xB3, 0x78, 0x61, 0x60, 0x27, 0x90, 0x04,
311fcf3ce44SJohn Forte 0xE5, 0x7A, 0xE6,
312fcf3ce44SJohn Forte 0xAF, 0x87, 0x4E, 0x73, 0x03, 0xCE, 0x53, 0x29, 0x9C, 0xCC, 0x04, 0x1C, 0x7B,
313fcf3ce44SJohn Forte 0xC3, 0x08, 0xD8,
314fcf3ce44SJohn Forte 0x2A, 0x56, 0x98, 0xF3, 0xA8, 0xD0, 0xC3, 0x82, 0x71, 0xAE, 0x35, 0xF8, 0xE9,
315fcf3ce44SJohn Forte 0xDB, 0xFB, 0xB6,
316fcf3ce44SJohn Forte 0x94, 0xB5, 0xC8, 0x03, 0xD8, 0x9F, 0x7A, 0xE4, 0x35, 0xDE, 0x23, 0x6D, 0x52,
317fcf3ce44SJohn Forte 0x5F, 0x54, 0x75,
318fcf3ce44SJohn Forte 0x9B, 0x65, 0xE3, 0x72, 0xFC, 0xD6, 0x8E, 0xF2, 0x0F, 0xA7, 0x11, 0x1F, 0x9E,
319fcf3ce44SJohn Forte 0x4A, 0xFF, 0x73
320fcf3ce44SJohn Forte };
321fcf3ce44SJohn Forte 
322fcf3ce44SJohn Forte /*
323fcf3ce44SJohn Forte  * myrand is used for test only, eventually it should be replaced by the random
324fcf3ce44SJohn Forte  * number. AND it is basically the private key.
325fcf3ce44SJohn Forte  */
326fcf3ce44SJohn Forte /* #define	MYRAND */
327fcf3ce44SJohn Forte #ifdef MYRAND
328fcf3ce44SJohn Forte unsigned char myrand[] =
329fcf3ce44SJohn Forte {0x11, 0x11, 0x22, 0x22,
330fcf3ce44SJohn Forte 	0x33, 0x33, 0x44, 0x44,
331fcf3ce44SJohn Forte 	0x55, 0x55, 0x66, 0x66,
332fcf3ce44SJohn Forte 	0x77, 0x77, 0x88, 0x88,
333fcf3ce44SJohn Forte 0x99, 0x99, 0x00, 0x00};
334fcf3ce44SJohn Forte #endif	/* MYRAND */
335fcf3ce44SJohn Forte 
336fcf3ce44SJohn Forte 
337fcf3ce44SJohn Forte 
338fcf3ce44SJohn Forte 
339fcf3ce44SJohn Forte /* Node Events */
340fcf3ce44SJohn Forte #define	NODE_EVENT_DEVICE_RM	0x0 /* Auth response timeout & fail */
341fcf3ce44SJohn Forte #define	NODE_EVENT_DEVICE_RECOVERY 0x1 /* Auth response timeout & recovery */
342fcf3ce44SJohn Forte #define	NODE_EVENT_RCV_AUTH_MSG	 0x2 /* Unsolicited Auth received */
343fcf3ce44SJohn Forte #define	NODE_EVENT_CMPL_AUTH_MSG 0x3
344fcf3ce44SJohn Forte #define	NODE_EVENT_MAX_EVENT	 0x4
345fcf3ce44SJohn Forte 
346fcf3ce44SJohn Forte emlxs_table_t emlxs_event_table[] =
347fcf3ce44SJohn Forte {
348fcf3ce44SJohn Forte 	{NODE_EVENT_DEVICE_RM, "DEVICE_REMOVE"},
349fcf3ce44SJohn Forte 	{NODE_EVENT_DEVICE_RECOVERY, "DEVICE_RECOVERY"},
350fcf3ce44SJohn Forte 	{NODE_EVENT_RCV_AUTH_MSG, "AUTH_MSG_RCVD"},
351fcf3ce44SJohn Forte 	{NODE_EVENT_CMPL_AUTH_MSG, "AUTH_MSG_CMPL"},
352fcf3ce44SJohn Forte 
353fcf3ce44SJohn Forte };	/* emlxs_event_table() */
354fcf3ce44SJohn Forte 
355fcf3ce44SJohn Forte emlxs_table_t emlxs_pstate_table[] =
356fcf3ce44SJohn Forte {
357fcf3ce44SJohn Forte 	{ELX_FABRIC_STATE_UNKNOWN, "FABRIC_STATE_UNKNOWN"},
358fcf3ce44SJohn Forte 	{ELX_FABRIC_AUTH_DISABLED, "FABRIC_AUTH_DISABLED"},
359fcf3ce44SJohn Forte 	{ELX_FABRIC_AUTH_FAILED, "FABRIC_AUTH_FAILED"},
360fcf3ce44SJohn Forte 	{ELX_FABRIC_AUTH_SUCCESS, "FABRIC_AUTH_SUCCESS"},
361fcf3ce44SJohn Forte 	{ELX_FABRIC_IN_AUTH, "FABRIC_IN_AUTH"},
362fcf3ce44SJohn Forte 	{ELX_FABRIC_IN_REAUTH, "FABRIC_IN_REAUTH"},
363fcf3ce44SJohn Forte 
364fcf3ce44SJohn Forte };	/* emlxs_pstate_table() */
365fcf3ce44SJohn Forte 
366fcf3ce44SJohn Forte emlxs_table_t emlxs_nstate_table[] =
367fcf3ce44SJohn Forte {
368fcf3ce44SJohn Forte {NODE_STATE_UNKNOWN, "STATE_UNKNOWN"},
369fcf3ce44SJohn Forte {NODE_STATE_AUTH_DISABLED, "AUTH_DISABLED"},
370fcf3ce44SJohn Forte {NODE_STATE_AUTH_FAILED, "AUTH_FAILED"},
371fcf3ce44SJohn Forte {NODE_STATE_AUTH_SUCCESS, "AUTH_SUCCESS"},
372fcf3ce44SJohn Forte {NODE_STATE_AUTH_NEGOTIATE_ISSUE, "NEGOTIATE_ISSUE"},
373fcf3ce44SJohn Forte {NODE_STATE_AUTH_NEGOTIATE_RCV, "NEGOTIATE_RCV"},
374fcf3ce44SJohn Forte {NODE_STATE_AUTH_NEGOTIATE_CMPL_WAIT4NEXT, "NEGOTIATE_CMPL"},
375fcf3ce44SJohn Forte {NODE_STATE_DHCHAP_CHALLENGE_ISSUE, "DHCHAP_CHALLENGE_ISSUE"},
376fcf3ce44SJohn Forte {NODE_STATE_DHCHAP_REPLY_ISSUE, "DHCHAP_REPLY_ISSUE"},
377fcf3ce44SJohn Forte {NODE_STATE_DHCHAP_CHALLENGE_CMPL_WAIT4NEXT, "DHCHAP_CHALLENGE_CMPL"},
378fcf3ce44SJohn Forte {NODE_STATE_DHCHAP_REPLY_CMPL_WAIT4NEXT, "DHCHAP_REPLY_CMPL"},
379fcf3ce44SJohn Forte {NODE_STATE_DHCHAP_SUCCESS_ISSUE, "DHCHAP_SUCCESS_ISSUE"},
380fcf3ce44SJohn Forte {NODE_STATE_DHCHAP_SUCCESS_ISSUE_WAIT4NEXT, "DHCHAP_SUCCESS_ISSUE_WAIT"},
381fcf3ce44SJohn Forte {NODE_STATE_DHCHAP_SUCCESS_CMPL_WAIT4NEXT, "DHCHAP_SUCCESS_CMPL"},
382fcf3ce44SJohn Forte };	/* emlxs_nstate_table() */
383fcf3ce44SJohn Forte 
384fcf3ce44SJohn Forte extern char *
emlxs_dhc_event_xlate(uint32_t state)385fcf3ce44SJohn Forte emlxs_dhc_event_xlate(uint32_t state)
386fcf3ce44SJohn Forte {
387fcf3ce44SJohn Forte 	static char buffer[32];
388fcf3ce44SJohn Forte 	uint32_t i;
389fcf3ce44SJohn Forte 	uint32_t count;
390fcf3ce44SJohn Forte 
391fcf3ce44SJohn Forte 	count = sizeof (emlxs_event_table) / sizeof (emlxs_table_t);
392fcf3ce44SJohn Forte 	for (i = 0; i < count; i++) {
393fcf3ce44SJohn Forte 		if (state == emlxs_event_table[i].code) {
394fcf3ce44SJohn Forte 			return (emlxs_event_table[i].string);
395fcf3ce44SJohn Forte 		}
396fcf3ce44SJohn Forte 	}
397fcf3ce44SJohn Forte 
398*8f23e9faSHans Rosenfeld 	(void) snprintf(buffer, sizeof (buffer), "event=0x%x", state);
399fcf3ce44SJohn Forte 	return (buffer);
400fcf3ce44SJohn Forte 
401fcf3ce44SJohn Forte } /* emlxs_dhc_event_xlate() */
402fcf3ce44SJohn Forte 
403fcf3ce44SJohn Forte 
404fcf3ce44SJohn Forte extern void
emlxs_dhc_state(emlxs_port_t * port,emlxs_node_t * ndlp,uint32_t state,uint32_t reason,uint32_t explaination)405fcf3ce44SJohn Forte emlxs_dhc_state(emlxs_port_t *port, emlxs_node_t *ndlp, uint32_t state,
406fcf3ce44SJohn Forte 	uint32_t reason, uint32_t explaination)
407fcf3ce44SJohn Forte {
408fcf3ce44SJohn Forte 	emlxs_hba_t *hba = HBA;
409fcf3ce44SJohn Forte 	emlxs_port_dhc_t *port_dhc = &port->port_dhc;
410fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
411fcf3ce44SJohn Forte 	uint32_t pstate;
412fcf3ce44SJohn Forte 
413fcf3ce44SJohn Forte 	if ((state != NODE_STATE_NOCHANGE) && (node_dhc->state != state)) {
414fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_state_msg,
415fcf3ce44SJohn Forte 		    "Node:0x%x %s --> %s", ndlp->nlp_DID,
416fcf3ce44SJohn Forte 		    emlxs_dhc_nstate_xlate(node_dhc->state),
417fcf3ce44SJohn Forte 		    emlxs_dhc_nstate_xlate(state));
418fcf3ce44SJohn Forte 
419fcf3ce44SJohn Forte 		node_dhc->prev_state = node_dhc->state;
420a9800bebSGarrett D'Amore 		node_dhc->state = (uint16_t)state;
421fcf3ce44SJohn Forte 
422fcf3ce44SJohn Forte 		/* Perform common functions based on state */
423fcf3ce44SJohn Forte 		switch (state) {
424fcf3ce44SJohn Forte 		case NODE_STATE_UNKNOWN:
425fcf3ce44SJohn Forte 		case NODE_STATE_AUTH_DISABLED:
426fcf3ce44SJohn Forte 			node_dhc->nlp_authrsp_tmo = 0;
427fcf3ce44SJohn Forte 			node_dhc->nlp_authrsp_tmocnt = 0;
428fcf3ce44SJohn Forte 			emlxs_dhc_set_reauth_time(port, ndlp, DISABLE);
429fcf3ce44SJohn Forte 			break;
430fcf3ce44SJohn Forte 
431fcf3ce44SJohn Forte 		case NODE_STATE_AUTH_SUCCESS:
432fcf3ce44SJohn Forte 			/* Record auth time */
43382527734SSukumar Swaminathan 			if (ndlp->nlp_DID == FABRIC_DID) {
434fcf3ce44SJohn Forte 				port_dhc->auth_time = DRV_TIME;
435fcf3ce44SJohn Forte 			} else if (node_dhc->parent_auth_cfg) {
436fcf3ce44SJohn Forte 				node_dhc->parent_auth_cfg->auth_time = DRV_TIME;
437fcf3ce44SJohn Forte 			}
438fcf3ce44SJohn Forte 			hba->rdn_flag = 0;
439fcf3ce44SJohn Forte 			node_dhc->nlp_authrsp_tmo = 0;
440fcf3ce44SJohn Forte 
441fcf3ce44SJohn Forte 			if (node_dhc->flag & NLP_SET_REAUTH_TIME) {
442fcf3ce44SJohn Forte 				emlxs_dhc_set_reauth_time(port, ndlp, ENABLE);
443fcf3ce44SJohn Forte 			}
444fcf3ce44SJohn Forte 			break;
445fcf3ce44SJohn Forte 
446fcf3ce44SJohn Forte 		default:
447fcf3ce44SJohn Forte 			break;
448fcf3ce44SJohn Forte 		}
449fcf3ce44SJohn Forte 
450fcf3ce44SJohn Forte 		/* Check for switch port */
45182527734SSukumar Swaminathan 		if (ndlp->nlp_DID == FABRIC_DID) {
452fcf3ce44SJohn Forte 			switch (state) {
453fcf3ce44SJohn Forte 			case NODE_STATE_UNKNOWN:
454fcf3ce44SJohn Forte 				pstate = ELX_FABRIC_STATE_UNKNOWN;
455fcf3ce44SJohn Forte 				break;
456fcf3ce44SJohn Forte 
457fcf3ce44SJohn Forte 			case NODE_STATE_AUTH_DISABLED:
458fcf3ce44SJohn Forte 				pstate = ELX_FABRIC_AUTH_DISABLED;
459fcf3ce44SJohn Forte 				break;
460fcf3ce44SJohn Forte 
461fcf3ce44SJohn Forte 			case NODE_STATE_AUTH_FAILED:
462fcf3ce44SJohn Forte 				pstate = ELX_FABRIC_AUTH_FAILED;
463fcf3ce44SJohn Forte 				break;
464fcf3ce44SJohn Forte 
465fcf3ce44SJohn Forte 			case NODE_STATE_AUTH_SUCCESS:
466fcf3ce44SJohn Forte 				pstate = ELX_FABRIC_AUTH_SUCCESS;
467fcf3ce44SJohn Forte 				break;
468fcf3ce44SJohn Forte 
469fcf3ce44SJohn Forte 				/* Auth active */
470fcf3ce44SJohn Forte 			default:
471fcf3ce44SJohn Forte 				if (port_dhc->state ==
472fcf3ce44SJohn Forte 				    ELX_FABRIC_AUTH_SUCCESS) {
473fcf3ce44SJohn Forte 					pstate = ELX_FABRIC_IN_REAUTH;
474fcf3ce44SJohn Forte 				} else if (port_dhc->state !=
475fcf3ce44SJohn Forte 				    ELX_FABRIC_IN_REAUTH) {
476fcf3ce44SJohn Forte 					pstate = ELX_FABRIC_IN_AUTH;
477fcf3ce44SJohn Forte 				}
478fcf3ce44SJohn Forte 				break;
479fcf3ce44SJohn Forte 			}
480fcf3ce44SJohn Forte 
481fcf3ce44SJohn Forte 			if (port_dhc->state != pstate) {
482fcf3ce44SJohn Forte 				EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_state_msg,
483fcf3ce44SJohn Forte 				    "Port: %s --> %s",
484fcf3ce44SJohn Forte 				    emlxs_dhc_pstate_xlate(port_dhc->state),
485fcf3ce44SJohn Forte 				    emlxs_dhc_pstate_xlate(pstate));
486fcf3ce44SJohn Forte 
487fcf3ce44SJohn Forte 				port_dhc->state = pstate;
488fcf3ce44SJohn Forte 			}
489fcf3ce44SJohn Forte 		}
490fcf3ce44SJohn Forte 	}
491fcf3ce44SJohn Forte 	/* Update auth status */
492fcf3ce44SJohn Forte 	mutex_enter(&hba->auth_lock);
493fcf3ce44SJohn Forte 	emlxs_dhc_status(port, ndlp, reason, explaination);
494fcf3ce44SJohn Forte 	mutex_exit(&hba->auth_lock);
495fcf3ce44SJohn Forte 
496fcf3ce44SJohn Forte 	return;
497fcf3ce44SJohn Forte 
498fcf3ce44SJohn Forte } /* emlxs_dhc_state() */
499fcf3ce44SJohn Forte 
500fcf3ce44SJohn Forte 
501fcf3ce44SJohn Forte /* auth_lock must be held when calling this */
502fcf3ce44SJohn Forte extern void
emlxs_dhc_status(emlxs_port_t * port,emlxs_node_t * ndlp,uint32_t reason,uint32_t explaination)503fcf3ce44SJohn Forte emlxs_dhc_status(emlxs_port_t *port, emlxs_node_t *ndlp, uint32_t reason,
504fcf3ce44SJohn Forte 	uint32_t explaination)
505fcf3ce44SJohn Forte {
506fcf3ce44SJohn Forte 	emlxs_port_dhc_t *port_dhc;
507fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc;
508fcf3ce44SJohn Forte 	dfc_auth_status_t *auth_status;
509fcf3ce44SJohn Forte 	uint32_t drv_time;
510fcf3ce44SJohn Forte 
511fcf3ce44SJohn Forte 	if (!ndlp || !ndlp->nlp_active || ndlp->node_dhc.state ==
512fcf3ce44SJohn Forte 	    NODE_STATE_UNKNOWN) {
513fcf3ce44SJohn Forte 		return;
514fcf3ce44SJohn Forte 	}
515fcf3ce44SJohn Forte 	port_dhc = &port->port_dhc;
516fcf3ce44SJohn Forte 	node_dhc = &ndlp->node_dhc;
517fcf3ce44SJohn Forte 
518fcf3ce44SJohn Forte 	/* Get auth status object */
51982527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
520fcf3ce44SJohn Forte 		auth_status = &port_dhc->auth_status;
521fcf3ce44SJohn Forte 	} else if (node_dhc->parent_auth_cfg) {
522fcf3ce44SJohn Forte 		auth_status = &node_dhc->parent_auth_cfg->auth_status;
523fcf3ce44SJohn Forte 	} else {
524fcf3ce44SJohn Forte 		/* No auth status to be updated */
525fcf3ce44SJohn Forte 		return;
526fcf3ce44SJohn Forte 	}
527fcf3ce44SJohn Forte 
528fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_status_msg,
529fcf3ce44SJohn Forte 	    "Node:0x%x state=%s rsn=0x%x exp=0x%x (%x,%x)",
530fcf3ce44SJohn Forte 	    ndlp->nlp_DID, emlxs_dhc_nstate_xlate(node_dhc->state), reason,
531fcf3ce44SJohn Forte 	    explaination, auth_status->auth_state,
532fcf3ce44SJohn Forte 	    auth_status->auth_failReason);
533fcf3ce44SJohn Forte 
534fcf3ce44SJohn Forte 	/* Set state and auth_failReason */
535fcf3ce44SJohn Forte 	switch (node_dhc->state) {
536fcf3ce44SJohn Forte 	case NODE_STATE_UNKNOWN:	/* Connection */
537fcf3ce44SJohn Forte 		if (auth_status->auth_state != DFC_AUTH_STATE_FAILED) {
538fcf3ce44SJohn Forte 			auth_status->auth_state = DFC_AUTH_STATE_OFF;
539fcf3ce44SJohn Forte 			auth_status->auth_failReason = 0;
540fcf3ce44SJohn Forte 		}
541fcf3ce44SJohn Forte 		break;
542fcf3ce44SJohn Forte 
543fcf3ce44SJohn Forte 	case NODE_STATE_AUTH_DISABLED:
544fcf3ce44SJohn Forte 		auth_status->auth_state = DFC_AUTH_STATE_OFF;
545fcf3ce44SJohn Forte 		auth_status->auth_failReason = 0;
546fcf3ce44SJohn Forte 		break;
547fcf3ce44SJohn Forte 
548fcf3ce44SJohn Forte 	case NODE_STATE_AUTH_FAILED:
549fcf3ce44SJohn Forte 		/* Check failure reason and update if neccessary */
550fcf3ce44SJohn Forte 		switch (reason) {
551fcf3ce44SJohn Forte 		case AUTHRJT_FAILURE:	/* 0x01 */
552fcf3ce44SJohn Forte 		case AUTHRJT_LOGIC_ERR:	/* 0x02 */
553fcf3ce44SJohn Forte 			auth_status->auth_state = DFC_AUTH_STATE_FAILED;
554fcf3ce44SJohn Forte 			auth_status->auth_failReason = DFC_AUTH_FAIL_REJECTED;
555fcf3ce44SJohn Forte 			break;
556fcf3ce44SJohn Forte 
557fcf3ce44SJohn Forte 		case LSRJT_AUTH_REQUIRED:	/* 0x03 */
558fcf3ce44SJohn Forte 			switch (explaination) {
559fcf3ce44SJohn Forte 			case LSEXP_AUTH_REQUIRED:
560fcf3ce44SJohn Forte 				auth_status->auth_state = DFC_AUTH_STATE_FAILED;
561fcf3ce44SJohn Forte 				auth_status->auth_failReason =
562fcf3ce44SJohn Forte 				    DFC_AUTH_FAIL_LS_RJT;
563fcf3ce44SJohn Forte 				break;
564fcf3ce44SJohn Forte 			default:
565fcf3ce44SJohn Forte 				auth_status->auth_state = DFC_AUTH_STATE_FAILED;
566fcf3ce44SJohn Forte 				auth_status->auth_failReason =
567fcf3ce44SJohn Forte 				    DFC_AUTH_FAIL_REJECTED;
568fcf3ce44SJohn Forte 			}
569fcf3ce44SJohn Forte 			break;
570fcf3ce44SJohn Forte 
571fcf3ce44SJohn Forte 		case LSRJT_AUTH_LOGICAL_BSY:	/* 0x05 */
572fcf3ce44SJohn Forte 			auth_status->auth_state = DFC_AUTH_STATE_FAILED;
573fcf3ce44SJohn Forte 			auth_status->auth_failReason = DFC_AUTH_FAIL_BSY_LS_RJT;
574fcf3ce44SJohn Forte 			break;
575fcf3ce44SJohn Forte 
576fcf3ce44SJohn Forte 		case LSRJT_AUTH_ELS_NOT_SUPPORTED:	/* 0x0B */
577fcf3ce44SJohn Forte 			auth_status->auth_state = DFC_AUTH_STATE_FAILED;
578fcf3ce44SJohn Forte 			auth_status->auth_failReason = DFC_AUTH_FAIL_LS_RJT;
579fcf3ce44SJohn Forte 			break;
580fcf3ce44SJohn Forte 
581fcf3ce44SJohn Forte 		case LSRJT_AUTH_NOT_LOGGED_IN:	/* 0x09 */
582fcf3ce44SJohn Forte 			auth_status->auth_state = DFC_AUTH_STATE_FAILED;
583fcf3ce44SJohn Forte 			auth_status->auth_failReason = DFC_AUTH_FAIL_BSY_LS_RJT;
584fcf3ce44SJohn Forte 			break;
585fcf3ce44SJohn Forte 		}
586fcf3ce44SJohn Forte 
587fcf3ce44SJohn Forte 		/* Make sure the state is set to failed at this point */
588fcf3ce44SJohn Forte 		if (auth_status->auth_state != DFC_AUTH_STATE_FAILED) {
589fcf3ce44SJohn Forte 			auth_status->auth_state = DFC_AUTH_STATE_FAILED;
590fcf3ce44SJohn Forte 			auth_status->auth_failReason = DFC_AUTH_FAIL_GENERIC;
591fcf3ce44SJohn Forte 		}
592fcf3ce44SJohn Forte 		break;
593fcf3ce44SJohn Forte 
594fcf3ce44SJohn Forte 	case NODE_STATE_AUTH_SUCCESS:
595fcf3ce44SJohn Forte 		auth_status->auth_state = DFC_AUTH_STATE_ON;
596fcf3ce44SJohn Forte 		auth_status->auth_failReason = 0;
597fcf3ce44SJohn Forte 		break;
598fcf3ce44SJohn Forte 
599fcf3ce44SJohn Forte 		/* Authentication currently active */
600fcf3ce44SJohn Forte 	default:
601fcf3ce44SJohn Forte 		/* Set defaults */
602fcf3ce44SJohn Forte 		auth_status->auth_state = DFC_AUTH_STATE_INP;
603fcf3ce44SJohn Forte 		auth_status->auth_failReason = 0;
604fcf3ce44SJohn Forte 
605fcf3ce44SJohn Forte 		/* Check codes for exceptions */
606fcf3ce44SJohn Forte 		switch (reason) {
607fcf3ce44SJohn Forte 		case AUTHRJT_FAILURE:	/* 0x01 */
608fcf3ce44SJohn Forte 			switch (explaination) {
609fcf3ce44SJohn Forte 			case AUTHEXP_AUTH_FAILED:	/* 0x05 */
610fcf3ce44SJohn Forte 			case AUTHEXP_BAD_PAYLOAD:	/* 0x06 */
611fcf3ce44SJohn Forte 			case AUTHEXP_BAD_PROTOCOL:	/* 0x07 */
612fcf3ce44SJohn Forte 				auth_status->auth_state = DFC_AUTH_STATE_FAILED;
613fcf3ce44SJohn Forte 				auth_status->auth_failReason =
614fcf3ce44SJohn Forte 				    DFC_AUTH_FAIL_REJECTED;
615fcf3ce44SJohn Forte 				break;
616fcf3ce44SJohn Forte 			}
617fcf3ce44SJohn Forte 			break;
618fcf3ce44SJohn Forte 
619fcf3ce44SJohn Forte 		case AUTHRJT_LOGIC_ERR:	/* 0x02 */
620fcf3ce44SJohn Forte 			switch (explaination) {
621fcf3ce44SJohn Forte 			case AUTHEXP_MECH_UNUSABLE:	/* 0x01 */
622fcf3ce44SJohn Forte 			case AUTHEXP_DHGROUP_UNUSABLE:	/* 0x02 */
623fcf3ce44SJohn Forte 			case AUTHEXP_HASHFUNC_UNUSABLE:	/* 0x03 */
624fcf3ce44SJohn Forte 			case AUTHEXP_CONCAT_UNSUPP:	/* 0x09 */
625fcf3ce44SJohn Forte 			case AUTHEXP_BAD_PROTOVERS:	/* 0x0A */
626fcf3ce44SJohn Forte 				auth_status->auth_state = DFC_AUTH_STATE_FAILED;
627fcf3ce44SJohn Forte 				auth_status->auth_failReason =
628fcf3ce44SJohn Forte 				    DFC_AUTH_FAIL_REJECTED;
629fcf3ce44SJohn Forte 				break;
630fcf3ce44SJohn Forte 			}
631fcf3ce44SJohn Forte 			break;
632fcf3ce44SJohn Forte 
633fcf3ce44SJohn Forte 		case LSRJT_AUTH_REQUIRED:	/* 0x03 */
634fcf3ce44SJohn Forte 			switch (explaination) {
635fcf3ce44SJohn Forte 			case LSEXP_AUTH_REQUIRED:
636fcf3ce44SJohn Forte 				auth_status->auth_state = DFC_AUTH_STATE_FAILED;
637fcf3ce44SJohn Forte 				auth_status->auth_failReason =
638fcf3ce44SJohn Forte 				    DFC_AUTH_FAIL_LS_RJT;
639fcf3ce44SJohn Forte 				break;
640fcf3ce44SJohn Forte 			}
641fcf3ce44SJohn Forte 			break;
642fcf3ce44SJohn Forte 
643fcf3ce44SJohn Forte 		case LSRJT_AUTH_LOGICAL_BSY:	/* 0x05 */
644fcf3ce44SJohn Forte 			auth_status->auth_state = DFC_AUTH_STATE_FAILED;
645fcf3ce44SJohn Forte 			auth_status->auth_failReason = DFC_AUTH_FAIL_BSY_LS_RJT;
646fcf3ce44SJohn Forte 			break;
647fcf3ce44SJohn Forte 
648fcf3ce44SJohn Forte 		case LSRJT_AUTH_ELS_NOT_SUPPORTED:	/* 0x0B */
649fcf3ce44SJohn Forte 			auth_status->auth_state = DFC_AUTH_STATE_FAILED;
650fcf3ce44SJohn Forte 			auth_status->auth_failReason = DFC_AUTH_FAIL_LS_RJT;
651fcf3ce44SJohn Forte 			break;
652fcf3ce44SJohn Forte 
653fcf3ce44SJohn Forte 		case LSRJT_AUTH_NOT_LOGGED_IN:	/* 0x09 */
654fcf3ce44SJohn Forte 			auth_status->auth_state = DFC_AUTH_STATE_FAILED;
655fcf3ce44SJohn Forte 			auth_status->auth_failReason = DFC_AUTH_FAIL_BSY_LS_RJT;
656fcf3ce44SJohn Forte 			break;
657fcf3ce44SJohn Forte 		}
658fcf3ce44SJohn Forte 		break;
659fcf3ce44SJohn Forte 	}
660fcf3ce44SJohn Forte 
661fcf3ce44SJohn Forte 	if (auth_status->auth_state != DFC_AUTH_STATE_ON) {
662fcf3ce44SJohn Forte 		auth_status->time_until_next_auth = 0;
663fcf3ce44SJohn Forte 		auth_status->localAuth = 0;
664fcf3ce44SJohn Forte 		auth_status->remoteAuth = 0;
665fcf3ce44SJohn Forte 		auth_status->group_priority = 0;
666fcf3ce44SJohn Forte 		auth_status->hash_priority = 0;
667fcf3ce44SJohn Forte 		auth_status->type_priority = 0;
668fcf3ce44SJohn Forte 	} else {
669fcf3ce44SJohn Forte 		switch (node_dhc->nlp_reauth_status) {
670fcf3ce44SJohn Forte 		case NLP_HOST_REAUTH_ENABLED:
671fcf3ce44SJohn Forte 		case NLP_HOST_REAUTH_IN_PROGRESS:
672fcf3ce44SJohn Forte 			drv_time = DRV_TIME;
673fcf3ce44SJohn Forte 
674fcf3ce44SJohn Forte 			if (node_dhc->nlp_reauth_tmo > drv_time) {
675fcf3ce44SJohn Forte 				auth_status->time_until_next_auth =
676fcf3ce44SJohn Forte 				    node_dhc->nlp_reauth_tmo - drv_time;
677fcf3ce44SJohn Forte 			} else {
678fcf3ce44SJohn Forte 				auth_status->time_until_next_auth = 0;
679fcf3ce44SJohn Forte 			}
680fcf3ce44SJohn Forte 			break;
681fcf3ce44SJohn Forte 
682fcf3ce44SJohn Forte 		case NLP_HOST_REAUTH_DISABLED:
683fcf3ce44SJohn Forte 		default:
684fcf3ce44SJohn Forte 			auth_status->time_until_next_auth = 0;
685fcf3ce44SJohn Forte 			break;
686fcf3ce44SJohn Forte 		}
687fcf3ce44SJohn Forte 
688fcf3ce44SJohn Forte 		if (node_dhc->flag & NLP_REMOTE_AUTH) {
689fcf3ce44SJohn Forte 			auth_status->localAuth = 0;
690fcf3ce44SJohn Forte 			auth_status->remoteAuth = 1;
691fcf3ce44SJohn Forte 		} else {
692fcf3ce44SJohn Forte 			auth_status->localAuth = 1;
693fcf3ce44SJohn Forte 			auth_status->remoteAuth = 0;
694fcf3ce44SJohn Forte 		}
695fcf3ce44SJohn Forte 
696fcf3ce44SJohn Forte 		auth_status->type_priority = DFC_AUTH_TYPE_DHCHAP;
697fcf3ce44SJohn Forte 
698fcf3ce44SJohn Forte 		switch (node_dhc->nlp_auth_dhgpid) {
699fcf3ce44SJohn Forte 		case GROUP_NULL:
700fcf3ce44SJohn Forte 			auth_status->group_priority = ELX_GROUP_NULL;
701fcf3ce44SJohn Forte 			break;
702fcf3ce44SJohn Forte 
703fcf3ce44SJohn Forte 		case GROUP_1024:
704fcf3ce44SJohn Forte 			auth_status->group_priority = ELX_GROUP_1024;
705fcf3ce44SJohn Forte 			break;
706fcf3ce44SJohn Forte 
707fcf3ce44SJohn Forte 		case GROUP_1280:
708fcf3ce44SJohn Forte 			auth_status->group_priority = ELX_GROUP_1280;
709fcf3ce44SJohn Forte 			break;
710fcf3ce44SJohn Forte 
711fcf3ce44SJohn Forte 		case GROUP_1536:
712fcf3ce44SJohn Forte 			auth_status->group_priority = ELX_GROUP_1536;
713fcf3ce44SJohn Forte 			break;
714fcf3ce44SJohn Forte 
715fcf3ce44SJohn Forte 		case GROUP_2048:
716fcf3ce44SJohn Forte 			auth_status->group_priority = ELX_GROUP_2048;
717fcf3ce44SJohn Forte 			break;
718fcf3ce44SJohn Forte 		}
719fcf3ce44SJohn Forte 
720fcf3ce44SJohn Forte 		switch (node_dhc->nlp_auth_hashid) {
721fcf3ce44SJohn Forte 		case 0:
722fcf3ce44SJohn Forte 			auth_status->hash_priority = 0;
723fcf3ce44SJohn Forte 			break;
724fcf3ce44SJohn Forte 
725fcf3ce44SJohn Forte 		case AUTH_SHA1:
726fcf3ce44SJohn Forte 			auth_status->hash_priority = ELX_SHA1;
727fcf3ce44SJohn Forte 			break;
728fcf3ce44SJohn Forte 
729fcf3ce44SJohn Forte 		case AUTH_MD5:
730fcf3ce44SJohn Forte 			auth_status->hash_priority = ELX_MD5;
731fcf3ce44SJohn Forte 			break;
732fcf3ce44SJohn Forte 		}
733fcf3ce44SJohn Forte 	}
734fcf3ce44SJohn Forte 
735fcf3ce44SJohn Forte 	return;
736fcf3ce44SJohn Forte 
737fcf3ce44SJohn Forte } /* emlxs_dhc_status()  */
738fcf3ce44SJohn Forte 
739fcf3ce44SJohn Forte static char *
emlxs_dhc_pstate_xlate(uint32_t state)740fcf3ce44SJohn Forte emlxs_dhc_pstate_xlate(uint32_t state)
741fcf3ce44SJohn Forte {
742fcf3ce44SJohn Forte 	static char buffer[32];
743fcf3ce44SJohn Forte 	uint32_t i;
744fcf3ce44SJohn Forte 	uint32_t count;
745fcf3ce44SJohn Forte 
746fcf3ce44SJohn Forte 	count = sizeof (emlxs_pstate_table) / sizeof (emlxs_table_t);
747fcf3ce44SJohn Forte 	for (i = 0; i < count; i++) {
748fcf3ce44SJohn Forte 		if (state == emlxs_pstate_table[i].code) {
749fcf3ce44SJohn Forte 			return (emlxs_pstate_table[i].string);
750fcf3ce44SJohn Forte 		}
751fcf3ce44SJohn Forte 	}
752fcf3ce44SJohn Forte 
753*8f23e9faSHans Rosenfeld 	(void) snprintf(buffer, sizeof (buffer), "state=0x%x", state);
754fcf3ce44SJohn Forte 	return (buffer);
755fcf3ce44SJohn Forte 
756fcf3ce44SJohn Forte } /* emlxs_dhc_pstate_xlate() */
757fcf3ce44SJohn Forte 
758fcf3ce44SJohn Forte 
759fcf3ce44SJohn Forte static char *
emlxs_dhc_nstate_xlate(uint32_t state)760fcf3ce44SJohn Forte emlxs_dhc_nstate_xlate(uint32_t state)
761fcf3ce44SJohn Forte {
762fcf3ce44SJohn Forte 	static char buffer[32];
763fcf3ce44SJohn Forte 	uint32_t i;
764fcf3ce44SJohn Forte 	uint32_t count;
765fcf3ce44SJohn Forte 
766fcf3ce44SJohn Forte 	count = sizeof (emlxs_nstate_table) / sizeof (emlxs_table_t);
767fcf3ce44SJohn Forte 	for (i = 0; i < count; i++) {
768fcf3ce44SJohn Forte 		if (state == emlxs_nstate_table[i].code) {
769fcf3ce44SJohn Forte 			return (emlxs_nstate_table[i].string);
770fcf3ce44SJohn Forte 		}
771fcf3ce44SJohn Forte 	}
772fcf3ce44SJohn Forte 
773*8f23e9faSHans Rosenfeld 	(void) snprintf(buffer, sizeof (buffer), "state=0x%x", state);
774fcf3ce44SJohn Forte 	return (buffer);
775fcf3ce44SJohn Forte 
776fcf3ce44SJohn Forte } /* emlxs_dhc_nstate_xlate() */
777fcf3ce44SJohn Forte 
778fcf3ce44SJohn Forte 
779fcf3ce44SJohn Forte static uint32_t
emlxs_check_dhgp(emlxs_port_t * port,NODELIST * ndlp,uint32_t * dh_id,uint16_t cnt,uint32_t * dhgp_id)780fcf3ce44SJohn Forte emlxs_check_dhgp(
781fcf3ce44SJohn Forte 	emlxs_port_t *port,
782fcf3ce44SJohn Forte 	NODELIST *ndlp,
783fcf3ce44SJohn Forte 	uint32_t *dh_id,
784fcf3ce44SJohn Forte 	uint16_t cnt,
785fcf3ce44SJohn Forte 	uint32_t *dhgp_id)
786fcf3ce44SJohn Forte {
787fcf3ce44SJohn Forte 	uint32_t i, j, rc = 1;
788fcf3ce44SJohn Forte 	uint32_t wnt;
789fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
790fcf3ce44SJohn Forte 
791fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
792fcf3ce44SJohn Forte 	    "dhgp: 0x%x, id[0..4]=0x%x 0x%x 0x%x 0x%x 0x%x pri[1]=0x%x",
793fcf3ce44SJohn Forte 	    cnt, dh_id[0], dh_id[1], dh_id[2], dh_id[3], dh_id[4],
794fcf3ce44SJohn Forte 	    node_dhc->auth_cfg.dh_group_priority[1]);
795fcf3ce44SJohn Forte 
796fcf3ce44SJohn Forte 	/*
797fcf3ce44SJohn Forte 	 * Here are the rules, as the responder We always try to select ours
798fcf3ce44SJohn Forte 	 * highest setup
799fcf3ce44SJohn Forte 	 */
800fcf3ce44SJohn Forte 
801fcf3ce44SJohn Forte 	/* Check to see if there is any repeated dhgp in initiator's list */
802fcf3ce44SJohn Forte 	/* If available, it is a invalid payload */
803fcf3ce44SJohn Forte 	if (cnt >= 2) {
804fcf3ce44SJohn Forte 		for (i = 0; i <= cnt - 2; i++) {
805fcf3ce44SJohn Forte 			for (j = i + 1; j <= cnt - 1; j++) {
806fcf3ce44SJohn Forte 				if (dh_id[i] == dh_id[j]) {
807fcf3ce44SJohn Forte 					rc = 2;
808fcf3ce44SJohn Forte 					EMLXS_MSGF(EMLXS_CONTEXT,
809fcf3ce44SJohn Forte 					    &emlxs_fcsp_detail_msg,
810fcf3ce44SJohn Forte 					    ":Rpt dhid[%x]=%x dhid[%x]=%x",
811fcf3ce44SJohn Forte 					    i, dh_id[i], j, dh_id[j]);
812fcf3ce44SJohn Forte 					break;
813fcf3ce44SJohn Forte 				}
814fcf3ce44SJohn Forte 			}
815fcf3ce44SJohn Forte 
816fcf3ce44SJohn Forte 			if (rc == 2) {
817fcf3ce44SJohn Forte 				break;
818fcf3ce44SJohn Forte 			}
819fcf3ce44SJohn Forte 		}
820fcf3ce44SJohn Forte 
821fcf3ce44SJohn Forte 		if ((i == cnt - 1) && (j == cnt)) {
822fcf3ce44SJohn Forte 			rc = 1;
823fcf3ce44SJohn Forte 		}
824fcf3ce44SJohn Forte 		if (rc == 2) {
825fcf3ce44SJohn Forte 			/* duplicate invalid payload */
826fcf3ce44SJohn Forte 			return (rc);
827fcf3ce44SJohn Forte 		}
828fcf3ce44SJohn Forte 	}
829fcf3ce44SJohn Forte 	/* Check how many dhgps the responder specified */
830fcf3ce44SJohn Forte 	wnt = 0;
831fcf3ce44SJohn Forte 	while (node_dhc->auth_cfg.dh_group_priority[wnt] != 0xF) {
832fcf3ce44SJohn Forte 		wnt++;
833fcf3ce44SJohn Forte 	}
834fcf3ce44SJohn Forte 
835fcf3ce44SJohn Forte 	/* Determine the most suitable dhgp the responder should use */
836fcf3ce44SJohn Forte 	for (i = 0; i < wnt; i++) {
837fcf3ce44SJohn Forte 		for (j = 0; j < cnt; j++) {
838fcf3ce44SJohn Forte 			if (node_dhc->auth_cfg.dh_group_priority[i] ==
839fcf3ce44SJohn Forte 			    dh_id[j]) {
840fcf3ce44SJohn Forte 				rc = 0;
841fcf3ce44SJohn Forte 				*dhgp_id =
842fcf3ce44SJohn Forte 				    node_dhc->auth_cfg.dh_group_priority[i];
843fcf3ce44SJohn Forte 				break;
844fcf3ce44SJohn Forte 			}
845fcf3ce44SJohn Forte 		}
846fcf3ce44SJohn Forte 
847fcf3ce44SJohn Forte 		if (rc == 0) {
848fcf3ce44SJohn Forte 			break;
849fcf3ce44SJohn Forte 		}
850fcf3ce44SJohn Forte 	}
851fcf3ce44SJohn Forte 
852fcf3ce44SJohn Forte 	if (i == wnt) {
853fcf3ce44SJohn Forte 		/* no match */
854fcf3ce44SJohn Forte 		rc = 1;
855fcf3ce44SJohn Forte 		return (1);
856fcf3ce44SJohn Forte 	}
857fcf3ce44SJohn Forte 
858fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
859*8f23e9faSHans Rosenfeld 	    "check_dhgp: dhgp_id=0x%x", *dhgp_id);
860fcf3ce44SJohn Forte 
861fcf3ce44SJohn Forte 	return (rc);
862fcf3ce44SJohn Forte } /* emlxs_check_dhgp */
863fcf3ce44SJohn Forte 
864fcf3ce44SJohn Forte 
865fcf3ce44SJohn Forte static void
emlxs_get_random_bytes(NODELIST * ndlp,uint8_t * rdn,uint32_t len)866fcf3ce44SJohn Forte emlxs_get_random_bytes(
867fcf3ce44SJohn Forte 	NODELIST *ndlp,
868fcf3ce44SJohn Forte 	uint8_t *rdn,
869fcf3ce44SJohn Forte 	uint32_t len)
870fcf3ce44SJohn Forte {
871fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
872fcf3ce44SJohn Forte 	hrtime_t now;
873fcf3ce44SJohn Forte 	uint8_t sha1_digest[20];
874fcf3ce44SJohn Forte 	SHA1_CTX sha1ctx;
875fcf3ce44SJohn Forte 
876fcf3ce44SJohn Forte 	now = gethrtime();
877fcf3ce44SJohn Forte 
878fcf3ce44SJohn Forte 	bzero(&sha1ctx, sizeof (SHA1_CTX));
879fcf3ce44SJohn Forte 	SHA1Init(&sha1ctx);
880fcf3ce44SJohn Forte 	SHA1Update(&sha1ctx, (void *) &node_dhc->auth_cfg.local_entity,
881fcf3ce44SJohn Forte 	    sizeof (NAME_TYPE));
882fcf3ce44SJohn Forte 	SHA1Update(&sha1ctx, (void *) &now, sizeof (hrtime_t));
883fcf3ce44SJohn Forte 	SHA1Final((void *) sha1_digest, &sha1ctx);
884fcf3ce44SJohn Forte 	bcopy((void *) &sha1_digest[0], (void *) &rdn[0], len);
885fcf3ce44SJohn Forte 
886fcf3ce44SJohn Forte 	return;
887fcf3ce44SJohn Forte 
888fcf3ce44SJohn Forte } /* emlxs_get_random_bytes */
889fcf3ce44SJohn Forte 
890fcf3ce44SJohn Forte 
891fcf3ce44SJohn Forte /* **************************** STATE MACHINE ************************** */
892fcf3ce44SJohn Forte 
893fcf3ce44SJohn Forte static void *emlxs_dhchap_action[] =
894fcf3ce44SJohn Forte {
895fcf3ce44SJohn Forte 	/* Action routine		Event */
896fcf3ce44SJohn Forte 
897fcf3ce44SJohn Forte /* NODE_STATE_UNKNOWN  0x00 */
898fcf3ce44SJohn Forte 	(void *) emlxs_disc_neverdev,	/* DEVICE_RM */
899fcf3ce44SJohn Forte 	(void *) emlxs_disc_neverdev,	/* DEVICE_RECOVERY */
900fcf3ce44SJohn Forte 	(void *) emlxs_disc_neverdev,	/* RCV_AUTH_MSG */
901fcf3ce44SJohn Forte 	(void *) emlxs_disc_neverdev,	/* CMPL_AUTH_MSG */
902fcf3ce44SJohn Forte 
903fcf3ce44SJohn Forte /* NODE_STATE_AUTH_DISABLED  0x01 */
904fcf3ce44SJohn Forte 	(void *) emlxs_disc_neverdev,	/* DEVICE_RM */
905fcf3ce44SJohn Forte 	(void *) emlxs_disc_neverdev,	/* DEVICE_RECOVERY */
906fcf3ce44SJohn Forte 	(void *) emlxs_disc_neverdev,	/* RCV_AUTH_MSG */
907fcf3ce44SJohn Forte 	(void *) emlxs_disc_neverdev,	/* CMPL_AUTH_MSG */
908fcf3ce44SJohn Forte 
909fcf3ce44SJohn Forte /* NODE_STATE_AUTH_FAILED  0x02 */
910fcf3ce44SJohn Forte 	(void *) emlxs_device_rm_npr_node,	/* DEVICE_RM */
911fcf3ce44SJohn Forte 	(void *) emlxs_device_recov_npr_node,	/* DEVICE_RECOVERY */
912fcf3ce44SJohn Forte 	(void *) emlxs_rcv_auth_msg_npr_node,	/* RCV_AUTH_MSG */
913fcf3ce44SJohn Forte 	(void *) emlxs_cmpl_auth_msg_npr_node,	/* CMPL_AUTH_MSG */
914fcf3ce44SJohn Forte 
915fcf3ce44SJohn Forte /* NODE_STATE_AUTH_SUCCESS  0x03 */
916fcf3ce44SJohn Forte 	(void *) emlxs_disc_neverdev,			/* DEVICE_RM */
917fcf3ce44SJohn Forte 	(void *) emlxs_device_recov_unmapped_node,	/* DEVICE_RECOVERY */
918fcf3ce44SJohn Forte 	(void *) emlxs_rcv_auth_msg_unmapped_node,	/* RCV_AUTH_MSG */
919fcf3ce44SJohn Forte 	(void *) emlxs_disc_neverdev,			/* CMPL_AUTH_MSG */
920fcf3ce44SJohn Forte 
921fcf3ce44SJohn Forte /* NODE_STATE_AUTH_NEGOTIATE_ISSUE  0x04 */
922fcf3ce44SJohn Forte 	(void *) emlxs_device_rem_auth,	/* DEVICE_RM */
923fcf3ce44SJohn Forte 	(void *) emlxs_device_recov_auth, /* DEVICE_RECOVERY */
924fcf3ce44SJohn Forte 	(void *) emlxs_rcv_auth_msg_auth_negotiate_issue, /* RCV_AUTH_MSG  */
925fcf3ce44SJohn Forte 	(void *) emlxs_cmpl_auth_msg_auth_negotiate_issue, /* CMPL_AUTH_MSG */
926fcf3ce44SJohn Forte 
927fcf3ce44SJohn Forte /* NODE_STATE_AUTH_NEGOTIATE_RCV  0x05 */
928fcf3ce44SJohn Forte 	(void *) emlxs_device_rem_auth,	/* DEVICE_RM */
929fcf3ce44SJohn Forte 	(void *) emlxs_device_recov_auth,	/* DEVICE_RECOVERY */
930fcf3ce44SJohn Forte 	(void *) emlxs_rcv_auth_msg_auth_negotiate_rcv,	/* RCV_AUTH_MSG */
931fcf3ce44SJohn Forte 	(void *) emlxs_cmpl_auth_msg_auth_negotiate_rcv, /* CMPL_AUTH_MSG */
932fcf3ce44SJohn Forte 
933fcf3ce44SJohn Forte /* NODE_STATE_AUTH_NEGOTIATE_CMPL_WAIT4NEXT  0x06 */
934fcf3ce44SJohn Forte 	(void *) emlxs_device_rem_auth,	/* DEVICE_RM */
935fcf3ce44SJohn Forte 	(void *) emlxs_device_recov_auth,	/* DEVICE_RECOVERY */
936fcf3ce44SJohn Forte 	(void *) emlxs_rcv_auth_msg_auth_negotiate_cmpl_wait4next,
937fcf3ce44SJohn Forte 						/* RCV_AUTH_MSG */
938fcf3ce44SJohn Forte 	(void *) emlxs_cmpl_auth_msg_auth_negotiate_cmpl_wait4next,
939fcf3ce44SJohn Forte 						/* CMPL_AUTH_MSG */
940fcf3ce44SJohn Forte 
941fcf3ce44SJohn Forte /* NODE_STATE_DHCHAP_CHALLENGE_ISSUE  0x07 */
942fcf3ce44SJohn Forte 	(void *) emlxs_device_rem_auth,	/* DEVICE_RM */
943fcf3ce44SJohn Forte 	(void *) emlxs_device_recov_auth,	/* DEVICE_RECOVERY */
944fcf3ce44SJohn Forte 	(void *) emlxs_rcv_auth_msg_dhchap_challenge_issue, /* RCV_AUTH_MSG */
945fcf3ce44SJohn Forte 	(void *) emlxs_cmpl_auth_msg_dhchap_challenge_issue, /* CMPL_AUTH_MSG */
946fcf3ce44SJohn Forte 
947fcf3ce44SJohn Forte /* NODE_STATE_DHCHAP_REPLY_ISSUE  0x08 */
948fcf3ce44SJohn Forte 	(void *) emlxs_device_rem_auth,	/* DEVICE_RM */
949fcf3ce44SJohn Forte 	(void *) emlxs_device_recov_auth,	/* DEVICE_RECOVERY */
950fcf3ce44SJohn Forte 	(void *) emlxs_rcv_auth_msg_dhchap_reply_issue,	/* RCV_AUTH_MSG */
951fcf3ce44SJohn Forte 	(void *) emlxs_cmpl_auth_msg_dhchap_reply_issue, /* CMPL_AUTH_MSG */
952fcf3ce44SJohn Forte 
953fcf3ce44SJohn Forte /* NODE_STATE_DHCHAP_CHALLENGE_CMPL_WAIT4NEXT  0x09 */
954fcf3ce44SJohn Forte 	(void *) emlxs_device_rem_auth,	/* DEVICE_RM */
955fcf3ce44SJohn Forte 	(void *) emlxs_device_recov_auth,	/* DEVICE_RECOVERY */
956fcf3ce44SJohn Forte 	(void *) emlxs_rcv_auth_msg_dhchap_challenge_cmpl_wait4next,
957fcf3ce44SJohn Forte 						/* RCV_AUTH_MSG   */
958fcf3ce44SJohn Forte 	(void *) emlxs_cmpl_auth_msg_dhchap_challenge_cmpl_wait4next,
959fcf3ce44SJohn Forte 						/* CMPL_AUTH_MSG */
960fcf3ce44SJohn Forte 
961fcf3ce44SJohn Forte /* NODE_STATE_DHCHAP_REPLY_CMPL_WAIT4NEXT  0x0A */
962fcf3ce44SJohn Forte 	(void *) emlxs_device_rem_auth,	/* DEVICE_RM */
963fcf3ce44SJohn Forte 	(void *) emlxs_device_recov_auth,	/* DEVICE_RECOVERY */
964fcf3ce44SJohn Forte 	(void *) emlxs_rcv_auth_msg_dhchap_reply_cmpl_wait4next,
965fcf3ce44SJohn Forte 						/* RCV_AUTH_MSG */
966fcf3ce44SJohn Forte 	(void *) emlxs_cmpl_auth_msg_dhchap_reply_cmpl_wait4next,
967fcf3ce44SJohn Forte 						/* CMPL_AUTH_MSG */
968fcf3ce44SJohn Forte 
969fcf3ce44SJohn Forte /* NODE_STATE_DHCHAP_SUCCESS_ISSUE  0x0B */
970fcf3ce44SJohn Forte 	(void *) emlxs_device_rem_auth,	/* DEVICE_RM */
971fcf3ce44SJohn Forte 	(void *) emlxs_device_recov_auth,	/* DEVICE_RECOVERY */
972fcf3ce44SJohn Forte 	(void *) emlxs_rcv_auth_msg_dhchap_success_issue,
973fcf3ce44SJohn Forte 						/* RCV_AUTH_MSG */
974fcf3ce44SJohn Forte 	(void *) emlxs_cmpl_auth_msg_dhchap_success_issue,
975fcf3ce44SJohn Forte 						/* CMPL_AUTH_MSG */
976fcf3ce44SJohn Forte 
977fcf3ce44SJohn Forte /* NODE_STATE_DHCHAP_SUCCESS_ISSUE_WAIT4NEXT  0x0C */
978fcf3ce44SJohn Forte 	(void *) emlxs_device_rem_auth,	/* DEVICE_RM */
979fcf3ce44SJohn Forte 	(void *) emlxs_device_recov_auth,	/* DEVICE_RECOVERY */
980fcf3ce44SJohn Forte 	(void *) emlxs_rcv_auth_msg_dhchap_success_issue_wait4next,
981fcf3ce44SJohn Forte 						/* RCV_AUTH_MSG */
982fcf3ce44SJohn Forte 	(void *) emlxs_cmpl_auth_msg_dhchap_success_issue_wait4next,
983fcf3ce44SJohn Forte 						/* CMPL_AUTH_MSG */
984fcf3ce44SJohn Forte 
985fcf3ce44SJohn Forte /* NODE_STATE_DHCHAP_SUCCESS_CMPL_WAIT4NEXT  0x0D */
986fcf3ce44SJohn Forte 	(void *) emlxs_device_rem_auth,	/* DEVICE_RM */
987fcf3ce44SJohn Forte 	(void *) emlxs_device_recov_auth,	/* DEVICE_RECOVERY */
988fcf3ce44SJohn Forte 	(void *) emlxs_rcv_auth_msg_dhchap_success_cmpl_wait4next,
989fcf3ce44SJohn Forte 						/* RCV_AUTH_MSG */
990fcf3ce44SJohn Forte 	(void *) emlxs_cmpl_auth_msg_dhchap_success_cmpl_wait4next,
991fcf3ce44SJohn Forte 						/* CMPL_AUTH_MSG */
992fcf3ce44SJohn Forte 
993fcf3ce44SJohn Forte }; /* emlxs_dhchap_action[] */
994fcf3ce44SJohn Forte 
995fcf3ce44SJohn Forte 
996fcf3ce44SJohn Forte extern int
emlxs_dhchap_state_machine(emlxs_port_t * port,CHANNEL * cp,IOCBQ * iocbq,MATCHMAP * mp,NODELIST * ndlp,int evt)99782527734SSukumar Swaminathan emlxs_dhchap_state_machine(emlxs_port_t *port, CHANNEL *cp,
998fcf3ce44SJohn Forte 		IOCBQ *iocbq, MATCHMAP *mp,
999fcf3ce44SJohn Forte 		NODELIST *ndlp, int evt)
1000fcf3ce44SJohn Forte {
1001fcf3ce44SJohn Forte 	emlxs_hba_t *hba = HBA;
1002fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
1003fcf3ce44SJohn Forte 	uint32_t rc;
100482527734SSukumar Swaminathan 	uint32_t(*func) (emlxs_port_t *, CHANNEL *, IOCBQ *, MATCHMAP *,
1005fcf3ce44SJohn Forte 	    NODELIST *, uint32_t);
1006fcf3ce44SJohn Forte 
1007fcf3ce44SJohn Forte 	mutex_enter(&hba->dhc_lock);
1008fcf3ce44SJohn Forte 
1009fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_event_msg,
1010fcf3ce44SJohn Forte 	    "%s: did=0x%x",
1011fcf3ce44SJohn Forte 	    emlxs_dhc_event_xlate(evt), ndlp->nlp_DID);
1012fcf3ce44SJohn Forte 
1013fcf3ce44SJohn Forte 	node_dhc->disc_refcnt++;
1014fcf3ce44SJohn Forte 
101582527734SSukumar Swaminathan 	func = (uint32_t(*) (emlxs_port_t *, CHANNEL *, IOCBQ *, MATCHMAP *,
1016fcf3ce44SJohn Forte 	    NODELIST *, uint32_t))
1017fcf3ce44SJohn Forte 	    emlxs_dhchap_action[(node_dhc->state * NODE_EVENT_MAX_EVENT) + evt];
1018fcf3ce44SJohn Forte 
101982527734SSukumar Swaminathan 	rc = (func) (port, cp, iocbq, mp, ndlp, evt);
1020fcf3ce44SJohn Forte 
1021fcf3ce44SJohn Forte 	node_dhc->disc_refcnt--;
1022fcf3ce44SJohn Forte 
1023fcf3ce44SJohn Forte 	mutex_exit(&hba->dhc_lock);
1024fcf3ce44SJohn Forte 
1025fcf3ce44SJohn Forte 	return (rc);
1026fcf3ce44SJohn Forte 
1027fcf3ce44SJohn Forte } /* emlxs_dhchap_state_machine() */
1028fcf3ce44SJohn Forte 
1029fcf3ce44SJohn Forte /* ARGSUSED */
1030fcf3ce44SJohn Forte static uint32_t
emlxs_disc_neverdev(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)1031fcf3ce44SJohn Forte emlxs_disc_neverdev(
1032fcf3ce44SJohn Forte emlxs_port_t *port,
103382527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
1034fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
1035fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
1036fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
1037fcf3ce44SJohn Forte uint32_t evt)
1038fcf3ce44SJohn Forte {
1039fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *) arg4;
1040fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
1041fcf3ce44SJohn Forte 
1042fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
1043*8f23e9faSHans Rosenfeld 	    "disc_neverdev: did=0x%x.",
1044fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
1045fcf3ce44SJohn Forte 
1046fcf3ce44SJohn Forte 	emlxs_dhc_state(port, ndlp, NODE_STATE_UNKNOWN, 0, 0);
1047fcf3ce44SJohn Forte 
1048fcf3ce44SJohn Forte 	return (node_dhc->state);
1049fcf3ce44SJohn Forte 
1050fcf3ce44SJohn Forte } /* emlxs_disc_neverdev() */
1051fcf3ce44SJohn Forte 
1052fcf3ce44SJohn Forte 
1053fcf3ce44SJohn Forte /*
1054fcf3ce44SJohn Forte  * ! emlxs_cmpl_dhchap_challenge_issue
1055fcf3ce44SJohn Forte  *
1056fcf3ce44SJohn Forte  * \pre \post \param   cmdiocb \param   rspiocb \return  void
1057fcf3ce44SJohn Forte  *
1058fcf3ce44SJohn Forte  * \b Description: iocb_cmpl callback function. when the ELS DHCHAP_Challenge
1059fcf3ce44SJohn Forte  * msg sent back got the ACC/RJT from initiator.
1060fcf3ce44SJohn Forte  *
1061fcf3ce44SJohn Forte  */
1062fcf3ce44SJohn Forte static void
emlxs_cmpl_dhchap_challenge_issue(fc_packet_t * pkt)1063fcf3ce44SJohn Forte emlxs_cmpl_dhchap_challenge_issue(fc_packet_t *pkt)
1064fcf3ce44SJohn Forte {
1065fcf3ce44SJohn Forte 	emlxs_port_t *port = pkt->pkt_ulp_private;
1066fcf3ce44SJohn Forte 	emlxs_buf_t *sbp;
1067fcf3ce44SJohn Forte 	NODELIST *ndlp;
1068fcf3ce44SJohn Forte 	uint32_t did;
1069fcf3ce44SJohn Forte 
1070fcf3ce44SJohn Forte 	did = pkt->pkt_cmd_fhdr.d_id;
1071fcf3ce44SJohn Forte 	sbp = (emlxs_buf_t *)pkt->pkt_fca_private;
1072fcf3ce44SJohn Forte 	ndlp = sbp->node;
1073fcf3ce44SJohn Forte 
1074fcf3ce44SJohn Forte 	if (!ndlp) {
1075*8f23e9faSHans Rosenfeld 		ndlp = emlxs_node_find_did(port, did, 1);
1076fcf3ce44SJohn Forte 	}
1077fcf3ce44SJohn Forte 	if (pkt->pkt_state != FC_PKT_SUCCESS) {
1078fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
1079*8f23e9faSHans Rosenfeld 		    "cmpl_dhchap_challenge_issue: did=0x%x state=%x",
1080fcf3ce44SJohn Forte 		    did, pkt->pkt_state);
1081fcf3ce44SJohn Forte 	} else {
1082fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
1083*8f23e9faSHans Rosenfeld 		    "cmpl_dhchap_challenge_issue: did=0x%x. Succcess.",
1084fcf3ce44SJohn Forte 		    did);
1085fcf3ce44SJohn Forte 	}
1086fcf3ce44SJohn Forte 
1087fcf3ce44SJohn Forte 	if (ndlp) {
1088fcf3ce44SJohn Forte 		if (pkt->pkt_state == FC_PKT_SUCCESS) {
1089fcf3ce44SJohn Forte 			(void) emlxs_dhchap_state_machine(port, NULL, NULL,
1090fcf3ce44SJohn Forte 			    NULL, ndlp, NODE_EVENT_CMPL_AUTH_MSG);
1091fcf3ce44SJohn Forte 		}
1092fcf3ce44SJohn Forte 	}
1093fcf3ce44SJohn Forte 	emlxs_pkt_free(pkt);
1094fcf3ce44SJohn Forte 
1095fcf3ce44SJohn Forte 	return;
1096fcf3ce44SJohn Forte 
1097fcf3ce44SJohn Forte } /* emlxs_cmpl_dhchap_challenge_issue */
1098fcf3ce44SJohn Forte 
1099fcf3ce44SJohn Forte 
1100fcf3ce44SJohn Forte 
1101fcf3ce44SJohn Forte 
1102fcf3ce44SJohn Forte /*
1103fcf3ce44SJohn Forte  * ! emlxs_cmpl_dhchap_success_issue
1104fcf3ce44SJohn Forte  *
1105fcf3ce44SJohn Forte  * \pre \post \param   phba \param   cmdiocb \param   rspiocb \return  void
1106fcf3ce44SJohn Forte  *
1107fcf3ce44SJohn Forte  * \b Description: iocb_cmpl callback function.
1108fcf3ce44SJohn Forte  *
1109fcf3ce44SJohn Forte  */
1110fcf3ce44SJohn Forte static void
emlxs_cmpl_dhchap_success_issue(fc_packet_t * pkt)1111fcf3ce44SJohn Forte emlxs_cmpl_dhchap_success_issue(fc_packet_t *pkt)
1112fcf3ce44SJohn Forte {
1113fcf3ce44SJohn Forte 	emlxs_port_t *port = pkt->pkt_ulp_private;
1114fcf3ce44SJohn Forte 	NODELIST *ndlp;
1115fcf3ce44SJohn Forte 	uint32_t did;
1116fcf3ce44SJohn Forte 	emlxs_buf_t *sbp;
1117fcf3ce44SJohn Forte 
1118fcf3ce44SJohn Forte 	did = pkt->pkt_cmd_fhdr.d_id;
1119fcf3ce44SJohn Forte 	sbp = (emlxs_buf_t *)pkt->pkt_fca_private;
1120fcf3ce44SJohn Forte 	ndlp = sbp->node;
1121fcf3ce44SJohn Forte 
1122fcf3ce44SJohn Forte 	if (!ndlp) {
1123*8f23e9faSHans Rosenfeld 		ndlp = emlxs_node_find_did(port, did, 1);
1124fcf3ce44SJohn Forte 	}
1125fcf3ce44SJohn Forte 	if (pkt->pkt_state != FC_PKT_SUCCESS) {
1126fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
1127*8f23e9faSHans Rosenfeld 		    "cmpl_dhchap_success_issue: 0x%x %x. No retry.",
1128fcf3ce44SJohn Forte 		    did, pkt->pkt_state);
1129fcf3ce44SJohn Forte 	} else {
1130fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
1131*8f23e9faSHans Rosenfeld 		    "cmpl_dhchap_success_issue: did=0x%x. Succcess.",
1132fcf3ce44SJohn Forte 		    did);
1133fcf3ce44SJohn Forte 	}
1134fcf3ce44SJohn Forte 
1135fcf3ce44SJohn Forte 	if (ndlp) {
1136fcf3ce44SJohn Forte 		if (pkt->pkt_state == FC_PKT_SUCCESS) {
1137fcf3ce44SJohn Forte 			(void) emlxs_dhchap_state_machine(port, NULL, NULL,
1138fcf3ce44SJohn Forte 			    NULL, ndlp, NODE_EVENT_CMPL_AUTH_MSG);
1139fcf3ce44SJohn Forte 		}
1140fcf3ce44SJohn Forte 	}
1141fcf3ce44SJohn Forte 	emlxs_pkt_free(pkt);
1142fcf3ce44SJohn Forte 
1143fcf3ce44SJohn Forte 	return;
1144fcf3ce44SJohn Forte 
1145fcf3ce44SJohn Forte } /* emlxs_cmpl_dhchap_success_issue */
1146fcf3ce44SJohn Forte 
1147fcf3ce44SJohn Forte 
1148fcf3ce44SJohn Forte /*
1149fcf3ce44SJohn Forte  * if rsp == NULL, this is only the DHCHAP_Success msg
1150fcf3ce44SJohn Forte  *
1151fcf3ce44SJohn Forte  * if rsp != NULL, DHCHAP_Success contains rsp to the challenge.
1152fcf3ce44SJohn Forte  */
1153fcf3ce44SJohn Forte /* ARGSUSED */
1154fcf3ce44SJohn Forte uint32_t
emlxs_issue_dhchap_success(emlxs_port_t * port,NODELIST * ndlp,int retry,uint8_t * rsp)1155fcf3ce44SJohn Forte emlxs_issue_dhchap_success(
1156fcf3ce44SJohn Forte 	emlxs_port_t *port,
1157fcf3ce44SJohn Forte 	NODELIST *ndlp,
1158fcf3ce44SJohn Forte 	int retry,
1159fcf3ce44SJohn Forte 	uint8_t *rsp)
1160fcf3ce44SJohn Forte {
1161fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
1162fcf3ce44SJohn Forte 	fc_packet_t *pkt;
1163fcf3ce44SJohn Forte 	uint32_t cmd_size;
1164fcf3ce44SJohn Forte 	uint32_t rsp_size;
1165fcf3ce44SJohn Forte 	uint8_t *pCmd;
1166fcf3ce44SJohn Forte 	uint16_t cmdsize;
1167fcf3ce44SJohn Forte 	DHCHAP_SUCCESS_HDR *ap;
1168fcf3ce44SJohn Forte 	uint8_t *tmp;
1169fcf3ce44SJohn Forte 	uint32_t len;
1170fcf3ce44SJohn Forte 	uint32_t ret;
1171fcf3ce44SJohn Forte 
1172fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
1173*8f23e9faSHans Rosenfeld 	    "issue_dhchap_success: did=0x%x", ndlp->nlp_DID);
1174fcf3ce44SJohn Forte 
117582527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
1176fcf3ce44SJohn Forte 		if (node_dhc->nlp_auth_hashid == AUTH_MD5)
1177fcf3ce44SJohn Forte 			len = MD5_LEN;
1178fcf3ce44SJohn Forte 		else
1179fcf3ce44SJohn Forte 			len = SHA1_LEN;
1180fcf3ce44SJohn Forte 	} else {
1181fcf3ce44SJohn Forte 		len = (node_dhc->nlp_auth_hashid == AUTH_MD5) ?
1182fcf3ce44SJohn Forte 		    MD5_LEN : SHA1_LEN;
1183fcf3ce44SJohn Forte 	}
1184fcf3ce44SJohn Forte 
1185fcf3ce44SJohn Forte 	if (rsp == NULL) {
1186fcf3ce44SJohn Forte 		cmdsize = sizeof (DHCHAP_SUCCESS_HDR);
1187fcf3ce44SJohn Forte 	} else {
1188fcf3ce44SJohn Forte 
1189fcf3ce44SJohn Forte 		cmdsize = sizeof (DHCHAP_SUCCESS_HDR) + len;
1190fcf3ce44SJohn Forte 	}
1191fcf3ce44SJohn Forte 
1192fcf3ce44SJohn Forte 	cmd_size = cmdsize;
1193fcf3ce44SJohn Forte 	rsp_size = 4;
1194fcf3ce44SJohn Forte 
1195fcf3ce44SJohn Forte 	if ((pkt = emlxs_prep_els_fc_pkt(port, ndlp->nlp_DID, cmd_size,
1196fcf3ce44SJohn Forte 	    rsp_size, 0, KM_NOSLEEP)) == NULL) {
1197fcf3ce44SJohn Forte 		return (1);
1198fcf3ce44SJohn Forte 	}
1199fcf3ce44SJohn Forte 	pCmd = (uint8_t *)pkt->pkt_cmd;
1200fcf3ce44SJohn Forte 
1201fcf3ce44SJohn Forte 	ap = (DHCHAP_SUCCESS_HDR *)pCmd;
1202fcf3ce44SJohn Forte 	tmp = (uint8_t *)pCmd;
1203fcf3ce44SJohn Forte 
1204fcf3ce44SJohn Forte 	ap->auth_els_code = ELS_CMD_AUTH_CODE;
1205fcf3ce44SJohn Forte 	ap->auth_els_flags = 0x0;
1206fcf3ce44SJohn Forte 	ap->auth_msg_code = DHCHAP_SUCCESS;
1207fcf3ce44SJohn Forte 	ap->proto_version = 0x01;
1208fcf3ce44SJohn Forte 
1209fcf3ce44SJohn Forte 	/*
1210fcf3ce44SJohn Forte 	 * In case of rsp == NULL meaning that this is DHCHAP_Success issued
1211fcf3ce44SJohn Forte 	 * when Host is the initiator AND this DHCHAP_Success is issused in
1212fcf3ce44SJohn Forte 	 * response to the bi-directional authentication, meaning Host
1213fcf3ce44SJohn Forte 	 * authenticate another entity, therefore no more DHCHAP_Success
1214fcf3ce44SJohn Forte 	 * expected. OR this DHCHAP_Success is issued by host when host is
1215fcf3ce44SJohn Forte 	 * the responder BUT it is uni-directional auth, therefore no more
1216fcf3ce44SJohn Forte 	 * DHCHAP_Success expected.
1217fcf3ce44SJohn Forte 	 *
1218fcf3ce44SJohn Forte 	 * In case of rsp != NULL it indicates this DHCHAP_Success is issued
1219fcf3ce44SJohn Forte 	 * when host is the responder AND this DHCHAP_Success has reply
1220fcf3ce44SJohn Forte 	 * embedded therefore the host expects DHCHAP_Success from other
1221fcf3ce44SJohn Forte 	 * entity in transaction.
1222fcf3ce44SJohn Forte 	 */
1223fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
1224*8f23e9faSHans Rosenfeld 	    "issue_dhchap_success: 0x%x 0x%x 0x%x 0x%x 0x%x %p",
1225fcf3ce44SJohn Forte 	    ndlp->nlp_DID, node_dhc->nlp_auth_hashid,
1226fcf3ce44SJohn Forte 	    node_dhc->nlp_auth_tranid_rsp,
1227fcf3ce44SJohn Forte 	    node_dhc->nlp_auth_tranid_ini, cmdsize, rsp);
1228fcf3ce44SJohn Forte 
1229fcf3ce44SJohn Forte 	if (rsp == NULL) {
123082527734SSukumar Swaminathan 		ap->msg_len = LE_SWAP32(0x00000004);
1231fcf3ce44SJohn Forte 		ap->RspVal_len = 0x0;
1232fcf3ce44SJohn Forte 
1233fcf3ce44SJohn Forte 		node_dhc->fc_dhchap_success_expected = 0;
1234fcf3ce44SJohn Forte 	} else {
1235fcf3ce44SJohn Forte 		node_dhc->fc_dhchap_success_expected = 1;
1236fcf3ce44SJohn Forte 
123782527734SSukumar Swaminathan 		ap->msg_len = LE_SWAP32(4 + len);
1238fcf3ce44SJohn Forte 
1239fcf3ce44SJohn Forte 		tmp += sizeof (DHCHAP_SUCCESS_HDR) - sizeof (uint32_t);
124082527734SSukumar Swaminathan 		*(uint32_t *)tmp = LE_SWAP32(len);
1241fcf3ce44SJohn Forte 		tmp += sizeof (uint32_t);
1242fcf3ce44SJohn Forte 		bcopy((void *)rsp, (void *)tmp, len);
1243fcf3ce44SJohn Forte 	}
1244fcf3ce44SJohn Forte 
1245fcf3ce44SJohn Forte 	if (node_dhc->nlp_reauth_status == NLP_HOST_REAUTH_IN_PROGRESS) {
124682527734SSukumar Swaminathan 		ap->tran_id = LE_SWAP32(node_dhc->nlp_auth_tranid_rsp);
1247fcf3ce44SJohn Forte 	} else {
1248fcf3ce44SJohn Forte 		if (node_dhc->nlp_auth_flag == 2) {
1249fcf3ce44SJohn Forte 			ap->tran_id =
125082527734SSukumar Swaminathan 			    LE_SWAP32(node_dhc->nlp_auth_tranid_rsp);
1251fcf3ce44SJohn Forte 		} else if (node_dhc->nlp_auth_flag == 1) {
1252fcf3ce44SJohn Forte 			ap->tran_id =
125382527734SSukumar Swaminathan 			    LE_SWAP32(node_dhc->nlp_auth_tranid_ini);
1254fcf3ce44SJohn Forte 		} else {
1255fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_debug_msg,
1256*8f23e9faSHans Rosenfeld 			    "is_dhch_success: (1) 0x%x 0x%x 0x%x 0x%x",
1257fcf3ce44SJohn Forte 			    ndlp->nlp_DID, node_dhc->nlp_auth_flag,
1258fcf3ce44SJohn Forte 			    node_dhc->nlp_auth_tranid_rsp,
1259fcf3ce44SJohn Forte 			    node_dhc->nlp_auth_tranid_ini);
1260fcf3ce44SJohn Forte 
1261fcf3ce44SJohn Forte 			return (1);
1262fcf3ce44SJohn Forte 		}
1263fcf3ce44SJohn Forte 	}
1264fcf3ce44SJohn Forte 
1265fcf3ce44SJohn Forte 	pkt->pkt_comp = emlxs_cmpl_dhchap_success_issue;
1266fcf3ce44SJohn Forte 
1267fcf3ce44SJohn Forte 	ret = emlxs_pkt_send(pkt, 1);
1268fcf3ce44SJohn Forte 
1269fcf3ce44SJohn Forte 	if (ret != FC_SUCCESS) {
1270fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
1271*8f23e9faSHans Rosenfeld 		    "issue_dhchap_success: Unable to send packet. 0x%x",
1272fcf3ce44SJohn Forte 		    ret);
1273fcf3ce44SJohn Forte 
1274fcf3ce44SJohn Forte 		emlxs_pkt_free(pkt);
1275fcf3ce44SJohn Forte 
1276fcf3ce44SJohn Forte 		return (1);
1277fcf3ce44SJohn Forte 	}
1278fcf3ce44SJohn Forte 	return (0);
1279fcf3ce44SJohn Forte 
1280fcf3ce44SJohn Forte } /* emlxs_issue_dhchap_success */
1281fcf3ce44SJohn Forte 
1282fcf3ce44SJohn Forte 
1283fcf3ce44SJohn Forte /*
1284fcf3ce44SJohn Forte  * ! emlxs_cmpl_auth_reject_issue
1285fcf3ce44SJohn Forte  *
1286fcf3ce44SJohn Forte  * \pre \post \param   phba \param   cmdiocb \param   rspiocb \return  void
1287fcf3ce44SJohn Forte  *
1288fcf3ce44SJohn Forte  * \b Description: iocb_cmpl callback function.
1289fcf3ce44SJohn Forte  *
1290fcf3ce44SJohn Forte  */
1291fcf3ce44SJohn Forte static void
emlxs_cmpl_auth_reject_issue(fc_packet_t * pkt)1292fcf3ce44SJohn Forte emlxs_cmpl_auth_reject_issue(fc_packet_t *pkt)
1293fcf3ce44SJohn Forte {
1294fcf3ce44SJohn Forte 	emlxs_port_t *port = pkt->pkt_ulp_private;
1295fcf3ce44SJohn Forte 	emlxs_buf_t *sbp;
1296fcf3ce44SJohn Forte 	NODELIST *ndlp;
1297fcf3ce44SJohn Forte 	uint32_t did;
1298fcf3ce44SJohn Forte 
1299fcf3ce44SJohn Forte 	did = pkt->pkt_cmd_fhdr.d_id;
1300fcf3ce44SJohn Forte 	sbp = (emlxs_buf_t *)pkt->pkt_fca_private;
1301fcf3ce44SJohn Forte 	ndlp = sbp->node;
1302fcf3ce44SJohn Forte 
1303fcf3ce44SJohn Forte 	if (!ndlp) {
1304*8f23e9faSHans Rosenfeld 		ndlp = emlxs_node_find_did(port, did, 1);
1305fcf3ce44SJohn Forte 	}
1306fcf3ce44SJohn Forte 	if (pkt->pkt_state != FC_PKT_SUCCESS) {
1307fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
1308*8f23e9faSHans Rosenfeld 		    "cmpl_auth_reject_issue: 0x%x %x. No retry.",
1309fcf3ce44SJohn Forte 		    did, pkt->pkt_state);
1310fcf3ce44SJohn Forte 	} else {
1311fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
1312*8f23e9faSHans Rosenfeld 		    "cmpl_auth_reject_issue: did=0x%x. Succcess.",
1313fcf3ce44SJohn Forte 		    did);
1314fcf3ce44SJohn Forte 	}
1315fcf3ce44SJohn Forte 
1316fcf3ce44SJohn Forte 	if (ndlp) {
1317fcf3ce44SJohn Forte 		/* setup the new state */
1318fcf3ce44SJohn Forte 		emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_FAILED, 0, 0);
1319fcf3ce44SJohn Forte 
1320fcf3ce44SJohn Forte 		if (pkt->pkt_state == FC_PKT_SUCCESS) {
1321fcf3ce44SJohn Forte 			(void) emlxs_dhchap_state_machine(port, NULL, NULL,
1322fcf3ce44SJohn Forte 			    NULL, ndlp, NODE_EVENT_CMPL_AUTH_MSG);
1323fcf3ce44SJohn Forte 		}
1324fcf3ce44SJohn Forte 	}
1325fcf3ce44SJohn Forte 	emlxs_pkt_free(pkt);
1326fcf3ce44SJohn Forte 
1327fcf3ce44SJohn Forte 	return;
1328fcf3ce44SJohn Forte 
1329fcf3ce44SJohn Forte } /* emlxs_cmpl_auth_reject_issue */
1330fcf3ce44SJohn Forte 
1331fcf3ce44SJohn Forte 
1332fcf3ce44SJohn Forte /*
1333fcf3ce44SJohn Forte  * If Logical Error and Reason Code Explanation is "Restart Authentication
1334fcf3ce44SJohn Forte  * Protocol" then the Transaction Identifier could be
1335fcf3ce44SJohn Forte  * any value.
1336fcf3ce44SJohn Forte  */
1337fcf3ce44SJohn Forte /* ARGSUSED */
1338fcf3ce44SJohn Forte static uint32_t
emlxs_issue_auth_reject(emlxs_port_t * port,NODELIST * ndlp,int retry,uint32_t * arg,uint8_t ReasonCode,uint8_t ReasonCodeExplanation)1339fcf3ce44SJohn Forte emlxs_issue_auth_reject(
1340fcf3ce44SJohn Forte 	emlxs_port_t *port,
1341fcf3ce44SJohn Forte 	NODELIST *ndlp,
1342fcf3ce44SJohn Forte 	int retry,
1343fcf3ce44SJohn Forte 	uint32_t *arg,
1344fcf3ce44SJohn Forte 	uint8_t ReasonCode,
1345fcf3ce44SJohn Forte 	uint8_t ReasonCodeExplanation)
1346fcf3ce44SJohn Forte {
1347fcf3ce44SJohn Forte 	fc_packet_t *pkt;
1348fcf3ce44SJohn Forte 	uint32_t cmd_size;
1349fcf3ce44SJohn Forte 	uint32_t rsp_size;
1350fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
1351fcf3ce44SJohn Forte 	uint16_t cmdsize;
1352fcf3ce44SJohn Forte 	AUTH_RJT *ap;
1353fcf3ce44SJohn Forte 	char info[64];
1354fcf3ce44SJohn Forte 
1355fcf3ce44SJohn Forte 	if (node_dhc->nlp_authrsp_tmo) {
1356fcf3ce44SJohn Forte 		node_dhc->nlp_authrsp_tmo = 0;
1357fcf3ce44SJohn Forte 	}
1358fcf3ce44SJohn Forte 	cmdsize = sizeof (AUTH_RJT);
1359fcf3ce44SJohn Forte 	cmd_size = cmdsize;
1360fcf3ce44SJohn Forte 	rsp_size = 4;
1361fcf3ce44SJohn Forte 
1362fcf3ce44SJohn Forte 	if ((pkt = emlxs_prep_els_fc_pkt(port, ndlp->nlp_DID, cmd_size,
1363fcf3ce44SJohn Forte 	    rsp_size, 0, KM_NOSLEEP)) == NULL) {
1364fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
1365fcf3ce44SJohn Forte 		    "Auth reject failed: Unable to allocate pkt. 0x%x %x %x",
1366fcf3ce44SJohn Forte 		    ndlp->nlp_DID, ReasonCode, ReasonCodeExplanation);
1367fcf3ce44SJohn Forte 
1368fcf3ce44SJohn Forte 		return (1);
1369fcf3ce44SJohn Forte 	}
1370fcf3ce44SJohn Forte 	ap = (AUTH_RJT *) pkt->pkt_cmd;
1371fcf3ce44SJohn Forte 	ap->auth_els_code = ELS_CMD_AUTH_CODE;
1372fcf3ce44SJohn Forte 	ap->auth_els_flags = 0x0;
1373fcf3ce44SJohn Forte 	ap->auth_msg_code = AUTH_REJECT;
1374fcf3ce44SJohn Forte 	ap->proto_version = 0x01;
137582527734SSukumar Swaminathan 	ap->msg_len = LE_SWAP32(4);
1376fcf3ce44SJohn Forte 
1377fcf3ce44SJohn Forte 	if (node_dhc->nlp_auth_flag == 2) {
137882527734SSukumar Swaminathan 		ap->tran_id = LE_SWAP32(node_dhc->nlp_auth_tranid_rsp);
1379fcf3ce44SJohn Forte 	} else if (node_dhc->nlp_auth_flag == 1) {
138082527734SSukumar Swaminathan 		ap->tran_id = LE_SWAP32(node_dhc->nlp_auth_tranid_ini);
1381fcf3ce44SJohn Forte 	} else {
1382fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
1383fcf3ce44SJohn Forte 		    "Auth reject failed.Invalid flag=%d. 0x%x %x expl=%x",
1384fcf3ce44SJohn Forte 		    ndlp->nlp_DID, node_dhc->nlp_auth_flag, ReasonCode,
1385fcf3ce44SJohn Forte 		    ReasonCodeExplanation);
1386fcf3ce44SJohn Forte 
1387fcf3ce44SJohn Forte 		emlxs_pkt_free(pkt);
1388fcf3ce44SJohn Forte 
1389fcf3ce44SJohn Forte 		return (1);
1390fcf3ce44SJohn Forte 	}
1391fcf3ce44SJohn Forte 
1392fcf3ce44SJohn Forte 	ap->ReasonCode = ReasonCode;
1393fcf3ce44SJohn Forte 	ap->ReasonCodeExplanation = ReasonCodeExplanation;
1394fcf3ce44SJohn Forte 
1395fcf3ce44SJohn Forte 	pkt->pkt_comp = emlxs_cmpl_auth_reject_issue;
1396fcf3ce44SJohn Forte 
1397fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_debug_msg,
1398fcf3ce44SJohn Forte 	    "Auth reject: did=0x%x reason=%x expl=%x",
1399fcf3ce44SJohn Forte 	    ndlp->nlp_DID, ReasonCode, ReasonCodeExplanation);
1400fcf3ce44SJohn Forte 
1401fcf3ce44SJohn Forte 	if (emlxs_pkt_send(pkt, 1) != FC_SUCCESS) {
1402fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
1403fcf3ce44SJohn Forte 		    "Auth reject failed. Unable to send pkt. 0x%x %x expl=%x",
1404fcf3ce44SJohn Forte 		    ndlp->nlp_DID, node_dhc->nlp_auth_flag, ReasonCode,
1405fcf3ce44SJohn Forte 		    ReasonCodeExplanation);
1406fcf3ce44SJohn Forte 
1407fcf3ce44SJohn Forte 		emlxs_pkt_free(pkt);
1408fcf3ce44SJohn Forte 
1409fcf3ce44SJohn Forte 		return (1);
1410fcf3ce44SJohn Forte 	}
1411*8f23e9faSHans Rosenfeld 	(void) snprintf(info, sizeof (info),
1412fcf3ce44SJohn Forte 	    "Auth-Reject: ReasonCode=0x%x, ReasonCodeExplanation=0x%x",
1413fcf3ce44SJohn Forte 	    ReasonCode, ReasonCodeExplanation);
1414fcf3ce44SJohn Forte 
1415*8f23e9faSHans Rosenfeld 	emlxs_log_auth_event(port, ndlp, "issue_auth_reject", info);
1416fcf3ce44SJohn Forte 
1417fcf3ce44SJohn Forte 	return (0);
1418fcf3ce44SJohn Forte 
1419fcf3ce44SJohn Forte } /* emlxs_issue_auth_reject */
1420fcf3ce44SJohn Forte 
1421fcf3ce44SJohn Forte 
1422fcf3ce44SJohn Forte static fc_packet_t *
emlxs_prep_els_fc_pkt(emlxs_port_t * port,uint32_t d_id,uint32_t cmd_size,uint32_t rsp_size,uint32_t datalen,int32_t sleepflag)1423fcf3ce44SJohn Forte 	emlxs_prep_els_fc_pkt(
1424fcf3ce44SJohn Forte 	emlxs_port_t *port,
1425fcf3ce44SJohn Forte 	uint32_t d_id,
1426fcf3ce44SJohn Forte 	uint32_t cmd_size,
1427fcf3ce44SJohn Forte 	uint32_t rsp_size,
1428fcf3ce44SJohn Forte 	uint32_t datalen,
1429fcf3ce44SJohn Forte 	int32_t sleepflag)
1430fcf3ce44SJohn Forte {
1431fcf3ce44SJohn Forte 	fc_packet_t *pkt;
1432fcf3ce44SJohn Forte 
1433fcf3ce44SJohn Forte 	/* simulate the ULP stack's fc_packet send out */
1434fcf3ce44SJohn Forte 	if (!(pkt = emlxs_pkt_alloc(port, cmd_size, rsp_size,
1435fcf3ce44SJohn Forte 	    datalen, sleepflag))) {
1436fcf3ce44SJohn Forte 		return (NULL);
1437fcf3ce44SJohn Forte 	}
1438fcf3ce44SJohn Forte 	pkt->pkt_tran_type = FC_PKT_EXCHANGE;
1439fcf3ce44SJohn Forte 	pkt->pkt_timeout = 35;
1440fcf3ce44SJohn Forte 
1441fcf3ce44SJohn Forte 	/* Build the fc header */
144282527734SSukumar Swaminathan 	pkt->pkt_cmd_fhdr.d_id = LE_SWAP24_LO(d_id);
1443fcf3ce44SJohn Forte 	pkt->pkt_cmd_fhdr.r_ctl = R_CTL_ELS_REQ;
144482527734SSukumar Swaminathan 	pkt->pkt_cmd_fhdr.s_id = LE_SWAP24_LO(port->did);
1445fcf3ce44SJohn Forte 	pkt->pkt_cmd_fhdr.type = FC_TYPE_EXTENDED_LS;
1446fcf3ce44SJohn Forte 	pkt->pkt_cmd_fhdr.f_ctl =
1447fcf3ce44SJohn Forte 	    F_CTL_FIRST_SEQ | F_CTL_END_SEQ | F_CTL_SEQ_INITIATIVE;
1448fcf3ce44SJohn Forte 	pkt->pkt_cmd_fhdr.seq_id = 0;
1449fcf3ce44SJohn Forte 	pkt->pkt_cmd_fhdr.df_ctl = 0;
1450fcf3ce44SJohn Forte 	pkt->pkt_cmd_fhdr.seq_cnt = 0;
1451fcf3ce44SJohn Forte 	pkt->pkt_cmd_fhdr.ox_id = 0xFFFF;
1452fcf3ce44SJohn Forte 	pkt->pkt_cmd_fhdr.rx_id = 0xFFFF;
1453fcf3ce44SJohn Forte 	pkt->pkt_cmd_fhdr.ro = 0;
1454fcf3ce44SJohn Forte 
1455fcf3ce44SJohn Forte 	return ((fc_packet_t *)pkt);
1456fcf3ce44SJohn Forte 
1457fcf3ce44SJohn Forte } /* emlxs_prep_els_fc_pkt */
1458fcf3ce44SJohn Forte 
1459fcf3ce44SJohn Forte 
1460fcf3ce44SJohn Forte /*
1461fcf3ce44SJohn Forte  * ! emlxs_issue_auth_negotiate
1462fcf3ce44SJohn Forte  *
1463fcf3ce44SJohn Forte  * \pre \post \param   port \param   ndlp \param   retry \param   flag \return
1464fcf3ce44SJohn Forte  * int
1465fcf3ce44SJohn Forte  *
1466fcf3ce44SJohn Forte  * \b Description:
1467fcf3ce44SJohn Forte  *
1468fcf3ce44SJohn Forte  * The routine is invoked when host as the authentication initiator which
1469fcf3ce44SJohn Forte  * issue the AUTH_ELS command AUTH_Negotiate to the other
1470fcf3ce44SJohn Forte  * entity ndlp. When this Auth_Negotiate command is completed, the iocb_cmpl
1471fcf3ce44SJohn Forte  * will get called as the solicited mbox cmd
1472fcf3ce44SJohn Forte  * callback. Some switch only support NULL dhchap in which case negotiate
1473fcf3ce44SJohn Forte  * should be modified to only have NULL DH specificed.
1474fcf3ce44SJohn Forte  *
1475fcf3ce44SJohn Forte  */
1476fcf3ce44SJohn Forte /* ARGSUSED */
1477fcf3ce44SJohn Forte static int
emlxs_issue_auth_negotiate(emlxs_port_t * port,emlxs_node_t * ndlp,uint8_t retry)1478fcf3ce44SJohn Forte emlxs_issue_auth_negotiate(
1479fcf3ce44SJohn Forte 	emlxs_port_t *port,
1480fcf3ce44SJohn Forte 	emlxs_node_t *ndlp,
1481fcf3ce44SJohn Forte 	uint8_t retry)
1482fcf3ce44SJohn Forte {
1483fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
1484fcf3ce44SJohn Forte 	fc_packet_t *pkt;
1485fcf3ce44SJohn Forte 	uint32_t cmd_size;
1486fcf3ce44SJohn Forte 	uint32_t rsp_size;
1487fcf3ce44SJohn Forte 	uint16_t cmdsize;
1488fcf3ce44SJohn Forte 	AUTH_MSG_NEGOT_NULL_1 *null_ap1;
1489fcf3ce44SJohn Forte 	AUTH_MSG_NEGOT_NULL_2 *null_ap2;
1490fcf3ce44SJohn Forte 	uint32_t num_hs = 0;
1491fcf3ce44SJohn Forte 	uint8_t flag;
1492fcf3ce44SJohn Forte 	AUTH_MSG_NEGOT_1 *ap1;
1493fcf3ce44SJohn Forte 	AUTH_MSG_NEGOT_2 *ap2;
1494fcf3ce44SJohn Forte 	uint16_t para_len = 0;
1495fcf3ce44SJohn Forte 	uint16_t hash_wcnt = 0;
1496fcf3ce44SJohn Forte 	uint16_t dhgp_wcnt = 0;
1497fcf3ce44SJohn Forte 
1498fcf3ce44SJohn Forte 
1499fcf3ce44SJohn Forte 	emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_NEGOTIATE_ISSUE, 0, 0);
1500fcf3ce44SJohn Forte 
1501fcf3ce44SJohn Forte 	/* Full DH group support limit:2, only NULL group support limit:1 */
1502fcf3ce44SJohn Forte 	flag = (node_dhc->nlp_auth_limit == 2) ? 1 : 0;
1503fcf3ce44SJohn Forte 
1504fcf3ce44SJohn Forte 	/* first: determine the cmdsize based on the auth cfg parameters */
1505fcf3ce44SJohn Forte 	if (flag == 1) {
1506fcf3ce44SJohn Forte 		/* May be Full DH group + 2 hash may not be */
1507fcf3ce44SJohn Forte 		cmdsize = sizeof (AUTH_MSG_NEGOT_NULL);
1508fcf3ce44SJohn Forte 
1509fcf3ce44SJohn Forte 		cmdsize += 2 + 2;	/* name tag: 2, name length: 2 */
1510fcf3ce44SJohn Forte 		cmdsize += 8;	/* WWN: 8 */
1511fcf3ce44SJohn Forte 		cmdsize += 4;	/* num of protocol: 4 */
1512fcf3ce44SJohn Forte 		cmdsize += 4;	/* protocol parms length: 4 */
1513fcf3ce44SJohn Forte 		cmdsize += 4;	/* protocol id: 4 */
1514fcf3ce44SJohn Forte 		para_len += 4;
1515fcf3ce44SJohn Forte 
1516fcf3ce44SJohn Forte 		cmdsize += 2 + 2;	/* hashlist: tag: 2, count:2 */
1517fcf3ce44SJohn Forte 		para_len += 4;
1518fcf3ce44SJohn Forte 
1519fcf3ce44SJohn Forte 		if (node_dhc->auth_cfg.hash_priority[1] == 0x00) {
1520fcf3ce44SJohn Forte 			/* only one hash func */
1521fcf3ce44SJohn Forte 			cmdsize += 4;
1522fcf3ce44SJohn Forte 			num_hs = 1;
1523fcf3ce44SJohn Forte 			para_len += 4;
1524fcf3ce44SJohn Forte 			hash_wcnt = 1;
1525fcf3ce44SJohn Forte 		} else {
1526fcf3ce44SJohn Forte 			/* two hash funcs */
1527fcf3ce44SJohn Forte 			cmdsize += 4 + 4;
1528fcf3ce44SJohn Forte 			num_hs = 2;
1529fcf3ce44SJohn Forte 			para_len += 4 + 4;
1530fcf3ce44SJohn Forte 			hash_wcnt = 2;
1531fcf3ce44SJohn Forte 		}
1532fcf3ce44SJohn Forte 
1533fcf3ce44SJohn Forte 		cmdsize += 2 + 2;
1534fcf3ce44SJohn Forte 		para_len += 4;
1535fcf3ce44SJohn Forte 		if (node_dhc->auth_cfg.dh_group_priority[1] == 0xf) {
1536fcf3ce44SJohn Forte 			/* only one dhgp specified: could be NULL or non-NULL */
1537fcf3ce44SJohn Forte 			cmdsize += 4;
1538fcf3ce44SJohn Forte 			para_len += 4;
1539fcf3ce44SJohn Forte 			dhgp_wcnt = 1;
1540fcf3ce44SJohn Forte 
1541fcf3ce44SJohn Forte 		} else if (node_dhc->auth_cfg.dh_group_priority[2] == 0xf) {
1542fcf3ce44SJohn Forte 			/* two dhgps specified */
1543fcf3ce44SJohn Forte 			cmdsize += 4 + 4;
1544fcf3ce44SJohn Forte 			para_len += 4 + 4;
1545fcf3ce44SJohn Forte 			dhgp_wcnt = 2;
1546fcf3ce44SJohn Forte 
1547fcf3ce44SJohn Forte 		} else if (node_dhc->auth_cfg.dh_group_priority[3] == 0xf) {
1548fcf3ce44SJohn Forte 			/* three dhgps specified */
1549fcf3ce44SJohn Forte 			cmdsize += 4 + 4 + 4;
1550fcf3ce44SJohn Forte 			para_len += 4 + 4 + 4;
1551fcf3ce44SJohn Forte 			dhgp_wcnt = 3;
1552fcf3ce44SJohn Forte 
1553fcf3ce44SJohn Forte 		} else if (node_dhc->auth_cfg.dh_group_priority[4] == 0xf) {
1554fcf3ce44SJohn Forte 			/* four dhgps specified */
1555fcf3ce44SJohn Forte 			cmdsize += 4 + 4 + 4 + 4;
1556fcf3ce44SJohn Forte 			para_len += 4 + 4 + 4 + 4;
1557fcf3ce44SJohn Forte 			dhgp_wcnt = 4;
1558fcf3ce44SJohn Forte 
1559fcf3ce44SJohn Forte 		} else if (node_dhc->auth_cfg.dh_group_priority[5] == 0xf) {
1560fcf3ce44SJohn Forte 			cmdsize += 4 + 4 + 4 + 4 + 4;
1561fcf3ce44SJohn Forte 			para_len += 4 + 4 + 4 + 4 + 4;
1562fcf3ce44SJohn Forte 			dhgp_wcnt = 5;
1563fcf3ce44SJohn Forte 
1564fcf3ce44SJohn Forte 		}
1565fcf3ce44SJohn Forte 	} else {
1566fcf3ce44SJohn Forte 		cmdsize = sizeof (AUTH_MSG_NEGOT_NULL);
1567fcf3ce44SJohn Forte 
1568fcf3ce44SJohn Forte 		/*
1569fcf3ce44SJohn Forte 		 * get the right payload size in byte: determined by config
1570fcf3ce44SJohn Forte 		 * parameters
1571fcf3ce44SJohn Forte 		 */
1572fcf3ce44SJohn Forte 		cmdsize += 2 + 2 + 8;	/* name tag:2, name length:2, name */
1573fcf3ce44SJohn Forte 					/* value content:8 */
1574fcf3ce44SJohn Forte 		cmdsize += 4;	/* number of usable authentication */
1575fcf3ce44SJohn Forte 				/* protocols:4 */
1576fcf3ce44SJohn Forte 		cmdsize += 4;	/* auth protocol params length: 4 */
1577fcf3ce44SJohn Forte 		cmdsize += 4;	/* auth protocol identifier: 4 */
1578fcf3ce44SJohn Forte 
1579fcf3ce44SJohn Forte 		/* hash list infor */
1580fcf3ce44SJohn Forte 		cmdsize += 4;	/* hashlist: tag:2, count:2 */
1581fcf3ce44SJohn Forte 
1582fcf3ce44SJohn Forte 		if (node_dhc->auth_cfg.hash_priority[1] == 0x00) {
1583fcf3ce44SJohn Forte 			cmdsize += 4;	/* only one hash function provided */
1584fcf3ce44SJohn Forte 			num_hs = 1;
1585fcf3ce44SJohn Forte 		} else {
1586fcf3ce44SJohn Forte 			num_hs = 2;
1587fcf3ce44SJohn Forte 			cmdsize += 4 + 4;	/* sha1: 4, md5: 4 */
1588fcf3ce44SJohn Forte 		}
1589fcf3ce44SJohn Forte 
1590fcf3ce44SJohn Forte 		/* dhgp list info */
1591fcf3ce44SJohn Forte 		/* since this is NULL DH group */
1592fcf3ce44SJohn Forte 		cmdsize += 4;	/* dhgroup: tag:2, count:2 */
1593fcf3ce44SJohn Forte 		cmdsize += 4;	/* set it to zero */
1594fcf3ce44SJohn Forte 	}
1595fcf3ce44SJohn Forte 
1596fcf3ce44SJohn Forte 	cmd_size = cmdsize;
1597fcf3ce44SJohn Forte 	rsp_size = 4;
1598fcf3ce44SJohn Forte 
1599fcf3ce44SJohn Forte 	if ((pkt = emlxs_prep_els_fc_pkt(port, ndlp->nlp_DID, cmd_size,
1600fcf3ce44SJohn Forte 	    rsp_size, 0, KM_NOSLEEP)) == NULL) {
1601fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
1602fcf3ce44SJohn Forte 		    "issue_auth_negotiate: Unable to allocate pkt. 0x%x %d",
1603fcf3ce44SJohn Forte 		    ndlp->nlp_DID, cmd_size);
1604fcf3ce44SJohn Forte 
1605fcf3ce44SJohn Forte 		return (1);
1606fcf3ce44SJohn Forte 	}
1607fcf3ce44SJohn Forte 	/* Fill in AUTH_MSG_NEGOT payload */
1608fcf3ce44SJohn Forte 	if (flag == 1) {
1609fcf3ce44SJohn Forte 		if (hash_wcnt == 1) {
1610fcf3ce44SJohn Forte 			ap1 = (AUTH_MSG_NEGOT_1 *)pkt->pkt_cmd;
1611fcf3ce44SJohn Forte 			ap1->auth_els_code = ELS_CMD_AUTH_CODE;
1612fcf3ce44SJohn Forte 			ap1->auth_els_flags = 0x00;
1613fcf3ce44SJohn Forte 			ap1->auth_msg_code = AUTH_NEGOTIATE;
1614fcf3ce44SJohn Forte 			ap1->proto_version = 0x01;
161582527734SSukumar Swaminathan 			ap1->msg_len = LE_SWAP32(cmdsize -
1616fcf3ce44SJohn Forte 			    sizeof (AUTH_MSG_NEGOT_NULL));
1617fcf3ce44SJohn Forte 		} else {
1618fcf3ce44SJohn Forte 			ap2 = (AUTH_MSG_NEGOT_2 *)pkt->pkt_cmd;
1619fcf3ce44SJohn Forte 			ap2->auth_els_code = ELS_CMD_AUTH_CODE;
1620fcf3ce44SJohn Forte 			ap2->auth_els_flags = 0x00;
1621fcf3ce44SJohn Forte 			ap2->auth_msg_code = AUTH_NEGOTIATE;
1622fcf3ce44SJohn Forte 			ap2->proto_version = 0x01;
162382527734SSukumar Swaminathan 			ap2->msg_len = LE_SWAP32(cmdsize -
1624fcf3ce44SJohn Forte 			    sizeof (AUTH_MSG_NEGOT_NULL));
1625fcf3ce44SJohn Forte 		}
1626fcf3ce44SJohn Forte 	} else {
1627fcf3ce44SJohn Forte 		if (node_dhc->auth_cfg.hash_priority[1] == 0x00) {
1628fcf3ce44SJohn Forte 			null_ap1 = (AUTH_MSG_NEGOT_NULL_1 *)pkt->pkt_cmd;
1629fcf3ce44SJohn Forte 			null_ap1->auth_els_code = ELS_CMD_AUTH_CODE;
1630fcf3ce44SJohn Forte 			null_ap1->auth_els_flags = 0x0;
1631fcf3ce44SJohn Forte 			null_ap1->auth_msg_code = AUTH_NEGOTIATE;
1632fcf3ce44SJohn Forte 			null_ap1->proto_version = 0x01;
163382527734SSukumar Swaminathan 			null_ap1->msg_len = LE_SWAP32(cmdsize -
1634fcf3ce44SJohn Forte 			    sizeof (AUTH_MSG_NEGOT_NULL));
1635fcf3ce44SJohn Forte 
1636fcf3ce44SJohn Forte 		} else {
1637fcf3ce44SJohn Forte 			null_ap2 = (AUTH_MSG_NEGOT_NULL_2 *)pkt->pkt_cmd;
1638fcf3ce44SJohn Forte 			null_ap2->auth_els_code = ELS_CMD_AUTH_CODE;
1639fcf3ce44SJohn Forte 			null_ap2->auth_els_flags = 0x0;
1640fcf3ce44SJohn Forte 			null_ap2->auth_msg_code = AUTH_NEGOTIATE;
1641fcf3ce44SJohn Forte 			null_ap2->proto_version = 0x01;
164282527734SSukumar Swaminathan 			null_ap2->msg_len = LE_SWAP32(cmdsize -
1643fcf3ce44SJohn Forte 			    sizeof (AUTH_MSG_NEGOT_NULL));
1644fcf3ce44SJohn Forte 		}
1645fcf3ce44SJohn Forte 	}
1646fcf3ce44SJohn Forte 
1647fcf3ce44SJohn Forte 	/*
1648fcf3ce44SJohn Forte 	 * For host reauthentication heart beat, the tran_id is incremented
1649fcf3ce44SJohn Forte 	 * by one for each heart beat being fired and round back to 1 when
1650fcf3ce44SJohn Forte 	 * 0xffffffff is reached. tran_id 0 is reserved as the initial linkup
1651fcf3ce44SJohn Forte 	 * authentication transaction id.
1652fcf3ce44SJohn Forte 	 */
1653fcf3ce44SJohn Forte 
1654fcf3ce44SJohn Forte 	/* responder flag:2, initiator flag:1 */
1655fcf3ce44SJohn Forte 	node_dhc->nlp_auth_flag = 2;	/* ndlp is the always the auth */
1656fcf3ce44SJohn Forte 					/* responder */
1657fcf3ce44SJohn Forte 
1658fcf3ce44SJohn Forte 	if (node_dhc->nlp_reauth_status == NLP_HOST_REAUTH_IN_PROGRESS) {
1659fcf3ce44SJohn Forte 		if (node_dhc->nlp_auth_tranid_rsp == 0xffffffff) {
1660fcf3ce44SJohn Forte 			node_dhc->nlp_auth_tranid_rsp = 1;
1661fcf3ce44SJohn Forte 		} else {
1662fcf3ce44SJohn Forte 			node_dhc->nlp_auth_tranid_rsp++;
1663fcf3ce44SJohn Forte 		}
1664fcf3ce44SJohn Forte 	} else {	/* !NLP_HOST_REAUTH_IN_PROGRESS */
1665fcf3ce44SJohn Forte 		node_dhc->nlp_auth_tranid_rsp = 0;
1666fcf3ce44SJohn Forte 	}
1667fcf3ce44SJohn Forte 
1668fcf3ce44SJohn Forte 	if (flag == 1) {
1669fcf3ce44SJohn Forte 		if (hash_wcnt == 1) {
1670fcf3ce44SJohn Forte 			ap1->tran_id =
167182527734SSukumar Swaminathan 			    LE_SWAP32(node_dhc->nlp_auth_tranid_rsp);
1672fcf3ce44SJohn Forte 
1673fcf3ce44SJohn Forte 			ap1->params.name_tag = AUTH_NAME_ID;
1674fcf3ce44SJohn Forte 			ap1->params.name_len = AUTH_NAME_LEN;
1675fcf3ce44SJohn Forte 			bcopy((void *)&port->wwpn,
1676fcf3ce44SJohn Forte 			    (void *) &ap1->params.nodeName, sizeof (NAME_TYPE));
1677fcf3ce44SJohn Forte 			ap1->params.proto_num = AUTH_PROTO_NUM;
167882527734SSukumar Swaminathan 			ap1->params.para_len = LE_SWAP32(para_len);
1679fcf3ce44SJohn Forte 			ap1->params.proto_id = AUTH_DHCHAP;
1680fcf3ce44SJohn Forte 			ap1->params.HashList_tag = HASH_LIST_TAG;
168182527734SSukumar Swaminathan 			ap1->params.HashList_wcnt = LE_SWAP16(hash_wcnt);
1682fcf3ce44SJohn Forte 			ap1->params.HashList_value1 =
1683fcf3ce44SJohn Forte 			    node_dhc->auth_cfg.hash_priority[0];
1684fcf3ce44SJohn Forte 			ap1->params.DHgIDList_tag = DHGID_LIST_TAG;
168582527734SSukumar Swaminathan 			ap1->params.DHgIDList_wnt = LE_SWAP16(dhgp_wcnt);
1686fcf3ce44SJohn Forte 
1687fcf3ce44SJohn Forte 			switch (dhgp_wcnt) {
1688fcf3ce44SJohn Forte 			case 5:
1689fcf3ce44SJohn Forte 				ap1->params.DHgIDList_g4 =
1690fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[4]);
1691fcf3ce44SJohn Forte 				ap1->params.DHgIDList_g3 =
1692fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[3]);
1693fcf3ce44SJohn Forte 				ap1->params.DHgIDList_g2 =
1694fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[2]);
1695fcf3ce44SJohn Forte 				ap1->params.DHgIDList_g1 =
1696fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[1]);
1697fcf3ce44SJohn Forte 				ap1->params.DHgIDList_g0 =
1698fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[0]);
1699fcf3ce44SJohn Forte 				break;
1700fcf3ce44SJohn Forte 			case 4:
1701fcf3ce44SJohn Forte 				ap1->params.DHgIDList_g3 =
1702fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[3]);
1703fcf3ce44SJohn Forte 				ap1->params.DHgIDList_g2 =
1704fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[2]);
1705fcf3ce44SJohn Forte 				ap1->params.DHgIDList_g1 =
1706fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[1]);
1707fcf3ce44SJohn Forte 				ap1->params.DHgIDList_g0 =
1708fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[0]);
1709fcf3ce44SJohn Forte 				break;
1710fcf3ce44SJohn Forte 			case 3:
1711fcf3ce44SJohn Forte 				ap1->params.DHgIDList_g2 =
1712fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[2]);
1713fcf3ce44SJohn Forte 				ap1->params.DHgIDList_g1 =
1714fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[1]);
1715fcf3ce44SJohn Forte 				ap1->params.DHgIDList_g0 =
1716fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[0]);
1717fcf3ce44SJohn Forte 				break;
1718fcf3ce44SJohn Forte 			case 2:
1719fcf3ce44SJohn Forte 				ap1->params.DHgIDList_g1 =
1720fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[1]);
1721fcf3ce44SJohn Forte 				ap1->params.DHgIDList_g0 =
1722fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[0]);
1723fcf3ce44SJohn Forte 				break;
1724fcf3ce44SJohn Forte 			case 1:
1725fcf3ce44SJohn Forte 				ap1->params.DHgIDList_g0 =
1726fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[0]);
1727fcf3ce44SJohn Forte 				break;
1728fcf3ce44SJohn Forte 			}
1729fcf3ce44SJohn Forte 		} else {
1730fcf3ce44SJohn Forte 			ap2->tran_id =
173182527734SSukumar Swaminathan 			    LE_SWAP32(node_dhc->nlp_auth_tranid_rsp);
1732fcf3ce44SJohn Forte 
1733fcf3ce44SJohn Forte 			ap2->params.name_tag = AUTH_NAME_ID;
1734fcf3ce44SJohn Forte 			ap2->params.name_len = AUTH_NAME_LEN;
1735fcf3ce44SJohn Forte 			bcopy((void *) &port->wwpn,
1736fcf3ce44SJohn Forte 			    (void *) &ap2->params.nodeName, sizeof (NAME_TYPE));
1737fcf3ce44SJohn Forte 			ap2->params.proto_num = AUTH_PROTO_NUM;
173882527734SSukumar Swaminathan 			ap2->params.para_len = LE_SWAP32(para_len);
1739fcf3ce44SJohn Forte 			ap2->params.proto_id = AUTH_DHCHAP;
1740fcf3ce44SJohn Forte 			ap2->params.HashList_tag = HASH_LIST_TAG;
174182527734SSukumar Swaminathan 			ap2->params.HashList_wcnt = LE_SWAP16(hash_wcnt);
1742fcf3ce44SJohn Forte 			ap2->params.HashList_value1 =
1743fcf3ce44SJohn Forte 			    (node_dhc->auth_cfg.hash_priority[0]);
1744fcf3ce44SJohn Forte 			ap2->params.HashList_value2 =
1745fcf3ce44SJohn Forte 			    (node_dhc->auth_cfg.hash_priority[1]);
1746fcf3ce44SJohn Forte 
1747fcf3ce44SJohn Forte 			ap2->params.DHgIDList_tag = DHGID_LIST_TAG;
174882527734SSukumar Swaminathan 			ap2->params.DHgIDList_wnt = LE_SWAP16(dhgp_wcnt);
1749fcf3ce44SJohn Forte 
1750fcf3ce44SJohn Forte 			switch (dhgp_wcnt) {
1751fcf3ce44SJohn Forte 			case 5:
1752fcf3ce44SJohn Forte 				ap2->params.DHgIDList_g4 =
1753fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[4]);
1754fcf3ce44SJohn Forte 				ap2->params.DHgIDList_g3 =
1755fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[3]);
1756fcf3ce44SJohn Forte 				ap2->params.DHgIDList_g2 =
1757fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[2]);
1758fcf3ce44SJohn Forte 				ap2->params.DHgIDList_g1 =
1759fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[1]);
1760fcf3ce44SJohn Forte 				ap2->params.DHgIDList_g0 =
1761fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[0]);
1762fcf3ce44SJohn Forte 				break;
1763fcf3ce44SJohn Forte 			case 4:
1764fcf3ce44SJohn Forte 				ap2->params.DHgIDList_g3 =
1765fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[3]);
1766fcf3ce44SJohn Forte 				ap2->params.DHgIDList_g2 =
1767fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[2]);
1768fcf3ce44SJohn Forte 				ap2->params.DHgIDList_g1 =
1769fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[1]);
1770fcf3ce44SJohn Forte 				ap2->params.DHgIDList_g0 =
1771fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[0]);
1772fcf3ce44SJohn Forte 				break;
1773fcf3ce44SJohn Forte 			case 3:
1774fcf3ce44SJohn Forte 				ap2->params.DHgIDList_g2 =
1775fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[2]);
1776fcf3ce44SJohn Forte 				ap2->params.DHgIDList_g1 =
1777fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[1]);
1778fcf3ce44SJohn Forte 				ap2->params.DHgIDList_g0 =
1779fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[0]);
1780fcf3ce44SJohn Forte 				break;
1781fcf3ce44SJohn Forte 			case 2:
1782fcf3ce44SJohn Forte 				ap2->params.DHgIDList_g1 =
1783fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[1]);
1784fcf3ce44SJohn Forte 				ap2->params.DHgIDList_g0 =
1785fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[0]);
1786fcf3ce44SJohn Forte 				break;
1787fcf3ce44SJohn Forte 			case 1:
1788fcf3ce44SJohn Forte 				ap2->params.DHgIDList_g0 =
1789fcf3ce44SJohn Forte 				    (node_dhc->auth_cfg.dh_group_priority[0]);
1790fcf3ce44SJohn Forte 				break;
1791fcf3ce44SJohn Forte 			}
1792fcf3ce44SJohn Forte 		}
1793fcf3ce44SJohn Forte 	} else {
1794fcf3ce44SJohn Forte 		if (num_hs == 1) {
1795fcf3ce44SJohn Forte 			null_ap1->tran_id =
179682527734SSukumar Swaminathan 			    LE_SWAP32(node_dhc->nlp_auth_tranid_rsp);
1797fcf3ce44SJohn Forte 
1798fcf3ce44SJohn Forte 			null_ap1->params.name_tag = AUTH_NAME_ID;
1799fcf3ce44SJohn Forte 			null_ap1->params.name_len = AUTH_NAME_LEN;
1800fcf3ce44SJohn Forte 			bcopy((void *) &port->wwpn,
1801fcf3ce44SJohn Forte 			    (void *) &null_ap1->params.nodeName,
1802fcf3ce44SJohn Forte 			    sizeof (NAME_TYPE));
1803fcf3ce44SJohn Forte 			null_ap1->params.proto_num = AUTH_PROTO_NUM;
180482527734SSukumar Swaminathan 			null_ap1->params.para_len = LE_SWAP32(0x00000014);
1805fcf3ce44SJohn Forte 			null_ap1->params.proto_id = AUTH_DHCHAP;
1806fcf3ce44SJohn Forte 			null_ap1->params.HashList_tag = HASH_LIST_TAG;
180782527734SSukumar Swaminathan 			null_ap1->params.HashList_wcnt = LE_SWAP16(0x0001);
1808fcf3ce44SJohn Forte 			null_ap1->params.HashList_value1 =
1809fcf3ce44SJohn Forte 			    (node_dhc->auth_cfg.hash_priority[0]);
1810fcf3ce44SJohn Forte 			null_ap1->params.DHgIDList_tag = DHGID_LIST_TAG;
181182527734SSukumar Swaminathan 			null_ap1->params.DHgIDList_wnt = LE_SWAP16(0x0001);
1812fcf3ce44SJohn Forte 			null_ap1->params.DHgIDList_g0 = 0x0;
1813fcf3ce44SJohn Forte 		} else {
1814fcf3ce44SJohn Forte 			null_ap2->tran_id =
181582527734SSukumar Swaminathan 			    LE_SWAP32(node_dhc->nlp_auth_tranid_rsp);
1816fcf3ce44SJohn Forte 
1817fcf3ce44SJohn Forte 			null_ap2->params.name_tag = AUTH_NAME_ID;
1818fcf3ce44SJohn Forte 			null_ap2->params.name_len = AUTH_NAME_LEN;
1819fcf3ce44SJohn Forte 			bcopy((void *) &port->wwpn,
1820fcf3ce44SJohn Forte 			    (void *) &null_ap2->params.nodeName,
1821fcf3ce44SJohn Forte 			    sizeof (NAME_TYPE));
1822fcf3ce44SJohn Forte 			null_ap2->params.proto_num = AUTH_PROTO_NUM;
182382527734SSukumar Swaminathan 			null_ap2->params.para_len = LE_SWAP32(0x00000018);
1824fcf3ce44SJohn Forte 			null_ap2->params.proto_id = AUTH_DHCHAP;
1825fcf3ce44SJohn Forte 
1826fcf3ce44SJohn Forte 			null_ap2->params.HashList_tag = HASH_LIST_TAG;
182782527734SSukumar Swaminathan 			null_ap2->params.HashList_wcnt = LE_SWAP16(0x0002);
1828fcf3ce44SJohn Forte 			null_ap2->params.HashList_value1 =
1829fcf3ce44SJohn Forte 			    (node_dhc->auth_cfg.hash_priority[0]);
1830fcf3ce44SJohn Forte 			null_ap2->params.HashList_value2 =
1831fcf3ce44SJohn Forte 			    (node_dhc->auth_cfg.hash_priority[1]);
1832fcf3ce44SJohn Forte 
1833fcf3ce44SJohn Forte 			null_ap2->params.DHgIDList_tag = DHGID_LIST_TAG;
183482527734SSukumar Swaminathan 			null_ap2->params.DHgIDList_wnt = LE_SWAP16(0x0001);
1835fcf3ce44SJohn Forte 			null_ap2->params.DHgIDList_g0 = 0x0;
1836fcf3ce44SJohn Forte 		}
1837fcf3ce44SJohn Forte 	}
1838fcf3ce44SJohn Forte 
1839fcf3ce44SJohn Forte 	pkt->pkt_comp = emlxs_cmpl_auth_negotiate_issue;
1840fcf3ce44SJohn Forte 
1841fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_debug_msg,
1842fcf3ce44SJohn Forte 	    "issue_auth_negotiate: %x flag=%d size=%d hash=%x,%x tid=%x,%x",
1843fcf3ce44SJohn Forte 	    ndlp->nlp_DID, flag, cmd_size,
1844fcf3ce44SJohn Forte 	    node_dhc->auth_cfg.hash_priority[0],
1845fcf3ce44SJohn Forte 	    node_dhc->auth_cfg.hash_priority[1],
1846fcf3ce44SJohn Forte 	    node_dhc->nlp_auth_tranid_rsp, node_dhc->nlp_auth_tranid_ini);
1847fcf3ce44SJohn Forte 
1848fcf3ce44SJohn Forte 	if (emlxs_pkt_send(pkt, 1) != FC_SUCCESS) {
1849fcf3ce44SJohn Forte 		emlxs_pkt_free(pkt);
1850fcf3ce44SJohn Forte 
1851fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
1852fcf3ce44SJohn Forte 		    "issue_auth_negotiate: Unable to send pkt. did=0x%x",
1853fcf3ce44SJohn Forte 		    ndlp->nlp_DID);
1854fcf3ce44SJohn Forte 
1855fcf3ce44SJohn Forte 		return (1);
1856fcf3ce44SJohn Forte 	}
1857fcf3ce44SJohn Forte 	return (0);
1858fcf3ce44SJohn Forte 
1859fcf3ce44SJohn Forte } /* emlxs_issue_auth_negotiate() */
1860fcf3ce44SJohn Forte 
1861fcf3ce44SJohn Forte 
1862fcf3ce44SJohn Forte 
1863fcf3ce44SJohn Forte /*
1864fcf3ce44SJohn Forte  * ! emlxs_cmpl_auth_negotiate_issue
1865fcf3ce44SJohn Forte  *
1866fcf3ce44SJohn Forte  * \pre \post \param   phba \param   cmdiocb \param   rspiocb \return  void
1867fcf3ce44SJohn Forte  *
1868fcf3ce44SJohn Forte  * \b Description: iocb_cmpl callback function.
1869fcf3ce44SJohn Forte  *
1870fcf3ce44SJohn Forte  */
1871fcf3ce44SJohn Forte static void
emlxs_cmpl_auth_negotiate_issue(fc_packet_t * pkt)1872fcf3ce44SJohn Forte emlxs_cmpl_auth_negotiate_issue(fc_packet_t *pkt)
1873fcf3ce44SJohn Forte {
1874fcf3ce44SJohn Forte 	emlxs_port_t *port = pkt->pkt_ulp_private;
1875fcf3ce44SJohn Forte 	emlxs_buf_t *sbp;
1876fcf3ce44SJohn Forte 	NODELIST *ndlp;
1877fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc;
1878fcf3ce44SJohn Forte 	uint32_t did;
1879fcf3ce44SJohn Forte 
1880fcf3ce44SJohn Forte 	did = pkt->pkt_cmd_fhdr.d_id;
1881fcf3ce44SJohn Forte 	sbp = (emlxs_buf_t *)pkt->pkt_fca_private;
1882fcf3ce44SJohn Forte 	ndlp = sbp->node;
1883fcf3ce44SJohn Forte 	node_dhc = &ndlp->node_dhc;
1884fcf3ce44SJohn Forte 
1885fcf3ce44SJohn Forte 	if (!ndlp) {
1886*8f23e9faSHans Rosenfeld 		ndlp = emlxs_node_find_did(port, did, 1);
1887fcf3ce44SJohn Forte 	}
1888fcf3ce44SJohn Forte 	if (pkt->pkt_state != FC_PKT_SUCCESS) {
1889fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
1890*8f23e9faSHans Rosenfeld 		    "cmpl_dhchap_negotiate_issue: 0x%x %x. Noretry.",
1891fcf3ce44SJohn Forte 		    did, pkt->pkt_state);
1892fcf3ce44SJohn Forte 	} else {
1893fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
1894*8f23e9faSHans Rosenfeld 		    "cmpl_dhchap_negotiate_issue: did=0x%x. Succcess.",
1895fcf3ce44SJohn Forte 		    did);
1896fcf3ce44SJohn Forte 	}
1897fcf3ce44SJohn Forte 
1898fcf3ce44SJohn Forte 	if (ndlp) {
1899fcf3ce44SJohn Forte 		if (pkt->pkt_state == FC_PKT_SUCCESS) {
1900fcf3ce44SJohn Forte 			(void) emlxs_dhchap_state_machine(port, NULL, NULL,
1901fcf3ce44SJohn Forte 			    NULL, ndlp, NODE_EVENT_CMPL_AUTH_MSG);
1902fcf3ce44SJohn Forte 		} else {
1903fcf3ce44SJohn Forte 			emlxs_dhc_set_reauth_time(port, ndlp, DISABLE);
1904fcf3ce44SJohn Forte 
1905fcf3ce44SJohn Forte 			emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_FAILED,
1906fcf3ce44SJohn Forte 			    0, 0);
1907fcf3ce44SJohn Forte 
1908fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_debug_msg,
1909fcf3ce44SJohn Forte 			    "Reauth disabled. did=0x%x state=%x",
1910fcf3ce44SJohn Forte 			    ndlp->nlp_DID, node_dhc->state);
1911fcf3ce44SJohn Forte 
1912fcf3ce44SJohn Forte 			emlxs_dhc_auth_complete(port, ndlp, 1);
1913fcf3ce44SJohn Forte 		}
1914fcf3ce44SJohn Forte 	}
1915fcf3ce44SJohn Forte 	emlxs_pkt_free(pkt);
1916fcf3ce44SJohn Forte 
1917fcf3ce44SJohn Forte 	return;
1918fcf3ce44SJohn Forte 
1919fcf3ce44SJohn Forte } /* emlxs_cmpl_auth_negotiate_issue */
1920fcf3ce44SJohn Forte 
1921fcf3ce44SJohn Forte 
1922fcf3ce44SJohn Forte /*
1923fcf3ce44SJohn Forte  * ! emlxs_cmpl_auth_msg_auth_negotiate_issue
1924fcf3ce44SJohn Forte  *
192582527734SSukumar Swaminathan  * \pre \post \param   port \param   CHANNEL * rp \param   arg \param   evt
1926fcf3ce44SJohn Forte  * \return  uint32_t \b Description:
1927fcf3ce44SJohn Forte  *
1928fcf3ce44SJohn Forte  * This routine is invoked when the host receive the solicited ACC/RJT ELS
1929fcf3ce44SJohn Forte  * cmd from an NxPort or FxPort that has received the ELS
1930fcf3ce44SJohn Forte  * AUTH Negotiate msg from the host. in case of RJT, Auth_Negotiate should
1931fcf3ce44SJohn Forte  * be retried in emlxs_cmpl_auth_negotiate_issue
1932fcf3ce44SJohn Forte  * call. in case of ACC, the host must be the initiator because its current
1933fcf3ce44SJohn Forte  * state could be "AUTH_NEGOTIATE_RCV" if it is the
1934fcf3ce44SJohn Forte  * responder. Then the next stat = AUTH_NEGOTIATE_CMPL_WAIT4NEXT
1935fcf3ce44SJohn Forte  */
1936fcf3ce44SJohn Forte /* ARGSUSED */
1937fcf3ce44SJohn Forte static uint32_t
emlxs_cmpl_auth_msg_auth_negotiate_issue(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)1938fcf3ce44SJohn Forte emlxs_cmpl_auth_msg_auth_negotiate_issue(
1939fcf3ce44SJohn Forte emlxs_port_t *port,
194082527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
1941fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
1942fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
1943fcf3ce44SJohn Forte /* NODELIST * ndlp, */ void *arg4,
1944fcf3ce44SJohn Forte uint32_t evt)
1945fcf3ce44SJohn Forte {
1946fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
1947fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
1948fcf3ce44SJohn Forte 
1949fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
1950*8f23e9faSHans Rosenfeld 	    "cmpl_auth_msg_auth_negotiate_issue: did=0x%x",
1951fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
1952fcf3ce44SJohn Forte 
1953fcf3ce44SJohn Forte 	/* start the emlxs_dhc_authrsp_timeout timer */
1954fcf3ce44SJohn Forte 	if (node_dhc->nlp_authrsp_tmo == 0) {
1955fcf3ce44SJohn Forte 		node_dhc->nlp_authrsp_tmo = DRV_TIME +
1956fcf3ce44SJohn Forte 		    node_dhc->auth_cfg.authentication_timeout;
1957fcf3ce44SJohn Forte 	}
1958fcf3ce44SJohn Forte 	/*
1959fcf3ce44SJohn Forte 	 * The next state should be
1960fcf3ce44SJohn Forte 	 * emlxs_rcv_auth_msg_auth_negotiate_cmpl_wait4next
1961fcf3ce44SJohn Forte 	 */
1962fcf3ce44SJohn Forte 	emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_NEGOTIATE_CMPL_WAIT4NEXT,
1963fcf3ce44SJohn Forte 	    0, 0);
1964fcf3ce44SJohn Forte 
1965fcf3ce44SJohn Forte 	return (node_dhc->state);
1966fcf3ce44SJohn Forte 
1967fcf3ce44SJohn Forte } /* emlxs_cmpl_auth_msg_auth_negotiate_issue */
1968fcf3ce44SJohn Forte 
1969fcf3ce44SJohn Forte 
1970fcf3ce44SJohn Forte 
1971fcf3ce44SJohn Forte /*
1972fcf3ce44SJohn Forte  * ! emlxs_rcv_auth_msg_auth_negotiate_issue
1973fcf3ce44SJohn Forte  *
1974fcf3ce44SJohn Forte  * \pre \post \param   phba \param   ndlp \param   arg \param   evt \return
1975fcf3ce44SJohn Forte  * uint32_t \b Description:
1976fcf3ce44SJohn Forte  *
1977fcf3ce44SJohn Forte  * This routine is supported for HBA in either auth initiator mode or
1978fcf3ce44SJohn Forte  * responder mode.
1979fcf3ce44SJohn Forte  *
1980fcf3ce44SJohn Forte  * This routine is invoked when the host receive an unsolicited ELS AUTH Msg
1981fcf3ce44SJohn Forte  * from an NxPort or FxPort to which the host has just
1982fcf3ce44SJohn Forte  * sent out an ELS AUTH negotiate msg. and the NxPort or FxPort also LS_ACC
1983fcf3ce44SJohn Forte  * to the host's AUTH_Negotiate msg.
1984fcf3ce44SJohn Forte  *
1985fcf3ce44SJohn Forte  * If this unsolicited ELS auth msg is from the FxPort or a NxPort with a
1986fcf3ce44SJohn Forte  * numerically lower WWPN, the host will be the winner in
1987fcf3ce44SJohn Forte  * this authentication transaction initiation phase, the host as the
1988fcf3ce44SJohn Forte  * initiator will send back ACC and then Auth_Reject message
1989fcf3ce44SJohn Forte  * with the Reason Code 'Logical Error' and Reason Code Explanation'
1990fcf3ce44SJohn Forte  * Authentication Transaction Already Started' and with the
1991fcf3ce44SJohn Forte  * current state unchanged and mark itself as auth_initiator.
1992fcf3ce44SJohn Forte  *
1993fcf3ce44SJohn Forte  * Otherwise, the host will be the responder that will reply to the received
1994fcf3ce44SJohn Forte  * AUTH_Negotiate message will ACC (or RJT?) and abort
1995fcf3ce44SJohn Forte  * its own transaction upon receipt of the AUTH_Reject message. The new state
1996fcf3ce44SJohn Forte  * will be "AUTH_NEGOTIATE_RCV" and mark the host as
1997fcf3ce44SJohn Forte  * auth_responder.
1998fcf3ce44SJohn Forte  */
1999fcf3ce44SJohn Forte /* ARGSUSED */
2000fcf3ce44SJohn Forte static uint32_t
emlxs_rcv_auth_msg_auth_negotiate_issue(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)2001fcf3ce44SJohn Forte emlxs_rcv_auth_msg_auth_negotiate_issue(
2002fcf3ce44SJohn Forte emlxs_port_t *port,
200382527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
2004fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
2005fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
2006fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
2007fcf3ce44SJohn Forte uint32_t evt)
2008fcf3ce44SJohn Forte {
2009fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
2010fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
2011fcf3ce44SJohn Forte 	IOCBQ *iocbq = (IOCBQ *) arg2;
2012fcf3ce44SJohn Forte 	uint8_t ReasonCode;
2013fcf3ce44SJohn Forte 	uint8_t ReasonCodeExplanation;
2014fcf3ce44SJohn Forte 
2015fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
2016*8f23e9faSHans Rosenfeld 	    "rcv_auth_msg_auth_negotiate_issue: did=0x%x",
2017fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
2018fcf3ce44SJohn Forte 
2019fcf3ce44SJohn Forte 	/* Anyway we accept it first and then send auth_reject */
2020fcf3ce44SJohn Forte 	(void) emlxs_els_reply(port, iocbq, ELS_CMD_ACC, ELS_CMD_AUTH, 0, 0);
2021fcf3ce44SJohn Forte 
2022fcf3ce44SJohn Forte 	/* host is always the initiator and it should win */
2023fcf3ce44SJohn Forte 	ReasonCode = AUTHRJT_LOGIC_ERR;
2024fcf3ce44SJohn Forte 	ReasonCodeExplanation = AUTHEXP_AUTHTRAN_STARTED;
2025fcf3ce44SJohn Forte 
2026fcf3ce44SJohn Forte 	emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_NEGOTIATE_ISSUE,
2027fcf3ce44SJohn Forte 	    ReasonCode, ReasonCodeExplanation);
2028fcf3ce44SJohn Forte 	(void) emlxs_issue_auth_reject(port, ndlp, 0, 0, ReasonCode,
2029fcf3ce44SJohn Forte 	    ReasonCodeExplanation);
2030fcf3ce44SJohn Forte 
2031fcf3ce44SJohn Forte 	return (node_dhc->state);
2032fcf3ce44SJohn Forte 
2033fcf3ce44SJohn Forte } /* emlxs_rcv_auth_msg_auth_negotiate_issue */
2034fcf3ce44SJohn Forte 
2035fcf3ce44SJohn Forte 
2036fcf3ce44SJohn Forte /*
2037fcf3ce44SJohn Forte  * ! emlxs_cmpl_dhchap_reply_issue
2038fcf3ce44SJohn Forte  *
2039fcf3ce44SJohn Forte  * \pre \post \param   phba \param   cmdiocb \param   rspiocb \return  void
2040fcf3ce44SJohn Forte  *
2041fcf3ce44SJohn Forte  * \b Description: iocb_cmpl callback function.
2042fcf3ce44SJohn Forte  *
2043fcf3ce44SJohn Forte  */
2044fcf3ce44SJohn Forte static void
emlxs_cmpl_dhchap_reply_issue(fc_packet_t * pkt)2045fcf3ce44SJohn Forte emlxs_cmpl_dhchap_reply_issue(fc_packet_t *pkt)
2046fcf3ce44SJohn Forte {
2047fcf3ce44SJohn Forte 	emlxs_port_t *port = pkt->pkt_ulp_private;
2048fcf3ce44SJohn Forte 	emlxs_buf_t *sbp;
2049fcf3ce44SJohn Forte 	NODELIST *ndlp;
2050fcf3ce44SJohn Forte 	uint32_t did;
2051fcf3ce44SJohn Forte 
2052fcf3ce44SJohn Forte 	did = pkt->pkt_cmd_fhdr.d_id;
2053fcf3ce44SJohn Forte 	sbp = (emlxs_buf_t *)pkt->pkt_fca_private;
2054fcf3ce44SJohn Forte 	ndlp = sbp->node;
2055fcf3ce44SJohn Forte 
2056fcf3ce44SJohn Forte 	if (!ndlp) {
2057*8f23e9faSHans Rosenfeld 		ndlp = emlxs_node_find_did(port, did, 1);
2058fcf3ce44SJohn Forte 	}
2059fcf3ce44SJohn Forte 	if (pkt->pkt_state != FC_PKT_SUCCESS) {
2060fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
2061*8f23e9faSHans Rosenfeld 		    "cmpl_dhchap_reply_issue: 0x%x %x. No retry.",
2062fcf3ce44SJohn Forte 		    did, pkt->pkt_state);
2063fcf3ce44SJohn Forte 	} else {
2064fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
2065*8f23e9faSHans Rosenfeld 		    "cmpl_dhchap_reply_issue: did=0x%x. Succcess.",
2066fcf3ce44SJohn Forte 		    did);
2067fcf3ce44SJohn Forte 	}
2068fcf3ce44SJohn Forte 
2069fcf3ce44SJohn Forte 	if (ndlp) {
2070fcf3ce44SJohn Forte 		if (pkt->pkt_state == FC_PKT_SUCCESS) {
2071fcf3ce44SJohn Forte 			(void) emlxs_dhchap_state_machine(port, NULL, NULL,
2072fcf3ce44SJohn Forte 			    NULL, ndlp, NODE_EVENT_CMPL_AUTH_MSG);
2073fcf3ce44SJohn Forte 		}
2074fcf3ce44SJohn Forte 	}
2075fcf3ce44SJohn Forte 	emlxs_pkt_free(pkt);
2076fcf3ce44SJohn Forte 
2077fcf3ce44SJohn Forte 	return;
2078fcf3ce44SJohn Forte 
2079fcf3ce44SJohn Forte } /* emlxs_cmpl_dhchap_reply_issue */
2080fcf3ce44SJohn Forte 
2081fcf3ce44SJohn Forte 
2082fcf3ce44SJohn Forte /*
2083fcf3ce44SJohn Forte  * arg: the AUTH_Negotiate payload from the initiator. payload_len: the
2084fcf3ce44SJohn Forte  * payload length
2085fcf3ce44SJohn Forte  *
2086fcf3ce44SJohn Forte  * We always send out the challenge parameter based on our preference
2087fcf3ce44SJohn Forte  * order configured on the host side no matter what perference
2088fcf3ce44SJohn Forte  * order looks like from auth_negotiate . In other words, if the host issue
2089fcf3ce44SJohn Forte  * the challenge the host will make the decision as to
2090fcf3ce44SJohn Forte  * what hash function, what dhgp_id is to be used.
2091fcf3ce44SJohn Forte  *
2092fcf3ce44SJohn Forte  * This challenge value should not be confused with the challenge value for
2093fcf3ce44SJohn Forte  * bi-dir as part of reply when host is the initiator.
2094fcf3ce44SJohn Forte  */
2095fcf3ce44SJohn Forte /* ARGSUSED */
2096fcf3ce44SJohn Forte uint32_t
emlxs_issue_dhchap_challenge(emlxs_port_t * port,NODELIST * ndlp,int retry,void * arg,uint32_t payload_len,uint32_t hash_id,uint32_t dhgp_id)2097fcf3ce44SJohn Forte emlxs_issue_dhchap_challenge(
2098fcf3ce44SJohn Forte 	emlxs_port_t *port,
2099fcf3ce44SJohn Forte 	NODELIST *ndlp,
2100fcf3ce44SJohn Forte 	int retry,
2101fcf3ce44SJohn Forte 	void *arg,
2102fcf3ce44SJohn Forte 	uint32_t payload_len,
2103fcf3ce44SJohn Forte 	uint32_t hash_id,
2104fcf3ce44SJohn Forte 	uint32_t dhgp_id)
2105fcf3ce44SJohn Forte {
2106fcf3ce44SJohn Forte 	emlxs_hba_t *hba = HBA;
2107fcf3ce44SJohn Forte 	fc_packet_t *pkt;
2108fcf3ce44SJohn Forte 	uint32_t cmd_size;
2109fcf3ce44SJohn Forte 	uint32_t rsp_size;
2110fcf3ce44SJohn Forte 	uint16_t cmdsize = 0;
2111fcf3ce44SJohn Forte 	uint8_t *pCmd;
2112fcf3ce44SJohn Forte 	emlxs_port_dhc_t *port_dhc = &port->port_dhc;
2113fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
2114fcf3ce44SJohn Forte 	DHCHAP_CHALL *chal;
2115fcf3ce44SJohn Forte 	uint8_t *tmp;
2116fcf3ce44SJohn Forte 	uint8_t random_number[20];
2117fcf3ce44SJohn Forte 	uint8_t dhval[256];
2118fcf3ce44SJohn Forte 	uint32_t dhval_len;
2119fcf3ce44SJohn Forte 	uint32_t tran_id;
2120fcf3ce44SJohn Forte 	BIG_ERR_CODE err = BIG_OK;
2121fcf3ce44SJohn Forte 
2122fcf3ce44SJohn Forte 	/*
2123fcf3ce44SJohn Forte 	 * we assume the HBAnyware should configure the driver the right
2124fcf3ce44SJohn Forte 	 * parameters for challenge. for now, we create our own challenge.
2125fcf3ce44SJohn Forte 	 */
2126fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
2127*8f23e9faSHans Rosenfeld 	    "issue_dhchap_challenge: did=0x%x hashlist=[%x,%x,%x,%x]",
2128fcf3ce44SJohn Forte 	    ndlp->nlp_DID, node_dhc->auth_cfg.hash_priority[0],
2129fcf3ce44SJohn Forte 	    node_dhc->auth_cfg.hash_priority[1],
2130fcf3ce44SJohn Forte 	    node_dhc->auth_cfg.hash_priority[2],
2131fcf3ce44SJohn Forte 	    node_dhc->auth_cfg.hash_priority[3]);
2132fcf3ce44SJohn Forte 
2133fcf3ce44SJohn Forte 	/*
2134fcf3ce44SJohn Forte 	 * Here is my own challenge structure:
2135fcf3ce44SJohn Forte 	 *
2136fcf3ce44SJohn Forte 	 * 1: AUTH_MSG_HDR (12 bytes + 4 bytes + 8 bytes) 2: hasd_id (4
2137fcf3ce44SJohn Forte 	 * bytes) 3: dhgp_id (4 bytes) 4: cval_len (4 bytes) 5: cval
2138fcf3ce44SJohn Forte 	 * (20 bytes or 16 bytes: cval_len bytes) 6: dhval_len (4 bytes)
2139fcf3ce44SJohn Forte 	 * 7: dhval (dhval_len bytes) all these information should be stored
2140fcf3ce44SJohn Forte 	 * in port_dhc struct
2141fcf3ce44SJohn Forte 	 */
2142fcf3ce44SJohn Forte 	if (hash_id == AUTH_SHA1) {
2143fcf3ce44SJohn Forte 		cmdsize = (12 + 4 + 8) + (4 + 4 + 4) + 20 + 4;
2144fcf3ce44SJohn Forte 	} else if (hash_id == AUTH_MD5) {
2145fcf3ce44SJohn Forte 		cmdsize = (12 + 4 + 8) + (4 + 4 + 4) + 16 + 4;
2146fcf3ce44SJohn Forte 	} else {
2147fcf3ce44SJohn Forte 		return (1);
2148fcf3ce44SJohn Forte 	}
2149fcf3ce44SJohn Forte 
2150fcf3ce44SJohn Forte 
2151fcf3ce44SJohn Forte 	switch (dhgp_id) {
2152fcf3ce44SJohn Forte 	case GROUP_NULL:
2153fcf3ce44SJohn Forte 		break;
2154fcf3ce44SJohn Forte 
2155fcf3ce44SJohn Forte 	case GROUP_1024:
2156fcf3ce44SJohn Forte 		cmdsize += 128;
2157fcf3ce44SJohn Forte 		break;
2158fcf3ce44SJohn Forte 
2159fcf3ce44SJohn Forte 	case GROUP_1280:
2160fcf3ce44SJohn Forte 		cmdsize += 160;
2161fcf3ce44SJohn Forte 		break;
2162fcf3ce44SJohn Forte 
2163fcf3ce44SJohn Forte 	case GROUP_1536:
2164fcf3ce44SJohn Forte 		cmdsize += 192;
2165fcf3ce44SJohn Forte 		break;
2166fcf3ce44SJohn Forte 
2167fcf3ce44SJohn Forte 	case GROUP_2048:
2168fcf3ce44SJohn Forte 		cmdsize += 256;
2169fcf3ce44SJohn Forte 		break;
2170fcf3ce44SJohn Forte 
2171fcf3ce44SJohn Forte 	default:
2172fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
2173*8f23e9faSHans Rosenfeld 		    "issue_dhchap_challenge: Invalid dhgp_id=0x%x",
2174fcf3ce44SJohn Forte 		    dhgp_id);
2175fcf3ce44SJohn Forte 		return (1);
2176fcf3ce44SJohn Forte 	}
2177fcf3ce44SJohn Forte 
2178fcf3ce44SJohn Forte 	cmd_size = cmdsize;
2179fcf3ce44SJohn Forte 	rsp_size = 4;
2180fcf3ce44SJohn Forte 
2181fcf3ce44SJohn Forte 	if ((pkt = emlxs_prep_els_fc_pkt(port, ndlp->nlp_DID, cmd_size,
2182fcf3ce44SJohn Forte 	    rsp_size,
2183fcf3ce44SJohn Forte 	    0, KM_NOSLEEP)) == NULL) {
2184fcf3ce44SJohn Forte 		return (1);
2185fcf3ce44SJohn Forte 	}
2186fcf3ce44SJohn Forte 	pCmd = (uint8_t *)pkt->pkt_cmd;
2187fcf3ce44SJohn Forte 
2188fcf3ce44SJohn Forte 	tmp = (uint8_t *)arg;
2189fcf3ce44SJohn Forte 	tmp += 8;
2190fcf3ce44SJohn Forte 	/* collect tran_id: this tran_id is set by the initiator */
2191fcf3ce44SJohn Forte 	tran_id = *(uint32_t *)tmp;
2192fcf3ce44SJohn Forte 
2193fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
2194*8f23e9faSHans Rosenfeld 	    "issue_dhchap_challenge: 0x%x 0x%x 0x%x %d 0x%x 0x%x 0x%x",
2195fcf3ce44SJohn Forte 	    ndlp->nlp_DID, node_dhc->nlp_auth_tranid_ini,
2196fcf3ce44SJohn Forte 	    node_dhc->nlp_auth_tranid_rsp,
2197fcf3ce44SJohn Forte 	    cmdsize, tran_id, hash_id, dhgp_id);
2198fcf3ce44SJohn Forte 
2199fcf3ce44SJohn Forte 	/* store the tran_id : ndlp is the initiator */
220082527734SSukumar Swaminathan 	node_dhc->nlp_auth_tranid_ini = LE_SWAP32(tran_id);
2201fcf3ce44SJohn Forte 
2202fcf3ce44SJohn Forte 	tmp += sizeof (uint32_t);
2203fcf3ce44SJohn Forte 
2204fcf3ce44SJohn Forte 	chal = (DHCHAP_CHALL *)pCmd;
2205fcf3ce44SJohn Forte 	chal->cnul.msg_hdr.auth_els_code = ELS_CMD_AUTH_CODE;
2206fcf3ce44SJohn Forte 	chal->cnul.msg_hdr.auth_els_flags = 0x0;
2207fcf3ce44SJohn Forte 	chal->cnul.msg_hdr.auth_msg_code = DHCHAP_CHALLENGE;
2208fcf3ce44SJohn Forte 	chal->cnul.msg_hdr.proto_version = 0x01;
220982527734SSukumar Swaminathan 	chal->cnul.msg_hdr.msg_len = LE_SWAP32(cmdsize - 12);
2210fcf3ce44SJohn Forte 	chal->cnul.msg_hdr.tran_id = tran_id;
2211fcf3ce44SJohn Forte 	chal->cnul.msg_hdr.name_tag = (AUTH_NAME_ID);
2212fcf3ce44SJohn Forte 	chal->cnul.msg_hdr.name_len = (AUTH_NAME_LEN);
2213fcf3ce44SJohn Forte 
2214fcf3ce44SJohn Forte 	bcopy((void *) &port->wwpn,
2215fcf3ce44SJohn Forte 	    (void *) &chal->cnul.msg_hdr.nodeName, sizeof (NAME_TYPE));
2216fcf3ce44SJohn Forte 
2217fcf3ce44SJohn Forte 	chal->cnul.hash_id = hash_id;
2218fcf3ce44SJohn Forte 	chal->cnul.dhgp_id = dhgp_id;
2219fcf3ce44SJohn Forte 
2220fcf3ce44SJohn Forte 	chal->cnul.cval_len = ((chal->cnul.hash_id == AUTH_SHA1) ?
222182527734SSukumar Swaminathan 	    LE_SWAP32(SHA1_LEN) : LE_SWAP32(MD5_LEN));
2222fcf3ce44SJohn Forte 
2223fcf3ce44SJohn Forte 	tmp = (uint8_t *)pCmd;
2224fcf3ce44SJohn Forte 	tmp += sizeof (DHCHAP_CHALL_NULL);
2225fcf3ce44SJohn Forte 
2226fcf3ce44SJohn Forte #ifdef RAND
2227fcf3ce44SJohn Forte 	/* generate a random number as the challenge */
222882527734SSukumar Swaminathan 	bzero(random_number, LE_SWAP32(chal->cnul.cval_len));
2229fcf3ce44SJohn Forte 
2230fcf3ce44SJohn Forte 	if (hba->rdn_flag == 1) {
2231fcf3ce44SJohn Forte 		emlxs_get_random_bytes(ndlp, random_number, 20);
2232fcf3ce44SJohn Forte 	} else {
2233e2ca2865SSukumar Swaminathan 		(void) random_get_pseudo_bytes(random_number,
223482527734SSukumar Swaminathan 		    LE_SWAP32(chal->cnul.cval_len));
2235fcf3ce44SJohn Forte 	}
2236fcf3ce44SJohn Forte 
2237fcf3ce44SJohn Forte 	/*
2238fcf3ce44SJohn Forte 	 * the host should store the challenge for later usage when later on
2239fcf3ce44SJohn Forte 	 * host get the reply msg, host needs to verify it by using its old
2240fcf3ce44SJohn Forte 	 * challenge, its private key as the input to the hash function. the
2241fcf3ce44SJohn Forte 	 * challenge as the random_number should be stored in
2242fcf3ce44SJohn Forte 	 * node_dhc->hrsp_cval[]
2243fcf3ce44SJohn Forte 	 */
224482527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
2245fcf3ce44SJohn Forte 		bcopy((void *) &random_number[0],
2246fcf3ce44SJohn Forte 		    (void *) &node_dhc->hrsp_cval[0],
224782527734SSukumar Swaminathan 		    LE_SWAP32(chal->cnul.cval_len));
2248fcf3ce44SJohn Forte 		/* save another copy in partner's ndlp */
2249fcf3ce44SJohn Forte 		bcopy((void *) &random_number[0],
2250fcf3ce44SJohn Forte 		    (void *) &node_dhc->nlp_auth_misc.hrsp_cval[0],
225182527734SSukumar Swaminathan 		    LE_SWAP32(chal->cnul.cval_len));
2252fcf3ce44SJohn Forte 	} else {
2253fcf3ce44SJohn Forte 		bcopy((void *) &random_number[0],
2254fcf3ce44SJohn Forte 		    (void *) &node_dhc->nlp_auth_misc.hrsp_cval[0],
225582527734SSukumar Swaminathan 		    LE_SWAP32(chal->cnul.cval_len));
2256fcf3ce44SJohn Forte 	}
2257fcf3ce44SJohn Forte 	bcopy((void *) &random_number[0], (void *) tmp,
225882527734SSukumar Swaminathan 	    LE_SWAP32(chal->cnul.cval_len));
2259fcf3ce44SJohn Forte 
2260fcf3ce44SJohn Forte #endif	/* RAND */
2261fcf3ce44SJohn Forte 
2262fcf3ce44SJohn Forte 	/* for test only hardcode the challenge value */
2263fcf3ce44SJohn Forte #ifdef MYRAND
226482527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
2265fcf3ce44SJohn Forte 		bcopy((void *) myrand, (void *) &node_dhc->hrsp_cval[0],
226682527734SSukumar Swaminathan 		    LE_SWAP32(chal->cnul.cval_len));
2267fcf3ce44SJohn Forte 		/* save another copy in partner's ndlp */
2268fcf3ce44SJohn Forte 		bcopy((void *) myrand,
2269fcf3ce44SJohn Forte 		    (void *) &node_dhc->nlp_auth_misc.hrsp_cval[0],
227082527734SSukumar Swaminathan 		    LE_SWAP32(chal->cnul.cval_len));
2271fcf3ce44SJohn Forte 	} else {
2272fcf3ce44SJohn Forte 		bcopy((void *) myrand,
2273fcf3ce44SJohn Forte 		    (void *) &node_dhc->nlp_auth_misc.hrsp_cval[0],
227482527734SSukumar Swaminathan 		    LE_SWAP32(chal->cnul.cval_len));
2275fcf3ce44SJohn Forte 	}
2276fcf3ce44SJohn Forte 	bcopy((void *) myrand, (void *) tmp,
227782527734SSukumar Swaminathan 	    LE_SWAP32(chal->cnul.cval_len));
2278fcf3ce44SJohn Forte 
2279fcf3ce44SJohn Forte #endif	/* MYRAND */
2280fcf3ce44SJohn Forte 
228182527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
228282527734SSukumar Swaminathan 		node_dhc->hrsp_cval_len = LE_SWAP32(chal->cnul.cval_len);
2283fcf3ce44SJohn Forte 		node_dhc->nlp_auth_misc.hrsp_cval_len =
228482527734SSukumar Swaminathan 		    LE_SWAP32(chal->cnul.cval_len);
2285fcf3ce44SJohn Forte 	} else {
2286fcf3ce44SJohn Forte 		node_dhc->nlp_auth_misc.hrsp_cval_len =
228782527734SSukumar Swaminathan 		    LE_SWAP32(chal->cnul.cval_len);
2288fcf3ce44SJohn Forte 	}
2289fcf3ce44SJohn Forte 
229082527734SSukumar Swaminathan 	tmp += LE_SWAP32(chal->cnul.cval_len);
2291fcf3ce44SJohn Forte 
2292fcf3ce44SJohn Forte 	/*
2293fcf3ce44SJohn Forte 	 * we need another random number as the private key x which will be
2294fcf3ce44SJohn Forte 	 * used to compute the public key i.e. g^x mod p we intentionally set
2295fcf3ce44SJohn Forte 	 * the length of private key as the same length of challenge. we have
2296fcf3ce44SJohn Forte 	 * to store the private key in node_dhc->hrsp_priv_key[20].
2297fcf3ce44SJohn Forte 	 */
2298fcf3ce44SJohn Forte #ifdef RAND
2299fcf3ce44SJohn Forte 
2300fcf3ce44SJohn Forte 	if (dhgp_id != GROUP_NULL) {
2301fcf3ce44SJohn Forte 
230282527734SSukumar Swaminathan 		bzero(random_number, LE_SWAP32(chal->cnul.cval_len));
2303fcf3ce44SJohn Forte 
2304fcf3ce44SJohn Forte 		if (hba->rdn_flag == 1) {
2305fcf3ce44SJohn Forte 			emlxs_get_random_bytes(ndlp, random_number, 20);
2306fcf3ce44SJohn Forte 		} else {
2307e2ca2865SSukumar Swaminathan 			(void) random_get_pseudo_bytes(random_number,
230882527734SSukumar Swaminathan 			    LE_SWAP32(chal->cnul.cval_len));
2309fcf3ce44SJohn Forte 		}
2310fcf3ce44SJohn Forte 
231182527734SSukumar Swaminathan 		if (ndlp->nlp_DID == FABRIC_DID) {
2312fcf3ce44SJohn Forte 			bcopy((void *) &random_number[0],
2313fcf3ce44SJohn Forte 			    (void *) node_dhc->hrsp_priv_key,
231482527734SSukumar Swaminathan 			    LE_SWAP32(chal->cnul.cval_len));
2315fcf3ce44SJohn Forte 			bcopy((void *) &random_number[0],
2316fcf3ce44SJohn Forte 			    (void *) node_dhc->nlp_auth_misc.hrsp_priv_key,
231782527734SSukumar Swaminathan 			    LE_SWAP32(chal->cnul.cval_len));
2318fcf3ce44SJohn Forte 		} else {
2319fcf3ce44SJohn Forte 			bcopy((void *) &random_number[0],
2320fcf3ce44SJohn Forte 			    (void *) node_dhc->nlp_auth_misc.hrsp_priv_key,
232182527734SSukumar Swaminathan 			    LE_SWAP32(chal->cnul.cval_len));
2322fcf3ce44SJohn Forte 		}
2323fcf3ce44SJohn Forte 	}
2324fcf3ce44SJohn Forte #endif	/* RAND */
2325fcf3ce44SJohn Forte 
2326fcf3ce44SJohn Forte #ifdef MYRAND
2327fcf3ce44SJohn Forte 	if (dhgp_id != GROUP_NULL) {
2328fcf3ce44SJohn Forte 		/* For test only we hardcode the priv_key here */
2329fcf3ce44SJohn Forte 		bcopy((void *) myrand, (void *) node_dhc->hrsp_priv_key,
233082527734SSukumar Swaminathan 		    LE_SWAP32(chal->cnul.cval_len));
2331fcf3ce44SJohn Forte 
233282527734SSukumar Swaminathan 		if (ndlp->nlp_DID == FABRIC_DID) {
2333fcf3ce44SJohn Forte 			bcopy((void *) myrand,
2334fcf3ce44SJohn Forte 			    (void *) node_dhc->hrsp_priv_key,
233582527734SSukumar Swaminathan 			    LE_SWAP32(chal->cnul.cval_len));
2336fcf3ce44SJohn Forte 			bcopy((void *) myrand,
2337fcf3ce44SJohn Forte 			    (void *) node_dhc->nlp_auth_misc.hrsp_priv_key,
233882527734SSukumar Swaminathan 			    LE_SWAP32(chal->cnul.cval_len));
2339fcf3ce44SJohn Forte 		} else {
2340fcf3ce44SJohn Forte 			bcopy((void *) myrand,
2341fcf3ce44SJohn Forte 			    (void *) node_dhc->nlp_auth_misc.hrsp_priv_key,
234282527734SSukumar Swaminathan 			    LE_SWAP32(chal->cnul.cval_len));
2343fcf3ce44SJohn Forte 		}
2344fcf3ce44SJohn Forte 	}
2345fcf3ce44SJohn Forte #endif	/* MYRAND */
2346fcf3ce44SJohn Forte 
2347fcf3ce44SJohn Forte 	/* also store the hash function and dhgp_id being used in challenge. */
2348fcf3ce44SJohn Forte 	/* These information could be configurable through HBAnyware */
2349fcf3ce44SJohn Forte 	node_dhc->nlp_auth_hashid = hash_id;
2350fcf3ce44SJohn Forte 	node_dhc->nlp_auth_dhgpid = dhgp_id;
2351fcf3ce44SJohn Forte 
2352fcf3ce44SJohn Forte 	/*
2353fcf3ce44SJohn Forte 	 * generate the DH value DH value is g^x mod p  and it is also called
2354fcf3ce44SJohn Forte 	 * public key in which g is 2, x is the random number ontained above.
2355fcf3ce44SJohn Forte 	 * p is the dhgp3_pVal
2356fcf3ce44SJohn Forte 	 */
2357fcf3ce44SJohn Forte 
2358fcf3ce44SJohn Forte #ifdef MYRAND
2359fcf3ce44SJohn Forte 
2360fcf3ce44SJohn Forte 	/* to get (g^x mod p) with x private key */
2361fcf3ce44SJohn Forte 	if (dhgp_id != GROUP_NULL) {
2362fcf3ce44SJohn Forte 
2363fcf3ce44SJohn Forte 		err = emlxs_BIGNUM_get_dhval(port, port_dhc, ndlp, dhval,
2364fcf3ce44SJohn Forte 		    &dhval_len, chal->cnul.dhgp_id,
236582527734SSukumar Swaminathan 		    myrand, LE_SWAP32(chal->cnul.cval_len));
2366fcf3ce44SJohn Forte 
2367fcf3ce44SJohn Forte 		if (err != BIG_OK) {
2368fcf3ce44SJohn Forte 			emlxs_pkt_free(pkt);
2369fcf3ce44SJohn Forte 
2370fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
2371*8f23e9faSHans Rosenfeld 			    "issue_dhchap_challenge: error. 0x%x",
2372fcf3ce44SJohn Forte 			    err);
2373fcf3ce44SJohn Forte 
2374fcf3ce44SJohn Forte 			return (1);
2375fcf3ce44SJohn Forte 		}
2376fcf3ce44SJohn Forte 		/* we are not going to use dhval and dhval_len */
2377fcf3ce44SJohn Forte 
2378fcf3ce44SJohn Forte 		/* *(uint32_t *)tmp = dhval_len; */
237982527734SSukumar Swaminathan 		if (ndlp->nlp_DID == FABRIC_DID) {
2380fcf3ce44SJohn Forte 			*(uint32_t *)tmp =
238182527734SSukumar Swaminathan 			    LE_SWAP32(node_dhc->hrsp_pubkey_len);
2382fcf3ce44SJohn Forte 		} else {
2383fcf3ce44SJohn Forte 			*(uint32_t *)tmp =
238482527734SSukumar Swaminathan 			    LE_SWAP32(
2385fcf3ce44SJohn Forte 			    node_dhc->nlp_auth_misc.hrsp_pubkey_len);
2386fcf3ce44SJohn Forte 		}
2387fcf3ce44SJohn Forte 
2388fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
2389*8f23e9faSHans Rosenfeld 		    "issue_dhchap_challenge: 0x%x: 0x%x 0x%x",
2390fcf3ce44SJohn Forte 		    ndlp->nlp_DID, *(uint32_t *)tmp, dhval_len);
2391fcf3ce44SJohn Forte 
2392fcf3ce44SJohn Forte 		tmp += sizeof (uint32_t);
2393fcf3ce44SJohn Forte 
239482527734SSukumar Swaminathan 		if (ndlp->nlp_DID == FABRIC_DID) {
2395fcf3ce44SJohn Forte 			bcopy((void *) node_dhc->hrsp_pub_key, (void *)tmp,
2396fcf3ce44SJohn Forte 			    node_dhc->hrsp_pubkey_len);
2397fcf3ce44SJohn Forte 		} else {
2398fcf3ce44SJohn Forte 			bcopy((void *) node_dhc->nlp_auth_misc.hrsp_pub_key,
2399fcf3ce44SJohn Forte 			    (void *)tmp,
2400fcf3ce44SJohn Forte 			    node_dhc->nlp_auth_misc.hrsp_pubkey_len);
2401fcf3ce44SJohn Forte 		}
2402fcf3ce44SJohn Forte 	} else {
2403fcf3ce44SJohn Forte 		/* NULL DHCHAP */
2404fcf3ce44SJohn Forte 		*(uint32_t *)tmp = 0;
2405fcf3ce44SJohn Forte 	}
2406fcf3ce44SJohn Forte 
2407fcf3ce44SJohn Forte #endif	/* MYRAND */
2408fcf3ce44SJohn Forte 
2409fcf3ce44SJohn Forte #ifdef RAND
2410fcf3ce44SJohn Forte 
2411fcf3ce44SJohn Forte 	/* to get (g^x mod p) with x private key */
2412fcf3ce44SJohn Forte 	if (dhgp_id != GROUP_NULL) {
2413fcf3ce44SJohn Forte 
2414fcf3ce44SJohn Forte 		err = emlxs_BIGNUM_get_dhval(port, port_dhc, ndlp, dhval,
2415fcf3ce44SJohn Forte 		    &dhval_len, chal->cnul.dhgp_id,
241682527734SSukumar Swaminathan 		    random_number, LE_SWAP32(chal->cnul.cval_len));
2417fcf3ce44SJohn Forte 
2418fcf3ce44SJohn Forte 		if (err != BIG_OK) {
2419fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
2420*8f23e9faSHans Rosenfeld 			    "issue_dhchap_challenge: error. 0x%x",
2421fcf3ce44SJohn Forte 			    err);
2422fcf3ce44SJohn Forte 
2423fcf3ce44SJohn Forte 			emlxs_pkt_free(pkt);
2424fcf3ce44SJohn Forte 			return (1);
2425fcf3ce44SJohn Forte 		}
2426fcf3ce44SJohn Forte 		/* we are not going to use dhval and dhval_len */
2427fcf3ce44SJohn Forte 
2428fcf3ce44SJohn Forte 		/* *(uint32_t *)tmp = dhval_len; */
242982527734SSukumar Swaminathan 		if (ndlp->nlp_DID == FABRIC_DID) {
2430fcf3ce44SJohn Forte 			*(uint32_t *)tmp =
243182527734SSukumar Swaminathan 			    LE_SWAP32(node_dhc->hrsp_pubkey_len);
2432fcf3ce44SJohn Forte 		} else {
2433fcf3ce44SJohn Forte 			*(uint32_t *)tmp =
243482527734SSukumar Swaminathan 			    LE_SWAP32(
2435fcf3ce44SJohn Forte 			    node_dhc->nlp_auth_misc.hrsp_pubkey_len);
2436fcf3ce44SJohn Forte 		}
2437fcf3ce44SJohn Forte 
2438fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
2439*8f23e9faSHans Rosenfeld 		    "issue_dhchap_challenge: did=0x%x: pubkey_len=0x%x",
2440fcf3ce44SJohn Forte 		    ndlp->nlp_DID, *(uint32_t *)tmp);
2441fcf3ce44SJohn Forte 
2442fcf3ce44SJohn Forte 		tmp += sizeof (uint32_t);
2443fcf3ce44SJohn Forte 
244482527734SSukumar Swaminathan 		if (ndlp->nlp_DID == FABRIC_DID) {
2445fcf3ce44SJohn Forte 			bcopy((void *) node_dhc->hrsp_pub_key, (void *)tmp,
2446fcf3ce44SJohn Forte 			    node_dhc->hrsp_pubkey_len);
2447fcf3ce44SJohn Forte 		} else {
2448fcf3ce44SJohn Forte 			bcopy((void *) node_dhc->nlp_auth_misc.hrsp_pub_key,
2449fcf3ce44SJohn Forte 			    (void *)tmp,
2450fcf3ce44SJohn Forte 			    node_dhc->nlp_auth_misc.hrsp_pubkey_len);
2451fcf3ce44SJohn Forte 		}
2452fcf3ce44SJohn Forte 	} else {
2453fcf3ce44SJohn Forte 		/* NULL DHCHAP */
2454fcf3ce44SJohn Forte 		*(uint32_t *)tmp = 0;
2455fcf3ce44SJohn Forte 	}
2456fcf3ce44SJohn Forte 
2457fcf3ce44SJohn Forte #endif	/* RAND */
2458fcf3ce44SJohn Forte 
2459fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
2460*8f23e9faSHans Rosenfeld 	    "issue_dhchap_challenge: 0x%x 0x%x 0x%x 0x%x 0x%x",
2461fcf3ce44SJohn Forte 	    ndlp->nlp_DID, node_dhc->nlp_auth_tranid_ini,
2462fcf3ce44SJohn Forte 	    node_dhc->nlp_auth_tranid_rsp,
2463fcf3ce44SJohn Forte 	    chal->cnul.hash_id, chal->cnul.dhgp_id);
2464fcf3ce44SJohn Forte 
2465fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
2466*8f23e9faSHans Rosenfeld 	    "issue_dhchap_challenge: 0x%x 0x%x 0x%x 0x%x",
2467fcf3ce44SJohn Forte 	    ndlp->nlp_DID, tran_id, node_dhc->nlp_auth_hashid,
2468fcf3ce44SJohn Forte 	    node_dhc->nlp_auth_dhgpid);
2469fcf3ce44SJohn Forte 
2470fcf3ce44SJohn Forte 	pkt->pkt_comp = emlxs_cmpl_dhchap_challenge_issue;
2471fcf3ce44SJohn Forte 
2472fcf3ce44SJohn Forte 	if (emlxs_pkt_send(pkt, 1) != FC_SUCCESS) {
2473fcf3ce44SJohn Forte 		emlxs_pkt_free(pkt);
2474fcf3ce44SJohn Forte 
2475fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
2476*8f23e9faSHans Rosenfeld 		    "issue_dhchap_challenge: Unable to send fc packet.");
2477fcf3ce44SJohn Forte 
2478fcf3ce44SJohn Forte 		return (1);
2479fcf3ce44SJohn Forte 	}
2480fcf3ce44SJohn Forte 	return (0);
2481fcf3ce44SJohn Forte 
2482fcf3ce44SJohn Forte } /* emlxs_issue_dhchap_challenge */
2483fcf3ce44SJohn Forte 
2484fcf3ce44SJohn Forte 
2485fcf3ce44SJohn Forte /*
2486fcf3ce44SJohn Forte  * DHCHAP_Reply msg
2487fcf3ce44SJohn Forte  */
2488fcf3ce44SJohn Forte /* ARGSUSED */
2489fcf3ce44SJohn Forte uint32_t
emlxs_issue_dhchap_reply(emlxs_port_t * port,NODELIST * ndlp,int retry,uint32_t * arg1,uint8_t * dhval,uint32_t dhval_len,uint8_t * arg2,uint32_t arg2_len)2490fcf3ce44SJohn Forte emlxs_issue_dhchap_reply(
2491fcf3ce44SJohn Forte 	emlxs_port_t *port,
2492fcf3ce44SJohn Forte 	NODELIST *ndlp,
2493fcf3ce44SJohn Forte 	int retry,
2494fcf3ce44SJohn Forte 	uint32_t *arg1, /* response */
2495fcf3ce44SJohn Forte 	uint8_t *dhval,
2496fcf3ce44SJohn Forte 	uint32_t dhval_len,
2497fcf3ce44SJohn Forte 	uint8_t *arg2,	/* random number */
2498fcf3ce44SJohn Forte 	uint32_t arg2_len)
2499fcf3ce44SJohn Forte {
2500fcf3ce44SJohn Forte 	fc_packet_t *pkt;
2501fcf3ce44SJohn Forte 	uint32_t cmd_size;
2502fcf3ce44SJohn Forte 	uint32_t rsp_size;
2503fcf3ce44SJohn Forte 	uint16_t cmdsize = 0;
2504fcf3ce44SJohn Forte 	DHCHAP_REPLY_HDR *ap;
2505fcf3ce44SJohn Forte 	uint8_t *pCmd;
2506fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
2507fcf3ce44SJohn Forte 
2508fcf3ce44SJohn Forte 	/* Header size */
2509fcf3ce44SJohn Forte 	cmdsize = sizeof (DHCHAP_REPLY_HDR);
2510fcf3ce44SJohn Forte 
2511fcf3ce44SJohn Forte 	/* Rsp value len size (4) + Response value size */
251282527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
2513fcf3ce44SJohn Forte 		if (node_dhc->hash_id == AUTH_MD5) {
2514fcf3ce44SJohn Forte 			cmdsize += 4 + MD5_LEN;
2515fcf3ce44SJohn Forte 		}
2516fcf3ce44SJohn Forte 		if (node_dhc->hash_id == AUTH_SHA1) {
2517fcf3ce44SJohn Forte 			cmdsize += 4 + SHA1_LEN;
2518fcf3ce44SJohn Forte 		}
2519fcf3ce44SJohn Forte 	} else {
2520fcf3ce44SJohn Forte 		if (node_dhc->nlp_auth_hashid == AUTH_MD5) {
2521fcf3ce44SJohn Forte 			cmdsize += 4 + MD5_LEN;
2522fcf3ce44SJohn Forte 		}
2523fcf3ce44SJohn Forte 		if (node_dhc->nlp_auth_hashid == AUTH_SHA1) {
2524fcf3ce44SJohn Forte 			cmdsize += 4 + SHA1_LEN;
2525fcf3ce44SJohn Forte 		}
2526fcf3ce44SJohn Forte 	}
2527fcf3ce44SJohn Forte 
2528fcf3ce44SJohn Forte 	/* DH value len size (4) + DH value size */
252982527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
2530fcf3ce44SJohn Forte 		switch (node_dhc->dhgp_id) {
2531fcf3ce44SJohn Forte 		case GROUP_NULL:
2532fcf3ce44SJohn Forte 
2533fcf3ce44SJohn Forte 			break;
2534fcf3ce44SJohn Forte 
2535fcf3ce44SJohn Forte 		case GROUP_1024:
2536fcf3ce44SJohn Forte 		case GROUP_1280:
2537fcf3ce44SJohn Forte 		case GROUP_1536:
2538fcf3ce44SJohn Forte 		case GROUP_2048:
2539fcf3ce44SJohn Forte 		default:
2540fcf3ce44SJohn Forte 			break;
2541fcf3ce44SJohn Forte 		}
2542fcf3ce44SJohn Forte 	}
2543fcf3ce44SJohn Forte 
2544fcf3ce44SJohn Forte 	cmdsize += 4 + dhval_len;
2545fcf3ce44SJohn Forte 
2546fcf3ce44SJohn Forte 	/* Challenge value len size (4) + Challenge value size */
2547fcf3ce44SJohn Forte 	if (node_dhc->auth_cfg.bidirectional == 0) {
2548fcf3ce44SJohn Forte 		cmdsize += 4;
2549fcf3ce44SJohn Forte 	} else {
255082527734SSukumar Swaminathan 		if (ndlp->nlp_DID == FABRIC_DID) {
2551fcf3ce44SJohn Forte 			cmdsize += 4 + ((node_dhc->hash_id == AUTH_MD5) ?
2552fcf3ce44SJohn Forte 			    MD5_LEN : SHA1_LEN);
2553fcf3ce44SJohn Forte 		} else {
2554fcf3ce44SJohn Forte 			cmdsize += 4 +
2555fcf3ce44SJohn Forte 			    ((node_dhc->nlp_auth_hashid == AUTH_MD5) ? MD5_LEN :
2556fcf3ce44SJohn Forte 			    SHA1_LEN);
2557fcf3ce44SJohn Forte 		}
2558fcf3ce44SJohn Forte 	}
2559fcf3ce44SJohn Forte 
2560fcf3ce44SJohn Forte 	cmd_size = cmdsize;
2561fcf3ce44SJohn Forte 	rsp_size = 4;
2562fcf3ce44SJohn Forte 
2563fcf3ce44SJohn Forte 	if ((pkt = emlxs_prep_els_fc_pkt(port, ndlp->nlp_DID, cmd_size,
2564fcf3ce44SJohn Forte 	    rsp_size, 0, KM_NOSLEEP)) == NULL) {
2565fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
2566*8f23e9faSHans Rosenfeld 		    "issue_dhchap_reply failed: did=0x%x size=%x,%x",
2567fcf3ce44SJohn Forte 		    ndlp->nlp_DID, cmd_size, rsp_size);
2568fcf3ce44SJohn Forte 
2569fcf3ce44SJohn Forte 		return (1);
2570fcf3ce44SJohn Forte 	}
2571fcf3ce44SJohn Forte 	pCmd = (uint8_t *)pkt->pkt_cmd;
2572fcf3ce44SJohn Forte 
2573fcf3ce44SJohn Forte 	ap = (DHCHAP_REPLY_HDR *)pCmd;
2574fcf3ce44SJohn Forte 	ap->auth_els_code = ELS_CMD_AUTH_CODE;
2575fcf3ce44SJohn Forte 	ap->auth_els_flags = 0x0;
2576fcf3ce44SJohn Forte 	ap->auth_msg_code = DHCHAP_REPLY;
2577fcf3ce44SJohn Forte 	ap->proto_version = 0x01;
257882527734SSukumar Swaminathan 	ap->msg_len = LE_SWAP32(cmdsize - sizeof (DHCHAP_REPLY_HDR));
257982527734SSukumar Swaminathan 	ap->tran_id = LE_SWAP32(node_dhc->nlp_auth_tranid_rsp);
2580fcf3ce44SJohn Forte 
2581fcf3ce44SJohn Forte 	pCmd = (uint8_t *)(pCmd + sizeof (DHCHAP_REPLY_HDR));
2582fcf3ce44SJohn Forte 
258382527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
2584fcf3ce44SJohn Forte 		if (node_dhc->hash_id == AUTH_MD5) {
258582527734SSukumar Swaminathan 			*(uint32_t *)pCmd = LE_SWAP32(MD5_LEN);
2586fcf3ce44SJohn Forte 		} else {
258782527734SSukumar Swaminathan 			*(uint32_t *)pCmd = LE_SWAP32(SHA1_LEN);
2588fcf3ce44SJohn Forte 		}
2589fcf3ce44SJohn Forte 	} else {
2590fcf3ce44SJohn Forte 		if (node_dhc->nlp_auth_hashid == AUTH_MD5) {
259182527734SSukumar Swaminathan 			*(uint32_t *)pCmd = LE_SWAP32(MD5_LEN);
2592fcf3ce44SJohn Forte 		} else {
259382527734SSukumar Swaminathan 			*(uint32_t *)pCmd = LE_SWAP32(SHA1_LEN);
2594fcf3ce44SJohn Forte 		}
2595fcf3ce44SJohn Forte 	}
2596fcf3ce44SJohn Forte 
2597fcf3ce44SJohn Forte 	pCmd = (uint8_t *)(pCmd + 4);
2598fcf3ce44SJohn Forte 
259982527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
2600fcf3ce44SJohn Forte 		if (node_dhc->hash_id == AUTH_MD5) {
2601fcf3ce44SJohn Forte 			bcopy((void *)arg1, pCmd, MD5_LEN);
2602fcf3ce44SJohn Forte 			pCmd = (uint8_t *)(pCmd + MD5_LEN);
2603fcf3ce44SJohn Forte 		} else {
2604fcf3ce44SJohn Forte 			bcopy((void *)arg1, (void *)pCmd, SHA1_LEN);
2605fcf3ce44SJohn Forte 
2606fcf3ce44SJohn Forte 			pCmd = (uint8_t *)(pCmd + SHA1_LEN);
2607fcf3ce44SJohn Forte 		}
2608fcf3ce44SJohn Forte 	} else {
2609fcf3ce44SJohn Forte 		if (node_dhc->nlp_auth_hashid == AUTH_MD5) {
2610fcf3ce44SJohn Forte 			bcopy((void *)arg1, pCmd, MD5_LEN);
2611fcf3ce44SJohn Forte 			pCmd = (uint8_t *)(pCmd + MD5_LEN);
2612fcf3ce44SJohn Forte 		} else {
2613fcf3ce44SJohn Forte 			bcopy((void *)arg1, (void *)pCmd, SHA1_LEN);
2614fcf3ce44SJohn Forte 			pCmd = (uint8_t *)(pCmd + SHA1_LEN);
2615fcf3ce44SJohn Forte 		}
2616fcf3ce44SJohn Forte 	}
2617fcf3ce44SJohn Forte 
261882527734SSukumar Swaminathan 	*(uint32_t *)pCmd = LE_SWAP32(dhval_len);
2619fcf3ce44SJohn Forte 
2620fcf3ce44SJohn Forte 	if (dhval_len != 0) {
2621fcf3ce44SJohn Forte 		pCmd = (uint8_t *)(pCmd + 4);
2622fcf3ce44SJohn Forte 
2623fcf3ce44SJohn Forte 		switch (node_dhc->dhgp_id) {
2624fcf3ce44SJohn Forte 		case GROUP_NULL:
2625fcf3ce44SJohn Forte 
2626fcf3ce44SJohn Forte 			break;
2627fcf3ce44SJohn Forte 
2628fcf3ce44SJohn Forte 		case GROUP_1024:
2629fcf3ce44SJohn Forte 		case GROUP_1280:
2630fcf3ce44SJohn Forte 		case GROUP_1536:
2631fcf3ce44SJohn Forte 		case GROUP_2048:
2632fcf3ce44SJohn Forte 		default:
2633fcf3ce44SJohn Forte 			break;
2634fcf3ce44SJohn Forte 		}
2635fcf3ce44SJohn Forte 		/* elx_bcopy((void *)dhval, (void *)pCmd, dhval_len); */
2636fcf3ce44SJohn Forte 		/*
2637fcf3ce44SJohn Forte 		 * The new DH parameter (g^y mod p) is stored in
2638fcf3ce44SJohn Forte 		 * node_dhc->pub_key
2639fcf3ce44SJohn Forte 		 */
2640fcf3ce44SJohn Forte 		/* pubkey_len should be equal to dhval_len */
2641fcf3ce44SJohn Forte 
264282527734SSukumar Swaminathan 		if (ndlp->nlp_DID == FABRIC_DID) {
2643fcf3ce44SJohn Forte 			bcopy((void *) node_dhc->pub_key, (void *)pCmd,
2644fcf3ce44SJohn Forte 			    node_dhc->pubkey_len);
2645fcf3ce44SJohn Forte 		} else {
2646fcf3ce44SJohn Forte 			bcopy((void *) node_dhc->nlp_auth_misc.pub_key,
2647fcf3ce44SJohn Forte 			    (void *)pCmd,
2648fcf3ce44SJohn Forte 			    node_dhc->nlp_auth_misc.pubkey_len);
2649fcf3ce44SJohn Forte 		}
2650fcf3ce44SJohn Forte 		pCmd = (uint8_t *)(pCmd + dhval_len);
2651fcf3ce44SJohn Forte 	} else
2652fcf3ce44SJohn Forte 		pCmd = (uint8_t *)(pCmd + 4);
2653fcf3ce44SJohn Forte 
2654fcf3ce44SJohn Forte 	if (node_dhc->auth_cfg.bidirectional == 0) {
2655fcf3ce44SJohn Forte 		*(uint32_t *)pCmd = 0x0;
2656fcf3ce44SJohn Forte 	} else {
265782527734SSukumar Swaminathan 		if (ndlp->nlp_DID == FABRIC_DID) {
2658fcf3ce44SJohn Forte 			if (node_dhc->hash_id == AUTH_MD5) {
265982527734SSukumar Swaminathan 				*(uint32_t *)pCmd = LE_SWAP32(MD5_LEN);
2660fcf3ce44SJohn Forte 				pCmd = (uint8_t *)(pCmd + 4);
2661fcf3ce44SJohn Forte 				bcopy((void *)arg2, (void *)pCmd, arg2_len);
2662fcf3ce44SJohn Forte 			} else if (node_dhc->hash_id == AUTH_SHA1) {
266382527734SSukumar Swaminathan 				*(uint32_t *)pCmd = LE_SWAP32(SHA1_LEN);
2664fcf3ce44SJohn Forte 				pCmd = (uint8_t *)(pCmd + 4);
2665fcf3ce44SJohn Forte 				/* store the challenge */
2666fcf3ce44SJohn Forte 				bcopy((void *)arg2, (void *)pCmd, arg2_len);
2667fcf3ce44SJohn Forte 			}
2668fcf3ce44SJohn Forte 		} else {
2669fcf3ce44SJohn Forte 			if (node_dhc->nlp_auth_hashid == AUTH_MD5) {
267082527734SSukumar Swaminathan 				*(uint32_t *)pCmd = LE_SWAP32(MD5_LEN);
2671fcf3ce44SJohn Forte 				pCmd = (uint8_t *)(pCmd + 4);
2672fcf3ce44SJohn Forte 				bcopy((void *)arg2, (void *)pCmd, arg2_len);
2673fcf3ce44SJohn Forte 			} else if (node_dhc->nlp_auth_hashid == AUTH_SHA1) {
267482527734SSukumar Swaminathan 				*(uint32_t *)pCmd = LE_SWAP32(SHA1_LEN);
2675fcf3ce44SJohn Forte 				pCmd = (uint8_t *)(pCmd + 4);
2676fcf3ce44SJohn Forte 				bcopy((void *)arg2, (void *)pCmd, arg2_len);
2677fcf3ce44SJohn Forte 			}
2678fcf3ce44SJohn Forte 		}
2679fcf3ce44SJohn Forte 	}
2680fcf3ce44SJohn Forte 
2681fcf3ce44SJohn Forte 	pkt->pkt_comp = emlxs_cmpl_dhchap_reply_issue;
2682fcf3ce44SJohn Forte 
2683fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
2684*8f23e9faSHans Rosenfeld 	    "issue_dhchap_reply: did=0x%x  (%x,%x,%x,%x,%x,%x)",
2685fcf3ce44SJohn Forte 	    ndlp->nlp_DID, dhval_len, arg2_len, cmdsize,
2686fcf3ce44SJohn Forte 	    node_dhc->hash_id, node_dhc->nlp_auth_hashid,
268782527734SSukumar Swaminathan 	    LE_SWAP32(ap->tran_id));
2688fcf3ce44SJohn Forte 
2689fcf3ce44SJohn Forte 	if (emlxs_pkt_send(pkt, 1) != FC_SUCCESS) {
2690fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
2691*8f23e9faSHans Rosenfeld 		    "issue_dhchap_reply failed: Unable to send packet.");
2692fcf3ce44SJohn Forte 
2693fcf3ce44SJohn Forte 		emlxs_pkt_free(pkt);
2694fcf3ce44SJohn Forte 
2695fcf3ce44SJohn Forte 		return (1);
2696fcf3ce44SJohn Forte 	}
2697fcf3ce44SJohn Forte 	return (0);
2698fcf3ce44SJohn Forte 
2699fcf3ce44SJohn Forte } /* emlxs_issue_dhchap_reply */
2700fcf3ce44SJohn Forte 
2701fcf3ce44SJohn Forte 
2702fcf3ce44SJohn Forte 
2703fcf3ce44SJohn Forte /*
2704fcf3ce44SJohn Forte  * ! emlxs_rcv_auth_msg_auth_negotiate_cmpl_wait4next
2705fcf3ce44SJohn Forte  *
2706fcf3ce44SJohn Forte  * \pre \post \param   phba \param   ndlp \param   arg \param   evt \return
2707fcf3ce44SJohn Forte  * uint32_t \b Description:
2708fcf3ce44SJohn Forte  *
2709fcf3ce44SJohn Forte  * This routine is invoked when the host received an unsolicted ELS AUTH MSG
2710fcf3ce44SJohn Forte  * from an NxPort or FxPort which already replied (ACC)
2711fcf3ce44SJohn Forte  * the ELS AUTH_Negotiate msg from the host. if msg is DHCHAP_Chellenge,
2712fcf3ce44SJohn Forte  * based on the msg content (DHCHAP computation etc.,)
2713fcf3ce44SJohn Forte  * the host send back ACC and 1. send back AUTH_Reject and set next state =
2714fcf3ce44SJohn Forte  * NPR_NODE or 2. send back DHCHAP_Reply msg and set
2715fcf3ce44SJohn Forte  * next state = DHCHAP_REPLY_ISSUE for bi-directional, the DHCHAP_Reply
2716fcf3ce44SJohn Forte  * includes challenge from host. for uni-directional, no
2717fcf3ce44SJohn Forte  * more challenge. if msg is AUTH_Reject or anything else, host send back
2718fcf3ce44SJohn Forte  * ACC and set next state = NPR_NODE. And based on the
2719fcf3ce44SJohn Forte  * reject code, host may need to retry negotiate with NULL DH only
2720fcf3ce44SJohn Forte  *
2721fcf3ce44SJohn Forte  * If the msg is AUTH_ELS cmd, cancel the nlp_authrsp_timeout timer immediately.
2722fcf3ce44SJohn Forte  *
2723fcf3ce44SJohn Forte  */
2724fcf3ce44SJohn Forte /* ARGSUSED */
2725fcf3ce44SJohn Forte static uint32_t
emlxs_rcv_auth_msg_auth_negotiate_cmpl_wait4next(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)2726fcf3ce44SJohn Forte emlxs_rcv_auth_msg_auth_negotiate_cmpl_wait4next(
2727fcf3ce44SJohn Forte emlxs_port_t *port,
272882527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
2729fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
2730fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
2731fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
2732fcf3ce44SJohn Forte uint32_t evt)
2733fcf3ce44SJohn Forte {
2734fcf3ce44SJohn Forte 	emlxs_hba_t *hba = HBA;
2735fcf3ce44SJohn Forte 	emlxs_port_dhc_t *port_dhc = &port->port_dhc;
2736fcf3ce44SJohn Forte 	IOCBQ *iocbq = (IOCBQ *)arg2;
2737fcf3ce44SJohn Forte 	MATCHMAP *mp = (MATCHMAP *)arg3;
2738fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
2739fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
2740fcf3ce44SJohn Forte 	uint8_t *bp;
2741fcf3ce44SJohn Forte 	uint32_t *lp;
2742fcf3ce44SJohn Forte 	DHCHAP_CHALL_NULL *ncval;
2743fcf3ce44SJohn Forte 	uint16_t namelen;
2744fcf3ce44SJohn Forte 	uint32_t dhvallen;
2745fcf3ce44SJohn Forte 	uint8_t *tmp;
2746fcf3ce44SJohn Forte 	uint8_t ReasonCode;
2747fcf3ce44SJohn Forte 	uint8_t ReasonCodeExplanation;
2748fcf3ce44SJohn Forte 
2749fcf3ce44SJohn Forte 	union challenge_val un_cval;
2750fcf3ce44SJohn Forte 
2751fcf3ce44SJohn Forte 	uint8_t *dhval = NULL;
2752fcf3ce44SJohn Forte 	uint8_t random_number[20];	/* for both SHA1 and MD5 */
2753fcf3ce44SJohn Forte 	uint32_t *arg5 = NULL;	/* response */
2754fcf3ce44SJohn Forte 	uint32_t tran_id;	/* Transaction Identifier */
2755fcf3ce44SJohn Forte 	uint32_t arg2len = 0;	/* len of new challenge for bidir auth */
2756fcf3ce44SJohn Forte 
2757fcf3ce44SJohn Forte 	AUTH_RJT *rjt;
2758fcf3ce44SJohn Forte 
2759fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
2760*8f23e9faSHans Rosenfeld 	    "rcv_auth_msg_auth_negotiate_cmpl_wait4next: did=0x%x",
2761fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
2762fcf3ce44SJohn Forte 
2763fcf3ce44SJohn Forte 	emlxs_dhc_state(port, ndlp, NODE_STATE_DHCHAP_REPLY_ISSUE, 0, 0);
2764fcf3ce44SJohn Forte 
2765fcf3ce44SJohn Forte 	(void) emlxs_els_reply(port, iocbq, ELS_CMD_ACC, ELS_CMD_AUTH, 0, 0);
2766fcf3ce44SJohn Forte 
2767fcf3ce44SJohn Forte 	bp = mp->virt;
2768fcf3ce44SJohn Forte 	lp = (uint32_t *)bp;
2769fcf3ce44SJohn Forte 
2770fcf3ce44SJohn Forte 	/*
2771fcf3ce44SJohn Forte 	 * 1. we process the DHCHAP_Challenge 2. ACC it first 3. based on the
2772fcf3ce44SJohn Forte 	 * result of 1 we DHCHAP_Reply or AUTH_Reject
2773fcf3ce44SJohn Forte 	 */
2774fcf3ce44SJohn Forte 	ncval = (DHCHAP_CHALL_NULL *)((uint8_t *)lp);
2775fcf3ce44SJohn Forte 
2776fcf3ce44SJohn Forte 	if (ncval->msg_hdr.auth_els_code != ELS_CMD_AUTH_CODE) {
2777fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
2778fcf3ce44SJohn Forte 		    "rcv_auth_msg_auth_negotiate_cmpl_wait4next: 0x%x %x",
2779fcf3ce44SJohn Forte 		    ndlp->nlp_DID, ncval->msg_hdr.auth_els_code);
2780fcf3ce44SJohn Forte 
2781fcf3ce44SJohn Forte 		/* need to setup reason code/reason explanation code  */
2782fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_FAILURE;
2783fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_BAD_PROTOCOL;
2784fcf3ce44SJohn Forte 		goto AUTH_Reject;
2785fcf3ce44SJohn Forte 	}
2786fcf3ce44SJohn Forte 	if (ncval->msg_hdr.auth_msg_code == AUTH_REJECT) {
2787fcf3ce44SJohn Forte 		rjt = (AUTH_RJT *)((uint8_t *)lp);
2788fcf3ce44SJohn Forte 		ReasonCode = rjt->ReasonCode;
2789fcf3ce44SJohn Forte 		ReasonCodeExplanation = rjt->ReasonCodeExplanation;
2790fcf3ce44SJohn Forte 
2791fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
2792fcf3ce44SJohn Forte 		    "rcv_auth_msg_auth_negotiate_cmpl_wait4next: 0x%x.%x,%x",
2793fcf3ce44SJohn Forte 		    ndlp->nlp_DID, ReasonCode, ReasonCodeExplanation);
2794fcf3ce44SJohn Forte 
2795fcf3ce44SJohn Forte 		switch (ReasonCode) {
2796fcf3ce44SJohn Forte 		case AUTHRJT_LOGIC_ERR:
2797fcf3ce44SJohn Forte 			switch (ReasonCodeExplanation) {
2798fcf3ce44SJohn Forte 			case AUTHEXP_MECH_UNUSABLE:
2799fcf3ce44SJohn Forte 			case AUTHEXP_DHGROUP_UNUSABLE:
2800fcf3ce44SJohn Forte 			case AUTHEXP_HASHFUNC_UNUSABLE:
2801fcf3ce44SJohn Forte 				ReasonCode = AUTHRJT_LOGIC_ERR;
2802fcf3ce44SJohn Forte 				ReasonCodeExplanation = AUTHEXP_RESTART_AUTH;
2803fcf3ce44SJohn Forte 				break;
2804fcf3ce44SJohn Forte 
2805fcf3ce44SJohn Forte 			case AUTHEXP_RESTART_AUTH:
2806fcf3ce44SJohn Forte 				/*
2807fcf3ce44SJohn Forte 				 * Cancel the rsp timer if not cancelled yet.
2808fcf3ce44SJohn Forte 				 * and restart auth tran now.
2809fcf3ce44SJohn Forte 				 */
2810fcf3ce44SJohn Forte 				if (node_dhc->nlp_authrsp_tmo != 0) {
2811fcf3ce44SJohn Forte 					node_dhc->nlp_authrsp_tmo = 0;
2812fcf3ce44SJohn Forte 					node_dhc->nlp_authrsp_tmocnt = 0;
2813fcf3ce44SJohn Forte 				}
2814fcf3ce44SJohn Forte 				if (emlxs_dhc_auth_start(port, ndlp, NULL,
2815fcf3ce44SJohn Forte 				    NULL) != 0) {
2816fcf3ce44SJohn Forte 					EMLXS_MSGF(EMLXS_CONTEXT,
2817fcf3ce44SJohn Forte 					    &emlxs_fcsp_debug_msg,
2818fcf3ce44SJohn Forte 					    "Reauth timeout. failed. 0x%x %x",
2819fcf3ce44SJohn Forte 					    ndlp->nlp_DID, node_dhc->state);
2820fcf3ce44SJohn Forte 				}
2821fcf3ce44SJohn Forte 				return (node_dhc->state);
2822fcf3ce44SJohn Forte 
2823fcf3ce44SJohn Forte 			default:
2824fcf3ce44SJohn Forte 				ReasonCode = AUTHRJT_FAILURE;
2825fcf3ce44SJohn Forte 				ReasonCodeExplanation = AUTHEXP_AUTH_FAILED;
2826fcf3ce44SJohn Forte 				break;
2827fcf3ce44SJohn Forte 			}
2828fcf3ce44SJohn Forte 			break;
2829fcf3ce44SJohn Forte 
2830fcf3ce44SJohn Forte 		case AUTHRJT_FAILURE:
2831fcf3ce44SJohn Forte 		default:
2832fcf3ce44SJohn Forte 			ReasonCode = AUTHRJT_FAILURE;
2833fcf3ce44SJohn Forte 			ReasonCodeExplanation = AUTHEXP_AUTH_FAILED;
2834fcf3ce44SJohn Forte 			break;
2835fcf3ce44SJohn Forte 		}
2836fcf3ce44SJohn Forte 
2837fcf3ce44SJohn Forte 		goto AUTH_Reject;
2838fcf3ce44SJohn Forte 	}
2839fcf3ce44SJohn Forte 	if (ncval->msg_hdr.auth_msg_code != DHCHAP_CHALLENGE) {
2840fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
2841*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_auth_negotiate_cmpl_wait4next: 0x%x.%x",
2842fcf3ce44SJohn Forte 		    ndlp->nlp_DID, ncval->msg_hdr.auth_msg_code);
2843fcf3ce44SJohn Forte 
2844fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_FAILURE;
2845fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_BAD_PROTOCOL;
2846fcf3ce44SJohn Forte 		goto AUTH_Reject;
2847fcf3ce44SJohn Forte 	}
2848fcf3ce44SJohn Forte 	tran_id = ncval->msg_hdr.tran_id;
2849fcf3ce44SJohn Forte 
285082527734SSukumar Swaminathan 	if (LE_SWAP32(tran_id) != node_dhc->nlp_auth_tranid_rsp) {
2851fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
2852fcf3ce44SJohn Forte 		    "rcv_auth_msg_auth_negotiate_cmpl_wait4next:0x%x %x!=%x",
285382527734SSukumar Swaminathan 		    ndlp->nlp_DID, LE_SWAP32(tran_id),
2854fcf3ce44SJohn Forte 		    node_dhc->nlp_auth_tranid_rsp);
2855fcf3ce44SJohn Forte 
2856fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_FAILURE;
2857fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD;
2858fcf3ce44SJohn Forte 		goto AUTH_Reject;
2859fcf3ce44SJohn Forte 	}
2860fcf3ce44SJohn Forte 	node_dhc->nlp_authrsp_tmo = 0;
2861fcf3ce44SJohn Forte 
2862fcf3ce44SJohn Forte 	namelen = ncval->msg_hdr.name_len;
2863fcf3ce44SJohn Forte 
2864fcf3ce44SJohn Forte 	if (namelen == AUTH_NAME_LEN) {
2865fcf3ce44SJohn Forte 		/*
2866fcf3ce44SJohn Forte 		 * store another copy of wwn of fabric/or nport used in
2867fcf3ce44SJohn Forte 		 * AUTH_ELS cmd
2868fcf3ce44SJohn Forte 		 */
2869fcf3ce44SJohn Forte 		bcopy((void *)&ncval->msg_hdr.nodeName,
2870fcf3ce44SJohn Forte 		    (void *)&node_dhc->nlp_auth_wwn, sizeof (NAME_TYPE));
2871fcf3ce44SJohn Forte 	}
2872fcf3ce44SJohn Forte 	/* Collect the challenge value */
2873fcf3ce44SJohn Forte 	tmp = (uint8_t *)((uint8_t *)lp + sizeof (DHCHAP_CHALL_NULL));
2874fcf3ce44SJohn Forte 
2875fcf3ce44SJohn Forte 	if (ncval->hash_id == AUTH_MD5) {
287682527734SSukumar Swaminathan 		if (ncval->cval_len != LE_SWAP32(MD5_LEN)) {
2877fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
2878fcf3ce44SJohn Forte 		    "rcv_auth_msg_auth_negotiate_cmpl_wait4next:0x%x.%x!=%x",
287982527734SSukumar Swaminathan 		    ndlp->nlp_DID, ncval->cval_len, LE_SWAP32(MD5_LEN));
2880fcf3ce44SJohn Forte 
2881fcf3ce44SJohn Forte 			ReasonCode = AUTHRJT_FAILURE;
2882fcf3ce44SJohn Forte 			ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD;
2883fcf3ce44SJohn Forte 			goto AUTH_Reject;
2884fcf3ce44SJohn Forte 		}
2885fcf3ce44SJohn Forte 		bzero(un_cval.md5.val, sizeof (MD5_CVAL));
2886fcf3ce44SJohn Forte 		bcopy((void *)tmp, (void *)un_cval.md5.val,
2887fcf3ce44SJohn Forte 		    sizeof (MD5_CVAL));
2888fcf3ce44SJohn Forte 		tmp += sizeof (MD5_CVAL);
2889fcf3ce44SJohn Forte 
2890fcf3ce44SJohn Forte 		arg2len = MD5_LEN;
2891fcf3ce44SJohn Forte 
2892fcf3ce44SJohn Forte 	} else if (ncval->hash_id == AUTH_SHA1) {
289382527734SSukumar Swaminathan 		if (ncval->cval_len != LE_SWAP32(SHA1_LEN)) {
2894fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
2895fcf3ce44SJohn Forte 		    "rcv_auth_msg_auth_negotiate_cmpl_wait4next: 0x%x %x!=%x",
289682527734SSukumar Swaminathan 		    ndlp->nlp_DID, ncval->cval_len, LE_SWAP32(MD5_LEN));
2897fcf3ce44SJohn Forte 
2898fcf3ce44SJohn Forte 			ReasonCode = AUTHRJT_FAILURE;
2899fcf3ce44SJohn Forte 			ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD;
2900fcf3ce44SJohn Forte 			goto AUTH_Reject;
2901fcf3ce44SJohn Forte 		}
2902fcf3ce44SJohn Forte 		bzero(un_cval.sha1.val, sizeof (SHA1_CVAL));
2903fcf3ce44SJohn Forte 		bcopy((void *)tmp, (void *)un_cval.sha1.val,
2904fcf3ce44SJohn Forte 		    sizeof (SHA1_CVAL));
2905fcf3ce44SJohn Forte 		tmp += sizeof (SHA1_CVAL);
2906fcf3ce44SJohn Forte 
2907fcf3ce44SJohn Forte 		arg2len = SHA1_LEN;
2908fcf3ce44SJohn Forte 
2909fcf3ce44SJohn Forte 	} else {
2910fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
2911*8f23e9faSHans Rosenfeld 	    "rcv_auth_msg_auth_negotiate_cmpl_wait4next: 0x%x %x",
2912fcf3ce44SJohn Forte 	    ndlp->nlp_DID, ncval->hash_id);
2913fcf3ce44SJohn Forte 
2914fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_FAILURE;
2915fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD;
2916fcf3ce44SJohn Forte 		goto AUTH_Reject;
2917fcf3ce44SJohn Forte 	}
2918fcf3ce44SJohn Forte 
2919fcf3ce44SJohn Forte 	/*
2920fcf3ce44SJohn Forte 	 * store hash_id for later usage : hash_id is set by responder in its
2921fcf3ce44SJohn Forte 	 * dhchap_challenge
2922fcf3ce44SJohn Forte 	 */
2923fcf3ce44SJohn Forte 	node_dhc->hash_id = ncval->hash_id;
2924fcf3ce44SJohn Forte 
2925fcf3ce44SJohn Forte 	/* always use this */
2926fcf3ce44SJohn Forte 	/* store another copy of the hash_id */
2927fcf3ce44SJohn Forte 	node_dhc->nlp_auth_hashid = ncval->hash_id;
2928fcf3ce44SJohn Forte 
2929fcf3ce44SJohn Forte 	/* store dhgp_id for later usage */
2930fcf3ce44SJohn Forte 	node_dhc->dhgp_id = ncval->dhgp_id;
2931fcf3ce44SJohn Forte 
2932fcf3ce44SJohn Forte 	/* store another copy of dhgp_id */
2933fcf3ce44SJohn Forte 	/* always use this */
2934fcf3ce44SJohn Forte 	node_dhc->nlp_auth_dhgpid = ncval->dhgp_id;
2935fcf3ce44SJohn Forte 
2936fcf3ce44SJohn Forte 	/*
2937fcf3ce44SJohn Forte 	 * ndlp->nlp_auth_hashid, nlp_auth_dhgpid store the hashid and dhgpid
2938fcf3ce44SJohn Forte 	 * when this very ndlp is the auth transaction responder (in other
2939fcf3ce44SJohn Forte 	 * words, responder means that this ndlp is send the host the
2940fcf3ce44SJohn Forte 	 * challenge. ndlp could be fffffe or another initiator or target
2941fcf3ce44SJohn Forte 	 * nport.
2942fcf3ce44SJohn Forte 	 */
2943fcf3ce44SJohn Forte 
2944fcf3ce44SJohn Forte 	dhvallen = *((uint32_t *)(tmp));
2945fcf3ce44SJohn Forte 
2946fcf3ce44SJohn Forte 	switch (ncval->dhgp_id) {
2947fcf3ce44SJohn Forte 	case GROUP_NULL:
2948fcf3ce44SJohn Forte 		/* null DHCHAP only */
294982527734SSukumar Swaminathan 		if (LE_SWAP32(dhvallen) != 0) {
2950fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
2951fcf3ce44SJohn Forte 		    "rcv_auth_msg_auth_negotiate_cmpl_wait4next: 0x%x %x %x",
295282527734SSukumar Swaminathan 		    ndlp->nlp_DID, ncval->dhgp_id, LE_SWAP32(dhvallen));
2953fcf3ce44SJohn Forte 
2954fcf3ce44SJohn Forte 			ReasonCode = AUTHRJT_FAILURE;
2955fcf3ce44SJohn Forte 			ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD;
2956fcf3ce44SJohn Forte 			goto AUTH_Reject;
2957fcf3ce44SJohn Forte 		}
2958fcf3ce44SJohn Forte 		break;
2959fcf3ce44SJohn Forte 
2960fcf3ce44SJohn Forte 	case GROUP_1024:
2961fcf3ce44SJohn Forte 	case GROUP_1280:
2962fcf3ce44SJohn Forte 	case GROUP_1536:
2963fcf3ce44SJohn Forte 	case GROUP_2048:
2964fcf3ce44SJohn Forte 		/* Collect the DH Value */
2965fcf3ce44SJohn Forte 		tmp += sizeof (uint32_t);
2966fcf3ce44SJohn Forte 
296782527734SSukumar Swaminathan 		dhval = (uint8_t *)kmem_zalloc(LE_SWAP32(dhvallen),
2968fcf3ce44SJohn Forte 		    KM_NOSLEEP);
2969fcf3ce44SJohn Forte 		if (dhval == NULL) {
2970fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
2971fcf3ce44SJohn Forte 		    "rcv_auth_msg_auth_negotiate_cmpl_wait4next: 0x%x %x %x",
2972fcf3ce44SJohn Forte 		    ndlp->nlp_DID, ncval->dhgp_id, dhval);
2973fcf3ce44SJohn Forte 
2974fcf3ce44SJohn Forte 			ReasonCode = AUTHRJT_LOGIC_ERR;
2975fcf3ce44SJohn Forte 			ReasonCodeExplanation = AUTHEXP_RESTART_AUTH;
2976fcf3ce44SJohn Forte 			goto AUTH_Reject;
2977fcf3ce44SJohn Forte 		}
297882527734SSukumar Swaminathan 		bcopy((void *)tmp, (void *)dhval, LE_SWAP32(dhvallen));
2979fcf3ce44SJohn Forte 		break;
2980fcf3ce44SJohn Forte 
2981fcf3ce44SJohn Forte 	default:
2982fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
2983fcf3ce44SJohn Forte 		    "rcv_auth_msg_auth_negotiate_cmpl_wait4next: 0x%x %x.",
2984fcf3ce44SJohn Forte 		    ndlp->nlp_DID, ncval->dhgp_id);
2985fcf3ce44SJohn Forte 
2986fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_FAILURE;
2987fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD;
2988fcf3ce44SJohn Forte 		goto AUTH_Reject;
2989fcf3ce44SJohn Forte 	}
2990fcf3ce44SJohn Forte 
2991fcf3ce44SJohn Forte 	/*
2992fcf3ce44SJohn Forte 	 * Calculate the hash value, hash function, DH group, secret etc.
2993fcf3ce44SJohn Forte 	 * could be stored in port_dhc.
2994fcf3ce44SJohn Forte 	 */
2995fcf3ce44SJohn Forte 
2996fcf3ce44SJohn Forte 	/* arg5 has the response with NULL or Full DH group support */
2997fcf3ce44SJohn Forte 	arg5 = (uint32_t *)emlxs_hash_rsp(port, port_dhc,
299882527734SSukumar Swaminathan 	    ndlp, tran_id, un_cval, dhval, LE_SWAP32(dhvallen));
2999fcf3ce44SJohn Forte 
3000fcf3ce44SJohn Forte 	/* Or should check ndlp->auth_cfg..... */
3001fcf3ce44SJohn Forte 	if (node_dhc->auth_cfg.bidirectional == 1) {
3002fcf3ce44SJohn Forte 		/* get arg2 here */
3003fcf3ce44SJohn Forte 		/*
3004fcf3ce44SJohn Forte 		 * arg2 is the new challenge C2 from initiator if bi-dir auth
3005fcf3ce44SJohn Forte 		 * is supported
3006fcf3ce44SJohn Forte 		 */
3007fcf3ce44SJohn Forte 		bzero(&random_number, sizeof (random_number));
3008fcf3ce44SJohn Forte 
3009fcf3ce44SJohn Forte 		if (hba->rdn_flag == 1) {
3010fcf3ce44SJohn Forte 			emlxs_get_random_bytes(ndlp, random_number, 20);
3011fcf3ce44SJohn Forte 		} else {
3012e2ca2865SSukumar Swaminathan 			(void) random_get_pseudo_bytes(random_number, arg2len);
3013fcf3ce44SJohn Forte 		}
3014fcf3ce44SJohn Forte 
3015fcf3ce44SJohn Forte 		/* cache it for later verification usage */
301682527734SSukumar Swaminathan 		if (ndlp->nlp_DID == FABRIC_DID) {
3017fcf3ce44SJohn Forte 			bcopy((void *)&random_number[0],
3018fcf3ce44SJohn Forte 			    (void *)&node_dhc->bi_cval[0], arg2len);
3019fcf3ce44SJohn Forte 			node_dhc->bi_cval_len = arg2len;
3020fcf3ce44SJohn Forte 
3021fcf3ce44SJohn Forte 			/* save another copy in our partner's ndlp */
3022fcf3ce44SJohn Forte 			bcopy((void *)&random_number[0],
3023fcf3ce44SJohn Forte 			    (void *)&node_dhc->nlp_auth_misc.bi_cval[0],
3024fcf3ce44SJohn Forte 			    arg2len);
3025fcf3ce44SJohn Forte 			node_dhc->nlp_auth_misc.bi_cval_len = arg2len;
3026fcf3ce44SJohn Forte 		} else {
3027fcf3ce44SJohn Forte 			bcopy((void *)&random_number[0],
3028fcf3ce44SJohn Forte 			    (void *)&node_dhc->nlp_auth_misc.bi_cval[0],
3029fcf3ce44SJohn Forte 			    arg2len);
3030fcf3ce44SJohn Forte 			node_dhc->nlp_auth_misc.bi_cval_len = arg2len;
3031fcf3ce44SJohn Forte 		}
3032fcf3ce44SJohn Forte 	}
3033fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
3034fcf3ce44SJohn Forte 	    "rcv_auth_msg_auth_negotiate_cmpl_wait4next:0x%x(%x,%x,%x,%x,%x)",
3035fcf3ce44SJohn Forte 	    ndlp->nlp_DID, node_dhc->nlp_auth_tranid_rsp,
3036fcf3ce44SJohn Forte 	    node_dhc->nlp_auth_tranid_ini,
3037fcf3ce44SJohn Forte 	    ncval->hash_id, ncval->dhgp_id, dhvallen);
3038fcf3ce44SJohn Forte 
3039fcf3ce44SJohn Forte 	/* Issue ELS DHCHAP_Reply */
3040fcf3ce44SJohn Forte 	/*
3041fcf3ce44SJohn Forte 	 * arg1 has the response, arg2 has the new challenge if needed (g^y
3042fcf3ce44SJohn Forte 	 * mod p) is the pubkey: all are ready and to go
3043fcf3ce44SJohn Forte 	 */
3044fcf3ce44SJohn Forte 
3045fcf3ce44SJohn Forte 	/* return 0 success, otherwise failure */
3046fcf3ce44SJohn Forte 	if (emlxs_issue_dhchap_reply(port, ndlp, 0, arg5, dhval,
304782527734SSukumar Swaminathan 	    LE_SWAP32(dhvallen),
3048fcf3ce44SJohn Forte 	    random_number, arg2len)) {
3049fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
3050fcf3ce44SJohn Forte 	    "rcv_auth_msg_auth_negotiate_cmpl_wait4next: 0x%x.failed.",
3051fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
3052fcf3ce44SJohn Forte 
305382527734SSukumar Swaminathan 		kmem_free(dhval, LE_SWAP32(dhvallen));
3054fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_LOGIC_ERR;
3055fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_RESTART_AUTH;
3056fcf3ce44SJohn Forte 		goto AUTH_Reject;
3057fcf3ce44SJohn Forte 	}
3058fcf3ce44SJohn Forte 	return (node_dhc->state);
3059fcf3ce44SJohn Forte 
3060fcf3ce44SJohn Forte AUTH_Reject:
3061fcf3ce44SJohn Forte 
3062fcf3ce44SJohn Forte 	emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_FAILED, ReasonCode,
3063fcf3ce44SJohn Forte 	    ReasonCodeExplanation);
3064fcf3ce44SJohn Forte 	(void) emlxs_issue_auth_reject(port, ndlp, 0, 0, ReasonCode,
3065fcf3ce44SJohn Forte 	    ReasonCodeExplanation);
3066fcf3ce44SJohn Forte 	emlxs_dhc_auth_complete(port, ndlp, 1);
3067fcf3ce44SJohn Forte 
3068fcf3ce44SJohn Forte 	return (node_dhc->state);
3069fcf3ce44SJohn Forte 
3070fcf3ce44SJohn Forte } /* emlxs_rcv_auth_msg_auth_negotiate_cmpl_wait4next */
3071fcf3ce44SJohn Forte 
3072fcf3ce44SJohn Forte 
3073fcf3ce44SJohn Forte /*
3074fcf3ce44SJohn Forte  * This routine should be set to emlxs_disc_neverdev
3075fcf3ce44SJohn Forte  *
3076fcf3ce44SJohn Forte  */
3077fcf3ce44SJohn Forte /* ARGSUSED */
3078fcf3ce44SJohn Forte static uint32_t
emlxs_cmpl_auth_msg_auth_negotiate_cmpl_wait4next(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)3079fcf3ce44SJohn Forte emlxs_cmpl_auth_msg_auth_negotiate_cmpl_wait4next(
3080fcf3ce44SJohn Forte emlxs_port_t	*port,
308182527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
3082fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
3083fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
3084fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
3085fcf3ce44SJohn Forte uint32_t evt)
3086fcf3ce44SJohn Forte {
3087fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
3088fcf3ce44SJohn Forte 
3089fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
3090fcf3ce44SJohn Forte 	    "cmpl_auth_msg_auth_negotiate_cmpl_wait4next.0x%x. Not iplted.",
3091fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
3092fcf3ce44SJohn Forte 
3093fcf3ce44SJohn Forte 	return (0);
3094fcf3ce44SJohn Forte } /* emlxs_cmpl_auth_msg_auth_negotiate_cmpl_wait4next() */
3095fcf3ce44SJohn Forte 
3096fcf3ce44SJohn Forte 
3097fcf3ce44SJohn Forte /*
3098fcf3ce44SJohn Forte  * ! emlxs_rcv_auth_msg_dhchap_reply_issue
3099fcf3ce44SJohn Forte  *
3100fcf3ce44SJohn Forte  * This routine is invoked when the host received an unsolicited ELS AUTH
3101fcf3ce44SJohn Forte  * msg from an NxPort or FxPort into which the host has
3102fcf3ce44SJohn Forte  * sent an ELS DHCHAP_Reply msg. since the host is the initiator and the
3103fcf3ce44SJohn Forte  * AUTH transaction is in progress between host and the
3104fcf3ce44SJohn Forte  * NxPort or FxPort, as a result, the host will send back ACC and AUTH_Reject
3105fcf3ce44SJohn Forte  * and set the next state = NPR_NODE.
3106fcf3ce44SJohn Forte  *
3107fcf3ce44SJohn Forte  */
3108fcf3ce44SJohn Forte /* ARGSUSED */
3109fcf3ce44SJohn Forte static uint32_t
emlxs_rcv_auth_msg_dhchap_reply_issue(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)3110fcf3ce44SJohn Forte emlxs_rcv_auth_msg_dhchap_reply_issue(
3111fcf3ce44SJohn Forte emlxs_port_t *port,
311282527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
3113fcf3ce44SJohn Forte /* IOCBQ   * iocbq, */ void *arg2,
3114fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
3115fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
3116fcf3ce44SJohn Forte uint32_t evt)
3117fcf3ce44SJohn Forte {
3118fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
3119fcf3ce44SJohn Forte 
3120fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
3121fcf3ce44SJohn Forte 	    "rcv_auth_msg_dhchap_reply_issue called. 0x%x. Not implemented.",
3122fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
3123fcf3ce44SJohn Forte 
3124fcf3ce44SJohn Forte 	return (0);
3125fcf3ce44SJohn Forte 
3126fcf3ce44SJohn Forte } /* emlxs_rcv_auth_msg_dhchap_reply_issue */
3127fcf3ce44SJohn Forte 
3128fcf3ce44SJohn Forte 
3129fcf3ce44SJohn Forte 
3130fcf3ce44SJohn Forte /*
3131fcf3ce44SJohn Forte  * ! emlxs_cmpl_auth_msg_dhchap_reply_issue
3132fcf3ce44SJohn Forte  *
3133fcf3ce44SJohn Forte  * This routine is invoked when
3134fcf3ce44SJohn Forte  * the host received a solicited ACC/RJT from ELS command from an NxPort
3135fcf3ce44SJohn Forte  * or FxPort that already received the ELS DHCHAP_Reply
3136fcf3ce44SJohn Forte  * msg from the host. in case of ACC, next state = DHCHAP_REPLY_CMPL_WAIT4NEXT
3137fcf3ce44SJohn Forte  * in case of RJT, next state = NPR_NODE
3138fcf3ce44SJohn Forte  */
3139fcf3ce44SJohn Forte /* ARGSUSED */
3140fcf3ce44SJohn Forte static uint32_t
emlxs_cmpl_auth_msg_dhchap_reply_issue(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)3141fcf3ce44SJohn Forte emlxs_cmpl_auth_msg_dhchap_reply_issue(
3142fcf3ce44SJohn Forte emlxs_port_t *port,
314382527734SSukumar Swaminathan /* CHANNEL  * rp, */ void *arg1,
3144fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
3145fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
3146fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
3147fcf3ce44SJohn Forte uint32_t evt)
3148fcf3ce44SJohn Forte {
3149fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *) arg4;
3150fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
3151fcf3ce44SJohn Forte 
3152fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
3153*8f23e9faSHans Rosenfeld 	    "cmpl_auth_msg_dhchap_reply_issue: did=0x%x",
3154fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
3155fcf3ce44SJohn Forte 
3156fcf3ce44SJohn Forte 	/* start the emlxs_dhc_authrsp_timeout timer now */
3157fcf3ce44SJohn Forte 	if (node_dhc->nlp_authrsp_tmo == 0) {
3158fcf3ce44SJohn Forte 		node_dhc->nlp_authrsp_tmo = DRV_TIME +
3159fcf3ce44SJohn Forte 		    node_dhc->auth_cfg.authentication_timeout;
3160fcf3ce44SJohn Forte 	}
3161fcf3ce44SJohn Forte 	/*
3162fcf3ce44SJohn Forte 	 * The next state should be
3163fcf3ce44SJohn Forte 	 * emlxs_rcv_auth_msg_dhchap_reply_cmpl_wait4next
3164fcf3ce44SJohn Forte 	 */
3165fcf3ce44SJohn Forte 	emlxs_dhc_state(port, ndlp,
3166fcf3ce44SJohn Forte 	    NODE_STATE_DHCHAP_REPLY_CMPL_WAIT4NEXT, 0, 0);
3167fcf3ce44SJohn Forte 
3168fcf3ce44SJohn Forte 	return (node_dhc->state);
3169fcf3ce44SJohn Forte 
3170fcf3ce44SJohn Forte } /* emlxs_cmpl_auth_msg_dhchap_reply_issue */
3171fcf3ce44SJohn Forte 
3172fcf3ce44SJohn Forte 
3173fcf3ce44SJohn Forte 
3174fcf3ce44SJohn Forte /*
3175fcf3ce44SJohn Forte  * ! emlxs_rcv_auth_msg_dhchap_reply_cmpl_wait4next
3176fcf3ce44SJohn Forte  *
3177fcf3ce44SJohn Forte  * \pre \post \param   phba \param   ndlp \param   arg \param   evt \return
3178fcf3ce44SJohn Forte  * uint32_t \b Description: This rountine is invoked
3179fcf3ce44SJohn Forte  * when the host received an unsolicited ELS AUTH Msg from the NxPort or
3180fcf3ce44SJohn Forte  * FxPort that already sent ACC back to the host after
3181fcf3ce44SJohn Forte  * receipt of DHCHAP_Reply msg. In normal case, this unsolicited msg could
3182fcf3ce44SJohn Forte  * be DHCHAP_Success msg.
3183fcf3ce44SJohn Forte  *
3184fcf3ce44SJohn Forte  * if msg is ELS DHCHAP_Success, based on the payload, host send back ACC and 1.
3185fcf3ce44SJohn Forte  * for uni-directional, and set next state =
3186fcf3ce44SJohn Forte  * REG_LOGIN. 2. for bi-directional,  and host do some computations
3187fcf3ce44SJohn Forte  * (hash etc) and send back either DHCHAP_Success Msg and set
3188fcf3ce44SJohn Forte  * next state = DHCHAP_SUCCESS_ISSUE_WAIT4NEXT or AUTH_Reject and set next
3189fcf3ce44SJohn Forte  * state = NPR_NODE. if msg is ELS AUTH_Reject, then
3190fcf3ce44SJohn Forte  * send back ACC and set next state = NPR_NODE if msg is anything else, then
3191fcf3ce44SJohn Forte  * RJT and set next state = NPR_NODE
3192fcf3ce44SJohn Forte  */
3193fcf3ce44SJohn Forte /* ARGSUSED */
3194fcf3ce44SJohn Forte static uint32_t
emlxs_rcv_auth_msg_dhchap_reply_cmpl_wait4next(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)3195fcf3ce44SJohn Forte emlxs_rcv_auth_msg_dhchap_reply_cmpl_wait4next(
3196fcf3ce44SJohn Forte emlxs_port_t *port,
319782527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
3198fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
3199fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
3200fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
3201fcf3ce44SJohn Forte uint32_t evt)
3202fcf3ce44SJohn Forte {
3203fcf3ce44SJohn Forte 	emlxs_port_dhc_t *port_dhc = &port->port_dhc;
3204fcf3ce44SJohn Forte 	IOCBQ *iocbq = (IOCBQ *)arg2;
3205fcf3ce44SJohn Forte 	MATCHMAP *mp = (MATCHMAP *)arg3;
3206fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
3207fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
3208fcf3ce44SJohn Forte 	uint8_t *bp;
3209fcf3ce44SJohn Forte 	uint32_t *lp;
3210fcf3ce44SJohn Forte 	DHCHAP_SUCCESS_HDR *dh_success;
3211fcf3ce44SJohn Forte 	uint8_t *tmp;
3212fcf3ce44SJohn Forte 	uint8_t rsp_size;
3213fcf3ce44SJohn Forte 	AUTH_RJT *auth_rjt;
3214fcf3ce44SJohn Forte 	uint32_t tran_id;
3215fcf3ce44SJohn Forte 	uint32_t *hash_val;
3216fcf3ce44SJohn Forte 	union challenge_val un_cval;
3217fcf3ce44SJohn Forte 	uint8_t ReasonCode;
3218fcf3ce44SJohn Forte 	uint8_t ReasonCodeExplanation;
3219291a2b48SSukumar Swaminathan 	char info[64];
3220fcf3ce44SJohn Forte 
3221fcf3ce44SJohn Forte 	bp = mp->virt;
3222fcf3ce44SJohn Forte 	lp = (uint32_t *)bp;
3223fcf3ce44SJohn Forte 
3224fcf3ce44SJohn Forte 	/*
3225fcf3ce44SJohn Forte 	 * 1. we process the DHCHAP_Success or AUTH_Reject 2. ACC it first 3.
3226fcf3ce44SJohn Forte 	 * based on the result of 1 we goto the next stage SCR etc.
3227fcf3ce44SJohn Forte 	 */
3228fcf3ce44SJohn Forte 
3229fcf3ce44SJohn Forte 	/* sp = (SERV_PARM *)((uint8_t *)lp + sizeof(uint32_t)); */
3230fcf3ce44SJohn Forte 	dh_success = (DHCHAP_SUCCESS_HDR *)((uint8_t *)lp);
3231fcf3ce44SJohn Forte 
3232fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
3233fcf3ce44SJohn Forte 	    "rcv_auth_msg_dhchap_reply_cmpl_wait4next: 0x%x 0x%x 0x%x",
3234fcf3ce44SJohn Forte 	    ndlp->nlp_DID, dh_success->auth_els_code,
3235fcf3ce44SJohn Forte 	    dh_success->auth_msg_code);
3236fcf3ce44SJohn Forte 
3237fcf3ce44SJohn Forte 	node_dhc->nlp_authrsp_tmo = 0;
3238fcf3ce44SJohn Forte 
3239fcf3ce44SJohn Forte 	(void) emlxs_els_reply(port, iocbq, ELS_CMD_ACC, ELS_CMD_AUTH, 0, 0);
3240fcf3ce44SJohn Forte 
3241fcf3ce44SJohn Forte 	if (dh_success->auth_msg_code == AUTH_REJECT) {
3242fcf3ce44SJohn Forte 		/* ACC it and retry etc.  */
3243fcf3ce44SJohn Forte 		auth_rjt = (AUTH_RJT *) dh_success;
3244fcf3ce44SJohn Forte 		ReasonCode = auth_rjt->ReasonCode;
3245fcf3ce44SJohn Forte 		ReasonCodeExplanation = auth_rjt->ReasonCodeExplanation;
3246fcf3ce44SJohn Forte 
3247fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
3248*8f23e9faSHans Rosenfeld 	    "rcv_auth_msg_dhchap_reply_cmpl_wait4next: 0x%x.(%x,%x)",
3249fcf3ce44SJohn Forte 	    ndlp->nlp_DID, ReasonCode, ReasonCodeExplanation);
3250fcf3ce44SJohn Forte 
3251fcf3ce44SJohn Forte 		switch (ReasonCode) {
3252fcf3ce44SJohn Forte 		case AUTHRJT_LOGIC_ERR:
3253fcf3ce44SJohn Forte 			switch (ReasonCodeExplanation) {
3254fcf3ce44SJohn Forte 			case AUTHEXP_MECH_UNUSABLE:
3255fcf3ce44SJohn Forte 			case AUTHEXP_DHGROUP_UNUSABLE:
3256fcf3ce44SJohn Forte 			case AUTHEXP_HASHFUNC_UNUSABLE:
3257fcf3ce44SJohn Forte 				ReasonCode = AUTHRJT_LOGIC_ERR;
3258fcf3ce44SJohn Forte 				ReasonCodeExplanation = AUTHEXP_RESTART_AUTH;
3259fcf3ce44SJohn Forte 				break;
3260fcf3ce44SJohn Forte 
3261fcf3ce44SJohn Forte 			case AUTHEXP_RESTART_AUTH:
3262fcf3ce44SJohn Forte 				/*
3263fcf3ce44SJohn Forte 				 * Cancel the rsp timer if not cancelled yet.
3264fcf3ce44SJohn Forte 				 * and restart auth tran now.
3265fcf3ce44SJohn Forte 				 */
3266fcf3ce44SJohn Forte 				if (node_dhc->nlp_authrsp_tmo != 0) {
3267fcf3ce44SJohn Forte 					node_dhc->nlp_authrsp_tmo = 0;
3268fcf3ce44SJohn Forte 					node_dhc->nlp_authrsp_tmocnt = 0;
3269fcf3ce44SJohn Forte 				}
3270fcf3ce44SJohn Forte 				if (emlxs_dhc_auth_start(port, ndlp,
3271fcf3ce44SJohn Forte 				    NULL, NULL) != 0) {
3272fcf3ce44SJohn Forte 					EMLXS_MSGF(EMLXS_CONTEXT,
3273fcf3ce44SJohn Forte 					    &emlxs_fcsp_debug_msg,
3274fcf3ce44SJohn Forte 					    "Reauth timeout.failed. 0x%x %x",
3275fcf3ce44SJohn Forte 					    ndlp->nlp_DID, node_dhc->state);
3276fcf3ce44SJohn Forte 				}
3277fcf3ce44SJohn Forte 				return (node_dhc->state);
3278fcf3ce44SJohn Forte 
3279fcf3ce44SJohn Forte 			default:
3280fcf3ce44SJohn Forte 				ReasonCode = AUTHRJT_FAILURE;
3281fcf3ce44SJohn Forte 				ReasonCodeExplanation = AUTHEXP_AUTH_FAILED;
3282fcf3ce44SJohn Forte 				break;
3283fcf3ce44SJohn Forte 			}
3284fcf3ce44SJohn Forte 			break;
3285fcf3ce44SJohn Forte 
3286fcf3ce44SJohn Forte 		case AUTHRJT_FAILURE:
3287fcf3ce44SJohn Forte 		default:
3288fcf3ce44SJohn Forte 			ReasonCode = AUTHRJT_FAILURE;
3289fcf3ce44SJohn Forte 			ReasonCodeExplanation = AUTHEXP_AUTH_FAILED;
3290fcf3ce44SJohn Forte 			emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_FAILED,
3291fcf3ce44SJohn Forte 			    ReasonCode, ReasonCodeExplanation);
3292fcf3ce44SJohn Forte 			goto out;
3293fcf3ce44SJohn Forte 		}
3294fcf3ce44SJohn Forte 
3295fcf3ce44SJohn Forte 		goto AUTH_Reject;
3296fcf3ce44SJohn Forte 	}
3297fcf3ce44SJohn Forte 	if (dh_success->auth_msg_code == DHCHAP_SUCCESS) {
3298fcf3ce44SJohn Forte 
3299fcf3ce44SJohn Forte 		/* Verify the tran_id */
3300fcf3ce44SJohn Forte 		tran_id = dh_success->tran_id;
3301fcf3ce44SJohn Forte 
3302fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
3303fcf3ce44SJohn Forte 	    "rcv_auth_msg_dhchap_reply_cmpl_wait4next: 0x%x 0x%x 0x%x 0x%x",
330482527734SSukumar Swaminathan 	    ndlp->nlp_DID, LE_SWAP32(tran_id),
3305fcf3ce44SJohn Forte 	    node_dhc->nlp_auth_tranid_rsp,
3306fcf3ce44SJohn Forte 	    node_dhc->nlp_auth_tranid_ini);
3307fcf3ce44SJohn Forte 
330882527734SSukumar Swaminathan 		if (LE_SWAP32(tran_id) != node_dhc->nlp_auth_tranid_rsp) {
3309fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
3310fcf3ce44SJohn Forte 		    "rcv_auth_msg_dhchap_reply_cmpl_wait4next:0x%x %x!=%x",
331182527734SSukumar Swaminathan 		    ndlp->nlp_DID, LE_SWAP32(tran_id),
3312fcf3ce44SJohn Forte 		    node_dhc->nlp_auth_tranid_rsp);
3313fcf3ce44SJohn Forte 
3314fcf3ce44SJohn Forte 			ReasonCode = AUTHRJT_FAILURE;
3315fcf3ce44SJohn Forte 			ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD;
3316fcf3ce44SJohn Forte 			goto AUTH_Reject;
3317fcf3ce44SJohn Forte 		}
3318fcf3ce44SJohn Forte 		if (node_dhc->auth_cfg.bidirectional == 0) {
3319fcf3ce44SJohn Forte 			node_dhc->flag |=
3320fcf3ce44SJohn Forte 			    (NLP_REMOTE_AUTH | NLP_SET_REAUTH_TIME);
3321fcf3ce44SJohn Forte 
3322fcf3ce44SJohn Forte 			emlxs_dhc_state(port, ndlp,
3323fcf3ce44SJohn Forte 			    NODE_STATE_AUTH_SUCCESS, 0, 0);
3324*8f23e9faSHans Rosenfeld 			emlxs_log_auth_event(port, ndlp,
3325*8f23e9faSHans Rosenfeld 			    "rcv_auth_msg_dhchap_reply_cmpl_wait4next",
3326fcf3ce44SJohn Forte 			    "Host-initiated-unidir-auth-success");
3327fcf3ce44SJohn Forte 			emlxs_dhc_auth_complete(port, ndlp, 0);
3328fcf3ce44SJohn Forte 		} else {
3329fcf3ce44SJohn Forte 			/* bidir auth needed */
333082527734SSukumar Swaminathan 			/* if (LE_SWAP32(dh_success->msg_len) > 4) { */
3331fcf3ce44SJohn Forte 
3332fcf3ce44SJohn Forte 			tmp = (uint8_t *)((uint8_t *)lp);
3333fcf3ce44SJohn Forte 			tmp += 8;
3334fcf3ce44SJohn Forte 			tran_id = *(uint32_t *)tmp;
3335fcf3ce44SJohn Forte 			tmp += 4;
3336fcf3ce44SJohn Forte 			rsp_size = *(uint32_t *)tmp;
3337fcf3ce44SJohn Forte 			tmp += 4;
3338fcf3ce44SJohn Forte 
3339fcf3ce44SJohn Forte 			/* tmp has the response from responder */
3340fcf3ce44SJohn Forte 
3341fcf3ce44SJohn Forte 			/*
3342fcf3ce44SJohn Forte 			 * node_dhc->bi_cval has the bidir challenge value
3343fcf3ce44SJohn Forte 			 * from initiator
3344fcf3ce44SJohn Forte 			 */
3345fcf3ce44SJohn Forte 
334682527734SSukumar Swaminathan 			if (LE_SWAP32(rsp_size) == 16) {
334782527734SSukumar Swaminathan 				bzero(un_cval.md5.val, LE_SWAP32(rsp_size));
334882527734SSukumar Swaminathan 				if (ndlp->nlp_DID == FABRIC_DID)
3349fcf3ce44SJohn Forte 					bcopy((void *)node_dhc->bi_cval,
3350fcf3ce44SJohn Forte 					    (void *)un_cval.md5.val,
335182527734SSukumar Swaminathan 					    LE_SWAP32(rsp_size));
3352fcf3ce44SJohn Forte 				else
3353fcf3ce44SJohn Forte 				bcopy(
3354fcf3ce44SJohn Forte 				    (void *)node_dhc->nlp_auth_misc.bi_cval,
3355fcf3ce44SJohn Forte 				    (void *)un_cval.md5.val,
335682527734SSukumar Swaminathan 				    LE_SWAP32(rsp_size));
3357fcf3ce44SJohn Forte 
335882527734SSukumar Swaminathan 			} else if (LE_SWAP32(rsp_size) == 20) {
3359fcf3ce44SJohn Forte 
336082527734SSukumar Swaminathan 				bzero(un_cval.sha1.val, LE_SWAP32(rsp_size));
336182527734SSukumar Swaminathan 				if (ndlp->nlp_DID == FABRIC_DID)
3362fcf3ce44SJohn Forte 					bcopy((void *)node_dhc->bi_cval,
3363fcf3ce44SJohn Forte 					    (void *)un_cval.sha1.val,
336482527734SSukumar Swaminathan 					    LE_SWAP32(rsp_size));
3365fcf3ce44SJohn Forte 				else
3366fcf3ce44SJohn Forte 				bcopy(
3367fcf3ce44SJohn Forte 				    (void *)node_dhc->nlp_auth_misc.bi_cval,
3368fcf3ce44SJohn Forte 				    (void *)un_cval.sha1.val,
336982527734SSukumar Swaminathan 				    LE_SWAP32(rsp_size));
3370fcf3ce44SJohn Forte 			}
3371fcf3ce44SJohn Forte 			/* verify the response */
3372fcf3ce44SJohn Forte 			/* NULL DHCHAP works for now */
3373fcf3ce44SJohn Forte 			/* for DH group as well */
3374fcf3ce44SJohn Forte 
3375fcf3ce44SJohn Forte 			/*
3376fcf3ce44SJohn Forte 			 * Cai2 = H (C2 || ((g^x mod p)^y mod p) ) = H (C2 ||
3377fcf3ce44SJohn Forte 			 * (g^xy mod p) )
3378fcf3ce44SJohn Forte 			 *
3379fcf3ce44SJohn Forte 			 * R = H (Ti || Km || Cai2) R ?= R2
3380fcf3ce44SJohn Forte 			 */
3381fcf3ce44SJohn Forte 			hash_val = emlxs_hash_vrf(port, port_dhc, ndlp,
3382fcf3ce44SJohn Forte 			    tran_id, un_cval);
3383fcf3ce44SJohn Forte 
3384fcf3ce44SJohn Forte 			if (bcmp((void *)tmp, (void *)hash_val,
338582527734SSukumar Swaminathan 			    LE_SWAP32(rsp_size))) {
3386fcf3ce44SJohn Forte 				if (hash_val != NULL) {
3387fcf3ce44SJohn Forte 					/* not identical */
3388fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
3389*8f23e9faSHans Rosenfeld 	    "rcv_auth_msg_dhchap_reply_cmpl_wait4next: 0x%x.failed. %x",
3390fcf3ce44SJohn Forte 	    ndlp->nlp_DID, *(uint32_t *)hash_val);
3391fcf3ce44SJohn Forte 				}
3392fcf3ce44SJohn Forte 				ReasonCode = AUTHRJT_FAILURE;
3393fcf3ce44SJohn Forte 				ReasonCodeExplanation = AUTHEXP_AUTH_FAILED;
3394fcf3ce44SJohn Forte 				goto AUTH_Reject;
3395fcf3ce44SJohn Forte 			}
3396fcf3ce44SJohn Forte 			emlxs_dhc_state(port, ndlp,
3397fcf3ce44SJohn Forte 			    NODE_STATE_DHCHAP_SUCCESS_ISSUE_WAIT4NEXT, 0, 0);
3398fcf3ce44SJohn Forte 
3399fcf3ce44SJohn Forte 			/* send out DHCHAP_SUCCESS */
3400fcf3ce44SJohn Forte 			(void) emlxs_issue_dhchap_success(port, ndlp, 0, 0);
3401fcf3ce44SJohn Forte 		}
3402fcf3ce44SJohn Forte 	}
3403fcf3ce44SJohn Forte 	return (node_dhc->state);
3404fcf3ce44SJohn Forte 
3405fcf3ce44SJohn Forte AUTH_Reject:
3406fcf3ce44SJohn Forte 
3407fcf3ce44SJohn Forte 	emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_FAILED,
3408fcf3ce44SJohn Forte 	    ReasonCode, ReasonCodeExplanation);
3409fcf3ce44SJohn Forte 	(void) emlxs_issue_auth_reject(port, ndlp, 0, 0, ReasonCode,
3410fcf3ce44SJohn Forte 	    ReasonCodeExplanation);
3411fcf3ce44SJohn Forte 	emlxs_dhc_auth_complete(port, ndlp, 1);
3412fcf3ce44SJohn Forte 
3413291a2b48SSukumar Swaminathan 	return (node_dhc->state);
3414fcf3ce44SJohn Forte out:
3415*8f23e9faSHans Rosenfeld 	(void) snprintf(info, sizeof (info),
3416291a2b48SSukumar Swaminathan 	    "Auth Failed: ReasonCode=0x%x, ReasonCodeExplanation=0x%x",
3417291a2b48SSukumar Swaminathan 	    ReasonCode, ReasonCodeExplanation);
3418291a2b48SSukumar Swaminathan 
3419*8f23e9faSHans Rosenfeld 	emlxs_log_auth_event(port, ndlp,
3420*8f23e9faSHans Rosenfeld 	    "rcv_auth_msg_dhchap_reply_cmpl_wait4next", info);
3421291a2b48SSukumar Swaminathan 	emlxs_dhc_auth_complete(port, ndlp, 1);
3422fcf3ce44SJohn Forte 
3423fcf3ce44SJohn Forte 	return (node_dhc->state);
3424fcf3ce44SJohn Forte 
3425fcf3ce44SJohn Forte } /* emlxs_rcv_auth_msg_dhchap_reply_cmpl_wait4next */
3426fcf3ce44SJohn Forte 
3427fcf3ce44SJohn Forte 
3428fcf3ce44SJohn Forte 
3429fcf3ce44SJohn Forte /*
3430fcf3ce44SJohn Forte  * This routine should be set to emlxs_disc_neverdev as it shouldnot happen.
3431fcf3ce44SJohn Forte  *
3432fcf3ce44SJohn Forte  */
3433fcf3ce44SJohn Forte /* ARGSUSED */
3434fcf3ce44SJohn Forte static uint32_t
emlxs_cmpl_auth_msg_dhchap_reply_cmpl_wait4next(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)3435fcf3ce44SJohn Forte emlxs_cmpl_auth_msg_dhchap_reply_cmpl_wait4next(
3436fcf3ce44SJohn Forte emlxs_port_t *port,
343782527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
3438fcf3ce44SJohn Forte /* IOCBQ  * iocbq, */ void *arg2,
3439fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
3440fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
3441fcf3ce44SJohn Forte uint32_t evt)
3442fcf3ce44SJohn Forte {
3443fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
3444fcf3ce44SJohn Forte 
3445fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
3446fcf3ce44SJohn Forte 	    "cmpl_auth_msg_dhchap_reply_cmpl_wait4next. 0x%x.Not ipleted.",
3447fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
3448fcf3ce44SJohn Forte 
3449fcf3ce44SJohn Forte 	return (0);
3450fcf3ce44SJohn Forte 
3451fcf3ce44SJohn Forte } /* emlxs_cmpl_auth_msg_dhchap_reply_cmpl_wait4next */
3452fcf3ce44SJohn Forte 
3453fcf3ce44SJohn Forte 
3454fcf3ce44SJohn Forte /*
3455fcf3ce44SJohn Forte  * emlxs_rcv_auth_msg_dhchap_success_issue_wait4next
3456fcf3ce44SJohn Forte  *
3457fcf3ce44SJohn Forte  * This routine is supported
3458fcf3ce44SJohn Forte  * for HBA in either auth initiator mode or responder mode.
3459fcf3ce44SJohn Forte  *
3460fcf3ce44SJohn Forte  * This routine is invoked when the host as the auth responder received
3461fcf3ce44SJohn Forte  * an unsolicited ELS AUTH msg from the NxPort as the auth
3462fcf3ce44SJohn Forte  * initiator that already received the ELS DHCHAP_Success.
3463fcf3ce44SJohn Forte  *
3464fcf3ce44SJohn Forte  * If the host is the auth initiator and since the AUTH transction is
3465fcf3ce44SJohn Forte  * already in progress, therefore, any auth els msg should not
3466fcf3ce44SJohn Forte  * happen and if happened, RJT and move to NPR_NODE.
3467fcf3ce44SJohn Forte  *
3468fcf3ce44SJohn Forte  * If the host is the auth reponder, this unsolicited els auth msg should
3469fcf3ce44SJohn Forte  * be DHCHAP_Success for this bi-directional auth
3470fcf3ce44SJohn Forte  * transaction. In which case, the host should send ACC back and move state
3471fcf3ce44SJohn Forte  * to REG_LOGIN. If this unsolicited els auth msg is
3472fcf3ce44SJohn Forte  * DHCHAP_Reject, which could mean that the auth failed, then host should
3473fcf3ce44SJohn Forte  * send back ACC and set the next state to NPR_NODE.
3474fcf3ce44SJohn Forte  *
3475fcf3ce44SJohn Forte  */
3476fcf3ce44SJohn Forte /* ARGSUSED */
3477fcf3ce44SJohn Forte static uint32_t
emlxs_rcv_auth_msg_dhchap_success_issue_wait4next(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)3478fcf3ce44SJohn Forte emlxs_rcv_auth_msg_dhchap_success_issue_wait4next(
3479fcf3ce44SJohn Forte emlxs_port_t *port,
348082527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
3481fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
3482fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
3483fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
3484fcf3ce44SJohn Forte uint32_t evt)
3485fcf3ce44SJohn Forte {
3486fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *) arg4;
3487fcf3ce44SJohn Forte 
3488fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
3489fcf3ce44SJohn Forte 	    "rcv_auth_msg_dhchap_success_issue_wait4next. 0x%x. Not iplted.",
3490fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
3491fcf3ce44SJohn Forte 
3492fcf3ce44SJohn Forte 	return (0);
3493fcf3ce44SJohn Forte 
3494fcf3ce44SJohn Forte } /* emlxs_rcv_auth_msg_dhchap_success_issue_wait4next */
3495fcf3ce44SJohn Forte 
3496fcf3ce44SJohn Forte 
3497fcf3ce44SJohn Forte 
3498fcf3ce44SJohn Forte /*
3499fcf3ce44SJohn Forte  * ! emlxs_cmpl_auth_msg_dhchap_success_issue_wait4next
3500fcf3ce44SJohn Forte  *
3501fcf3ce44SJohn Forte  * This routine is invoked when
3502fcf3ce44SJohn Forte  * the host as the auth initiator received an solicited ACC/RJT from the
3503fcf3ce44SJohn Forte  * NxPort or FxPort that already received DHCHAP_Success
3504fcf3ce44SJohn Forte  * Msg the host sent before. in case of ACC, set next state = REG_LOGIN.
3505fcf3ce44SJohn Forte  * in case of RJT, set next state = NPR_NODE.
3506fcf3ce44SJohn Forte  *
3507fcf3ce44SJohn Forte  */
3508fcf3ce44SJohn Forte /* ARGSUSED */
3509fcf3ce44SJohn Forte static uint32_t
emlxs_cmpl_auth_msg_dhchap_success_issue_wait4next(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)3510fcf3ce44SJohn Forte emlxs_cmpl_auth_msg_dhchap_success_issue_wait4next(
3511fcf3ce44SJohn Forte emlxs_port_t *port,
351282527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
3513fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
3514fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
3515fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
3516fcf3ce44SJohn Forte uint32_t evt)
3517fcf3ce44SJohn Forte {
3518fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
3519fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
3520fcf3ce44SJohn Forte 
3521fcf3ce44SJohn Forte 	/*
3522fcf3ce44SJohn Forte 	 * Either host is the initiator and auth or (reauth bi-direct) is
3523fcf3ce44SJohn Forte 	 * done, so start host reauth heartbeat timer now if host side reauth
3524fcf3ce44SJohn Forte 	 * heart beat never get started. Or host is the responder and the
3525fcf3ce44SJohn Forte 	 * other entity is done with its reauth heart beat with
3526fcf3ce44SJohn Forte 	 * uni-directional auth. Anyway we start host side reauth heart beat
3527fcf3ce44SJohn Forte 	 * timer now.
3528fcf3ce44SJohn Forte 	 */
3529fcf3ce44SJohn Forte 
3530fcf3ce44SJohn Forte 	node_dhc->flag &= ~NLP_REMOTE_AUTH;
3531fcf3ce44SJohn Forte 	node_dhc->flag |= NLP_SET_REAUTH_TIME;
3532fcf3ce44SJohn Forte 
3533fcf3ce44SJohn Forte 	emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_SUCCESS, 0, 0);
3534*8f23e9faSHans Rosenfeld 	emlxs_log_auth_event(port, ndlp,
3535*8f23e9faSHans Rosenfeld 	    "cmpl_auth_msg_dhchap_success_issue_wait4next",
3536fcf3ce44SJohn Forte 	    "Host-initiated-bidir-auth-success");
3537fcf3ce44SJohn Forte 	emlxs_dhc_auth_complete(port, ndlp, 0);
3538fcf3ce44SJohn Forte 
3539fcf3ce44SJohn Forte 	return (node_dhc->state);
3540fcf3ce44SJohn Forte 
3541fcf3ce44SJohn Forte } /* emlxs_cmpl_auth_msg_dhchap_success_issue_wait4next */
3542fcf3ce44SJohn Forte 
3543fcf3ce44SJohn Forte 
3544fcf3ce44SJohn Forte /*
3545fcf3ce44SJohn Forte  * ! emlxs_cmpl_auth_msg_auth_negotiate_rcv
3546fcf3ce44SJohn Forte  *
3547fcf3ce44SJohn Forte  * This routine is invoked when
3548fcf3ce44SJohn Forte  * the host received the solicited ACC/RJT ELS cmd from an FxPort or an
3549fcf3ce44SJohn Forte  * NxPort that has received the ELS DHCHAP_Challenge.
3550fcf3ce44SJohn Forte  * The host is the auth responder and the auth transaction is still in
3551fcf3ce44SJohn Forte  * progress.
3552fcf3ce44SJohn Forte  *
3553fcf3ce44SJohn Forte  */
3554fcf3ce44SJohn Forte /* ARGSUSED */
3555fcf3ce44SJohn Forte static uint32_t
emlxs_cmpl_auth_msg_auth_negotiate_rcv(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)3556fcf3ce44SJohn Forte emlxs_cmpl_auth_msg_auth_negotiate_rcv(
3557fcf3ce44SJohn Forte emlxs_port_t *port,
355882527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
3559fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
3560fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
3561fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
3562fcf3ce44SJohn Forte uint32_t evt)
3563fcf3ce44SJohn Forte {
3564fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
3565fcf3ce44SJohn Forte 
3566fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
3567fcf3ce44SJohn Forte 	    "cmpl_auth_msg_auth_negotiate_rcv called. 0x%x. Not implemented.",
3568fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
3569fcf3ce44SJohn Forte 
3570fcf3ce44SJohn Forte 	return (0);
3571fcf3ce44SJohn Forte 
3572fcf3ce44SJohn Forte } /* emlxs_cmpl_auth_msg_auth_negotiate_rcv */
3573fcf3ce44SJohn Forte 
3574fcf3ce44SJohn Forte 
3575fcf3ce44SJohn Forte 
3576fcf3ce44SJohn Forte /*
3577fcf3ce44SJohn Forte  * ! emlxs_rcv_auth_msg_dhchap_challenge_issue
3578fcf3ce44SJohn Forte  *
3579fcf3ce44SJohn Forte  * \pre \post \param   phba \param   ndlp \param   arg \param   evt \return
3580fcf3ce44SJohn Forte  * uint32_t \b Description: This routine should be
3581fcf3ce44SJohn Forte  * emlxs_disc_neverdev. The host is the auth responder and the auth
3582fcf3ce44SJohn Forte  * transaction is still in progress, any unsolicited els auth
3583fcf3ce44SJohn Forte  * msg is unexpected and should not happen in normal case.
3584fcf3ce44SJohn Forte  *
3585fcf3ce44SJohn Forte  * If DHCHAP_Reject, ACC and next state = NPR_NODE. anything else, RJT and
3586fcf3ce44SJohn Forte  * next state = NPR_NODE.
3587fcf3ce44SJohn Forte  */
3588fcf3ce44SJohn Forte /* ARGSUSED */
3589fcf3ce44SJohn Forte static uint32_t
emlxs_rcv_auth_msg_dhchap_challenge_issue(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)3590fcf3ce44SJohn Forte emlxs_rcv_auth_msg_dhchap_challenge_issue(
3591fcf3ce44SJohn Forte emlxs_port_t *port,
359282527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
3593fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
3594fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
3595fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
3596fcf3ce44SJohn Forte uint32_t evt)
3597fcf3ce44SJohn Forte {
3598fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
3599fcf3ce44SJohn Forte 
3600fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
3601fcf3ce44SJohn Forte 	    "rcv_auth_msg_dhchap_challenge_issue called. 0x%x. Not iplted.",
3602fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
3603fcf3ce44SJohn Forte 
3604fcf3ce44SJohn Forte 	return (0);
3605fcf3ce44SJohn Forte 
3606fcf3ce44SJohn Forte } /* emlxs_rcv_auth_msg_dhchap_challenge_issue */
3607fcf3ce44SJohn Forte 
3608fcf3ce44SJohn Forte 
3609fcf3ce44SJohn Forte 
3610fcf3ce44SJohn Forte /*
3611fcf3ce44SJohn Forte  * ! emlxs_cmpl_auth_msg_dhchap_challenge_issue
3612fcf3ce44SJohn Forte  *
3613fcf3ce44SJohn Forte  * \pre \post \param   phba \param   ndlp \param   arg \param   evt \return
3614fcf3ce44SJohn Forte  * uint32_t \b Description: This routine is invoked when
3615fcf3ce44SJohn Forte  * the host as the responder received the solicited response (ACC or RJT)
3616fcf3ce44SJohn Forte  * from initiator to the DHCHAP_Challenge msg sent from
3617fcf3ce44SJohn Forte  * host. In case of ACC, the next state = DHCHAP_CHALLENGE_CMPL_WAIT4NEXT
3618fcf3ce44SJohn Forte  * In case of RJT, the next state = NPR_NODE.
3619fcf3ce44SJohn Forte  *
3620fcf3ce44SJohn Forte  */
3621fcf3ce44SJohn Forte /* ARGSUSED */
3622fcf3ce44SJohn Forte static uint32_t
emlxs_cmpl_auth_msg_dhchap_challenge_issue(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)3623fcf3ce44SJohn Forte emlxs_cmpl_auth_msg_dhchap_challenge_issue(
3624fcf3ce44SJohn Forte emlxs_port_t *port,
362582527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
3626fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
3627fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
3628fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
3629fcf3ce44SJohn Forte uint32_t evt)
3630fcf3ce44SJohn Forte {
3631fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
3632fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
3633fcf3ce44SJohn Forte 
3634fcf3ce44SJohn Forte 	/*
3635fcf3ce44SJohn Forte 	 * The next state should be
3636fcf3ce44SJohn Forte 	 * emlxs_rcv_auth_msg_dhchap_challenge_cmpl_wait4next
3637fcf3ce44SJohn Forte 	 */
3638fcf3ce44SJohn Forte 	emlxs_dhc_state(port, ndlp,
3639fcf3ce44SJohn Forte 	    NODE_STATE_DHCHAP_CHALLENGE_CMPL_WAIT4NEXT, 0, 0);
3640fcf3ce44SJohn Forte 
3641fcf3ce44SJohn Forte 	/* Start the fc_authrsp_timeout timer */
3642fcf3ce44SJohn Forte 	if (node_dhc->nlp_authrsp_tmo == 0) {
3643fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
3644fcf3ce44SJohn Forte 	    "cmpl_auth_msg_dhchap_challenge_issue: Starting authrsp timer.");
3645fcf3ce44SJohn Forte 
3646fcf3ce44SJohn Forte 		node_dhc->nlp_authrsp_tmo = DRV_TIME +
3647fcf3ce44SJohn Forte 		    node_dhc->auth_cfg.authentication_timeout;
3648fcf3ce44SJohn Forte 	}
3649fcf3ce44SJohn Forte 	return (node_dhc->state);
3650fcf3ce44SJohn Forte 
3651fcf3ce44SJohn Forte } /* emlxs_cmpl_auth_msg_dhchap_challenge_issue */
3652fcf3ce44SJohn Forte 
3653fcf3ce44SJohn Forte 
3654fcf3ce44SJohn Forte /*
3655fcf3ce44SJohn Forte  * ! emlxs_rcv_auth_msg_dhchap_challenge_cmpl_wait4next
3656fcf3ce44SJohn Forte  *
3657fcf3ce44SJohn Forte  * \pre \post \param   phba \param   ndlp \param   arg \param   evt \return
3658fcf3ce44SJohn Forte  * uint32_t \b Description: This routine is invoked when
3659fcf3ce44SJohn Forte  * the host as the auth responder received an unsolicited auth msg from the
3660fcf3ce44SJohn Forte  * FxPort or NxPort that already sent ACC to the DHCH_
3661fcf3ce44SJohn Forte  * Challenge it received. In normal case this unsolicited auth msg should
3662fcf3ce44SJohn Forte  * be DHCHAP_Reply msg from the initiator.
3663fcf3ce44SJohn Forte  *
3664fcf3ce44SJohn Forte  * For DHCHAP_Reply msg, the host send back ACC and then do verification
3665fcf3ce44SJohn Forte  * (hash?) and send back DHCHAP_Success and next state as
3666fcf3ce44SJohn Forte  * DHCHAP_SUCCESS_ISSUE or DHCHAP_Reject and next state as NPR_NODE based on
3667fcf3ce44SJohn Forte  * the verification result.
3668fcf3ce44SJohn Forte  *
3669fcf3ce44SJohn Forte  * For bi-directional auth transaction, Reply msg should have the new
3670fcf3ce44SJohn Forte  * challenge value from the initiator. thus the Success msg
3671fcf3ce44SJohn Forte  * sent out should have the corresponding Reply from the responder.
3672fcf3ce44SJohn Forte  *
3673fcf3ce44SJohn Forte  * For uni-directional, Reply msg received does not contains the new
3674fcf3ce44SJohn Forte  * challenge and therefore the Success msg does not include the
3675fcf3ce44SJohn Forte  * Reply msg.
3676fcf3ce44SJohn Forte  *
3677fcf3ce44SJohn Forte  * For DHCHAP_Reject, send ACC and moved to the next state NPR_NODE. For
3678fcf3ce44SJohn Forte  * anything else, send RJT and moved to NPR_NODE.
3679fcf3ce44SJohn Forte  *
3680fcf3ce44SJohn Forte  */
3681fcf3ce44SJohn Forte /* ARGSUSED */
3682fcf3ce44SJohn Forte static uint32_t
emlxs_rcv_auth_msg_dhchap_challenge_cmpl_wait4next(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)3683fcf3ce44SJohn Forte emlxs_rcv_auth_msg_dhchap_challenge_cmpl_wait4next(
3684fcf3ce44SJohn Forte emlxs_port_t *port,
368582527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
3686fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
3687fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
3688fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
3689fcf3ce44SJohn Forte uint32_t evt)
3690fcf3ce44SJohn Forte {
3691fcf3ce44SJohn Forte 	emlxs_port_dhc_t *port_dhc = &port->port_dhc;
3692fcf3ce44SJohn Forte 	IOCBQ *iocbq = (IOCBQ *)arg2;
3693fcf3ce44SJohn Forte 	MATCHMAP *mp = (MATCHMAP *)arg3;
3694fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
3695fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
3696fcf3ce44SJohn Forte 	uint8_t *bp;
3697fcf3ce44SJohn Forte 	uint32_t *lp;
3698fcf3ce44SJohn Forte 	DHCHAP_REPLY_HDR *dh_reply;
3699fcf3ce44SJohn Forte 	uint8_t *tmp;
3700fcf3ce44SJohn Forte 	uint32_t rsp_len;
3701fcf3ce44SJohn Forte 	uint8_t rsp[20];	/* should cover SHA-1 and MD5's rsp */
3702fcf3ce44SJohn Forte 	uint32_t dhval_len;
3703fcf3ce44SJohn Forte 	uint8_t dhval[512];
3704fcf3ce44SJohn Forte 	uint32_t cval_len;
3705fcf3ce44SJohn Forte 	uint8_t cval[20];
3706fcf3ce44SJohn Forte 	uint32_t tran_id;
3707fcf3ce44SJohn Forte 	uint32_t *hash_val = NULL;
3708fcf3ce44SJohn Forte 	uint8_t ReasonCode;
3709fcf3ce44SJohn Forte 	uint8_t ReasonCodeExplanation;
3710fcf3ce44SJohn Forte 	AUTH_RJT *rjt;
3711fcf3ce44SJohn Forte 
3712fcf3ce44SJohn Forte 	/* ACC the ELS DHCHAP_Reply msg first */
3713fcf3ce44SJohn Forte 
3714fcf3ce44SJohn Forte 	(void) emlxs_els_reply(port, iocbq, ELS_CMD_ACC, ELS_CMD_AUTH, 0, 0);
3715fcf3ce44SJohn Forte 
3716fcf3ce44SJohn Forte 	bp = mp->virt;
3717fcf3ce44SJohn Forte 	lp = (uint32_t *)bp;
3718fcf3ce44SJohn Forte 
3719fcf3ce44SJohn Forte 	/*
3720fcf3ce44SJohn Forte 	 * send back ELS AUTH_Reject or DHCHAP_Success msg based on the
3721fcf3ce44SJohn Forte 	 * verification result. i.e., hash computation etc.
3722fcf3ce44SJohn Forte 	 */
3723fcf3ce44SJohn Forte 	dh_reply = (DHCHAP_REPLY_HDR *)((uint8_t *)lp);
3724fcf3ce44SJohn Forte 	tmp = (uint8_t *)((uint8_t *)lp);
3725fcf3ce44SJohn Forte 
3726fcf3ce44SJohn Forte 	tran_id = dh_reply->tran_id;
3727fcf3ce44SJohn Forte 
372882527734SSukumar Swaminathan 	if (LE_SWAP32(tran_id) != node_dhc->nlp_auth_tranid_ini) {
3729fcf3ce44SJohn Forte 
3730fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
3731fcf3ce44SJohn Forte 	    "rcv_auth_msg_dhchap_challenge_cmpl_wait4next:0x%x 0x%x 0x%x",
3732fcf3ce44SJohn Forte 	    ndlp->nlp_DID, tran_id, node_dhc->nlp_auth_tranid_ini);
3733fcf3ce44SJohn Forte 
3734fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_FAILURE;
3735fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_BAD_PROTOCOL;
3736fcf3ce44SJohn Forte 		goto Reject;
3737fcf3ce44SJohn Forte 	}
3738fcf3ce44SJohn Forte 
3739fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
3740fcf3ce44SJohn Forte 	    "rcv_a_m_dhch_chll_cmpl_wait4next:0x%x 0x%x 0x%x 0x%x 0x%x",
3741fcf3ce44SJohn Forte 	    ndlp->nlp_DID, tran_id, node_dhc->nlp_auth_tranid_ini,
3742fcf3ce44SJohn Forte 	    node_dhc->nlp_auth_tranid_rsp, dh_reply->auth_msg_code);
3743fcf3ce44SJohn Forte 
3744fcf3ce44SJohn Forte 	/* cancel the nlp_authrsp_timeout timer and send out Auth_Reject */
3745fcf3ce44SJohn Forte 	if (node_dhc->nlp_authrsp_tmo) {
3746fcf3ce44SJohn Forte 		node_dhc->nlp_authrsp_tmo = 0;
3747fcf3ce44SJohn Forte 	}
3748fcf3ce44SJohn Forte 	if (dh_reply->auth_msg_code == AUTH_REJECT) {
3749fcf3ce44SJohn Forte 
3750fcf3ce44SJohn Forte 		rjt = (AUTH_RJT *)((uint8_t *)lp);
3751fcf3ce44SJohn Forte 		ReasonCode = rjt->ReasonCode;
3752fcf3ce44SJohn Forte 		ReasonCodeExplanation = rjt->ReasonCodeExplanation;
3753fcf3ce44SJohn Forte 
3754fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
3755fcf3ce44SJohn Forte 	    "rcv_a_msg_dhch_chall_cmpl_wait4next:RJT rcved:0x%x 0x%x",
3756fcf3ce44SJohn Forte 	    ReasonCode, ReasonCodeExplanation);
3757fcf3ce44SJohn Forte 
3758fcf3ce44SJohn Forte 		switch (ReasonCode) {
3759fcf3ce44SJohn Forte 		case AUTHRJT_LOGIC_ERR:
3760fcf3ce44SJohn Forte 			switch (ReasonCodeExplanation) {
3761fcf3ce44SJohn Forte 			case AUTHEXP_MECH_UNUSABLE:
3762fcf3ce44SJohn Forte 			case AUTHEXP_DHGROUP_UNUSABLE:
3763fcf3ce44SJohn Forte 			case AUTHEXP_HASHFUNC_UNUSABLE:
3764fcf3ce44SJohn Forte 				ReasonCode = AUTHRJT_LOGIC_ERR;
3765fcf3ce44SJohn Forte 				ReasonCodeExplanation = AUTHEXP_RESTART_AUTH;
3766fcf3ce44SJohn Forte 				break;
3767fcf3ce44SJohn Forte 
3768fcf3ce44SJohn Forte 			case AUTHEXP_RESTART_AUTH:
3769fcf3ce44SJohn Forte 				/*
3770fcf3ce44SJohn Forte 				 * Cancel the rsp timer if not cancelled yet.
3771fcf3ce44SJohn Forte 				 * and restart auth tran now.
3772fcf3ce44SJohn Forte 				 */
3773fcf3ce44SJohn Forte 				if (node_dhc->nlp_authrsp_tmo != 0) {
3774fcf3ce44SJohn Forte 					node_dhc->nlp_authrsp_tmo = 0;
3775fcf3ce44SJohn Forte 					node_dhc->nlp_authrsp_tmocnt = 0;
3776fcf3ce44SJohn Forte 				}
3777fcf3ce44SJohn Forte 				if (emlxs_dhc_auth_start(port, ndlp,
3778fcf3ce44SJohn Forte 				    NULL, NULL) != 0) {
3779fcf3ce44SJohn Forte 				EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_debug_msg,
3780fcf3ce44SJohn Forte 				    "Reauth timeout.Auth initfailed. 0x%x %x",
3781fcf3ce44SJohn Forte 				    ndlp->nlp_DID, node_dhc->state);
3782fcf3ce44SJohn Forte 				}
3783fcf3ce44SJohn Forte 				return (node_dhc->state);
3784fcf3ce44SJohn Forte 
3785fcf3ce44SJohn Forte 			default:
3786fcf3ce44SJohn Forte 				ReasonCode = AUTHRJT_FAILURE;
3787fcf3ce44SJohn Forte 				ReasonCodeExplanation = AUTHEXP_AUTH_FAILED;
3788fcf3ce44SJohn Forte 				break;
3789fcf3ce44SJohn Forte 			}
3790fcf3ce44SJohn Forte 			break;
3791fcf3ce44SJohn Forte 
3792fcf3ce44SJohn Forte 		case AUTHRJT_FAILURE:
3793fcf3ce44SJohn Forte 		default:
3794fcf3ce44SJohn Forte 			ReasonCode = AUTHRJT_FAILURE;
3795fcf3ce44SJohn Forte 			ReasonCodeExplanation = AUTHEXP_AUTH_FAILED;
3796fcf3ce44SJohn Forte 			break;
3797fcf3ce44SJohn Forte 		}
3798fcf3ce44SJohn Forte 
3799fcf3ce44SJohn Forte 		goto Reject;
3800fcf3ce44SJohn Forte 
3801fcf3ce44SJohn Forte 	}
3802fcf3ce44SJohn Forte 	if (dh_reply->auth_msg_code == DHCHAP_REPLY) {
3803fcf3ce44SJohn Forte 
3804fcf3ce44SJohn Forte 		/* We must send out DHCHAP_Success msg and wait for ACC */
3805fcf3ce44SJohn Forte 		/* _AND_ if bi-dir auth, we have to wait for next */
3806fcf3ce44SJohn Forte 
3807fcf3ce44SJohn Forte 		/*
3808fcf3ce44SJohn Forte 		 * Send back DHCHAP_Success or AUTH_Reject based on the
3809fcf3ce44SJohn Forte 		 * verification result
3810fcf3ce44SJohn Forte 		 */
3811fcf3ce44SJohn Forte 		tmp += sizeof (DHCHAP_REPLY_HDR);
381282527734SSukumar Swaminathan 		rsp_len = LE_SWAP32(*(uint32_t *)tmp);
3813fcf3ce44SJohn Forte 		tmp += sizeof (uint32_t);
3814fcf3ce44SJohn Forte 
3815fcf3ce44SJohn Forte 		/* collect the response data */
3816fcf3ce44SJohn Forte 		bcopy((void *)tmp, (void *)rsp, rsp_len);
3817fcf3ce44SJohn Forte 
3818fcf3ce44SJohn Forte 		tmp += rsp_len;
381982527734SSukumar Swaminathan 		dhval_len = LE_SWAP32(*(uint32_t *)tmp);
3820fcf3ce44SJohn Forte 
3821fcf3ce44SJohn Forte 		tmp += sizeof (uint32_t);
3822fcf3ce44SJohn Forte 
3823fcf3ce44SJohn Forte 
3824fcf3ce44SJohn Forte 
3825fcf3ce44SJohn Forte 		if (dhval_len != 0) {
3826fcf3ce44SJohn Forte 			/* collect the DH value */
3827fcf3ce44SJohn Forte 			bcopy((void *)tmp, (void *)dhval, dhval_len);
3828fcf3ce44SJohn Forte 			tmp += dhval_len;
3829fcf3ce44SJohn Forte 		}
3830fcf3ce44SJohn Forte 		/*
3831fcf3ce44SJohn Forte 		 * Check to see if there is any challenge for bi-dir auth in
3832fcf3ce44SJohn Forte 		 * the reply msg
3833fcf3ce44SJohn Forte 		 */
383482527734SSukumar Swaminathan 		cval_len = LE_SWAP32(*(uint32_t *)tmp);
3835fcf3ce44SJohn Forte 		if (cval_len != 0) {
3836fcf3ce44SJohn Forte 			/* collect challenge value */
3837fcf3ce44SJohn Forte 			tmp += sizeof (uint32_t);
3838fcf3ce44SJohn Forte 			bcopy((void *)tmp, (void *)cval, cval_len);
3839fcf3ce44SJohn Forte 
384082527734SSukumar Swaminathan 			if (ndlp->nlp_DID == FABRIC_DID) {
3841fcf3ce44SJohn Forte 				node_dhc->nlp_auth_bidir = 1;
3842fcf3ce44SJohn Forte 			} else {
3843fcf3ce44SJohn Forte 				node_dhc->nlp_auth_bidir = 1;
3844fcf3ce44SJohn Forte 			}
3845fcf3ce44SJohn Forte 		} else {
3846fcf3ce44SJohn Forte 			node_dhc->nlp_auth_bidir = 0;
3847fcf3ce44SJohn Forte 		}
3848fcf3ce44SJohn Forte 
3849fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
3850fcf3ce44SJohn Forte 	    "rcv_a_m_dhchap_challenge_cmpl_wait4next:Reply:%x %lx %x %x %x\n",
3851fcf3ce44SJohn Forte 	    ndlp->nlp_DID, *(uint32_t *)rsp, rsp_len, dhval_len, cval_len);
3852fcf3ce44SJohn Forte 
3853fcf3ce44SJohn Forte 		/* Verify the response based on the hash func, dhgp_id etc. */
3854fcf3ce44SJohn Forte 		/*
3855fcf3ce44SJohn Forte 		 * all the information needed are stored in
3856fcf3ce44SJohn Forte 		 * node_dhc->hrsp_xxx or ndlp->nlp_auth_misc.
3857fcf3ce44SJohn Forte 		 */
3858fcf3ce44SJohn Forte 		/*
3859fcf3ce44SJohn Forte 		 * Basically compare the rsp value with the computed hash
3860fcf3ce44SJohn Forte 		 * value
3861fcf3ce44SJohn Forte 		 */
3862fcf3ce44SJohn Forte 
3863fcf3ce44SJohn Forte 		/* allocate hash_val first as rsp_len bytes */
3864fcf3ce44SJohn Forte 		/*
3865fcf3ce44SJohn Forte 		 * we set bi-cval pointer as NULL because we are using
3866fcf3ce44SJohn Forte 		 * node_dhc->hrsp_cval[]
3867fcf3ce44SJohn Forte 		 */
3868fcf3ce44SJohn Forte 		hash_val = emlxs_hash_verification(port, port_dhc, ndlp,
3869fcf3ce44SJohn Forte 		    (tran_id), dhval, (dhval_len), 1, 0);
3870fcf3ce44SJohn Forte 
3871fcf3ce44SJohn Forte 		if (hash_val == NULL) {
3872fcf3ce44SJohn Forte 			ReasonCode = AUTHRJT_FAILURE;
3873fcf3ce44SJohn Forte 			ReasonCodeExplanation = AUTHEXP_AUTH_FAILED;
3874fcf3ce44SJohn Forte 			goto Reject;
3875fcf3ce44SJohn Forte 		}
3876fcf3ce44SJohn Forte 		if (bcmp((void *) rsp, (void *)hash_val, rsp_len)) {
3877fcf3ce44SJohn Forte 			/* not identical */
3878fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
3879fcf3ce44SJohn Forte 	    "rcv_auth_msg_dhchap_challenge_cmpl_wait4next: Not authted(1).");
3880fcf3ce44SJohn Forte 
3881fcf3ce44SJohn Forte 			ReasonCode = AUTHRJT_FAILURE;
3882fcf3ce44SJohn Forte 			ReasonCodeExplanation = AUTHEXP_AUTH_FAILED;
3883fcf3ce44SJohn Forte 			goto Reject;
3884fcf3ce44SJohn Forte 		}
3885fcf3ce44SJohn Forte 		kmem_free(hash_val, rsp_len);
3886fcf3ce44SJohn Forte 		hash_val = NULL;
3887fcf3ce44SJohn Forte 
3888fcf3ce44SJohn Forte 		/* generate the reply based on the challenge received if any */
3889fcf3ce44SJohn Forte 		if ((cval_len) != 0) {
3890fcf3ce44SJohn Forte 			/*
3891fcf3ce44SJohn Forte 			 * Cal R2 = H (Ti || Km || Ca2) Ca2 = H (C2 || ((g^y
3892fcf3ce44SJohn Forte 			 * mod p)^x mod p) ) = H (C2 || (g^(x*y) mod p)) = H
3893fcf3ce44SJohn Forte 			 * (C2 || seskey) Km is the password associated with
3894fcf3ce44SJohn Forte 			 * responder. Here cval: C2 dhval: (g^y mod p)
3895fcf3ce44SJohn Forte 			 */
3896fcf3ce44SJohn Forte 			hash_val = emlxs_hash_get_R2(port, port_dhc,
3897fcf3ce44SJohn Forte 			    ndlp, (tran_id), dhval,
3898fcf3ce44SJohn Forte 			    (dhval_len), 1, cval);
3899fcf3ce44SJohn Forte 
3900fcf3ce44SJohn Forte 			if (hash_val == NULL) {
3901fcf3ce44SJohn Forte 				ReasonCode = AUTHRJT_FAILURE;
3902fcf3ce44SJohn Forte 				ReasonCodeExplanation = AUTHEXP_AUTH_FAILED;
3903fcf3ce44SJohn Forte 				goto Reject;
3904fcf3ce44SJohn Forte 			}
3905fcf3ce44SJohn Forte 		}
3906fcf3ce44SJohn Forte 		emlxs_dhc_state(port, ndlp,
3907fcf3ce44SJohn Forte 		    NODE_STATE_DHCHAP_SUCCESS_ISSUE, 0, 0);
3908fcf3ce44SJohn Forte 
3909fcf3ce44SJohn Forte 		if (emlxs_issue_dhchap_success(port, ndlp, 0,
3910fcf3ce44SJohn Forte 		    (uint8_t *)hash_val)) {
3911fcf3ce44SJohn Forte 			ReasonCode = AUTHRJT_FAILURE;
3912fcf3ce44SJohn Forte 			ReasonCodeExplanation = AUTHEXP_AUTH_FAILED;
3913fcf3ce44SJohn Forte 			goto Reject;
3914fcf3ce44SJohn Forte 		}
3915fcf3ce44SJohn Forte 	}
3916fcf3ce44SJohn Forte 	return (node_dhc->state);
3917fcf3ce44SJohn Forte 
3918fcf3ce44SJohn Forte Reject:
3919fcf3ce44SJohn Forte 
3920fcf3ce44SJohn Forte 	emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_FAILED,
3921fcf3ce44SJohn Forte 	    ReasonCode, ReasonCodeExplanation);
3922fcf3ce44SJohn Forte 	(void) emlxs_issue_auth_reject(port, ndlp, 0, 0, ReasonCode,
3923fcf3ce44SJohn Forte 	    ReasonCodeExplanation);
3924fcf3ce44SJohn Forte 	emlxs_dhc_auth_complete(port, ndlp, 1);
3925fcf3ce44SJohn Forte 
3926fcf3ce44SJohn Forte out:
3927fcf3ce44SJohn Forte 
3928fcf3ce44SJohn Forte 	return (node_dhc->state);
3929fcf3ce44SJohn Forte 
3930fcf3ce44SJohn Forte } /* emlxs_rcv_auth_msg_dhchap_challenge_cmpl_wait4next */
3931fcf3ce44SJohn Forte 
3932fcf3ce44SJohn Forte 
3933fcf3ce44SJohn Forte 
3934fcf3ce44SJohn Forte /*
3935fcf3ce44SJohn Forte  * This routine should be emlxs_disc_neverdev.
3936fcf3ce44SJohn Forte  *
3937fcf3ce44SJohn Forte  */
3938fcf3ce44SJohn Forte /* ARGSUSED */
3939fcf3ce44SJohn Forte static uint32_t
emlxs_cmpl_auth_msg_dhchap_challenge_cmpl_wait4next(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)3940fcf3ce44SJohn Forte emlxs_cmpl_auth_msg_dhchap_challenge_cmpl_wait4next(
3941fcf3ce44SJohn Forte emlxs_port_t *port,
394282527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
3943fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
3944fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
3945fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
3946fcf3ce44SJohn Forte uint32_t evt)
3947fcf3ce44SJohn Forte {
3948fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
3949fcf3ce44SJohn Forte 
3950fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
3951fcf3ce44SJohn Forte 	    "cmpl_a_m_dhch_chall_cmpl_wait4next.0x%x. Not implemented.",
3952fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
3953fcf3ce44SJohn Forte 
3954fcf3ce44SJohn Forte 	return (0);
3955fcf3ce44SJohn Forte 
3956fcf3ce44SJohn Forte } /* emlxs_cmpl_auth_msg_dhchap_challenge_cmpl_wait4next */
3957fcf3ce44SJohn Forte 
3958fcf3ce44SJohn Forte 
3959fcf3ce44SJohn Forte /*
3960fcf3ce44SJohn Forte  * ! emlxs_rcv_auth_msg_dhchap_success_issue
3961fcf3ce44SJohn Forte  *
3962fcf3ce44SJohn Forte  * \pre \post \param   phba \param   ndlp \param   arg \param   evt \return
3963fcf3ce44SJohn Forte  * uint32_t \b Description:
3964fcf3ce44SJohn Forte  *
3965fcf3ce44SJohn Forte  * The host is the auth responder and the auth transaction is still in
3966fcf3ce44SJohn Forte  * progress, any unsolicited els auth msg is unexpected and
3967fcf3ce44SJohn Forte  * should not happen. If DHCHAP_Reject received, ACC back and move to next
3968fcf3ce44SJohn Forte  * state NPR_NODE. anything else, RJT and move to
3969fcf3ce44SJohn Forte  * NPR_NODE.
3970fcf3ce44SJohn Forte  */
3971fcf3ce44SJohn Forte /* ARGSUSED */
3972fcf3ce44SJohn Forte static uint32_t
emlxs_rcv_auth_msg_dhchap_success_issue(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)3973fcf3ce44SJohn Forte emlxs_rcv_auth_msg_dhchap_success_issue(
3974fcf3ce44SJohn Forte emlxs_port_t *port,
397582527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
3976fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
3977fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
3978fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
3979fcf3ce44SJohn Forte uint32_t evt)
3980fcf3ce44SJohn Forte {
3981fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
3982fcf3ce44SJohn Forte 
3983fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
3984fcf3ce44SJohn Forte 	    "rcv_a_m_dhch_success_issue called. did=0x%x. Not implemented.",
3985fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
3986fcf3ce44SJohn Forte 
3987fcf3ce44SJohn Forte 	return (0);
3988fcf3ce44SJohn Forte 
3989fcf3ce44SJohn Forte } /* emlxs_rcv_auth_msg_dhchap_success_issue */
3990fcf3ce44SJohn Forte 
3991fcf3ce44SJohn Forte 
3992fcf3ce44SJohn Forte 
3993fcf3ce44SJohn Forte /*
3994fcf3ce44SJohn Forte  * emlxs_cmpl_auth_msg_dhchap_success_issue
3995fcf3ce44SJohn Forte  *
3996fcf3ce44SJohn Forte  * This routine is invoked when
3997fcf3ce44SJohn Forte  * host as the auth responder received the solicited response (ACC or RJT)
3998fcf3ce44SJohn Forte  * from the initiator that received DHCHAP_ Success.
3999fcf3ce44SJohn Forte  *
4000fcf3ce44SJohn Forte  * For uni-dirctional authentication, we are done so the next state =
4001fcf3ce44SJohn Forte  * REG_LOGIN for bi-directional authentication, we will expect
4002fcf3ce44SJohn Forte  * DHCHAP_Success msg. so the next state = DHCHAP_SUCCESS_CMPL_WAIT4NEXT
4003fcf3ce44SJohn Forte  * and start the emlxs_dhc_authrsp_timeout timer
4004fcf3ce44SJohn Forte  */
4005fcf3ce44SJohn Forte /* ARGSUSED */
4006fcf3ce44SJohn Forte static uint32_t
emlxs_cmpl_auth_msg_dhchap_success_issue(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)4007fcf3ce44SJohn Forte emlxs_cmpl_auth_msg_dhchap_success_issue(
4008fcf3ce44SJohn Forte emlxs_port_t *port,
400982527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
4010fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
4011fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
4012fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
4013fcf3ce44SJohn Forte uint32_t evt)
4014fcf3ce44SJohn Forte {
4015fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
4016fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
4017fcf3ce44SJohn Forte 
4018fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4019fcf3ce44SJohn Forte 	    "cmpl_a_m_dhch_success_issue: did=0x%x auth_bidir=0x%x",
4020fcf3ce44SJohn Forte 	    ndlp->nlp_DID, node_dhc->nlp_auth_bidir);
4021fcf3ce44SJohn Forte 
4022fcf3ce44SJohn Forte 	if (node_dhc->nlp_auth_bidir == 1) {
4023fcf3ce44SJohn Forte 		/* we would expect the bi-dir authentication result */
4024fcf3ce44SJohn Forte 
4025fcf3ce44SJohn Forte 		/*
4026fcf3ce44SJohn Forte 		 * the next state should be
4027fcf3ce44SJohn Forte 		 * emlxs_rcv_auth_msg_dhchap_success_cmpl_wait4next
4028fcf3ce44SJohn Forte 		 */
4029fcf3ce44SJohn Forte 		emlxs_dhc_state(port, ndlp,
4030fcf3ce44SJohn Forte 		    NODE_STATE_DHCHAP_SUCCESS_CMPL_WAIT4NEXT, 0, 0);
4031fcf3ce44SJohn Forte 
4032fcf3ce44SJohn Forte 		/* start the emlxs_dhc_authrsp_timeout timer */
4033fcf3ce44SJohn Forte 		node_dhc->nlp_authrsp_tmo = DRV_TIME +
4034fcf3ce44SJohn Forte 		    node_dhc->auth_cfg.authentication_timeout;
4035fcf3ce44SJohn Forte 	} else {
4036fcf3ce44SJohn Forte 		node_dhc->flag &= ~NLP_REMOTE_AUTH;
4037fcf3ce44SJohn Forte 
4038fcf3ce44SJohn Forte 		emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_SUCCESS, 0, 0);
4039*8f23e9faSHans Rosenfeld 		emlxs_log_auth_event(port, ndlp,
4040*8f23e9faSHans Rosenfeld 		    "cmpl_auth_msg_dhchap_success_issue",
4041fcf3ce44SJohn Forte 		    "Node-initiated-unidir-reauth-success");
4042fcf3ce44SJohn Forte 		emlxs_dhc_auth_complete(port, ndlp, 0);
4043fcf3ce44SJohn Forte 	}
4044fcf3ce44SJohn Forte 
4045fcf3ce44SJohn Forte 	return (node_dhc->state);
4046fcf3ce44SJohn Forte 
4047fcf3ce44SJohn Forte } /* emlxs_cmpl_auth_msg_dhchap_success_issue */
4048fcf3ce44SJohn Forte 
4049fcf3ce44SJohn Forte 
4050fcf3ce44SJohn Forte /* ARGSUSED */
4051fcf3ce44SJohn Forte static uint32_t
emlxs_device_recov_unmapped_node(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)4052fcf3ce44SJohn Forte emlxs_device_recov_unmapped_node(
4053fcf3ce44SJohn Forte 	emlxs_port_t *port,
4054fcf3ce44SJohn Forte 	void *arg1,
4055fcf3ce44SJohn Forte 	void *arg2,
4056fcf3ce44SJohn Forte 	void *arg3,
4057fcf3ce44SJohn Forte 	void *arg4,
4058fcf3ce44SJohn Forte 	uint32_t evt)
4059fcf3ce44SJohn Forte {
4060fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
4061fcf3ce44SJohn Forte 
4062fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4063*8f23e9faSHans Rosenfeld 	    "device_recov_unmapped_node called. 0x%x. Not implemented.",
4064fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
4065fcf3ce44SJohn Forte 
4066fcf3ce44SJohn Forte 	return (0);
4067fcf3ce44SJohn Forte 
4068fcf3ce44SJohn Forte } /* emlxs_device_recov_unmapped_node */
4069fcf3ce44SJohn Forte 
4070fcf3ce44SJohn Forte 
4071fcf3ce44SJohn Forte 
4072fcf3ce44SJohn Forte /* ARGSUSED */
4073fcf3ce44SJohn Forte static uint32_t
emlxs_device_rm_npr_node(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)4074fcf3ce44SJohn Forte emlxs_device_rm_npr_node(
4075fcf3ce44SJohn Forte 	emlxs_port_t *port,
4076fcf3ce44SJohn Forte 	void *arg1,
4077fcf3ce44SJohn Forte 	void *arg2,
4078fcf3ce44SJohn Forte 	void *arg3,
4079fcf3ce44SJohn Forte 	void *arg4,
4080fcf3ce44SJohn Forte 	uint32_t evt)
4081fcf3ce44SJohn Forte {
4082fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
4083fcf3ce44SJohn Forte 
4084fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4085*8f23e9faSHans Rosenfeld 	    "device_rm_npr_node called. 0x%x. Not implemented.",
4086fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
4087fcf3ce44SJohn Forte 
4088fcf3ce44SJohn Forte 	return (0);
4089fcf3ce44SJohn Forte 
4090fcf3ce44SJohn Forte } /* emlxs_device_rm_npr_node */
4091fcf3ce44SJohn Forte 
4092fcf3ce44SJohn Forte 
4093fcf3ce44SJohn Forte /* ARGSUSED */
4094fcf3ce44SJohn Forte static uint32_t
emlxs_device_recov_npr_node(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)4095fcf3ce44SJohn Forte emlxs_device_recov_npr_node(
4096fcf3ce44SJohn Forte 	emlxs_port_t *port,
4097fcf3ce44SJohn Forte 	void *arg1,
4098fcf3ce44SJohn Forte 	void *arg2,
4099fcf3ce44SJohn Forte 	void *arg3,
4100fcf3ce44SJohn Forte 	void *arg4,
4101fcf3ce44SJohn Forte 	uint32_t evt)
4102fcf3ce44SJohn Forte {
4103fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
4104fcf3ce44SJohn Forte 
4105fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4106*8f23e9faSHans Rosenfeld 	    "device_recov_npr_node called. 0x%x. Not implemented.",
4107fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
4108fcf3ce44SJohn Forte 
4109fcf3ce44SJohn Forte 	return (0);
4110fcf3ce44SJohn Forte 
4111fcf3ce44SJohn Forte } /* emlxs_device_recov_npr_node */
4112fcf3ce44SJohn Forte 
4113fcf3ce44SJohn Forte 
4114fcf3ce44SJohn Forte /* ARGSUSED */
4115fcf3ce44SJohn Forte static uint32_t
emlxs_device_rem_auth(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)4116fcf3ce44SJohn Forte emlxs_device_rem_auth(
4117fcf3ce44SJohn Forte emlxs_port_t *port,
411882527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
4119fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
4120fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
4121fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
4122fcf3ce44SJohn Forte uint32_t evt)
4123fcf3ce44SJohn Forte {
4124fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
4125fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
4126fcf3ce44SJohn Forte 
4127fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4128*8f23e9faSHans Rosenfeld 	    "device_rem_auth: 0x%x.",
4129fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
4130fcf3ce44SJohn Forte 
4131fcf3ce44SJohn Forte 	emlxs_dhc_state(port, ndlp, NODE_STATE_UNKNOWN, 0, 0);
4132fcf3ce44SJohn Forte 
4133fcf3ce44SJohn Forte 	return (node_dhc->state);
4134fcf3ce44SJohn Forte 
4135fcf3ce44SJohn Forte } /* emlxs_device_rem_auth */
4136fcf3ce44SJohn Forte 
4137fcf3ce44SJohn Forte 
4138fcf3ce44SJohn Forte /*
4139fcf3ce44SJohn Forte  * This routine is invoked when linkdown event happens during authentication
4140fcf3ce44SJohn Forte  */
4141fcf3ce44SJohn Forte /* ARGSUSED */
4142fcf3ce44SJohn Forte static uint32_t
emlxs_device_recov_auth(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)4143fcf3ce44SJohn Forte emlxs_device_recov_auth(
4144fcf3ce44SJohn Forte emlxs_port_t *port,
414582527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
4146fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
4147fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
4148fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
4149fcf3ce44SJohn Forte uint32_t evt)
4150fcf3ce44SJohn Forte {
4151fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
4152fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
4153fcf3ce44SJohn Forte 
4154fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4155*8f23e9faSHans Rosenfeld 	    "device_recov_auth: 0x%x.",
4156fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
4157fcf3ce44SJohn Forte 
4158fcf3ce44SJohn Forte 	node_dhc->nlp_authrsp_tmo = 0;
4159fcf3ce44SJohn Forte 
4160fcf3ce44SJohn Forte 	emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_FAILED, 0, 0);
4161fcf3ce44SJohn Forte 
4162fcf3ce44SJohn Forte 	return (node_dhc->state);
4163fcf3ce44SJohn Forte 
4164fcf3ce44SJohn Forte } /* emlxs_device_recov_auth */
4165fcf3ce44SJohn Forte 
4166fcf3ce44SJohn Forte 
4167fcf3ce44SJohn Forte 
4168fcf3ce44SJohn Forte /*
4169fcf3ce44SJohn Forte  * This routine is invoked when the host as the responder sent out the
4170fcf3ce44SJohn Forte  * ELS DHCHAP_Success to the initiator, the initiator ACC
4171fcf3ce44SJohn Forte  * it. AND then the host received an unsolicited auth msg from the initiator,
4172fcf3ce44SJohn Forte  * this msg is supposed to be the ELS DHCHAP_Success
4173fcf3ce44SJohn Forte  * msg for the bi-directional authentication.
4174fcf3ce44SJohn Forte  *
4175fcf3ce44SJohn Forte  * next state should be REG_LOGIN
4176fcf3ce44SJohn Forte  */
4177fcf3ce44SJohn Forte /* ARGSUSED */
4178fcf3ce44SJohn Forte static uint32_t
emlxs_rcv_auth_msg_dhchap_success_cmpl_wait4next(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)4179fcf3ce44SJohn Forte emlxs_rcv_auth_msg_dhchap_success_cmpl_wait4next(
4180fcf3ce44SJohn Forte emlxs_port_t *port,
418182527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
4182fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
4183fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
4184fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
4185fcf3ce44SJohn Forte uint32_t evt)
4186fcf3ce44SJohn Forte {
4187fcf3ce44SJohn Forte 	IOCBQ *iocbq = (IOCBQ *)arg2;
4188fcf3ce44SJohn Forte 	MATCHMAP *mp = (MATCHMAP *)arg3;
4189fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
4190fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
4191fcf3ce44SJohn Forte 	uint8_t *bp;
4192fcf3ce44SJohn Forte 	uint32_t *lp;
4193fcf3ce44SJohn Forte 	DHCHAP_SUCCESS_HDR *dh_success;
4194fcf3ce44SJohn Forte 	AUTH_RJT *auth_rjt;
4195fcf3ce44SJohn Forte 	uint8_t ReasonCode;
4196fcf3ce44SJohn Forte 	uint8_t ReasonCodeExplanation;
4197fcf3ce44SJohn Forte 
4198fcf3ce44SJohn Forte 	bp = mp->virt;
4199fcf3ce44SJohn Forte 	lp = (uint32_t *)bp;
4200fcf3ce44SJohn Forte 
4201fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4202*8f23e9faSHans Rosenfeld 	    "rcv_auth_msg_dhchap_success_cmpl_wait4next: did=0x%x",
4203fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
4204fcf3ce44SJohn Forte 
4205fcf3ce44SJohn Forte 	dh_success = (DHCHAP_SUCCESS_HDR *)((uint8_t *)lp);
4206fcf3ce44SJohn Forte 
4207fcf3ce44SJohn Forte 	(void) emlxs_els_reply(port, iocbq, ELS_CMD_ACC, ELS_CMD_AUTH, 0, 0);
4208fcf3ce44SJohn Forte 
4209fcf3ce44SJohn Forte 	if (dh_success->auth_msg_code == AUTH_REJECT) {
4210fcf3ce44SJohn Forte 		/* ACC it and retry etc.  */
4211fcf3ce44SJohn Forte 		auth_rjt = (AUTH_RJT *)dh_success;
4212fcf3ce44SJohn Forte 		ReasonCode = auth_rjt->ReasonCode;
4213fcf3ce44SJohn Forte 		ReasonCodeExplanation = auth_rjt->ReasonCodeExplanation;
4214fcf3ce44SJohn Forte 
4215fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4216fcf3ce44SJohn Forte 	    "rcv_a_m_dhch_success_cmpl_wait4next:REJECT rvd. 0x%x 0x%x 0x%x",
4217fcf3ce44SJohn Forte 	    ndlp->nlp_DID, ReasonCode, ReasonCodeExplanation);
4218fcf3ce44SJohn Forte 
4219fcf3ce44SJohn Forte 		switch (ReasonCode) {
4220fcf3ce44SJohn Forte 		case AUTHRJT_LOGIC_ERR:
4221fcf3ce44SJohn Forte 			switch (ReasonCodeExplanation) {
4222fcf3ce44SJohn Forte 			case AUTHEXP_MECH_UNUSABLE:
4223fcf3ce44SJohn Forte 			case AUTHEXP_DHGROUP_UNUSABLE:
4224fcf3ce44SJohn Forte 			case AUTHEXP_HASHFUNC_UNUSABLE:
4225fcf3ce44SJohn Forte 				ReasonCode = AUTHRJT_LOGIC_ERR;
4226fcf3ce44SJohn Forte 				ReasonCodeExplanation = AUTHEXP_RESTART_AUTH;
4227fcf3ce44SJohn Forte 				break;
4228fcf3ce44SJohn Forte 
4229fcf3ce44SJohn Forte 			case AUTHEXP_RESTART_AUTH:
4230fcf3ce44SJohn Forte 				/*
4231fcf3ce44SJohn Forte 				 * Cancel the rsp timer if not cancelled yet.
4232fcf3ce44SJohn Forte 				 * and restart auth tran now.
4233fcf3ce44SJohn Forte 				 */
4234fcf3ce44SJohn Forte 				if (node_dhc->nlp_authrsp_tmo != 0) {
4235fcf3ce44SJohn Forte 					node_dhc->nlp_authrsp_tmo = 0;
4236fcf3ce44SJohn Forte 					node_dhc->nlp_authrsp_tmocnt = 0;
4237fcf3ce44SJohn Forte 				}
4238fcf3ce44SJohn Forte 				if (emlxs_dhc_auth_start(port, ndlp,
4239fcf3ce44SJohn Forte 				    NULL, NULL) != 0) {
4240fcf3ce44SJohn Forte 				EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_debug_msg,
4241fcf3ce44SJohn Forte 				    "Reauth timeout. Auth initfailed. 0x%x %x",
4242fcf3ce44SJohn Forte 				    ndlp->nlp_DID, node_dhc->state);
4243fcf3ce44SJohn Forte 				}
4244fcf3ce44SJohn Forte 				return (node_dhc->state);
4245fcf3ce44SJohn Forte 
4246fcf3ce44SJohn Forte 			default:
4247fcf3ce44SJohn Forte 				ReasonCode = AUTHRJT_FAILURE;
4248fcf3ce44SJohn Forte 				ReasonCodeExplanation = AUTHEXP_AUTH_FAILED;
4249fcf3ce44SJohn Forte 				break;
4250fcf3ce44SJohn Forte 
4251fcf3ce44SJohn Forte 			}
4252fcf3ce44SJohn Forte 			break;
4253fcf3ce44SJohn Forte 
4254fcf3ce44SJohn Forte 		case AUTHRJT_FAILURE:
4255fcf3ce44SJohn Forte 		default:
4256fcf3ce44SJohn Forte 			ReasonCode = AUTHRJT_FAILURE;
4257fcf3ce44SJohn Forte 			ReasonCodeExplanation = AUTHEXP_AUTH_FAILED;
4258fcf3ce44SJohn Forte 			break;
4259fcf3ce44SJohn Forte 
4260fcf3ce44SJohn Forte 		}
4261fcf3ce44SJohn Forte 
4262fcf3ce44SJohn Forte 		goto Reject;
4263fcf3ce44SJohn Forte 
4264fcf3ce44SJohn Forte 	} else if (dh_success->auth_msg_code == DHCHAP_SUCCESS) {
426582527734SSukumar Swaminathan 		if (LE_SWAP32(dh_success->tran_id) !=
4266fcf3ce44SJohn Forte 		    node_dhc->nlp_auth_tranid_ini) {
4267fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4268fcf3ce44SJohn Forte 	    "rcv_a_m_dhch_success_cmpl_wait4next: 0x%x 0x%lx, 0x%lx",
4269fcf3ce44SJohn Forte 	    ndlp->nlp_DID, dh_success->tran_id, node_dhc->nlp_auth_tranid_ini);
4270fcf3ce44SJohn Forte 
4271fcf3ce44SJohn Forte 			ReasonCode = AUTHRJT_FAILURE;
4272fcf3ce44SJohn Forte 			ReasonCodeExplanation = AUTHEXP_BAD_PROTOCOL;
4273fcf3ce44SJohn Forte 			goto Reject;
4274fcf3ce44SJohn Forte 		}
4275fcf3ce44SJohn Forte 		node_dhc->flag |= NLP_REMOTE_AUTH;
4276fcf3ce44SJohn Forte 
4277fcf3ce44SJohn Forte 		emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_SUCCESS, 0, 0);
4278*8f23e9faSHans Rosenfeld 		emlxs_log_auth_event(port, ndlp,
4279*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_dhchap_success_cmpl_wait4next",
4280fcf3ce44SJohn Forte 		    "Node-initiated-bidir-reauth-success");
4281fcf3ce44SJohn Forte 		emlxs_dhc_auth_complete(port, ndlp, 0);
4282fcf3ce44SJohn Forte 	} else {
4283fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_FAILURE;
4284fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_BAD_PROTOCOL;
4285fcf3ce44SJohn Forte 		goto Reject;
4286fcf3ce44SJohn Forte 	}
4287fcf3ce44SJohn Forte 
4288fcf3ce44SJohn Forte 	return (node_dhc->state);
4289fcf3ce44SJohn Forte 
4290fcf3ce44SJohn Forte Reject:
4291fcf3ce44SJohn Forte 
4292fcf3ce44SJohn Forte 	emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_FAILED,
4293fcf3ce44SJohn Forte 	    ReasonCode, ReasonCodeExplanation);
4294fcf3ce44SJohn Forte 	(void) emlxs_issue_auth_reject(port, ndlp, 0, 0, ReasonCode,
4295fcf3ce44SJohn Forte 	    ReasonCodeExplanation);
4296fcf3ce44SJohn Forte 	emlxs_dhc_auth_complete(port, ndlp, 1);
4297fcf3ce44SJohn Forte 
4298fcf3ce44SJohn Forte out:
4299fcf3ce44SJohn Forte 
4300fcf3ce44SJohn Forte 	return (node_dhc->state);
4301fcf3ce44SJohn Forte 
4302fcf3ce44SJohn Forte } /* emlxs_rcv_auth_msg_dhchap_success_cmpl_wait4next */
4303fcf3ce44SJohn Forte 
4304fcf3ce44SJohn Forte 
4305fcf3ce44SJohn Forte /* ARGSUSED */
4306fcf3ce44SJohn Forte static uint32_t
emlxs_cmpl_auth_msg_dhchap_success_cmpl_wait4next(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)4307fcf3ce44SJohn Forte emlxs_cmpl_auth_msg_dhchap_success_cmpl_wait4next(
4308fcf3ce44SJohn Forte emlxs_port_t *port,
430982527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
4310fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
4311fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
4312fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
4313fcf3ce44SJohn Forte uint32_t evt)
4314fcf3ce44SJohn Forte {
4315fcf3ce44SJohn Forte 
4316fcf3ce44SJohn Forte 	return (0);
4317fcf3ce44SJohn Forte 
4318fcf3ce44SJohn Forte } /* emlxs_cmpl_auth_msg_dhchap_success_cmpl_wait4next */
4319fcf3ce44SJohn Forte 
4320fcf3ce44SJohn Forte 
4321fcf3ce44SJohn Forte /* ARGSUSED */
4322fcf3ce44SJohn Forte static uint32_t
emlxs_rcv_auth_msg_auth_negotiate_rcv(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)4323fcf3ce44SJohn Forte emlxs_rcv_auth_msg_auth_negotiate_rcv(
4324fcf3ce44SJohn Forte emlxs_port_t *port,
432582527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
4326fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
4327fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
4328fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
4329fcf3ce44SJohn Forte uint32_t evt)
4330fcf3ce44SJohn Forte {
4331fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
4332fcf3ce44SJohn Forte 
4333fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4334fcf3ce44SJohn Forte 	    "rcv_a_m_auth_negotiate_rcv called. did=0x%x. Not implemented.",
4335fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
4336fcf3ce44SJohn Forte 
4337fcf3ce44SJohn Forte 	return (0);
4338fcf3ce44SJohn Forte 
4339fcf3ce44SJohn Forte } /* emlxs_rcv_auth_msg_auth_negotiate_rcv */
4340fcf3ce44SJohn Forte 
4341fcf3ce44SJohn Forte 
4342fcf3ce44SJohn Forte /* ARGSUSED */
4343fcf3ce44SJohn Forte static uint32_t
emlxs_rcv_auth_msg_npr_node(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)4344fcf3ce44SJohn Forte emlxs_rcv_auth_msg_npr_node(
4345fcf3ce44SJohn Forte emlxs_port_t *port,
434682527734SSukumar Swaminathan /* CHANNEL  * rp, */ void *arg1,
4347fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
4348fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
4349fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
4350fcf3ce44SJohn Forte 	uint32_t evt)
4351fcf3ce44SJohn Forte {
4352fcf3ce44SJohn Forte 	IOCBQ *iocbq = (IOCBQ *)arg2;
4353fcf3ce44SJohn Forte 	MATCHMAP *mp = (MATCHMAP *)arg3;
4354fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
4355fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
4356fcf3ce44SJohn Forte 	uint8_t *bp;
4357fcf3ce44SJohn Forte 
4358fcf3ce44SJohn Forte 	uint32_t *lp;
4359fcf3ce44SJohn Forte 	uint32_t msglen;
4360fcf3ce44SJohn Forte 	uint8_t *tmp;
4361fcf3ce44SJohn Forte 
4362fcf3ce44SJohn Forte 	AUTH_MSG_HDR *msg;
4363fcf3ce44SJohn Forte 
4364fcf3ce44SJohn Forte 	uint8_t *temp;
4365fcf3ce44SJohn Forte 	uint32_t rc, i, hs_id[2], dh_id[5];
4366fcf3ce44SJohn Forte 					/* from initiator */
4367fcf3ce44SJohn Forte 	uint32_t hash_id, dhgp_id;	/* to be used by responder */
4368fcf3ce44SJohn Forte 	uint16_t num_hs = 0;
4369fcf3ce44SJohn Forte 	uint16_t num_dh = 0;
4370fcf3ce44SJohn Forte 
4371fcf3ce44SJohn Forte 	bp = mp->virt;
4372fcf3ce44SJohn Forte 	lp = (uint32_t *)bp;
4373fcf3ce44SJohn Forte 
4374fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4375*8f23e9faSHans Rosenfeld 	    "rcv_auth_msg_npr_node:");
4376fcf3ce44SJohn Forte 
4377fcf3ce44SJohn Forte 	/*
4378fcf3ce44SJohn Forte 	 * 1. process the auth msg, should acc first no matter what. 2.
4379fcf3ce44SJohn Forte 	 * return DHCHAP_Challenge for AUTH_Negotiate auth msg, AUTH_Reject
4380fcf3ce44SJohn Forte 	 * for anything else.
4381fcf3ce44SJohn Forte 	 */
4382fcf3ce44SJohn Forte 	(void) emlxs_els_reply(port, iocbq, ELS_CMD_ACC, ELS_CMD_AUTH, 0, 0);
4383fcf3ce44SJohn Forte 
4384fcf3ce44SJohn Forte 	msg = (AUTH_MSG_HDR *)((uint8_t *)lp);
4385fcf3ce44SJohn Forte 	msglen = msg->msg_len;
4386fcf3ce44SJohn Forte 	tmp = ((uint8_t *)lp);
4387fcf3ce44SJohn Forte 
4388fcf3ce44SJohn Forte 	/* temp is used for error checking */
4389fcf3ce44SJohn Forte 	temp = (uint8_t *)((uint8_t *)lp);
4390fcf3ce44SJohn Forte 	/* Check the auth_els_code */
439182527734SSukumar Swaminathan 	if (((*(uint32_t *)temp) & 0xFFFFFFFF) != LE_SWAP32(0x90000B01)) {
4392fcf3ce44SJohn Forte 		/* ReasonCode = AUTHRJT_FAILURE; */
4393fcf3ce44SJohn Forte 		/* ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD; */
4394fcf3ce44SJohn Forte 
4395fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4396*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_npr_node: payload(1)=0x%x",
4397fcf3ce44SJohn Forte 		    (*(uint32_t *)temp));
4398fcf3ce44SJohn Forte 
4399fcf3ce44SJohn Forte 		goto AUTH_Reject;
4400fcf3ce44SJohn Forte 	}
4401fcf3ce44SJohn Forte 	temp += 3 * sizeof (uint32_t);
4402fcf3ce44SJohn Forte 	/* Check name tag and name length */
440382527734SSukumar Swaminathan 	if (((*(uint32_t *)temp) & 0xFFFFFFFF) != LE_SWAP32(0x00010008)) {
4404fcf3ce44SJohn Forte 		/* ReasonCode = AUTHRJT_FAILURE; */
4405fcf3ce44SJohn Forte 		/* ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD; */
4406fcf3ce44SJohn Forte 
4407fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4408*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_npr_node: payload(2)=0x%x",
4409fcf3ce44SJohn Forte 		    (*(uint32_t *)temp));
4410fcf3ce44SJohn Forte 
4411fcf3ce44SJohn Forte 		goto AUTH_Reject;
4412fcf3ce44SJohn Forte 	}
4413fcf3ce44SJohn Forte 	temp += sizeof (uint32_t) + 8;
4414fcf3ce44SJohn Forte 	/* Check proto_num */
441582527734SSukumar Swaminathan 	if (((*(uint32_t *)temp) & 0xFFFFFFFF) != LE_SWAP32(0x00000001)) {
4416fcf3ce44SJohn Forte 		/* ReasonCode = AUTHRJT_FAILURE; */
4417fcf3ce44SJohn Forte 		/* ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD; */
4418fcf3ce44SJohn Forte 
4419fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4420*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_npr_node: payload(3)=0x%x",
4421fcf3ce44SJohn Forte 		    (*(uint32_t *)temp));
4422fcf3ce44SJohn Forte 
4423fcf3ce44SJohn Forte 		goto AUTH_Reject;
4424fcf3ce44SJohn Forte 	}
4425fcf3ce44SJohn Forte 	temp += sizeof (uint32_t);
4426fcf3ce44SJohn Forte 	/* Get para_len */
442782527734SSukumar Swaminathan 	/* para_len = LE_SWAP32(*(uint32_t *)temp); */
4428fcf3ce44SJohn Forte 
4429fcf3ce44SJohn Forte 	temp += sizeof (uint32_t);
4430fcf3ce44SJohn Forte 	/* Check proto_id */
4431fcf3ce44SJohn Forte 	if (((*(uint32_t *)temp) & 0xFFFFFFFF) != AUTH_DHCHAP) {
4432fcf3ce44SJohn Forte 		/* ReasonCode = AUTHRJT_FAILURE; */
4433fcf3ce44SJohn Forte 		/* ReasonCodeExplanation = AUTHEXP_BAD_PROTOCOL; */
4434fcf3ce44SJohn Forte 
4435fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4436*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_npr_node: payload(4)=0x%x",
4437fcf3ce44SJohn Forte 		    (*(uint32_t *)temp));
4438fcf3ce44SJohn Forte 
4439fcf3ce44SJohn Forte 		goto AUTH_Reject;
4440fcf3ce44SJohn Forte 	}
4441fcf3ce44SJohn Forte 	temp += sizeof (uint32_t);
4442fcf3ce44SJohn Forte 	/* Check hashlist tag */
444382527734SSukumar Swaminathan 	if ((LE_SWAP32(*(uint32_t *)temp) & 0xFFFF0000) >> 16 !=
444482527734SSukumar Swaminathan 	    LE_SWAP16(HASH_LIST_TAG)) {
4445fcf3ce44SJohn Forte 		/* ReasonCode = AUTHRJT_FAILURE; */
4446fcf3ce44SJohn Forte 		/* ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD; */
4447fcf3ce44SJohn Forte 
4448fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4449*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_npr_node: payload(5)=0x%x",
445082527734SSukumar Swaminathan 		    (LE_SWAP32(*(uint32_t *)temp) & 0xFFFF0000) >> 16);
4451fcf3ce44SJohn Forte 
4452fcf3ce44SJohn Forte 		goto AUTH_Reject;
4453fcf3ce44SJohn Forte 	}
4454fcf3ce44SJohn Forte 	/* Get num_hs  */
445582527734SSukumar Swaminathan 	num_hs = LE_SWAP32(*(uint32_t *)temp) & 0x0000FFFF;
4456fcf3ce44SJohn Forte 
4457fcf3ce44SJohn Forte 	temp += sizeof (uint32_t);
4458fcf3ce44SJohn Forte 	/* Check HashList_value1 */
4459fcf3ce44SJohn Forte 	hs_id[0] = *(uint32_t *)temp;
4460fcf3ce44SJohn Forte 
4461fcf3ce44SJohn Forte 	if ((hs_id[0] != AUTH_MD5) && (hs_id[0] != AUTH_SHA1)) {
4462fcf3ce44SJohn Forte 		/* ReasonCode = AUTHRJT_LOGIC_ERR; */
4463fcf3ce44SJohn Forte 		/* ReasonCodeExplanation = AUTHEXP_HASHFUNC_UNUSABLE; */
4464fcf3ce44SJohn Forte 
4465fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4466*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_npr_node: payload(6)=0x%x",
4467fcf3ce44SJohn Forte 		    (*(uint32_t *)temp));
4468fcf3ce44SJohn Forte 
4469fcf3ce44SJohn Forte 		goto AUTH_Reject;
4470fcf3ce44SJohn Forte 	}
4471fcf3ce44SJohn Forte 	if (num_hs == 1) {
4472fcf3ce44SJohn Forte 		hs_id[1] = 0;
4473fcf3ce44SJohn Forte 	} else if (num_hs == 2) {
4474fcf3ce44SJohn Forte 		temp += sizeof (uint32_t);
4475fcf3ce44SJohn Forte 		hs_id[1] = *(uint32_t *)temp;
4476fcf3ce44SJohn Forte 
4477fcf3ce44SJohn Forte 		if ((hs_id[1] != AUTH_MD5) && (hs_id[1] != AUTH_SHA1)) {
4478fcf3ce44SJohn Forte 			/* ReasonCode = AUTHRJT_LOGIC_ERR; */
4479fcf3ce44SJohn Forte 			/* ReasonCodeExplanation = AUTHEXP_HASHFUNC_UNUSABLE; */
4480fcf3ce44SJohn Forte 
4481fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4482*8f23e9faSHans Rosenfeld 			    "rcv_auth_msg_npr_node: payload(7)=0x%x",
4483fcf3ce44SJohn Forte 			    (*(uint32_t *)temp));
4484fcf3ce44SJohn Forte 
4485fcf3ce44SJohn Forte 			goto AUTH_Reject;
4486fcf3ce44SJohn Forte 		}
4487fcf3ce44SJohn Forte 		if (hs_id[0] == hs_id[1]) {
4488fcf3ce44SJohn Forte 			/* ReasonCode = AUTHRJT_FAILURE; */
4489fcf3ce44SJohn Forte 			/* ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD; */
4490fcf3ce44SJohn Forte 
4491fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4492*8f23e9faSHans Rosenfeld 			    "rcv_auth_msg_npr_node: payload(8)=0x%x",
4493fcf3ce44SJohn Forte 			    (*(uint32_t *)temp));
4494fcf3ce44SJohn Forte 
4495fcf3ce44SJohn Forte 			goto AUTH_Reject;
4496fcf3ce44SJohn Forte 		}
4497fcf3ce44SJohn Forte 	} else {
4498fcf3ce44SJohn Forte 		/* ReasonCode = AUTHRJT_FAILURE; */
4499fcf3ce44SJohn Forte 		/* ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD; */
4500fcf3ce44SJohn Forte 
4501fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4502*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_npr_node: payload(9)=0x%x",
4503fcf3ce44SJohn Forte 		    (*(uint32_t *)(temp - sizeof (uint32_t))));
4504fcf3ce44SJohn Forte 
4505fcf3ce44SJohn Forte 		goto AUTH_Reject;
4506fcf3ce44SJohn Forte 	}
4507fcf3ce44SJohn Forte 
4508fcf3ce44SJohn Forte 	/* Which hash_id should we use */
4509fcf3ce44SJohn Forte 	if (num_hs == 1) {
4510fcf3ce44SJohn Forte 		/*
4511fcf3ce44SJohn Forte 		 * We always use the highest priority specified by us if we
4512fcf3ce44SJohn Forte 		 * match initiator's , Otherwise, we use the next higher we
4513fcf3ce44SJohn Forte 		 * both have. CR 26238
4514fcf3ce44SJohn Forte 		 */
4515fcf3ce44SJohn Forte 		if (node_dhc->auth_cfg.hash_priority[0] == hs_id[0]) {
4516fcf3ce44SJohn Forte 			hash_id = node_dhc->auth_cfg.hash_priority[0];
4517fcf3ce44SJohn Forte 		} else if (node_dhc->auth_cfg.hash_priority[1] == hs_id[0]) {
4518fcf3ce44SJohn Forte 			hash_id = node_dhc->auth_cfg.hash_priority[1];
4519fcf3ce44SJohn Forte 		} else {
4520fcf3ce44SJohn Forte 			/* ReasonCode = AUTHRJT_LOGIC_ERR; */
4521fcf3ce44SJohn Forte 			/* ReasonCodeExplanation = AUTHEXP_HASHFUNC_UNUSABLE; */
4522fcf3ce44SJohn Forte 
4523fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4524*8f23e9faSHans Rosenfeld 			    "rcv_auth_msg_npr_node: payload(10)=0x%lx",
4525fcf3ce44SJohn Forte 			    (*(uint32_t *)temp));
4526fcf3ce44SJohn Forte 
4527fcf3ce44SJohn Forte 			goto AUTH_Reject;
4528fcf3ce44SJohn Forte 		}
4529fcf3ce44SJohn Forte 	} else {
4530fcf3ce44SJohn Forte 		/*
4531fcf3ce44SJohn Forte 		 * Since the initiator specified two hashs, we always select
4532fcf3ce44SJohn Forte 		 * our first one.
4533fcf3ce44SJohn Forte 		 */
4534fcf3ce44SJohn Forte 		hash_id = node_dhc->auth_cfg.hash_priority[0];
4535fcf3ce44SJohn Forte 	}
4536fcf3ce44SJohn Forte 
4537fcf3ce44SJohn Forte 	temp += sizeof (uint32_t);
4538fcf3ce44SJohn Forte 	/* Check DHgIDList_tag */
453982527734SSukumar Swaminathan 	if ((LE_SWAP32(*(uint32_t *)temp) & 0xFFFF0000) >> 16 !=
454082527734SSukumar Swaminathan 	    LE_SWAP16(DHGID_LIST_TAG)) {
4541fcf3ce44SJohn Forte 		/* ReasonCode = AUTHRJT_FAILURE; */
4542fcf3ce44SJohn Forte 		/* ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD; */
4543fcf3ce44SJohn Forte 
4544fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4545*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_npr_node: payload(11)=0x%lx",
4546fcf3ce44SJohn Forte 		    (*(uint32_t *)temp));
4547fcf3ce44SJohn Forte 
4548fcf3ce44SJohn Forte 		goto AUTH_Reject;
4549fcf3ce44SJohn Forte 	}
4550fcf3ce44SJohn Forte 	/* Get num_dh */
455182527734SSukumar Swaminathan 	num_dh = LE_SWAP32(*(uint32_t *)temp) & 0x0000FFFF;
4552fcf3ce44SJohn Forte 
4553fcf3ce44SJohn Forte 	if (num_dh == 0) {
4554fcf3ce44SJohn Forte 		/* ReasonCode = AUTHRJT_FAILURE; */
4555fcf3ce44SJohn Forte 		/* ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD; */
4556fcf3ce44SJohn Forte 
4557fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4558*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_npr_node: payload(12)=0x%lx",
4559fcf3ce44SJohn Forte 		    (*(uint32_t *)temp));
4560fcf3ce44SJohn Forte 
4561fcf3ce44SJohn Forte 		goto AUTH_Reject;
4562fcf3ce44SJohn Forte 	}
4563fcf3ce44SJohn Forte 	for (i = 0; i < num_dh; i++) {
4564fcf3ce44SJohn Forte 		temp += sizeof (uint32_t);
4565fcf3ce44SJohn Forte 		/* Check DHgIDList_g0 */
4566fcf3ce44SJohn Forte 		dh_id[i] = (*(uint32_t *)temp);
4567fcf3ce44SJohn Forte 	}
4568fcf3ce44SJohn Forte 
4569fcf3ce44SJohn Forte 	rc = emlxs_check_dhgp(port, ndlp, dh_id, num_dh, &dhgp_id);
4570fcf3ce44SJohn Forte 
4571fcf3ce44SJohn Forte 	if (rc == 1) {
4572fcf3ce44SJohn Forte 		/* ReasonCode = AUTHRJT_LOGIC_ERR; */
4573fcf3ce44SJohn Forte 		/* ReasonCodeExplanation = AUTHEXP_DHGROUP_UNUSABLE; */
4574fcf3ce44SJohn Forte 
4575fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4576*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_npr_node: payload(13)=0x%lx",
4577fcf3ce44SJohn Forte 		    (*(uint32_t *)temp));
4578fcf3ce44SJohn Forte 
4579fcf3ce44SJohn Forte 		goto AUTH_Reject;
4580fcf3ce44SJohn Forte 	} else if (rc == 2) {
4581fcf3ce44SJohn Forte 		/* ReasonCode = AUTHRJT_FAILURE; */
4582fcf3ce44SJohn Forte 		/* ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD; */
4583fcf3ce44SJohn Forte 
4584fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
4585*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_npr_node: payload(14)=0x%lx",
4586fcf3ce44SJohn Forte 		    (*(uint32_t *)temp));
4587fcf3ce44SJohn Forte 
4588fcf3ce44SJohn Forte 		goto AUTH_Reject;
4589fcf3ce44SJohn Forte 	}
4590fcf3ce44SJohn Forte 	/* We should update the tran_id */
4591fcf3ce44SJohn Forte 	node_dhc->nlp_auth_tranid_ini = msg->tran_id;
4592fcf3ce44SJohn Forte 
4593fcf3ce44SJohn Forte 	if (msg->auth_msg_code == AUTH_NEGOTIATE) {
4594fcf3ce44SJohn Forte 		node_dhc->nlp_auth_flag = 1;	/* ndlp is the initiator */
4595fcf3ce44SJohn Forte 
4596fcf3ce44SJohn Forte 		/* Send back the DHCHAP_Challenge with the proper paramaters */
4597fcf3ce44SJohn Forte 		if (emlxs_issue_dhchap_challenge(port, ndlp, 0, tmp,
459882527734SSukumar Swaminathan 		    LE_SWAP32(msglen),
4599fcf3ce44SJohn Forte 		    hash_id, dhgp_id)) {
4600fcf3ce44SJohn Forte 			goto AUTH_Reject;
4601fcf3ce44SJohn Forte 		}
4602fcf3ce44SJohn Forte 		emlxs_dhc_state(port, ndlp,
4603fcf3ce44SJohn Forte 		    NODE_STATE_DHCHAP_CHALLENGE_ISSUE, 0, 0);
4604fcf3ce44SJohn Forte 
4605fcf3ce44SJohn Forte 	} else {
4606fcf3ce44SJohn Forte 		goto AUTH_Reject;
4607fcf3ce44SJohn Forte 	}
4608fcf3ce44SJohn Forte 
4609fcf3ce44SJohn Forte 	return (node_dhc->state);
4610fcf3ce44SJohn Forte 
4611fcf3ce44SJohn Forte AUTH_Reject:
4612fcf3ce44SJohn Forte 
4613fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4614*8f23e9faSHans Rosenfeld 	    "rcv_auth_msg_npr_node: AUTH_Reject it.");
4615fcf3ce44SJohn Forte 
4616fcf3ce44SJohn Forte 	return (node_dhc->state);
4617fcf3ce44SJohn Forte 
4618fcf3ce44SJohn Forte } /* emlxs_rcv_auth_msg_npr_node */
4619fcf3ce44SJohn Forte 
4620fcf3ce44SJohn Forte 
4621fcf3ce44SJohn Forte /* ARGSUSED */
4622fcf3ce44SJohn Forte static uint32_t
emlxs_cmpl_auth_msg_npr_node(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)4623fcf3ce44SJohn Forte emlxs_cmpl_auth_msg_npr_node(
4624fcf3ce44SJohn Forte emlxs_port_t *port,
462582527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
4626fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
4627fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
4628fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
4629fcf3ce44SJohn Forte uint32_t evt)
4630fcf3ce44SJohn Forte {
4631fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
4632fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
4633fcf3ce44SJohn Forte 
4634fcf3ce44SJohn Forte 	/*
4635fcf3ce44SJohn Forte 	 * we donot cancel the nodev timeout here because we donot know if we
4636fcf3ce44SJohn Forte 	 * can get the authentication restarted from other side once we got
4637fcf3ce44SJohn Forte 	 * the new auth transaction kicked off we cancel nodev tmo
4638fcf3ce44SJohn Forte 	 * immediately.
4639fcf3ce44SJohn Forte 	 */
4640fcf3ce44SJohn Forte 	/* we goto change the hba state back to where it used to be */
4641fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4642*8f23e9faSHans Rosenfeld 	    "cmpl_auth_msg_npr_node: 0x%x 0x%x prev_state=0x%x\n",
4643fcf3ce44SJohn Forte 	    ndlp->nlp_DID, node_dhc->state, node_dhc->prev_state);
4644fcf3ce44SJohn Forte 
4645fcf3ce44SJohn Forte 	return (node_dhc->state);
4646fcf3ce44SJohn Forte 
4647fcf3ce44SJohn Forte } /* emlxs_cmpl_auth_msg_npr_node */
4648fcf3ce44SJohn Forte 
4649fcf3ce44SJohn Forte 
4650fcf3ce44SJohn Forte /*
4651fcf3ce44SJohn Forte  * ! emlxs_rcv_auth_msg_unmapped_node
4652fcf3ce44SJohn Forte  *
4653fcf3ce44SJohn Forte  * \pre \post \param   phba \param   ndlp \param   arg \param   evt \return
4654fcf3ce44SJohn Forte  * uint32_t
4655fcf3ce44SJohn Forte  *
4656fcf3ce44SJohn Forte  * \b Description: This routine is invoked when the host received an
4657fcf3ce44SJohn Forte  * unsolicited els authentication msg from the Fx_Port which is
4658fcf3ce44SJohn Forte  * wellknown port 0xFFFFFE in unmapped state, or from Nx_Port which is
4659fcf3ce44SJohn Forte  * in the unmapped state meaning that it is either a target
4660fcf3ce44SJohn Forte  * which there is no scsi id associated with it or it could be another
4661fcf3ce44SJohn Forte  * initiator. (end-to-end)
4662fcf3ce44SJohn Forte  *
4663fcf3ce44SJohn Forte  * For the Fabric F_Port (FFFFFE) we mark the port to the state in re_auth
4664fcf3ce44SJohn Forte  * state without disruppting the traffic. Then the fabric
4665fcf3ce44SJohn Forte  * will go through the authentication processes until it is done.
4666fcf3ce44SJohn Forte  *
4667fcf3ce44SJohn Forte  * most of the cases, the fabric should send us AUTH_Negotiate ELS msg. Once
4668fcf3ce44SJohn Forte  * host received this auth_negotiate els msg, host
4669fcf3ce44SJohn Forte  * should sent back ACC first and then send random challenge, plus DH value
4670fcf3ce44SJohn Forte  * (i.e., host's publick key)
4671fcf3ce44SJohn Forte  *
4672fcf3ce44SJohn Forte  * Host side needs to store the challenge value and public key for later
4673fcf3ce44SJohn Forte  * verification usage. (i.e., to verify the response from
4674fcf3ce44SJohn Forte  * initiator)
4675fcf3ce44SJohn Forte  *
4676fcf3ce44SJohn Forte  * If two FC_Ports start the reauthentication transaction at the same time,
4677fcf3ce44SJohn Forte  * one of the two authentication transactions shall be
4678fcf3ce44SJohn Forte  * aborted. In case of Host and Fabric the Nx_Port shall remain the
4679fcf3ce44SJohn Forte  * authentication initiator, while the Fx_Port shall become
4680fcf3ce44SJohn Forte  * the authentication responder.
4681fcf3ce44SJohn Forte  *
4682fcf3ce44SJohn Forte  */
4683fcf3ce44SJohn Forte /* ARGSUSED */
4684fcf3ce44SJohn Forte static uint32_t
emlxs_rcv_auth_msg_unmapped_node(emlxs_port_t * port,void * arg1,void * arg2,void * arg3,void * arg4,uint32_t evt)4685fcf3ce44SJohn Forte emlxs_rcv_auth_msg_unmapped_node(
4686fcf3ce44SJohn Forte emlxs_port_t *port,
468782527734SSukumar Swaminathan /* CHANNEL * rp, */ void *arg1,
4688fcf3ce44SJohn Forte /* IOCBQ * iocbq, */ void *arg2,
4689fcf3ce44SJohn Forte /* MATCHMAP * mp, */ void *arg3,
4690fcf3ce44SJohn Forte /* NODELIST * ndlp */ void *arg4,
4691fcf3ce44SJohn Forte 	uint32_t evt)
4692fcf3ce44SJohn Forte {
4693fcf3ce44SJohn Forte 	IOCBQ *iocbq = (IOCBQ *)arg2;
4694fcf3ce44SJohn Forte 	MATCHMAP *mp = (MATCHMAP *)arg3;
4695fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg4;
4696fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
4697fcf3ce44SJohn Forte 	uint8_t *bp;
4698fcf3ce44SJohn Forte 	uint32_t *lp;
4699fcf3ce44SJohn Forte 	uint32_t msglen;
4700fcf3ce44SJohn Forte 	uint8_t *tmp;
4701fcf3ce44SJohn Forte 
4702fcf3ce44SJohn Forte 	uint8_t ReasonCode;
4703fcf3ce44SJohn Forte 	uint8_t ReasonCodeExplanation;
4704fcf3ce44SJohn Forte 	AUTH_MSG_HDR *msg;
4705fcf3ce44SJohn Forte 	uint8_t *temp;
4706fcf3ce44SJohn Forte 	uint32_t rc, i, hs_id[2], dh_id[5];
4707fcf3ce44SJohn Forte 					/* from initiator */
4708fcf3ce44SJohn Forte 	uint32_t hash_id, dhgp_id;	/* to be used by responder */
4709fcf3ce44SJohn Forte 	uint16_t num_hs = 0;
4710fcf3ce44SJohn Forte 	uint16_t num_dh = 0;
4711fcf3ce44SJohn Forte 
4712fcf3ce44SJohn Forte 	/*
4713fcf3ce44SJohn Forte 	 * 1. process the auth msg, should acc first no matter what. 2.
4714fcf3ce44SJohn Forte 	 * return DHCHAP_Challenge for AUTH_Negotiate auth msg, AUTH_Reject
4715fcf3ce44SJohn Forte 	 * for anything else.
4716fcf3ce44SJohn Forte 	 */
4717fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4718*8f23e9faSHans Rosenfeld 	    "rcv_auth_msg_unmapped_node: Sending ACC: did=0x%x",
4719fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
4720fcf3ce44SJohn Forte 
4721fcf3ce44SJohn Forte 	(void) emlxs_els_reply(port, iocbq, ELS_CMD_ACC, ELS_CMD_AUTH, 0, 0);
4722fcf3ce44SJohn Forte 
4723fcf3ce44SJohn Forte 	bp = mp->virt;
4724fcf3ce44SJohn Forte 	lp = (uint32_t *)bp;
4725fcf3ce44SJohn Forte 
4726fcf3ce44SJohn Forte 	msg = (AUTH_MSG_HDR *)((uint8_t *)lp);
4727fcf3ce44SJohn Forte 	msglen = msg->msg_len;
4728fcf3ce44SJohn Forte 
4729fcf3ce44SJohn Forte 	tmp = ((uint8_t *)lp);
4730fcf3ce44SJohn Forte 
4731fcf3ce44SJohn Forte 	/* temp is used for error checking */
4732fcf3ce44SJohn Forte 	temp = (uint8_t *)((uint8_t *)lp);
4733fcf3ce44SJohn Forte 	/* Check the auth_els_code */
473482527734SSukumar Swaminathan 	if (((*(uint32_t *)temp) & 0xFFFFFFFF) != LE_SWAP32(0x90000B01)) {
4735fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_FAILURE;
4736fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD;
4737fcf3ce44SJohn Forte 
4738fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4739*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_unmapped_node: payload(1)=0x%x",
4740fcf3ce44SJohn Forte 		    (*(uint32_t *)temp));
4741fcf3ce44SJohn Forte 
4742fcf3ce44SJohn Forte 		goto AUTH_Reject;
4743fcf3ce44SJohn Forte 	}
4744fcf3ce44SJohn Forte 	temp += 3 * sizeof (uint32_t);
4745fcf3ce44SJohn Forte 	/* Check name tag and name length */
474682527734SSukumar Swaminathan 	if (((*(uint32_t *)temp) & 0xFFFFFFFF) != LE_SWAP32(0x00010008)) {
4747fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_FAILURE;
4748fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD;
4749fcf3ce44SJohn Forte 
4750fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4751*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_unmapped_node: payload(2)=0x%x",
4752fcf3ce44SJohn Forte 		    (*(uint32_t *)temp));
4753fcf3ce44SJohn Forte 
4754fcf3ce44SJohn Forte 		goto AUTH_Reject;
4755fcf3ce44SJohn Forte 	}
4756fcf3ce44SJohn Forte 	temp += sizeof (uint32_t) + 8;
4757fcf3ce44SJohn Forte 	/* Check proto_num */
475882527734SSukumar Swaminathan 	if (((*(uint32_t *)temp) & 0xFFFFFFFF) != LE_SWAP32(0x00000001)) {
4759fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_FAILURE;
4760fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD;
4761fcf3ce44SJohn Forte 
4762fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4763*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_unmapped_node: payload(3)=0x%x",
4764fcf3ce44SJohn Forte 		    (*(uint32_t *)temp));
4765fcf3ce44SJohn Forte 
4766fcf3ce44SJohn Forte 		goto AUTH_Reject;
4767fcf3ce44SJohn Forte 	}
4768fcf3ce44SJohn Forte 	temp += sizeof (uint32_t);
4769fcf3ce44SJohn Forte 
4770fcf3ce44SJohn Forte 	/* Get para_len */
4771fcf3ce44SJohn Forte 	/* para_len = *(uint32_t *)temp; */
4772fcf3ce44SJohn Forte 	temp += sizeof (uint32_t);
4773fcf3ce44SJohn Forte 
4774fcf3ce44SJohn Forte 	/* Check proto_id */
4775fcf3ce44SJohn Forte 	if (((*(uint32_t *)temp) & 0xFFFFFFFF) != AUTH_DHCHAP) {
4776fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_FAILURE;
4777fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_BAD_PROTOCOL;
4778fcf3ce44SJohn Forte 
4779fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4780*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_unmapped_node: payload(4)=0x%x",
4781fcf3ce44SJohn Forte 		    (*(uint32_t *)temp));
4782fcf3ce44SJohn Forte 
4783fcf3ce44SJohn Forte 		goto AUTH_Reject;
4784fcf3ce44SJohn Forte 	}
4785fcf3ce44SJohn Forte 	temp += sizeof (uint32_t);
4786fcf3ce44SJohn Forte 	/* Check hashlist tag */
478782527734SSukumar Swaminathan 	if ((LE_SWAP32(*(uint32_t *)temp) & 0xFFFF0000) >> 16 !=
478882527734SSukumar Swaminathan 	    LE_SWAP16(HASH_LIST_TAG)) {
4789fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_FAILURE;
4790fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD;
4791fcf3ce44SJohn Forte 
4792fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4793*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_unmapped_node: payload(5)=0x%x",
479482527734SSukumar Swaminathan 		    (LE_SWAP32(*(uint32_t *)temp) & 0xFFFF0000) >> 16);
4795fcf3ce44SJohn Forte 
4796fcf3ce44SJohn Forte 		goto AUTH_Reject;
4797fcf3ce44SJohn Forte 	}
4798fcf3ce44SJohn Forte 	/* Get num_hs  */
479982527734SSukumar Swaminathan 	num_hs = LE_SWAP32(*(uint32_t *)temp) & 0x0000FFFF;
4800fcf3ce44SJohn Forte 
4801fcf3ce44SJohn Forte 	temp += sizeof (uint32_t);
4802fcf3ce44SJohn Forte 	/* Check HashList_value1 */
4803fcf3ce44SJohn Forte 	hs_id[0] = *(uint32_t *)temp;
4804fcf3ce44SJohn Forte 
4805fcf3ce44SJohn Forte 	if ((hs_id[0] != AUTH_MD5) && (hs_id[0] != AUTH_SHA1)) {
4806fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_LOGIC_ERR;
4807fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_HASHFUNC_UNUSABLE;
4808fcf3ce44SJohn Forte 
4809fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4810*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_unmapped_node: payload(6)=0x%x",
4811fcf3ce44SJohn Forte 		    (*(uint32_t *)temp));
4812fcf3ce44SJohn Forte 
4813fcf3ce44SJohn Forte 		goto AUTH_Reject;
4814fcf3ce44SJohn Forte 	}
4815fcf3ce44SJohn Forte 	if (num_hs == 1) {
4816fcf3ce44SJohn Forte 		hs_id[1] = 0;
4817fcf3ce44SJohn Forte 	} else if (num_hs == 2) {
4818fcf3ce44SJohn Forte 		temp += sizeof (uint32_t);
4819fcf3ce44SJohn Forte 		hs_id[1] = *(uint32_t *)temp;
4820fcf3ce44SJohn Forte 
4821fcf3ce44SJohn Forte 		if ((hs_id[1] != AUTH_MD5) && (hs_id[1] != AUTH_SHA1)) {
4822fcf3ce44SJohn Forte 			ReasonCode = AUTHRJT_LOGIC_ERR;
4823fcf3ce44SJohn Forte 			ReasonCodeExplanation = AUTHEXP_HASHFUNC_UNUSABLE;
4824fcf3ce44SJohn Forte 
4825fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4826*8f23e9faSHans Rosenfeld 			    "rcv_auth_msg_unmapped_node: payload(7)=0x%x",
4827fcf3ce44SJohn Forte 			    (*(uint32_t *)temp));
4828fcf3ce44SJohn Forte 
4829fcf3ce44SJohn Forte 			goto AUTH_Reject;
4830fcf3ce44SJohn Forte 		}
4831fcf3ce44SJohn Forte 		if (hs_id[0] == hs_id[1]) {
4832fcf3ce44SJohn Forte 			ReasonCode = AUTHRJT_FAILURE;
4833fcf3ce44SJohn Forte 			ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD;
4834fcf3ce44SJohn Forte 
4835fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4836*8f23e9faSHans Rosenfeld 			    "rcv_auth_msg_unmapped_node: payload(8)=0x%x",
4837fcf3ce44SJohn Forte 			    (*(uint32_t *)temp));
4838fcf3ce44SJohn Forte 
4839fcf3ce44SJohn Forte 			goto AUTH_Reject;
4840fcf3ce44SJohn Forte 		}
4841fcf3ce44SJohn Forte 	} else {
4842fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_FAILURE;
4843fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD;
4844fcf3ce44SJohn Forte 
4845fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4846*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_unmapped_node: payload(9)=0x%x",
4847fcf3ce44SJohn Forte 		    (*(uint32_t *)(temp - sizeof (uint32_t))));
4848fcf3ce44SJohn Forte 
4849fcf3ce44SJohn Forte 		goto AUTH_Reject;
4850fcf3ce44SJohn Forte 	}
4851fcf3ce44SJohn Forte 
4852fcf3ce44SJohn Forte 	/* Which hash_id should we use */
4853fcf3ce44SJohn Forte 	if (num_hs == 1) {
4854fcf3ce44SJohn Forte 		/*
4855fcf3ce44SJohn Forte 		 * We always use the highest priority specified by us if we
4856fcf3ce44SJohn Forte 		 * match initiator's , Otherwise, we use the next higher we
4857fcf3ce44SJohn Forte 		 * both have. CR 26238
4858fcf3ce44SJohn Forte 		 */
4859fcf3ce44SJohn Forte 		if (node_dhc->auth_cfg.hash_priority[0] == hs_id[0]) {
4860fcf3ce44SJohn Forte 			hash_id = node_dhc->auth_cfg.hash_priority[0];
4861fcf3ce44SJohn Forte 		} else if (node_dhc->auth_cfg.hash_priority[1] == hs_id[0]) {
4862fcf3ce44SJohn Forte 			hash_id = node_dhc->auth_cfg.hash_priority[1];
4863fcf3ce44SJohn Forte 		} else {
4864fcf3ce44SJohn Forte 			ReasonCode = AUTHRJT_LOGIC_ERR;
4865fcf3ce44SJohn Forte 			ReasonCodeExplanation = AUTHEXP_HASHFUNC_UNUSABLE;
4866fcf3ce44SJohn Forte 
4867fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4868*8f23e9faSHans Rosenfeld 			    "rcv_auth_msg_unmapped_node: pload(10)=0x%x",
4869fcf3ce44SJohn Forte 			    (*(uint32_t *)temp));
4870fcf3ce44SJohn Forte 
4871fcf3ce44SJohn Forte 			goto AUTH_Reject;
4872fcf3ce44SJohn Forte 		}
4873fcf3ce44SJohn Forte 	} else {
4874fcf3ce44SJohn Forte 		/*
4875fcf3ce44SJohn Forte 		 * Since the initiator specified two hashs, we always select
4876fcf3ce44SJohn Forte 		 * our first one.
4877fcf3ce44SJohn Forte 		 */
4878fcf3ce44SJohn Forte 		hash_id = node_dhc->auth_cfg.hash_priority[0];
4879fcf3ce44SJohn Forte 	}
4880fcf3ce44SJohn Forte 
4881fcf3ce44SJohn Forte 	temp += sizeof (uint32_t);
4882fcf3ce44SJohn Forte 	/* Check DHgIDList_tag */
488382527734SSukumar Swaminathan 	if ((LE_SWAP32(*(uint32_t *)temp) & 0xFFFF0000) >> 16 !=
488482527734SSukumar Swaminathan 	    LE_SWAP16(DHGID_LIST_TAG)) {
4885fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_FAILURE;
4886fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD;
4887fcf3ce44SJohn Forte 
4888fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4889*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_unmapped_node: payload(11)=0x%x",
4890fcf3ce44SJohn Forte 		    (*(uint32_t *)temp));
4891fcf3ce44SJohn Forte 
4892fcf3ce44SJohn Forte 		goto AUTH_Reject;
4893fcf3ce44SJohn Forte 	}
4894fcf3ce44SJohn Forte 	/* Get num_dh */
489582527734SSukumar Swaminathan 	num_dh = LE_SWAP32(*(uint32_t *)temp) & 0x0000FFFF;
4896fcf3ce44SJohn Forte 
4897fcf3ce44SJohn Forte 	if (num_dh == 0) {
4898fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_FAILURE;
4899fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD;
4900fcf3ce44SJohn Forte 
4901fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4902*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_unmapped_node: payload(12)=0x%x",
4903fcf3ce44SJohn Forte 		    (*(uint32_t *)temp));
4904fcf3ce44SJohn Forte 
4905fcf3ce44SJohn Forte 		goto AUTH_Reject;
4906fcf3ce44SJohn Forte 	}
4907fcf3ce44SJohn Forte 	for (i = 0; i < num_dh; i++) {
4908fcf3ce44SJohn Forte 		temp += sizeof (uint32_t);
4909fcf3ce44SJohn Forte 		/* Check DHgIDList_g0 */
4910fcf3ce44SJohn Forte 		dh_id[i] = (*(uint32_t *)temp);
4911fcf3ce44SJohn Forte 	}
4912fcf3ce44SJohn Forte 
4913fcf3ce44SJohn Forte 	rc = emlxs_check_dhgp(port, ndlp, dh_id, num_dh, &dhgp_id);
4914fcf3ce44SJohn Forte 
4915fcf3ce44SJohn Forte 	if (rc == 1) {
4916fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_LOGIC_ERR;
4917fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_DHGROUP_UNUSABLE;
4918fcf3ce44SJohn Forte 
4919fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4920*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_unmapped_node: payload(13)=0x%x",
4921fcf3ce44SJohn Forte 		    (*(uint32_t *)temp));
4922fcf3ce44SJohn Forte 
4923fcf3ce44SJohn Forte 		goto AUTH_Reject;
4924fcf3ce44SJohn Forte 	} else if (rc == 2) {
4925fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_FAILURE;
4926fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_BAD_PAYLOAD;
4927fcf3ce44SJohn Forte 
4928fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4929*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_unmapped_node: payload(14)=0x%x",
4930fcf3ce44SJohn Forte 		    (*(uint32_t *)temp));
4931fcf3ce44SJohn Forte 
4932fcf3ce44SJohn Forte 		goto AUTH_Reject;
4933fcf3ce44SJohn Forte 	}
4934fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4935*8f23e9faSHans Rosenfeld 	    "rcv_auth_msg_unmapped_node: 0x%x 0x%x 0x%x 0x%x 0x%x",
4936fcf3ce44SJohn Forte 	    hash_id, dhgp_id, msg->auth_msg_code, msglen, msg->tran_id);
4937fcf3ce44SJohn Forte 
4938fcf3ce44SJohn Forte 	/*
4939fcf3ce44SJohn Forte 	 * since ndlp is the initiator, tran_id is store in
4940fcf3ce44SJohn Forte 	 * nlp_auth_tranid_ini
4941fcf3ce44SJohn Forte 	 */
494282527734SSukumar Swaminathan 	node_dhc->nlp_auth_tranid_ini = LE_SWAP32(msg->tran_id);
4943fcf3ce44SJohn Forte 
4944fcf3ce44SJohn Forte 	if (msg->auth_msg_code == AUTH_NEGOTIATE) {
4945fcf3ce44SJohn Forte 
4946fcf3ce44SJohn Forte 		/*
4947fcf3ce44SJohn Forte 		 * at this point, we know for sure we received the
4948fcf3ce44SJohn Forte 		 * auth-negotiate msg from another entity, so cancel the
4949fcf3ce44SJohn Forte 		 * auth-rsp timeout timer if we are expecting it. should
4950fcf3ce44SJohn Forte 		 * never happen?
4951fcf3ce44SJohn Forte 		 */
4952fcf3ce44SJohn Forte 		node_dhc->nlp_auth_flag = 1;
4953fcf3ce44SJohn Forte 
4954fcf3ce44SJohn Forte 		if (node_dhc->nlp_authrsp_tmo) {
4955fcf3ce44SJohn Forte 			node_dhc->nlp_authrsp_tmo = 0;
4956fcf3ce44SJohn Forte 		}
4957fcf3ce44SJohn Forte 		/*
4958fcf3ce44SJohn Forte 		 * If at this point, the host is doing reauthentication
4959fcf3ce44SJohn Forte 		 * (reauth heart beat) to this ndlp, then Host should remain
4960fcf3ce44SJohn Forte 		 * as the auth initiator, host should reply to the received
4961fcf3ce44SJohn Forte 		 * AUTH_Negotiate message with an AUTH_Reject message with
4962fcf3ce44SJohn Forte 		 * Reason Code 'Logical Error' and Reason Code Explanation
4963fcf3ce44SJohn Forte 		 * 'Authentication Transaction Already Started'.
4964fcf3ce44SJohn Forte 		 */
4965fcf3ce44SJohn Forte 		if (node_dhc->nlp_reauth_status ==
4966fcf3ce44SJohn Forte 		    NLP_HOST_REAUTH_IN_PROGRESS) {
4967fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
4968*8f23e9faSHans Rosenfeld 		    "rcv_auth_msg_unmapped_node: Ht reauth inprgress.");
4969fcf3ce44SJohn Forte 
4970fcf3ce44SJohn Forte 			ReasonCode = AUTHRJT_LOGIC_ERR;
4971fcf3ce44SJohn Forte 			ReasonCodeExplanation = AUTHEXP_AUTHTRAN_STARTED;
4972fcf3ce44SJohn Forte 
4973fcf3ce44SJohn Forte 			goto AUTH_Reject;
4974fcf3ce44SJohn Forte 		}
4975fcf3ce44SJohn Forte 		/* Send back the DHCHAP_Challenge with the proper paramaters */
4976fcf3ce44SJohn Forte 		if (emlxs_issue_dhchap_challenge(port, ndlp, 0, tmp,
497782527734SSukumar Swaminathan 		    LE_SWAP32(msglen),
4978fcf3ce44SJohn Forte 		    hash_id, dhgp_id)) {
4979fcf3ce44SJohn Forte 
4980fcf3ce44SJohn Forte 			goto AUTH_Reject;
4981fcf3ce44SJohn Forte 		}
4982fcf3ce44SJohn Forte 		/* setup the proper state */
4983fcf3ce44SJohn Forte 		emlxs_dhc_state(port, ndlp,
4984fcf3ce44SJohn Forte 		    NODE_STATE_DHCHAP_CHALLENGE_ISSUE, 0, 0);
4985fcf3ce44SJohn Forte 
4986fcf3ce44SJohn Forte 	} else {
4987fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_FAILURE;
4988fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_BAD_PROTOCOL;
4989fcf3ce44SJohn Forte 
4990fcf3ce44SJohn Forte 		goto AUTH_Reject;
4991fcf3ce44SJohn Forte 	}
4992fcf3ce44SJohn Forte 
4993fcf3ce44SJohn Forte 	return (node_dhc->state);
4994fcf3ce44SJohn Forte 
4995fcf3ce44SJohn Forte AUTH_Reject:
4996fcf3ce44SJohn Forte 
4997fcf3ce44SJohn Forte 	emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_FAILED,
4998fcf3ce44SJohn Forte 	    ReasonCode, ReasonCodeExplanation);
4999fcf3ce44SJohn Forte 	(void) emlxs_issue_auth_reject(port, ndlp, 0, 0, ReasonCode,
5000fcf3ce44SJohn Forte 	    ReasonCodeExplanation);
5001fcf3ce44SJohn Forte 	emlxs_dhc_auth_complete(port, ndlp, 1);
5002fcf3ce44SJohn Forte 
5003fcf3ce44SJohn Forte 	return (node_dhc->state);
5004fcf3ce44SJohn Forte 
5005fcf3ce44SJohn Forte } /* emlxs_rcv_auth_msg_unmapped_node */
5006fcf3ce44SJohn Forte 
5007fcf3ce44SJohn Forte 
5008fcf3ce44SJohn Forte 
5009fcf3ce44SJohn Forte 
5010fcf3ce44SJohn Forte /*
5011fcf3ce44SJohn Forte  * emlxs_hash_vrf for verification only the host is the initiator in
5012fcf3ce44SJohn Forte  * the routine.
5013fcf3ce44SJohn Forte  */
5014fcf3ce44SJohn Forte /* ARGSUSED */
5015fcf3ce44SJohn Forte static uint32_t *
emlxs_hash_vrf(emlxs_port_t * port,emlxs_port_dhc_t * port_dhc,NODELIST * ndlp,uint32_t tran_id,union challenge_val un_cval)5016fcf3ce44SJohn Forte emlxs_hash_vrf(
5017fcf3ce44SJohn Forte 	emlxs_port_t *port,
5018fcf3ce44SJohn Forte 	emlxs_port_dhc_t *port_dhc,
5019fcf3ce44SJohn Forte 	NODELIST *ndlp,
5020fcf3ce44SJohn Forte 	uint32_t tran_id,
5021fcf3ce44SJohn Forte 	union challenge_val un_cval)
5022fcf3ce44SJohn Forte {
5023fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
5024fcf3ce44SJohn Forte 	uint32_t dhgp_id;
5025fcf3ce44SJohn Forte 	uint32_t hash_id;
5026fcf3ce44SJohn Forte 	uint32_t *hash_val;
5027fcf3ce44SJohn Forte 	uint32_t hash_size;
5028fcf3ce44SJohn Forte 	MD5_CTX mdctx;
5029fcf3ce44SJohn Forte 	SHA1_CTX sha1ctx;
5030fcf3ce44SJohn Forte 	uint8_t sha1_digest[20];
5031fcf3ce44SJohn Forte 	uint8_t md5_digest[16];
5032fcf3ce44SJohn Forte 	uint8_t mytran_id = 0x00;
5033fcf3ce44SJohn Forte 
5034fcf3ce44SJohn Forte 	char *remote_key;
5035fcf3ce44SJohn Forte 
5036fcf3ce44SJohn Forte 	tran_id = (AUTH_TRAN_ID_MASK & tran_id);
503782527734SSukumar Swaminathan 	mytran_id = (uint8_t)(LE_SWAP32(tran_id));
5038fcf3ce44SJohn Forte 
5039fcf3ce44SJohn Forte 
504082527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
5041fcf3ce44SJohn Forte 		remote_key = (char *)node_dhc->auth_key.remote_password;
5042fcf3ce44SJohn Forte 		hash_id = node_dhc->hash_id;
5043fcf3ce44SJohn Forte 		dhgp_id = node_dhc->dhgp_id;
5044fcf3ce44SJohn Forte 	} else {
5045fcf3ce44SJohn Forte 		remote_key = (char *)node_dhc->auth_key.remote_password;
5046fcf3ce44SJohn Forte 		hash_id = node_dhc->nlp_auth_hashid;
5047fcf3ce44SJohn Forte 		dhgp_id = node_dhc->nlp_auth_dhgpid;
5048fcf3ce44SJohn Forte 	}
5049fcf3ce44SJohn Forte 
5050fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
5051*8f23e9faSHans Rosenfeld 	    "hash_vrf: 0x%x 0x%x 0x%x tran_id=0x%x",
5052fcf3ce44SJohn Forte 	    ndlp->nlp_DID, hash_id, dhgp_id, mytran_id);
5053fcf3ce44SJohn Forte 
5054fcf3ce44SJohn Forte 	if (dhgp_id == 0) {
5055fcf3ce44SJohn Forte 		/* NULL DHCHAP */
5056fcf3ce44SJohn Forte 		if (hash_id == AUTH_MD5) {
5057fcf3ce44SJohn Forte 			bzero(&mdctx, sizeof (MD5_CTX));
5058fcf3ce44SJohn Forte 
5059fcf3ce44SJohn Forte 			hash_size = MD5_LEN;
5060fcf3ce44SJohn Forte 
5061fcf3ce44SJohn Forte 			MD5Init(&mdctx);
5062fcf3ce44SJohn Forte 
5063fcf3ce44SJohn Forte 			/* Transaction Identifier T */
5064fcf3ce44SJohn Forte 			MD5Update(&mdctx, (unsigned char *) &mytran_id, 1);
5065fcf3ce44SJohn Forte 
5066fcf3ce44SJohn Forte 			MD5Update(&mdctx, (unsigned char *) remote_key,
5067fcf3ce44SJohn Forte 			    node_dhc->auth_key.remote_password_length);
5068fcf3ce44SJohn Forte 
5069fcf3ce44SJohn Forte 			/* Augmented challenge: NULL DHCHAP i.e., Challenge */
5070fcf3ce44SJohn Forte 			MD5Update(&mdctx,
5071fcf3ce44SJohn Forte 			    (unsigned char *)&(un_cval.md5.val[0]), MD5_LEN);
5072fcf3ce44SJohn Forte 
5073fcf3ce44SJohn Forte 			MD5Final((uint8_t *)md5_digest, &mdctx);
5074fcf3ce44SJohn Forte 
5075fcf3ce44SJohn Forte 			hash_val = (uint32_t *)kmem_alloc(hash_size,
5076fcf3ce44SJohn Forte 			    KM_NOSLEEP);
5077fcf3ce44SJohn Forte 			if (hash_val == NULL) {
5078fcf3ce44SJohn Forte 				return (NULL);
5079fcf3ce44SJohn Forte 			} else {
5080fcf3ce44SJohn Forte 				bcopy((void *)&md5_digest,
5081fcf3ce44SJohn Forte 				    (void *)hash_val, MD5_LEN);
5082fcf3ce44SJohn Forte 			}
5083fcf3ce44SJohn Forte 			/*
5084fcf3ce44SJohn Forte 			 * emlxs_md5_digest_to_hex((uint8_t *)hash_val,
5085fcf3ce44SJohn Forte 			 * output);
5086fcf3ce44SJohn Forte 			 */
5087fcf3ce44SJohn Forte 		}
5088fcf3ce44SJohn Forte 		if (hash_id == AUTH_SHA1) {
5089fcf3ce44SJohn Forte 			bzero(&sha1ctx, sizeof (SHA1_CTX));
5090fcf3ce44SJohn Forte 			hash_size = SHA1_LEN;
5091fcf3ce44SJohn Forte 			SHA1Init(&sha1ctx);
5092fcf3ce44SJohn Forte 
5093fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx, (void *)&mytran_id, 1);
5094fcf3ce44SJohn Forte 
5095fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx, (void *)remote_key,
5096fcf3ce44SJohn Forte 			    node_dhc->auth_key.remote_password_length);
5097fcf3ce44SJohn Forte 
5098fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx,
5099fcf3ce44SJohn Forte 			    (void *)&(un_cval.sha1.val[0]), SHA1_LEN);
5100fcf3ce44SJohn Forte 
5101fcf3ce44SJohn Forte 			SHA1Final((void *)sha1_digest, &sha1ctx);
5102fcf3ce44SJohn Forte 
5103fcf3ce44SJohn Forte 			/*
5104fcf3ce44SJohn Forte 			 * emlxs_sha1_digest_to_hex((uint8_t *)hash_val,
5105fcf3ce44SJohn Forte 			 * output);
5106fcf3ce44SJohn Forte 			 */
5107fcf3ce44SJohn Forte 
5108fcf3ce44SJohn Forte 			hash_val = (uint32_t *)kmem_alloc(hash_size,
5109fcf3ce44SJohn Forte 			    KM_NOSLEEP);
5110fcf3ce44SJohn Forte 			if (hash_val == NULL) {
5111fcf3ce44SJohn Forte 				return (NULL);
5112fcf3ce44SJohn Forte 			} else {
5113fcf3ce44SJohn Forte 				bcopy((void *)&sha1_digest,
5114fcf3ce44SJohn Forte 				    (void *)hash_val, SHA1_LEN);
5115fcf3ce44SJohn Forte 			}
5116fcf3ce44SJohn Forte 		}
5117fcf3ce44SJohn Forte 		return ((uint32_t *)hash_val);
5118fcf3ce44SJohn Forte 	} else {
5119fcf3ce44SJohn Forte 		/* Verification of bi-dir auth for DH-CHAP group */
5120fcf3ce44SJohn Forte 		/* original challenge is node_dhc->bi_cval[] */
5121fcf3ce44SJohn Forte 		/* session key is node_dhc->ses_key[] */
5122fcf3ce44SJohn Forte 		/* That's IT */
5123fcf3ce44SJohn Forte 		/*
5124fcf3ce44SJohn Forte 		 * H(bi_cval || ses_key) = C H(Ti || Km || C)  = hash_val
5125fcf3ce44SJohn Forte 		 */
5126fcf3ce44SJohn Forte 		if (hash_id == AUTH_MD5) {
5127fcf3ce44SJohn Forte 			bzero(&mdctx, sizeof (MD5_CTX));
5128fcf3ce44SJohn Forte 			hash_size = MD5_LEN;
5129fcf3ce44SJohn Forte 
5130fcf3ce44SJohn Forte 			MD5Init(&mdctx);
5131fcf3ce44SJohn Forte 
5132fcf3ce44SJohn Forte 			MD5Update(&mdctx,
5133fcf3ce44SJohn Forte 			    (void *)&(un_cval.md5.val[0]), MD5_LEN);
5134fcf3ce44SJohn Forte 
513582527734SSukumar Swaminathan 			if (ndlp->nlp_DID == FABRIC_DID) {
5136fcf3ce44SJohn Forte 				MD5Update(&mdctx,
5137fcf3ce44SJohn Forte 				    (void *)&node_dhc->ses_key[0],
5138fcf3ce44SJohn Forte 				    node_dhc->seskey_len);
5139fcf3ce44SJohn Forte 			} else {
5140fcf3ce44SJohn Forte 				/* ses_key is obtained in emlxs_hash_rsp */
5141fcf3ce44SJohn Forte 				MD5Update(&mdctx,
5142fcf3ce44SJohn Forte 				    (void *)&node_dhc->nlp_auth_misc.ses_key[0],
5143fcf3ce44SJohn Forte 				    node_dhc->nlp_auth_misc.seskey_len);
5144fcf3ce44SJohn Forte 			}
5145fcf3ce44SJohn Forte 
5146fcf3ce44SJohn Forte 			MD5Final((void *)md5_digest, &mdctx);
5147fcf3ce44SJohn Forte 
5148fcf3ce44SJohn Forte 			MD5Init(&mdctx);
5149fcf3ce44SJohn Forte 
5150fcf3ce44SJohn Forte 			MD5Update(&mdctx, (void *)&mytran_id, 1);
5151fcf3ce44SJohn Forte 
5152fcf3ce44SJohn Forte 			MD5Update(&mdctx, (void *)remote_key,
5153fcf3ce44SJohn Forte 			    node_dhc->auth_key.remote_password_length);
5154fcf3ce44SJohn Forte 
5155fcf3ce44SJohn Forte 			MD5Update(&mdctx, (void *)md5_digest, MD5_LEN);
5156fcf3ce44SJohn Forte 
5157fcf3ce44SJohn Forte 			MD5Final((void *)md5_digest, &mdctx);
5158fcf3ce44SJohn Forte 
5159fcf3ce44SJohn Forte 			hash_val = (uint32_t *)kmem_alloc(hash_size,
5160fcf3ce44SJohn Forte 			    KM_NOSLEEP);
5161fcf3ce44SJohn Forte 			if (hash_val == NULL) {
5162fcf3ce44SJohn Forte 				return (NULL);
5163fcf3ce44SJohn Forte 			} else {
5164fcf3ce44SJohn Forte 				bcopy((void *)&md5_digest,
5165fcf3ce44SJohn Forte 				    (void *)hash_val, MD5_LEN);
5166fcf3ce44SJohn Forte 			}
5167fcf3ce44SJohn Forte 		}
5168fcf3ce44SJohn Forte 		if (hash_id == AUTH_SHA1) {
5169fcf3ce44SJohn Forte 			bzero(&sha1ctx, sizeof (SHA1_CTX));
5170fcf3ce44SJohn Forte 			hash_size = SHA1_LEN;
5171fcf3ce44SJohn Forte 
5172fcf3ce44SJohn Forte 			SHA1Init(&sha1ctx);
5173fcf3ce44SJohn Forte 
5174fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx,
5175fcf3ce44SJohn Forte 			    (void *)&(un_cval.sha1.val[0]), SHA1_LEN);
5176fcf3ce44SJohn Forte 
517782527734SSukumar Swaminathan 			if (ndlp->nlp_DID == FABRIC_DID) {
5178fcf3ce44SJohn Forte 				SHA1Update(&sha1ctx,
5179fcf3ce44SJohn Forte 				    (void *)&node_dhc->ses_key[0],
5180fcf3ce44SJohn Forte 				    node_dhc->seskey_len);
5181fcf3ce44SJohn Forte 			} else {
5182fcf3ce44SJohn Forte 				/* ses_key was obtained in emlxs_hash_rsp */
5183fcf3ce44SJohn Forte 				SHA1Update(&sha1ctx,
5184fcf3ce44SJohn Forte 				    (void *)&node_dhc->nlp_auth_misc.ses_key[0],
5185fcf3ce44SJohn Forte 				    node_dhc->nlp_auth_misc.seskey_len);
5186fcf3ce44SJohn Forte 			}
5187fcf3ce44SJohn Forte 
5188fcf3ce44SJohn Forte 			SHA1Final((void *)sha1_digest, &sha1ctx);
5189fcf3ce44SJohn Forte 
5190fcf3ce44SJohn Forte 			SHA1Init(&sha1ctx);
5191fcf3ce44SJohn Forte 
5192fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx, (void *)&mytran_id, 1);
5193fcf3ce44SJohn Forte 
5194fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx, (void *)remote_key,
5195fcf3ce44SJohn Forte 			    node_dhc->auth_key.remote_password_length);
5196fcf3ce44SJohn Forte 
5197fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx, (void *)sha1_digest, SHA1_LEN);
5198fcf3ce44SJohn Forte 
5199fcf3ce44SJohn Forte 			SHA1Final((void *)sha1_digest, &sha1ctx);
5200fcf3ce44SJohn Forte 
5201fcf3ce44SJohn Forte 			hash_val = (uint32_t *)kmem_alloc(hash_size,
5202fcf3ce44SJohn Forte 			    KM_NOSLEEP);
5203fcf3ce44SJohn Forte 			if (hash_val == NULL) {
5204fcf3ce44SJohn Forte 				return (NULL);
5205fcf3ce44SJohn Forte 			} else {
5206fcf3ce44SJohn Forte 				bcopy((void *)&sha1_digest,
5207fcf3ce44SJohn Forte 				    (void *)hash_val, SHA1_LEN);
5208fcf3ce44SJohn Forte 			}
5209fcf3ce44SJohn Forte 		}
5210fcf3ce44SJohn Forte 		return ((uint32_t *)hash_val);
5211fcf3ce44SJohn Forte 	}
5212fcf3ce44SJohn Forte 
5213fcf3ce44SJohn Forte } /* emlxs_hash_vrf */
5214fcf3ce44SJohn Forte 
5215fcf3ce44SJohn Forte 
5216fcf3ce44SJohn Forte /*
5217fcf3ce44SJohn Forte  * If dhval == NULL, NULL DHCHAP else, DHCHAP group.
5218fcf3ce44SJohn Forte  *
5219fcf3ce44SJohn Forte  * This routine is used by the auth transaction initiator (Who does the
5220fcf3ce44SJohn Forte  * auth-negotiate) to calculate the R1 (response) based on
5221fcf3ce44SJohn Forte  * the dh value it received, its own random private key, the challenge it
5222fcf3ce44SJohn Forte  * received, and Transaction id, as well as the password
5223fcf3ce44SJohn Forte  * associated with this very initiator in the auth pair.
5224fcf3ce44SJohn Forte  */
5225fcf3ce44SJohn Forte uint32_t *
emlxs_hash_rsp(emlxs_port_t * port,emlxs_port_dhc_t * port_dhc,NODELIST * ndlp,uint32_t tran_id,union challenge_val un_cval,uint8_t * dhval,uint32_t dhvallen)5226fcf3ce44SJohn Forte emlxs_hash_rsp(
5227fcf3ce44SJohn Forte emlxs_port_t *port,
5228fcf3ce44SJohn Forte emlxs_port_dhc_t *port_dhc,
5229fcf3ce44SJohn Forte NODELIST *ndlp,
5230fcf3ce44SJohn Forte uint32_t tran_id,
5231fcf3ce44SJohn Forte union challenge_val un_cval,
5232fcf3ce44SJohn Forte uint8_t *dhval,
5233fcf3ce44SJohn Forte uint32_t dhvallen)
5234fcf3ce44SJohn Forte {
5235fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
5236fcf3ce44SJohn Forte 	uint32_t dhgp_id;
5237fcf3ce44SJohn Forte 	uint32_t hash_id;
5238fcf3ce44SJohn Forte 	uint32_t *hash_val;
5239fcf3ce44SJohn Forte 	uint32_t hash_size;
5240fcf3ce44SJohn Forte 	MD5_CTX mdctx;
5241fcf3ce44SJohn Forte 	SHA1_CTX sha1ctx;
5242fcf3ce44SJohn Forte 	uint8_t sha1_digest[20];
5243fcf3ce44SJohn Forte 	uint8_t md5_digest[16];
5244fcf3ce44SJohn Forte 	uint8_t Cai[20];
5245fcf3ce44SJohn Forte 	uint8_t mytran_id = 0x00;
5246fcf3ce44SJohn Forte 	char *mykey;
5247fcf3ce44SJohn Forte 	BIG_ERR_CODE err = BIG_OK;
5248fcf3ce44SJohn Forte 
524982527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
5250fcf3ce44SJohn Forte 		hash_id = node_dhc->hash_id;
5251fcf3ce44SJohn Forte 		dhgp_id = node_dhc->dhgp_id;
5252fcf3ce44SJohn Forte 	} else {
5253fcf3ce44SJohn Forte 		hash_id = node_dhc->nlp_auth_hashid;
5254fcf3ce44SJohn Forte 		dhgp_id = node_dhc->nlp_auth_dhgpid;
5255fcf3ce44SJohn Forte 	}
5256fcf3ce44SJohn Forte 
5257fcf3ce44SJohn Forte 	tran_id = (AUTH_TRAN_ID_MASK & tran_id);
525882527734SSukumar Swaminathan 	mytran_id = (uint8_t)(LE_SWAP32(tran_id));
5259fcf3ce44SJohn Forte 
5260fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
5261*8f23e9faSHans Rosenfeld 	    "hash_rsp: 0x%x 0x%x 0x%x 0x%x dhvallen=0x%x",
5262fcf3ce44SJohn Forte 	    ndlp->nlp_DID, hash_id, dhgp_id, mytran_id, dhvallen);
5263fcf3ce44SJohn Forte 
526482527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
5265fcf3ce44SJohn Forte 		mykey = (char *)node_dhc->auth_key.local_password;
5266fcf3ce44SJohn Forte 
5267fcf3ce44SJohn Forte 	} else {
5268fcf3ce44SJohn Forte 		mykey = (char *)node_dhc->auth_key.local_password;
5269fcf3ce44SJohn Forte 	}
5270fcf3ce44SJohn Forte 
5271fcf3ce44SJohn Forte 	if (dhval == NULL) {
5272fcf3ce44SJohn Forte 		/* NULL DHCHAP */
5273fcf3ce44SJohn Forte 		if (hash_id == AUTH_MD5) {
5274fcf3ce44SJohn Forte 			bzero(&mdctx, sizeof (MD5_CTX));
5275fcf3ce44SJohn Forte 			hash_size = MD5_LEN;
5276fcf3ce44SJohn Forte 
5277fcf3ce44SJohn Forte 			MD5Init(&mdctx);
5278fcf3ce44SJohn Forte 
5279fcf3ce44SJohn Forte 			MD5Update(&mdctx, (unsigned char *)&mytran_id, 1);
5280fcf3ce44SJohn Forte 
5281fcf3ce44SJohn Forte 			MD5Update(&mdctx, (unsigned char *)mykey,
5282fcf3ce44SJohn Forte 			    node_dhc->auth_key.local_password_length);
5283fcf3ce44SJohn Forte 
5284fcf3ce44SJohn Forte 			MD5Update(&mdctx,
5285fcf3ce44SJohn Forte 			    (unsigned char *)&(un_cval.md5.val[0]),
5286fcf3ce44SJohn Forte 			    MD5_LEN);
5287fcf3ce44SJohn Forte 
5288fcf3ce44SJohn Forte 			MD5Final((uint8_t *)md5_digest, &mdctx);
5289fcf3ce44SJohn Forte 
5290fcf3ce44SJohn Forte 			hash_val = (uint32_t *)kmem_alloc(hash_size,
5291fcf3ce44SJohn Forte 			    KM_NOSLEEP);
5292fcf3ce44SJohn Forte 			if (hash_val == NULL) {
5293fcf3ce44SJohn Forte 				return (NULL);
5294fcf3ce44SJohn Forte 			} else {
5295fcf3ce44SJohn Forte 				bcopy((void *)&md5_digest,
5296fcf3ce44SJohn Forte 				    (void *)hash_val, MD5_LEN);
5297fcf3ce44SJohn Forte 			}
5298fcf3ce44SJohn Forte 
5299fcf3ce44SJohn Forte 			/*
5300fcf3ce44SJohn Forte 			 * emlxs_md5_digest_to_hex((uint8_t *)hash_val,
5301fcf3ce44SJohn Forte 			 * output);
5302fcf3ce44SJohn Forte 			 */
5303fcf3ce44SJohn Forte 
5304fcf3ce44SJohn Forte 		}
5305fcf3ce44SJohn Forte 		if (hash_id == AUTH_SHA1) {
5306fcf3ce44SJohn Forte 			bzero(&sha1ctx, sizeof (SHA1_CTX));
5307fcf3ce44SJohn Forte 			hash_size = SHA1_LEN;
5308fcf3ce44SJohn Forte 			SHA1Init(&sha1ctx);
5309fcf3ce44SJohn Forte 
5310fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx, (void *)&mytran_id, 1);
5311fcf3ce44SJohn Forte 
5312fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx, (void *)mykey,
5313fcf3ce44SJohn Forte 			    node_dhc->auth_key.local_password_length);
5314fcf3ce44SJohn Forte 
5315fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx,
5316fcf3ce44SJohn Forte 			    (void *)&(un_cval.sha1.val[0]), SHA1_LEN);
5317fcf3ce44SJohn Forte 
5318fcf3ce44SJohn Forte 			SHA1Final((void *)sha1_digest, &sha1ctx);
5319fcf3ce44SJohn Forte 
5320fcf3ce44SJohn Forte 			/*
5321fcf3ce44SJohn Forte 			 * emlxs_sha1_digest_to_hex((uint8_t *)hash_val,
5322fcf3ce44SJohn Forte 			 * output);
5323fcf3ce44SJohn Forte 			 */
5324fcf3ce44SJohn Forte 
5325fcf3ce44SJohn Forte 			hash_val = (uint32_t *)kmem_alloc(hash_size,
5326fcf3ce44SJohn Forte 			    KM_NOSLEEP);
5327fcf3ce44SJohn Forte 			if (hash_val == NULL) {
5328fcf3ce44SJohn Forte 				return (NULL);
5329fcf3ce44SJohn Forte 			} else {
5330fcf3ce44SJohn Forte 				bcopy((void *)&sha1_digest,
5331fcf3ce44SJohn Forte 				    (void *)hash_val, SHA1_LEN);
5332fcf3ce44SJohn Forte 			}
5333fcf3ce44SJohn Forte 		}
5334fcf3ce44SJohn Forte 		return ((uint32_t *)hash_val);
5335fcf3ce44SJohn Forte 	} else {
5336fcf3ce44SJohn Forte 
5337fcf3ce44SJohn Forte 		/* process DH grops */
5338fcf3ce44SJohn Forte 		/*
5339fcf3ce44SJohn Forte 		 * calculate interm hash value Ca1 Ca1 = H(C1 || (g^x mod
5340fcf3ce44SJohn Forte 		 * p)^y mod p) in which C1 is the challenge received. g^x mod
5341fcf3ce44SJohn Forte 		 * p is the dhval received y is the random number in 16 bytes
5342fcf3ce44SJohn Forte 		 * for MD5, 20 bytes for SHA1 p is hardcoded value based on
5343fcf3ce44SJohn Forte 		 * different DH groups.
5344fcf3ce44SJohn Forte 		 *
5345fcf3ce44SJohn Forte 		 * To calculate hash value R1 R1 = H (Ti || Kn || Cai) in which
5346fcf3ce44SJohn Forte 		 * Ti is the transaction identifier Kn is the shared secret.
5347fcf3ce44SJohn Forte 		 * Cai is the result from interm hash.
5348fcf3ce44SJohn Forte 		 *
5349fcf3ce44SJohn Forte 		 * g^y mod p is reserved in port_dhc as pubkey (public key).for
5350fcf3ce44SJohn Forte 		 * bi-dir challenge is another random number. y is prikey
5351fcf3ce44SJohn Forte 		 * (private key). ((g^x mod p)^y mod p) is sekey (session
5352fcf3ce44SJohn Forte 		 * key)
5353fcf3ce44SJohn Forte 		 */
5354fcf3ce44SJohn Forte 		err = emlxs_interm_hash(port, port_dhc, ndlp,
5355fcf3ce44SJohn Forte 		    (void *)&Cai, tran_id,
5356fcf3ce44SJohn Forte 		    un_cval, dhval, &dhvallen);
5357fcf3ce44SJohn Forte 
5358fcf3ce44SJohn Forte 		if (err != BIG_OK) {
5359fcf3ce44SJohn Forte 			return (NULL);
5360fcf3ce44SJohn Forte 		}
5361fcf3ce44SJohn Forte 		if (hash_id == AUTH_MD5) {
5362fcf3ce44SJohn Forte 			bzero(&mdctx, sizeof (MD5_CTX));
5363fcf3ce44SJohn Forte 			hash_size = MD5_LEN;
5364fcf3ce44SJohn Forte 
5365fcf3ce44SJohn Forte 			MD5Init(&mdctx);
5366fcf3ce44SJohn Forte 
5367fcf3ce44SJohn Forte 			MD5Update(&mdctx, (unsigned char *)&mytran_id, 1);
5368fcf3ce44SJohn Forte 
5369fcf3ce44SJohn Forte 			MD5Update(&mdctx, (unsigned char *)mykey,
5370fcf3ce44SJohn Forte 			    node_dhc->auth_key.local_password_length);
5371fcf3ce44SJohn Forte 
5372fcf3ce44SJohn Forte 			MD5Update(&mdctx, (unsigned char *)Cai, MD5_LEN);
5373fcf3ce44SJohn Forte 
5374fcf3ce44SJohn Forte 			MD5Final((uint8_t *)md5_digest, &mdctx);
5375fcf3ce44SJohn Forte 
5376fcf3ce44SJohn Forte 			hash_val = (uint32_t *)kmem_alloc(hash_size,
5377fcf3ce44SJohn Forte 			    KM_NOSLEEP);
5378fcf3ce44SJohn Forte 			if (hash_val == NULL) {
5379fcf3ce44SJohn Forte 				return (NULL);
5380fcf3ce44SJohn Forte 			} else {
5381fcf3ce44SJohn Forte 				bcopy((void *)&md5_digest,
5382fcf3ce44SJohn Forte 				    (void *)hash_val, MD5_LEN);
5383fcf3ce44SJohn Forte 			}
5384fcf3ce44SJohn Forte 		}
5385fcf3ce44SJohn Forte 		if (hash_id == AUTH_SHA1) {
5386fcf3ce44SJohn Forte 			bzero(&sha1ctx, sizeof (SHA1_CTX));
5387fcf3ce44SJohn Forte 			hash_size = SHA1_LEN;
5388fcf3ce44SJohn Forte 
5389fcf3ce44SJohn Forte 			SHA1Init(&sha1ctx);
5390fcf3ce44SJohn Forte 
5391fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx, (void *)&mytran_id, 1);
5392fcf3ce44SJohn Forte 
5393fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx, (void *)mykey,
5394fcf3ce44SJohn Forte 			    node_dhc->auth_key.local_password_length);
5395fcf3ce44SJohn Forte 
5396fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx, (void *)&Cai[0], SHA1_LEN);
5397fcf3ce44SJohn Forte 
5398fcf3ce44SJohn Forte 			SHA1Final((void *)sha1_digest, &sha1ctx);
5399fcf3ce44SJohn Forte 
5400fcf3ce44SJohn Forte 			hash_val = (uint32_t *)kmem_alloc(hash_size,
5401fcf3ce44SJohn Forte 			    KM_NOSLEEP);
5402fcf3ce44SJohn Forte 			if (hash_val == NULL) {
5403fcf3ce44SJohn Forte 				return (NULL);
5404fcf3ce44SJohn Forte 			} else {
5405fcf3ce44SJohn Forte 				bcopy((void *)&sha1_digest,
5406fcf3ce44SJohn Forte 				    (void *)hash_val, SHA1_LEN);
5407fcf3ce44SJohn Forte 			}
5408fcf3ce44SJohn Forte 		}
5409fcf3ce44SJohn Forte 		return ((uint32_t *)hash_val);
5410fcf3ce44SJohn Forte 	}
5411fcf3ce44SJohn Forte 
5412fcf3ce44SJohn Forte } /* emlxs_hash_rsp */
5413fcf3ce44SJohn Forte 
5414fcf3ce44SJohn Forte 
5415fcf3ce44SJohn Forte /*
5416fcf3ce44SJohn Forte  * To get the augmented challenge Cai Stored in hash_val
5417fcf3ce44SJohn Forte  *
5418fcf3ce44SJohn Forte  * Cai = Hash (C1 || ((g^x mod p)^y mod p)) = Hash (C1 || (g^(x*y) mod p)
5419fcf3ce44SJohn Forte  *
5420fcf3ce44SJohn Forte  * C1:challenge received from the remote entity (g^x mod p): dh val
5421fcf3ce44SJohn Forte  * received from the remote entity (remote entity's pubkey) y:
5422fcf3ce44SJohn Forte  * random private key from the local entity Hash: hash function used in
5423fcf3ce44SJohn Forte  * agreement. (g^(x*y) mod p): shared session key (aka
5424fcf3ce44SJohn Forte  * shared secret) (g^y mod p): local entity's pubkey
5425fcf3ce44SJohn Forte  */
5426fcf3ce44SJohn Forte /* ARGSUSED */
5427fcf3ce44SJohn Forte BIG_ERR_CODE
emlxs_interm_hash(emlxs_port_t * port,emlxs_port_dhc_t * port_dhc,NODELIST * ndlp,void * hash_val,uint32_t tran_id,union challenge_val un_cval,uint8_t * dhval,uint32_t * dhvallen)5428fcf3ce44SJohn Forte emlxs_interm_hash(
5429fcf3ce44SJohn Forte emlxs_port_t *port,
5430fcf3ce44SJohn Forte emlxs_port_dhc_t *port_dhc,
5431fcf3ce44SJohn Forte NODELIST *ndlp,
5432fcf3ce44SJohn Forte void *hash_val,
5433fcf3ce44SJohn Forte uint32_t tran_id,
5434fcf3ce44SJohn Forte union challenge_val un_cval,
5435fcf3ce44SJohn Forte uint8_t *dhval,
5436fcf3ce44SJohn Forte uint32_t *dhvallen)
5437fcf3ce44SJohn Forte {
5438fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
5439fcf3ce44SJohn Forte 	uint32_t dhgp_id;
5440fcf3ce44SJohn Forte 	uint32_t hash_id;
5441fcf3ce44SJohn Forte 	MD5_CTX mdctx;
5442fcf3ce44SJohn Forte 	SHA1_CTX sha1ctx;
5443fcf3ce44SJohn Forte 	uint8_t sha1_digest[20];
5444fcf3ce44SJohn Forte 	uint8_t md5_digest[16];
5445fcf3ce44SJohn Forte 	uint32_t hash_size;
5446fcf3ce44SJohn Forte 	BIG_ERR_CODE err = BIG_OK;
5447fcf3ce44SJohn Forte 
544882527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
5449fcf3ce44SJohn Forte 		hash_id = node_dhc->hash_id;
5450fcf3ce44SJohn Forte 		dhgp_id = node_dhc->dhgp_id;
5451fcf3ce44SJohn Forte 	} else {
5452fcf3ce44SJohn Forte 		hash_id = node_dhc->nlp_auth_hashid;
5453fcf3ce44SJohn Forte 		dhgp_id = node_dhc->nlp_auth_dhgpid;
5454fcf3ce44SJohn Forte 	}
5455fcf3ce44SJohn Forte 
5456fcf3ce44SJohn Forte 	if (hash_id == AUTH_MD5) {
5457fcf3ce44SJohn Forte 		bzero(&mdctx, sizeof (MD5_CTX));
5458fcf3ce44SJohn Forte 		hash_size = MD5_LEN;
5459fcf3ce44SJohn Forte 		MD5Init(&mdctx);
5460fcf3ce44SJohn Forte 		MD5Update(&mdctx,
5461fcf3ce44SJohn Forte 		    (unsigned char *)&(un_cval.md5.val[0]), MD5_LEN);
5462fcf3ce44SJohn Forte 
5463fcf3ce44SJohn Forte 		/*
5464fcf3ce44SJohn Forte 		 * get the pub key (g^y mod p) and session key (g^(x*y) mod
5465fcf3ce44SJohn Forte 		 * p) and stored them in the partner's ndlp structure
5466fcf3ce44SJohn Forte 		 */
5467fcf3ce44SJohn Forte 		err = emlxs_BIGNUM_get_pubkey(port, port_dhc, ndlp,
5468fcf3ce44SJohn Forte 		    dhval, dhvallen, hash_size, dhgp_id);
5469fcf3ce44SJohn Forte 
5470fcf3ce44SJohn Forte 		if (err != BIG_OK) {
5471fcf3ce44SJohn Forte 			return (err);
5472fcf3ce44SJohn Forte 		}
547382527734SSukumar Swaminathan 		if (ndlp->nlp_DID == FABRIC_DID) {
5474fcf3ce44SJohn Forte 			MD5Update(&mdctx,
5475fcf3ce44SJohn Forte 			    (unsigned char *)&node_dhc->ses_key[0],
5476fcf3ce44SJohn Forte 			    node_dhc->seskey_len);
5477fcf3ce44SJohn Forte 		} else {
5478fcf3ce44SJohn Forte 		MD5Update(&mdctx,
5479fcf3ce44SJohn Forte 		    (unsigned char *)&node_dhc->nlp_auth_misc.ses_key[0],
5480fcf3ce44SJohn Forte 		    node_dhc->nlp_auth_misc.seskey_len);
5481fcf3ce44SJohn Forte 		}
5482fcf3ce44SJohn Forte 
5483fcf3ce44SJohn Forte 		MD5Final((uint8_t *)md5_digest, &mdctx);
5484fcf3ce44SJohn Forte 
5485fcf3ce44SJohn Forte 		bcopy((void *)&md5_digest, (void *)hash_val, MD5_LEN);
5486fcf3ce44SJohn Forte 	}
5487fcf3ce44SJohn Forte 	if (hash_id == AUTH_SHA1) {
5488fcf3ce44SJohn Forte 		bzero(&sha1ctx, sizeof (SHA1_CTX));
5489fcf3ce44SJohn Forte 
5490fcf3ce44SJohn Forte 		hash_size = SHA1_LEN;
5491fcf3ce44SJohn Forte 
5492fcf3ce44SJohn Forte 		SHA1Init(&sha1ctx);
5493fcf3ce44SJohn Forte 
5494fcf3ce44SJohn Forte 		SHA1Update(&sha1ctx, (void *)&(un_cval.sha1.val[0]), SHA1_LEN);
5495fcf3ce44SJohn Forte 
5496fcf3ce44SJohn Forte 		/* get the pub key and session key */
5497fcf3ce44SJohn Forte 		err = emlxs_BIGNUM_get_pubkey(port, port_dhc, ndlp,
5498fcf3ce44SJohn Forte 		    dhval, dhvallen, hash_size, dhgp_id);
5499fcf3ce44SJohn Forte 
5500fcf3ce44SJohn Forte 		if (err != BIG_OK) {
5501fcf3ce44SJohn Forte 			return (err);
5502fcf3ce44SJohn Forte 		}
550382527734SSukumar Swaminathan 		if (ndlp->nlp_DID == FABRIC_DID) {
5504fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx, (void *)&node_dhc->ses_key[0],
5505fcf3ce44SJohn Forte 			    node_dhc->seskey_len);
5506fcf3ce44SJohn Forte 		} else {
5507fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx,
5508fcf3ce44SJohn Forte 			    (void *)&node_dhc->nlp_auth_misc.ses_key[0],
5509fcf3ce44SJohn Forte 			    node_dhc->nlp_auth_misc.seskey_len);
5510fcf3ce44SJohn Forte 		}
5511fcf3ce44SJohn Forte 
5512fcf3ce44SJohn Forte 		SHA1Final((void *)sha1_digest, &sha1ctx);
5513fcf3ce44SJohn Forte 
5514fcf3ce44SJohn Forte 		bcopy((void *)&sha1_digest, (void *)hash_val, SHA1_LEN);
5515fcf3ce44SJohn Forte 	}
5516fcf3ce44SJohn Forte 	return (err);
5517fcf3ce44SJohn Forte 
5518fcf3ce44SJohn Forte } /* emlxs_interm_hash */
5519fcf3ce44SJohn Forte 
5520fcf3ce44SJohn Forte /*
5521fcf3ce44SJohn Forte  * This routine get the pubkey and session key. these pubkey and session
5522fcf3ce44SJohn Forte  * key are stored in the partner's ndlp structure.
5523fcf3ce44SJohn Forte  */
5524fcf3ce44SJohn Forte /* ARGSUSED */
5525fcf3ce44SJohn Forte BIG_ERR_CODE
emlxs_BIGNUM_get_pubkey(emlxs_port_t * port,emlxs_port_dhc_t * port_dhc,NODELIST * ndlp,uint8_t * dhval,uint32_t * dhvallen,uint32_t hash_size,uint32_t dhgp_id)5526fcf3ce44SJohn Forte emlxs_BIGNUM_get_pubkey(
5527fcf3ce44SJohn Forte 			emlxs_port_t *port,
5528fcf3ce44SJohn Forte 			emlxs_port_dhc_t *port_dhc,
5529fcf3ce44SJohn Forte 			NODELIST *ndlp,
5530fcf3ce44SJohn Forte 			uint8_t *dhval,
5531fcf3ce44SJohn Forte 			uint32_t *dhvallen,
5532fcf3ce44SJohn Forte 			uint32_t hash_size,
5533fcf3ce44SJohn Forte 			uint32_t dhgp_id)
5534fcf3ce44SJohn Forte {
5535fcf3ce44SJohn Forte 	emlxs_hba_t *hba = HBA;
5536fcf3ce44SJohn Forte 
5537fcf3ce44SJohn Forte 	BIGNUM a, e, n, result;
5538fcf3ce44SJohn Forte 	uint32_t plen;
5539fcf3ce44SJohn Forte 	uint8_t random_number[20];
5540fcf3ce44SJohn Forte 	unsigned char *tmp = NULL;
5541fcf3ce44SJohn Forte 	BIGNUM g, result1;
5542fcf3ce44SJohn Forte 
5543fcf3ce44SJohn Forte #ifdef BIGNUM_CHUNK_32
5544fcf3ce44SJohn Forte 	uint8_t gen[] = {0x00, 0x00, 0x00, 0x02};
5545fcf3ce44SJohn Forte #else
5546fcf3ce44SJohn Forte 	uint8_t gen[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02};
5547fcf3ce44SJohn Forte #endif /* BIGNUM_CHUNK_32 */
5548fcf3ce44SJohn Forte 
5549fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
5550fcf3ce44SJohn Forte 	BIG_ERR_CODE err = BIG_OK;
5551fcf3ce44SJohn Forte 
5552fcf3ce44SJohn Forte 	/*
5553fcf3ce44SJohn Forte 	 * compute a^e mod n assume a < n, n odd, result->value at least as
5554fcf3ce44SJohn Forte 	 * long as n->value.
5555fcf3ce44SJohn Forte 	 *
5556fcf3ce44SJohn Forte 	 * a is the public key received from responder. e is the private key
5557fcf3ce44SJohn Forte 	 * generated by me. n is the wellknown modulus.
5558fcf3ce44SJohn Forte 	 */
5559fcf3ce44SJohn Forte 
5560fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
5561*8f23e9faSHans Rosenfeld 	    "BIGNUM_get_pubkey: 0x%x 0x%x 0x%x 0x%x",
5562fcf3ce44SJohn Forte 	    ndlp->nlp_DID, *dhvallen, hash_size, dhgp_id);
5563fcf3ce44SJohn Forte 
5564fcf3ce44SJohn Forte 	/* size should be in the unit of (BIG_CHUNK_TYPE) words */
5565fcf3ce44SJohn Forte 	if (big_init(&a, CHARLEN2BIGNUMLEN(*dhvallen))  != BIG_OK) {
5566fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
5567*8f23e9faSHans Rosenfeld 		    "BIGNUM_get_pubkey: big_init failed. a size=%d",
5568fcf3ce44SJohn Forte 		    CHARLEN2BIGNUMLEN(*dhvallen));
5569fcf3ce44SJohn Forte 
5570fcf3ce44SJohn Forte 		err = BIG_NO_MEM;
5571fcf3ce44SJohn Forte 		return (err);
5572fcf3ce44SJohn Forte 	}
5573fcf3ce44SJohn Forte 	/* a: (g^x mod p) */
5574fcf3ce44SJohn Forte 	/*
5575fcf3ce44SJohn Forte 	 * dhval is in big-endian format. This call converts from
5576fcf3ce44SJohn Forte 	 * byte-big-endian format to big number format (words in little
5577fcf3ce44SJohn Forte 	 * endian order, but bytes within the words big endian)
5578fcf3ce44SJohn Forte 	 */
5579fcf3ce44SJohn Forte 	bytestring2bignum(&a, (unsigned char *)dhval, *dhvallen);
5580fcf3ce44SJohn Forte 
5581fcf3ce44SJohn Forte 	if (big_init(&e, CHARLEN2BIGNUMLEN(hash_size)) != BIG_OK) {
5582fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
5583*8f23e9faSHans Rosenfeld 		    "BIGNUM_get_pubkey: big_init failed. e size=%d",
5584fcf3ce44SJohn Forte 		    CHARLEN2BIGNUMLEN(hash_size));
5585fcf3ce44SJohn Forte 
5586fcf3ce44SJohn Forte 		err = BIG_NO_MEM;
5587fcf3ce44SJohn Forte 		goto ret1;
5588fcf3ce44SJohn Forte 	}
5589fcf3ce44SJohn Forte #ifdef RAND
5590fcf3ce44SJohn Forte 
5591fcf3ce44SJohn Forte 	bzero(&random_number, hash_size);
5592fcf3ce44SJohn Forte 
5593fcf3ce44SJohn Forte 	/* to get random private key: y */
5594fcf3ce44SJohn Forte 	/* remember y is short lived private key */
5595fcf3ce44SJohn Forte 	if (hba->rdn_flag == 1) {
5596fcf3ce44SJohn Forte 		emlxs_get_random_bytes(ndlp, random_number, 20);
5597fcf3ce44SJohn Forte 	} else {
5598e2ca2865SSukumar Swaminathan 		(void) random_get_pseudo_bytes(random_number, hash_size);
5599fcf3ce44SJohn Forte 	}
5600fcf3ce44SJohn Forte 
5601fcf3ce44SJohn Forte 	/* e: y */
5602fcf3ce44SJohn Forte 	bytestring2bignum(&e, (unsigned char *)random_number, hash_size);
5603fcf3ce44SJohn Forte 
5604fcf3ce44SJohn Forte #endif	/* RAND */
5605fcf3ce44SJohn Forte 
5606fcf3ce44SJohn Forte #ifdef MYRAND
5607fcf3ce44SJohn Forte 	bytestring2bignum(&e, (unsigned char *)myrand, hash_size);
5608fcf3ce44SJohn Forte 
5609fcf3ce44SJohn Forte 	printf("myrand random_number as Y ================\n");
5610fcf3ce44SJohn Forte 	for (i = 0; i < 5; i++) {
5611fcf3ce44SJohn Forte 		for (j = 0; j < 4; j++) {
5612fcf3ce44SJohn Forte 			printf("%x", myrand[(i * 4) + j]);
5613fcf3ce44SJohn Forte 		}
5614fcf3ce44SJohn Forte 		printf("\n");
5615fcf3ce44SJohn Forte 	}
5616fcf3ce44SJohn Forte #endif	/* MYRAND */
5617fcf3ce44SJohn Forte 
5618fcf3ce44SJohn Forte 	switch (dhgp_id) {
5619fcf3ce44SJohn Forte 	case GROUP_1024:
5620fcf3ce44SJohn Forte 		plen = 128;
5621fcf3ce44SJohn Forte 		tmp = dhgp1_pVal;
5622fcf3ce44SJohn Forte 		break;
5623fcf3ce44SJohn Forte 
5624fcf3ce44SJohn Forte 	case GROUP_1280:
5625fcf3ce44SJohn Forte 		plen = 160;
5626fcf3ce44SJohn Forte 		tmp = dhgp2_pVal;
5627fcf3ce44SJohn Forte 		break;
5628fcf3ce44SJohn Forte 
5629fcf3ce44SJohn Forte 	case GROUP_1536:
5630fcf3ce44SJohn Forte 		plen = 192;
5631fcf3ce44SJohn Forte 		tmp = dhgp3_pVal;
5632fcf3ce44SJohn Forte 		break;
5633fcf3ce44SJohn Forte 
5634fcf3ce44SJohn Forte 	case GROUP_2048:
5635fcf3ce44SJohn Forte 		plen = 256;
5636fcf3ce44SJohn Forte 		tmp = dhgp4_pVal;
5637fcf3ce44SJohn Forte 		break;
5638fcf3ce44SJohn Forte 	}
5639fcf3ce44SJohn Forte 
5640fcf3ce44SJohn Forte 	if (big_init(&n, CHARLEN2BIGNUMLEN(plen)) != BIG_OK) {
5641fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
5642*8f23e9faSHans Rosenfeld 		    "BIGNUM_get_pubkey: big_init failed. n size=%d",
5643fcf3ce44SJohn Forte 		    CHARLEN2BIGNUMLEN(plen));
5644fcf3ce44SJohn Forte 		err = BIG_NO_MEM;
5645fcf3ce44SJohn Forte 		goto ret2;
5646fcf3ce44SJohn Forte 	}
5647fcf3ce44SJohn Forte 	bytestring2bignum(&n, (unsigned char *)tmp, plen);
5648fcf3ce44SJohn Forte 
5649fcf3ce44SJohn Forte 	if (big_init(&result, CHARLEN2BIGNUMLEN(512)) != BIG_OK) {
5650fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
5651*8f23e9faSHans Rosenfeld 		    "BIGNUM_get_pubkey: big_init failed. result size=%d",
5652fcf3ce44SJohn Forte 		    CHARLEN2BIGNUMLEN(512));
5653fcf3ce44SJohn Forte 
5654fcf3ce44SJohn Forte 		err = BIG_NO_MEM;
5655fcf3ce44SJohn Forte 		goto ret3;
5656fcf3ce44SJohn Forte 	}
5657fcf3ce44SJohn Forte 	if (big_cmp_abs(&a, &n) > 0) {
5658fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
5659*8f23e9faSHans Rosenfeld 		    "BIGNUM_get_pubkey: big_cmp_abs error.");
5660fcf3ce44SJohn Forte 		err = BIG_GENERAL_ERR;
5661fcf3ce44SJohn Forte 		goto ret4;
5662fcf3ce44SJohn Forte 	}
5663fcf3ce44SJohn Forte 	/* perform computation on big numbers to get seskey  */
5664fcf3ce44SJohn Forte 	/* a^e mod n */
5665fcf3ce44SJohn Forte 	/* i.e., (g^x mod p)^y mod p  */
5666fcf3ce44SJohn Forte 
5667fcf3ce44SJohn Forte 	if (big_modexp(&result, &a, &e, &n, NULL) != BIG_OK) {
5668fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
5669*8f23e9faSHans Rosenfeld 		    "BIGNUM_get_pubkey: big_modexp result error");
5670fcf3ce44SJohn Forte 		err = BIG_NO_MEM;
5671fcf3ce44SJohn Forte 		goto ret4;
5672fcf3ce44SJohn Forte 	}
5673fcf3ce44SJohn Forte 	/* convert big number ses_key to bytestring */
567482527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
5675fcf3ce44SJohn Forte 		/*
5676fcf3ce44SJohn Forte 		 * This call converts from big number format to
5677fcf3ce44SJohn Forte 		 * byte-big-endian format. big number format is words in
5678fcf3ce44SJohn Forte 		 * little endian order, but bytes within words in native byte
5679fcf3ce44SJohn Forte 		 * order
5680fcf3ce44SJohn Forte 		 */
5681fcf3ce44SJohn Forte 		bignum2bytestring(node_dhc->ses_key, &result,
5682fcf3ce44SJohn Forte 		    sizeof (BIG_CHUNK_TYPE) * (result.len));
5683fcf3ce44SJohn Forte 		node_dhc->seskey_len = sizeof (BIG_CHUNK_TYPE) * (result.len);
5684fcf3ce44SJohn Forte 
5685fcf3ce44SJohn Forte 		/* we can store another copy in ndlp */
5686fcf3ce44SJohn Forte 		bignum2bytestring(node_dhc->nlp_auth_misc.ses_key, &result,
5687fcf3ce44SJohn Forte 		    sizeof (BIG_CHUNK_TYPE) * (result.len));
5688fcf3ce44SJohn Forte 		node_dhc->nlp_auth_misc.seskey_len =
5689fcf3ce44SJohn Forte 		    sizeof (BIG_CHUNK_TYPE) * (result.len);
5690fcf3ce44SJohn Forte 	} else {
5691fcf3ce44SJohn Forte 		/* for end-to-end auth */
5692fcf3ce44SJohn Forte 		bignum2bytestring(node_dhc->nlp_auth_misc.ses_key, &result,
5693fcf3ce44SJohn Forte 		    sizeof (BIG_CHUNK_TYPE) * (result.len));
5694fcf3ce44SJohn Forte 		node_dhc->nlp_auth_misc.seskey_len =
5695fcf3ce44SJohn Forte 		    sizeof (BIG_CHUNK_TYPE) * (result.len);
5696fcf3ce44SJohn Forte 	}
5697fcf3ce44SJohn Forte 
5698fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
5699*8f23e9faSHans Rosenfeld 	    "BIGNUM_get_pubkey: after seskey cal: 0x%x 0x%x 0x%x",
5700fcf3ce44SJohn Forte 	    node_dhc->nlp_auth_misc.seskey_len, result.size, result.len);
5701fcf3ce44SJohn Forte 
5702fcf3ce44SJohn Forte 
5703fcf3ce44SJohn Forte 	/* to get pub_key: g^y mod p, g is 2 */
5704fcf3ce44SJohn Forte 
5705fcf3ce44SJohn Forte 	if (big_init(&g, 1) != BIG_OK) {
5706fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
5707*8f23e9faSHans Rosenfeld 		    "BIGNUM_get_pubkey: big_init failed. g size=1");
5708fcf3ce44SJohn Forte 
5709fcf3ce44SJohn Forte 		err = BIG_NO_MEM;
5710fcf3ce44SJohn Forte 		goto ret4;
5711fcf3ce44SJohn Forte 	}
5712fcf3ce44SJohn Forte 	if (big_init(&result1, CHARLEN2BIGNUMLEN(512)) != BIG_OK) {
5713fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
5714*8f23e9faSHans Rosenfeld 		    "BIGNUM_get_pubkey: big_init failed. result1 size=%d",
5715fcf3ce44SJohn Forte 		    CHARLEN2BIGNUMLEN(512));
5716fcf3ce44SJohn Forte 		err = BIG_NO_MEM;
5717fcf3ce44SJohn Forte 		goto ret5;
5718fcf3ce44SJohn Forte 	}
5719fcf3ce44SJohn Forte 
5720fcf3ce44SJohn Forte 	bytestring2bignum(&g,
5721fcf3ce44SJohn Forte 	    (unsigned char *)&gen, sizeof (BIG_CHUNK_TYPE));
5722fcf3ce44SJohn Forte 
5723fcf3ce44SJohn Forte 	if (big_modexp(&result1, &g, &e, &n, NULL) != BIG_OK) {
5724fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
5725*8f23e9faSHans Rosenfeld 		    "BIGNUM_get_pubkey: big_modexp result1 error");
5726fcf3ce44SJohn Forte 		err = BIG_NO_MEM;
5727fcf3ce44SJohn Forte 		goto ret6;
5728fcf3ce44SJohn Forte 	}
5729fcf3ce44SJohn Forte 	/* convert big number pub_key to bytestring */
573082527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
5731fcf3ce44SJohn Forte 
5732fcf3ce44SJohn Forte 		bignum2bytestring(node_dhc->pub_key, &result1,
5733fcf3ce44SJohn Forte 		    sizeof (BIG_CHUNK_TYPE) * (result1.len));
5734fcf3ce44SJohn Forte 		node_dhc->pubkey_len = (result1.len) * sizeof (BIG_CHUNK_TYPE);
5735fcf3ce44SJohn Forte 
5736fcf3ce44SJohn Forte 		/* save another copy in ndlp */
5737fcf3ce44SJohn Forte 		bignum2bytestring(node_dhc->nlp_auth_misc.pub_key, &result1,
5738fcf3ce44SJohn Forte 		    sizeof (BIG_CHUNK_TYPE) * (result1.len));
5739fcf3ce44SJohn Forte 		node_dhc->nlp_auth_misc.pubkey_len =
5740fcf3ce44SJohn Forte 		    (result1.len) * sizeof (BIG_CHUNK_TYPE);
5741fcf3ce44SJohn Forte 
5742fcf3ce44SJohn Forte 	} else {
5743fcf3ce44SJohn Forte 		/* for end-to-end auth */
5744fcf3ce44SJohn Forte 		bignum2bytestring(node_dhc->nlp_auth_misc.pub_key, &result1,
5745fcf3ce44SJohn Forte 		    sizeof (BIG_CHUNK_TYPE) * (result1.len));
5746fcf3ce44SJohn Forte 		node_dhc->nlp_auth_misc.pubkey_len =
5747fcf3ce44SJohn Forte 		    (result1.len) * sizeof (BIG_CHUNK_TYPE);
5748fcf3ce44SJohn Forte 	}
5749fcf3ce44SJohn Forte 
5750fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
5751*8f23e9faSHans Rosenfeld 	    "BIGNUM_get_pubkey: after pubkey cal: 0x%x 0x%x 0x%x",
5752fcf3ce44SJohn Forte 	    node_dhc->nlp_auth_misc.pubkey_len, result1.size, result1.len);
5753fcf3ce44SJohn Forte 
5754fcf3ce44SJohn Forte 
5755fcf3ce44SJohn Forte ret6:
5756fcf3ce44SJohn Forte 	big_finish(&result1);
5757fcf3ce44SJohn Forte ret5:
5758fcf3ce44SJohn Forte 	big_finish(&g);
5759fcf3ce44SJohn Forte ret4:
5760fcf3ce44SJohn Forte 	big_finish(&result);
5761fcf3ce44SJohn Forte ret3:
5762fcf3ce44SJohn Forte 	big_finish(&n);
5763fcf3ce44SJohn Forte ret2:
5764fcf3ce44SJohn Forte 	big_finish(&e);
5765fcf3ce44SJohn Forte ret1:
5766fcf3ce44SJohn Forte 	big_finish(&a);
5767fcf3ce44SJohn Forte 
5768fcf3ce44SJohn Forte 	return (err);
5769fcf3ce44SJohn Forte 
5770fcf3ce44SJohn Forte } /* emlxs_BIGNUM_get_pubkey */
5771fcf3ce44SJohn Forte 
5772fcf3ce44SJohn Forte 
5773fcf3ce44SJohn Forte /*
5774fcf3ce44SJohn Forte  * g^x mod p x is the priv_key g and p are wellknow based on dhgp_id
5775fcf3ce44SJohn Forte  */
5776fcf3ce44SJohn Forte /* ARGSUSED */
5777fcf3ce44SJohn Forte static BIG_ERR_CODE
emlxs_BIGNUM_get_dhval(emlxs_port_t * port,emlxs_port_dhc_t * port_dhc,NODELIST * ndlp,uint8_t * dhval,uint32_t * dhval_len,uint32_t dhgp_id,uint8_t * priv_key,uint32_t privkey_len)5778fcf3ce44SJohn Forte emlxs_BIGNUM_get_dhval(
5779fcf3ce44SJohn Forte emlxs_port_t *port,
5780fcf3ce44SJohn Forte emlxs_port_dhc_t *port_dhc,
5781fcf3ce44SJohn Forte NODELIST *ndlp,
5782fcf3ce44SJohn Forte uint8_t *dhval,
5783fcf3ce44SJohn Forte uint32_t *dhval_len,
5784fcf3ce44SJohn Forte uint32_t dhgp_id,
5785fcf3ce44SJohn Forte uint8_t *priv_key,
5786fcf3ce44SJohn Forte uint32_t privkey_len)
5787fcf3ce44SJohn Forte {
5788fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
5789fcf3ce44SJohn Forte 	BIGNUM g, e, n, result1;
5790fcf3ce44SJohn Forte 	uint32_t plen;
5791fcf3ce44SJohn Forte 	unsigned char *tmp = NULL;
5792fcf3ce44SJohn Forte 
5793fcf3ce44SJohn Forte #ifdef BIGNUM_CHUNK_32
5794fcf3ce44SJohn Forte 	uint8_t gen[] = {0x00, 0x00, 0x00, 0x02};
5795fcf3ce44SJohn Forte #else
5796fcf3ce44SJohn Forte 	uint8_t gen[] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02};
5797fcf3ce44SJohn Forte #endif /* BIGNUM_CHUNK_32 */
5798fcf3ce44SJohn Forte 
5799fcf3ce44SJohn Forte 	BIG_ERR_CODE err = BIG_OK;
5800fcf3ce44SJohn Forte 
5801fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
5802*8f23e9faSHans Rosenfeld 	    "BIGNUM_get_dhval: did=0x%x privkey_len=0x%x dhgp_id=0x%x",
5803fcf3ce44SJohn Forte 	    ndlp->nlp_DID, privkey_len, dhgp_id);
5804fcf3ce44SJohn Forte 
5805fcf3ce44SJohn Forte 	if (big_init(&result1, CHARLEN2BIGNUMLEN(512)) != BIG_OK) {
5806fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
5807*8f23e9faSHans Rosenfeld 		    "BIGNUM_get_dhval: big_init failed. result1 size=%d",
5808fcf3ce44SJohn Forte 		    CHARLEN2BIGNUMLEN(512));
5809fcf3ce44SJohn Forte 
5810fcf3ce44SJohn Forte 		err = BIG_NO_MEM;
5811fcf3ce44SJohn Forte 		return (err);
5812fcf3ce44SJohn Forte 	}
5813fcf3ce44SJohn Forte 	if (big_init(&g, 1) != BIG_OK) {
5814fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
5815*8f23e9faSHans Rosenfeld 		    "BIGNUM_get_dhval: big_init failed. g size=1");
5816fcf3ce44SJohn Forte 
5817fcf3ce44SJohn Forte 		err = BIG_NO_MEM;
5818fcf3ce44SJohn Forte 		goto ret1;
5819fcf3ce44SJohn Forte 	}
5820fcf3ce44SJohn Forte 	/* get g */
5821fcf3ce44SJohn Forte 	bytestring2bignum(&g, (unsigned char *)gen, sizeof (BIG_CHUNK_TYPE));
5822fcf3ce44SJohn Forte 
5823fcf3ce44SJohn Forte 	if (big_init(&e, CHARLEN2BIGNUMLEN(privkey_len)) != BIG_OK) {
5824fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
5825*8f23e9faSHans Rosenfeld 		    "BIGNUM_get_dhval: big_init failed. e size=%d",
5826fcf3ce44SJohn Forte 		    CHARLEN2BIGNUMLEN(privkey_len));
5827fcf3ce44SJohn Forte 
5828fcf3ce44SJohn Forte 		err = BIG_NO_MEM;
5829fcf3ce44SJohn Forte 		goto ret2;
5830fcf3ce44SJohn Forte 	}
5831fcf3ce44SJohn Forte 	/* get x */
5832fcf3ce44SJohn Forte 	bytestring2bignum(&e, (unsigned char *)priv_key, privkey_len);
5833fcf3ce44SJohn Forte 
5834fcf3ce44SJohn Forte 	switch (dhgp_id) {
5835fcf3ce44SJohn Forte 	case GROUP_1024:
5836fcf3ce44SJohn Forte 		plen = 128;
5837fcf3ce44SJohn Forte 		tmp = dhgp1_pVal;
5838fcf3ce44SJohn Forte 		break;
5839fcf3ce44SJohn Forte 
5840fcf3ce44SJohn Forte 	case GROUP_1280:
5841fcf3ce44SJohn Forte 		plen = 160;
5842fcf3ce44SJohn Forte 		tmp = dhgp2_pVal;
5843fcf3ce44SJohn Forte 		break;
5844fcf3ce44SJohn Forte 
5845fcf3ce44SJohn Forte 	case GROUP_1536:
5846fcf3ce44SJohn Forte 		plen = 192;
5847fcf3ce44SJohn Forte 		tmp = dhgp3_pVal;
5848fcf3ce44SJohn Forte 		break;
5849fcf3ce44SJohn Forte 
5850fcf3ce44SJohn Forte 	case GROUP_2048:
5851fcf3ce44SJohn Forte 		plen = 256;
5852fcf3ce44SJohn Forte 		tmp = dhgp4_pVal;
5853fcf3ce44SJohn Forte 		break;
5854fcf3ce44SJohn Forte 	}
5855fcf3ce44SJohn Forte 
5856fcf3ce44SJohn Forte 	if (big_init(&n, CHARLEN2BIGNUMLEN(plen)) != BIG_OK) {
5857fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
5858*8f23e9faSHans Rosenfeld 		    "BIGNUM_get_dhval: big_init failed. n size=%d",
5859fcf3ce44SJohn Forte 		    CHARLEN2BIGNUMLEN(plen));
5860fcf3ce44SJohn Forte 
5861fcf3ce44SJohn Forte 		err = BIG_NO_MEM;
5862fcf3ce44SJohn Forte 		goto ret3;
5863fcf3ce44SJohn Forte 	}
5864fcf3ce44SJohn Forte 	/* get p */
5865fcf3ce44SJohn Forte 	bytestring2bignum(&n, (unsigned char *)tmp, plen);
5866fcf3ce44SJohn Forte 
5867fcf3ce44SJohn Forte 	/* to cal: (g^x mod p) */
5868fcf3ce44SJohn Forte 	if (big_modexp(&result1, &g, &e, &n, NULL) != BIG_OK) {
5869fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
5870*8f23e9faSHans Rosenfeld 		    "BIGNUM_get_dhval: big_modexp result1 error");
5871fcf3ce44SJohn Forte 
5872fcf3ce44SJohn Forte 		err = BIG_GENERAL_ERR;
5873fcf3ce44SJohn Forte 		goto ret4;
5874fcf3ce44SJohn Forte 	}
5875fcf3ce44SJohn Forte 	/* convert big number pub_key to bytestring */
587682527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
5877fcf3ce44SJohn Forte 		bignum2bytestring(node_dhc->hrsp_pub_key, &result1,
5878fcf3ce44SJohn Forte 		    sizeof (BIG_CHUNK_TYPE) * (result1.len));
5879fcf3ce44SJohn Forte 		node_dhc->hrsp_pubkey_len =
5880fcf3ce44SJohn Forte 		    (result1.len) * sizeof (BIG_CHUNK_TYPE);
5881fcf3ce44SJohn Forte 
5882fcf3ce44SJohn Forte 		/* save another copy in partner's ndlp */
5883fcf3ce44SJohn Forte 		bignum2bytestring(node_dhc->nlp_auth_misc.hrsp_pub_key,
5884fcf3ce44SJohn Forte 		    &result1,
5885fcf3ce44SJohn Forte 		    sizeof (BIG_CHUNK_TYPE) * (result1.len));
5886fcf3ce44SJohn Forte 
5887fcf3ce44SJohn Forte 		node_dhc->nlp_auth_misc.hrsp_pubkey_len =
5888fcf3ce44SJohn Forte 		    (result1.len) * sizeof (BIG_CHUNK_TYPE);
5889fcf3ce44SJohn Forte 	} else {
5890fcf3ce44SJohn Forte 		bignum2bytestring(node_dhc->nlp_auth_misc.hrsp_pub_key,
5891fcf3ce44SJohn Forte 		    &result1,
5892fcf3ce44SJohn Forte 		    sizeof (BIG_CHUNK_TYPE) * (result1.len));
5893fcf3ce44SJohn Forte 		node_dhc->nlp_auth_misc.hrsp_pubkey_len =
5894fcf3ce44SJohn Forte 		    (result1.len) * sizeof (BIG_CHUNK_TYPE);
5895fcf3ce44SJohn Forte 	}
5896fcf3ce44SJohn Forte 
5897fcf3ce44SJohn Forte 
589882527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
5899fcf3ce44SJohn Forte 		bcopy((void *)node_dhc->hrsp_pub_key, (void *)dhval,
5900fcf3ce44SJohn Forte 		    node_dhc->hrsp_pubkey_len);
5901fcf3ce44SJohn Forte 	} else {
5902fcf3ce44SJohn Forte 		bcopy((void *)node_dhc->nlp_auth_misc.hrsp_pub_key,
5903fcf3ce44SJohn Forte 		    (void *)dhval,
5904fcf3ce44SJohn Forte 		    node_dhc->nlp_auth_misc.hrsp_pubkey_len);
5905fcf3ce44SJohn Forte 	}
5906fcf3ce44SJohn Forte 
5907fcf3ce44SJohn Forte 	*(uint32_t *)dhval_len = (result1.len) * sizeof (BIG_CHUNK_TYPE);
5908fcf3ce44SJohn Forte 
5909fcf3ce44SJohn Forte 
5910fcf3ce44SJohn Forte ret4:
5911fcf3ce44SJohn Forte 	big_finish(&result1);
5912fcf3ce44SJohn Forte ret3:
5913fcf3ce44SJohn Forte 	big_finish(&e);
5914fcf3ce44SJohn Forte ret2:
5915fcf3ce44SJohn Forte 	big_finish(&n);
5916fcf3ce44SJohn Forte ret1:
5917fcf3ce44SJohn Forte 	big_finish(&g);
5918fcf3ce44SJohn Forte 
5919fcf3ce44SJohn Forte 	return (err);
5920fcf3ce44SJohn Forte 
5921fcf3ce44SJohn Forte } /* emlxs_BIGNUM_get_dhval */
5922fcf3ce44SJohn Forte 
5923fcf3ce44SJohn Forte 
5924fcf3ce44SJohn Forte /*
5925fcf3ce44SJohn Forte  * to get ((g^y mod p)^x mod p) a^e mod n
5926fcf3ce44SJohn Forte  */
5927fcf3ce44SJohn Forte BIG_ERR_CODE
emlxs_BIGNUM_pubkey(emlxs_port_t * port,void * pubkey,uint8_t * dhval,uint32_t dhvallen,uint8_t * key,uint32_t key_size,uint32_t dhgp_id,uint32_t * pubkeylen)5928fcf3ce44SJohn Forte emlxs_BIGNUM_pubkey(
5929fcf3ce44SJohn Forte 		    emlxs_port_t *port,
5930fcf3ce44SJohn Forte 		    void *pubkey,
5931fcf3ce44SJohn Forte 		    uint8_t *dhval,	/* g^y mod p */
5932fcf3ce44SJohn Forte 		    uint32_t dhvallen,
5933fcf3ce44SJohn Forte 		    uint8_t *key,	/* x */
5934fcf3ce44SJohn Forte 		    uint32_t key_size,
5935fcf3ce44SJohn Forte 		    uint32_t dhgp_id,
5936fcf3ce44SJohn Forte 		    uint32_t *pubkeylen)
5937fcf3ce44SJohn Forte {
5938fcf3ce44SJohn Forte 	BIGNUM a, e, n, result;
5939fcf3ce44SJohn Forte 	uint32_t plen;
5940fcf3ce44SJohn Forte 	unsigned char *tmp = NULL;
5941fcf3ce44SJohn Forte 	BIG_ERR_CODE err = BIG_OK;
5942fcf3ce44SJohn Forte 
5943fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
5944*8f23e9faSHans Rosenfeld 	    "BIGNUM_pubkey: dhvallen=0x%x dhgp_id=0x%x",
5945fcf3ce44SJohn Forte 	    dhvallen, dhgp_id);
5946fcf3ce44SJohn Forte 
5947fcf3ce44SJohn Forte 	if (big_init(&a, CHARLEN2BIGNUMLEN(dhvallen)) != BIG_OK) {
5948fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
5949*8f23e9faSHans Rosenfeld 		    "BIGNUM_pubkey: big_init failed. a size=%d",
5950fcf3ce44SJohn Forte 		    CHARLEN2BIGNUMLEN(dhvallen));
5951fcf3ce44SJohn Forte 
5952fcf3ce44SJohn Forte 		err = BIG_NO_MEM;
5953fcf3ce44SJohn Forte 		return (err);
5954fcf3ce44SJohn Forte 	}
5955fcf3ce44SJohn Forte 	/* get g^y mod p */
5956fcf3ce44SJohn Forte 	bytestring2bignum(&a, (unsigned char *)dhval, dhvallen);
5957fcf3ce44SJohn Forte 
5958fcf3ce44SJohn Forte 	if (big_init(&e, CHARLEN2BIGNUMLEN(key_size)) != BIG_OK) {
5959fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
5960*8f23e9faSHans Rosenfeld 		    "BIGNUM_pubkey: big_init failed. e size=%d",
5961fcf3ce44SJohn Forte 		    CHARLEN2BIGNUMLEN(key_size));
5962fcf3ce44SJohn Forte 
5963fcf3ce44SJohn Forte 		err = BIG_NO_MEM;
5964fcf3ce44SJohn Forte 		goto ret1;
5965fcf3ce44SJohn Forte 	}
5966fcf3ce44SJohn Forte 	/* get x */
5967fcf3ce44SJohn Forte 	bytestring2bignum(&e, (unsigned char *)key, key_size);
5968fcf3ce44SJohn Forte 
5969fcf3ce44SJohn Forte 	switch (dhgp_id) {
5970fcf3ce44SJohn Forte 	case GROUP_1024:
5971fcf3ce44SJohn Forte 		plen = 128;
5972fcf3ce44SJohn Forte 		tmp = dhgp1_pVal;
5973fcf3ce44SJohn Forte 		break;
5974fcf3ce44SJohn Forte 
5975fcf3ce44SJohn Forte 	case GROUP_1280:
5976fcf3ce44SJohn Forte 		plen = 160;
5977fcf3ce44SJohn Forte 		tmp = dhgp2_pVal;
5978fcf3ce44SJohn Forte 		break;
5979fcf3ce44SJohn Forte 
5980fcf3ce44SJohn Forte 	case GROUP_1536:
5981fcf3ce44SJohn Forte 		plen = 192;
5982fcf3ce44SJohn Forte 		tmp = dhgp3_pVal;
5983fcf3ce44SJohn Forte 		break;
5984fcf3ce44SJohn Forte 
5985fcf3ce44SJohn Forte 	case GROUP_2048:
5986fcf3ce44SJohn Forte 		plen = 256;
5987fcf3ce44SJohn Forte 		tmp = dhgp4_pVal;
5988fcf3ce44SJohn Forte 		break;
5989fcf3ce44SJohn Forte 	}
5990fcf3ce44SJohn Forte 
5991fcf3ce44SJohn Forte 	if (big_init(&n, CHARLEN2BIGNUMLEN(plen)) != BIG_OK) {
5992fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
5993*8f23e9faSHans Rosenfeld 		    "BIGNUM_pubkey: big_init failed. n size=%d",
5994fcf3ce44SJohn Forte 		    CHARLEN2BIGNUMLEN(plen));
5995fcf3ce44SJohn Forte 
5996fcf3ce44SJohn Forte 		err = BIG_NO_MEM;
5997fcf3ce44SJohn Forte 		goto ret2;
5998fcf3ce44SJohn Forte 	}
5999fcf3ce44SJohn Forte 	bytestring2bignum(&n, (unsigned char *)tmp, plen);
6000fcf3ce44SJohn Forte 
6001fcf3ce44SJohn Forte 	if (big_init(&result, CHARLEN2BIGNUMLEN(512)) != BIG_OK) {
6002fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
6003*8f23e9faSHans Rosenfeld 		    "BIGNUM_pubkey: big_init failed. result size=%d",
6004fcf3ce44SJohn Forte 		    CHARLEN2BIGNUMLEN(512));
6005fcf3ce44SJohn Forte 
6006fcf3ce44SJohn Forte 		err = BIG_NO_MEM;
6007fcf3ce44SJohn Forte 		goto ret3;
6008fcf3ce44SJohn Forte 	}
6009fcf3ce44SJohn Forte 	if (big_cmp_abs(&a, &n) > 0) {
6010fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
6011*8f23e9faSHans Rosenfeld 		    "BIGNUM_pubkey: big_cmp_abs error");
6012fcf3ce44SJohn Forte 
6013fcf3ce44SJohn Forte 		err = BIG_GENERAL_ERR;
6014fcf3ce44SJohn Forte 		goto ret4;
6015fcf3ce44SJohn Forte 	}
6016fcf3ce44SJohn Forte 	if (big_modexp(&result, &a, &e, &n, NULL) != BIG_OK) {
6017fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
6018*8f23e9faSHans Rosenfeld 		    "BIGNUM_pubkey: big_modexp result error");
6019fcf3ce44SJohn Forte 
6020fcf3ce44SJohn Forte 		err = BIG_NO_MEM;
6021fcf3ce44SJohn Forte 		goto ret4;
6022fcf3ce44SJohn Forte 	}
6023fcf3ce44SJohn Forte 	bignum2bytestring(pubkey, &result,
6024fcf3ce44SJohn Forte 	    sizeof (BIG_CHUNK_TYPE) * (result.len));
6025fcf3ce44SJohn Forte 	*pubkeylen = sizeof (BIG_CHUNK_TYPE) * (result.len);
6026fcf3ce44SJohn Forte 
6027fcf3ce44SJohn Forte 	/* This pubkey is actually session key */
6028fcf3ce44SJohn Forte 
6029fcf3ce44SJohn Forte ret4:
6030fcf3ce44SJohn Forte 	big_finish(&result);
6031fcf3ce44SJohn Forte ret3:
6032fcf3ce44SJohn Forte 	big_finish(&n);
6033fcf3ce44SJohn Forte ret2:
6034fcf3ce44SJohn Forte 	big_finish(&e);
6035fcf3ce44SJohn Forte ret1:
6036fcf3ce44SJohn Forte 	big_finish(&a);
6037fcf3ce44SJohn Forte 
6038fcf3ce44SJohn Forte 	return (err);
6039fcf3ce44SJohn Forte 
6040fcf3ce44SJohn Forte } /* emlxs_BIGNUM_pubkey */
6041fcf3ce44SJohn Forte 
6042fcf3ce44SJohn Forte 
6043fcf3ce44SJohn Forte /*
6044fcf3ce44SJohn Forte  * key: x dhval: (g^y mod p) tran_id: Ti bi_cval: C2 hash_id: H dhgp_id: p/g
6045fcf3ce44SJohn Forte  *
6046fcf3ce44SJohn Forte  * Cai = H (C2 || ((g^y mod p)^x mod p) )
6047fcf3ce44SJohn Forte  *
6048fcf3ce44SJohn Forte  */
6049fcf3ce44SJohn Forte /* ARGSUSED */
6050fcf3ce44SJohn Forte BIG_ERR_CODE
emlxs_hash_Cai(emlxs_port_t * port,emlxs_port_dhc_t * port_dhc,NODELIST * ndlp,void * Cai,uint32_t hash_id,uint32_t dhgp_id,uint32_t tran_id,uint8_t * cval,uint32_t cval_len,uint8_t * key,uint8_t * dhval,uint32_t dhvallen)6051fcf3ce44SJohn Forte emlxs_hash_Cai(
6052fcf3ce44SJohn Forte 	emlxs_port_t *port,
6053fcf3ce44SJohn Forte 	emlxs_port_dhc_t *port_dhc,
6054fcf3ce44SJohn Forte 	NODELIST *ndlp,
6055fcf3ce44SJohn Forte 	void *Cai,
6056fcf3ce44SJohn Forte 	uint32_t hash_id,
6057fcf3ce44SJohn Forte 	uint32_t dhgp_id,
6058fcf3ce44SJohn Forte 	uint32_t tran_id,
6059fcf3ce44SJohn Forte 	uint8_t *cval,
6060fcf3ce44SJohn Forte 	uint32_t cval_len,
6061fcf3ce44SJohn Forte 	uint8_t *key,
6062fcf3ce44SJohn Forte 	uint8_t *dhval,
6063fcf3ce44SJohn Forte 	uint32_t dhvallen)
6064fcf3ce44SJohn Forte {
6065fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
6066fcf3ce44SJohn Forte 	MD5_CTX mdctx;
6067fcf3ce44SJohn Forte 	SHA1_CTX sha1ctx;
6068fcf3ce44SJohn Forte 	uint8_t sha1_digest[20];
6069fcf3ce44SJohn Forte 	uint8_t md5_digest[16];
6070fcf3ce44SJohn Forte 	uint8_t pubkey[512];
6071fcf3ce44SJohn Forte 	uint32_t pubkey_len = 0;
6072fcf3ce44SJohn Forte 	uint32_t key_size;
6073fcf3ce44SJohn Forte 	BIG_ERR_CODE err = BIG_OK;
6074fcf3ce44SJohn Forte 
6075fcf3ce44SJohn Forte 	key_size = cval_len;
6076fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
6077*8f23e9faSHans Rosenfeld 	    "hash_Cai: 0x%x 0x%x 0x%x 0x%x 0x%x",
6078fcf3ce44SJohn Forte 	    ndlp->nlp_DID, hash_id, dhgp_id, tran_id, dhvallen);
6079fcf3ce44SJohn Forte 
6080fcf3ce44SJohn Forte 	if (hash_id == AUTH_MD5) {
6081fcf3ce44SJohn Forte 		bzero(&mdctx, sizeof (MD5_CTX));
6082fcf3ce44SJohn Forte 		MD5Init(&mdctx);
6083fcf3ce44SJohn Forte 		MD5Update(&mdctx, (unsigned char *)cval, cval_len);
6084fcf3ce44SJohn Forte 
6085fcf3ce44SJohn Forte 		/* this pubkey obtained is actually the session key */
6086fcf3ce44SJohn Forte 		/*
6087fcf3ce44SJohn Forte 		 * pubkey: ((g^y mod p)^x mod p)
6088fcf3ce44SJohn Forte 		 */
6089fcf3ce44SJohn Forte 		err = emlxs_BIGNUM_pubkey(port, pubkey, dhval, dhvallen,
6090fcf3ce44SJohn Forte 		    key, key_size, dhgp_id, &pubkey_len);
6091fcf3ce44SJohn Forte 
6092fcf3ce44SJohn Forte 		if (err != BIG_OK) {
6093fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
6094*8f23e9faSHans Rosenfeld 			    "hash_Cai: MD5 BIGNUM_pubkey error: 0x%x",
6095fcf3ce44SJohn Forte 			    err);
6096fcf3ce44SJohn Forte 
6097fcf3ce44SJohn Forte 			err = BIG_GENERAL_ERR;
6098fcf3ce44SJohn Forte 			return (err);
6099fcf3ce44SJohn Forte 		}
6100fcf3ce44SJohn Forte 		if (pubkey_len == 0) {
6101fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
6102*8f23e9faSHans Rosenfeld 			    "hash_Cai: MD5 BIGNUM_pubkey error: len=0");
6103fcf3ce44SJohn Forte 
6104fcf3ce44SJohn Forte 			err = BIG_GENERAL_ERR;
6105fcf3ce44SJohn Forte 			return (err);
6106fcf3ce44SJohn Forte 		}
610782527734SSukumar Swaminathan 		if (ndlp->nlp_DID == FABRIC_DID) {
6108fcf3ce44SJohn Forte 			bcopy((void *)pubkey,
6109fcf3ce44SJohn Forte 			    (void *)node_dhc->hrsp_ses_key, pubkey_len);
6110fcf3ce44SJohn Forte 			node_dhc->hrsp_seskey_len = pubkey_len;
6111fcf3ce44SJohn Forte 
6112fcf3ce44SJohn Forte 			/* store extra copy */
6113fcf3ce44SJohn Forte 			bcopy((void *)pubkey,
6114fcf3ce44SJohn Forte 			    (void *)node_dhc->nlp_auth_misc.hrsp_ses_key,
6115fcf3ce44SJohn Forte 			    pubkey_len);
6116fcf3ce44SJohn Forte 			node_dhc->nlp_auth_misc.hrsp_seskey_len = pubkey_len;
6117fcf3ce44SJohn Forte 
6118fcf3ce44SJohn Forte 		} else {
6119fcf3ce44SJohn Forte 			bcopy((void *)pubkey,
6120fcf3ce44SJohn Forte 			    (void *)node_dhc->nlp_auth_misc.hrsp_ses_key,
6121fcf3ce44SJohn Forte 			    pubkey_len);
6122fcf3ce44SJohn Forte 			node_dhc->nlp_auth_misc.hrsp_seskey_len = pubkey_len;
6123fcf3ce44SJohn Forte 		}
6124fcf3ce44SJohn Forte 
6125fcf3ce44SJohn Forte 		MD5Update(&mdctx, (unsigned char *)pubkey, pubkey_len);
6126fcf3ce44SJohn Forte 		MD5Final((uint8_t *)md5_digest, &mdctx);
6127fcf3ce44SJohn Forte 		bcopy((void *)&md5_digest, (void *)Cai, MD5_LEN);
6128fcf3ce44SJohn Forte 	}
6129fcf3ce44SJohn Forte 	if (hash_id == AUTH_SHA1) {
6130fcf3ce44SJohn Forte 		bzero(&sha1ctx, sizeof (SHA1_CTX));
6131fcf3ce44SJohn Forte 		SHA1Init(&sha1ctx);
6132fcf3ce44SJohn Forte 
6133fcf3ce44SJohn Forte 		SHA1Update(&sha1ctx, (void *)cval, cval_len);
6134fcf3ce44SJohn Forte 
6135fcf3ce44SJohn Forte 		err = emlxs_BIGNUM_pubkey(port, pubkey, dhval, dhvallen,
6136fcf3ce44SJohn Forte 		    key, key_size, dhgp_id, &pubkey_len);
6137fcf3ce44SJohn Forte 
6138fcf3ce44SJohn Forte 		if (err != BIG_OK) {
6139fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
6140*8f23e9faSHans Rosenfeld 			    "hash_Cai: SHA1 BIGNUM_pubkey error: 0x%x",
6141fcf3ce44SJohn Forte 			    err);
6142fcf3ce44SJohn Forte 
6143fcf3ce44SJohn Forte 			err = BIG_GENERAL_ERR;
6144fcf3ce44SJohn Forte 			return (err);
6145fcf3ce44SJohn Forte 		}
6146fcf3ce44SJohn Forte 		if (pubkey_len == 0) {
6147fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
6148*8f23e9faSHans Rosenfeld 			    "hash_Cai: SA1 BUM_pubkey error: key_len=0");
6149fcf3ce44SJohn Forte 
6150fcf3ce44SJohn Forte 			err = BIG_GENERAL_ERR;
6151fcf3ce44SJohn Forte 			return (err);
6152fcf3ce44SJohn Forte 		}
615382527734SSukumar Swaminathan 		if (ndlp->nlp_DID == FABRIC_DID) {
6154fcf3ce44SJohn Forte 			bcopy((void *)pubkey,
6155fcf3ce44SJohn Forte 			    (void *)node_dhc->hrsp_ses_key,
6156fcf3ce44SJohn Forte 			    pubkey_len);
6157fcf3ce44SJohn Forte 			node_dhc->hrsp_seskey_len = pubkey_len;
6158fcf3ce44SJohn Forte 
6159fcf3ce44SJohn Forte 			/* store extra copy */
6160fcf3ce44SJohn Forte 			bcopy((void *)pubkey,
6161fcf3ce44SJohn Forte 			    (void *)node_dhc->nlp_auth_misc.hrsp_ses_key,
6162fcf3ce44SJohn Forte 			    pubkey_len);
6163fcf3ce44SJohn Forte 			node_dhc->nlp_auth_misc.hrsp_seskey_len = pubkey_len;
6164fcf3ce44SJohn Forte 
6165fcf3ce44SJohn Forte 		} else {
6166fcf3ce44SJohn Forte 			bcopy((void *)pubkey,
6167fcf3ce44SJohn Forte 			    (void *)node_dhc->nlp_auth_misc.hrsp_ses_key,
6168fcf3ce44SJohn Forte 			    pubkey_len);
6169fcf3ce44SJohn Forte 			node_dhc->nlp_auth_misc.hrsp_seskey_len = pubkey_len;
6170fcf3ce44SJohn Forte 		}
6171fcf3ce44SJohn Forte 
6172fcf3ce44SJohn Forte 		SHA1Update(&sha1ctx, (void *)pubkey, pubkey_len);
6173fcf3ce44SJohn Forte 		SHA1Final((void *)sha1_digest, &sha1ctx);
6174fcf3ce44SJohn Forte 		bcopy((void *)&sha1_digest, (void *)Cai, SHA1_LEN);
6175fcf3ce44SJohn Forte 	}
6176fcf3ce44SJohn Forte 	return (err);
6177fcf3ce44SJohn Forte 
6178fcf3ce44SJohn Forte } /* emlxs_hash_Cai */
6179fcf3ce44SJohn Forte 
6180fcf3ce44SJohn Forte 
6181fcf3ce44SJohn Forte /*
6182fcf3ce44SJohn Forte  * This routine is to verify the DHCHAP_Reply from initiator by the host
6183fcf3ce44SJohn Forte  * as the responder.
6184fcf3ce44SJohn Forte  *
6185fcf3ce44SJohn Forte  * flag: 1: if host is the responder 0: if host is the initiator
6186fcf3ce44SJohn Forte  *
6187fcf3ce44SJohn Forte  * if bi_cval != NULL, this routine is used to calculate the response based
6188fcf3ce44SJohn Forte  * on the challenge from initiator as part of
6189fcf3ce44SJohn Forte  * DHCHAP_Reply for bi-dirctional authentication.
6190fcf3ce44SJohn Forte  *
6191fcf3ce44SJohn Forte  */
6192fcf3ce44SJohn Forte /* ARGSUSED */
6193fcf3ce44SJohn Forte static uint32_t *
emlxs_hash_verification(emlxs_port_t * port,emlxs_port_dhc_t * port_dhc,NODELIST * ndlp,uint32_t tran_id,uint8_t * dhval,uint32_t dhval_len,uint32_t flag,uint8_t * bi_cval)6194fcf3ce44SJohn Forte emlxs_hash_verification(
6195fcf3ce44SJohn Forte 	emlxs_port_t *port,
6196fcf3ce44SJohn Forte 	emlxs_port_dhc_t *port_dhc,
6197fcf3ce44SJohn Forte 	NODELIST *ndlp,
6198fcf3ce44SJohn Forte 	uint32_t tran_id,
6199fcf3ce44SJohn Forte 	uint8_t *dhval,
6200fcf3ce44SJohn Forte 	uint32_t dhval_len,
6201fcf3ce44SJohn Forte 	uint32_t flag,	/* always 1 for now */
6202fcf3ce44SJohn Forte 	uint8_t *bi_cval)
6203fcf3ce44SJohn Forte {			/* always 0 for now */
6204fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
6205fcf3ce44SJohn Forte 	uint32_t dhgp_id;
6206fcf3ce44SJohn Forte 	uint32_t hash_id;
6207fcf3ce44SJohn Forte 	uint32_t *hash_val = NULL;
6208fcf3ce44SJohn Forte 	uint32_t hash_size;
6209fcf3ce44SJohn Forte 	MD5_CTX mdctx;
6210fcf3ce44SJohn Forte 	SHA1_CTX sha1ctx;
6211fcf3ce44SJohn Forte 	uint8_t sha1_digest[20];
6212fcf3ce44SJohn Forte 	uint8_t md5_digest[16];
6213fcf3ce44SJohn Forte 	uint8_t Cai[20];
6214fcf3ce44SJohn Forte 	/* union challenge_val un_cval; */
6215fcf3ce44SJohn Forte 	uint8_t key[20];
6216fcf3ce44SJohn Forte 	uint8_t cval[20];
6217fcf3ce44SJohn Forte 	uint32_t cval_len;
6218fcf3ce44SJohn Forte 	uint8_t mytran_id = 0x00;
6219fcf3ce44SJohn Forte 	char *remote_key;
6220fcf3ce44SJohn Forte 	BIG_ERR_CODE err = BIG_OK;
6221fcf3ce44SJohn Forte 
6222fcf3ce44SJohn Forte 	tran_id = (AUTH_TRAN_ID_MASK & tran_id);
622382527734SSukumar Swaminathan 	mytran_id = (uint8_t)(LE_SWAP32(tran_id));
6224fcf3ce44SJohn Forte 
622582527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
6226fcf3ce44SJohn Forte 		remote_key = (char *)node_dhc->auth_key.remote_password;
6227fcf3ce44SJohn Forte 	} else {
6228fcf3ce44SJohn Forte 		/*
6229fcf3ce44SJohn Forte 		 * in case of end-to-end auth, this remote password should be
6230fcf3ce44SJohn Forte 		 * the password associated with the remote entity. (i.e.,)
6231fcf3ce44SJohn Forte 		 * for now it is actually local_password.
6232fcf3ce44SJohn Forte 		 */
6233fcf3ce44SJohn Forte 		remote_key = (char *)node_dhc->auth_key.remote_password;
6234fcf3ce44SJohn Forte 	}
6235fcf3ce44SJohn Forte 
6236fcf3ce44SJohn Forte 	if (flag == 0) {
6237fcf3ce44SJohn Forte 		dhgp_id = node_dhc->dhgp_id;
6238fcf3ce44SJohn Forte 		hash_id = node_dhc->hash_id;
6239fcf3ce44SJohn Forte 	} else {
6240fcf3ce44SJohn Forte 		dhgp_id = node_dhc->nlp_auth_dhgpid;
6241fcf3ce44SJohn Forte 		hash_id = node_dhc->nlp_auth_hashid;
6242fcf3ce44SJohn Forte 	}
6243fcf3ce44SJohn Forte 
6244fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
6245*8f23e9faSHans Rosenfeld 	    "hash_verification: 0x%x 0x%x hash_id=0x%x dhgp_id=0x%x",
6246fcf3ce44SJohn Forte 	    ndlp->nlp_DID, mytran_id, hash_id, dhgp_id);
6247fcf3ce44SJohn Forte 
6248fcf3ce44SJohn Forte 	if (dhval_len == 0) {
6249fcf3ce44SJohn Forte 		/* NULL DHCHAP group */
6250fcf3ce44SJohn Forte 		if (hash_id == AUTH_MD5) {
6251fcf3ce44SJohn Forte 			bzero(&mdctx, sizeof (MD5_CTX));
6252fcf3ce44SJohn Forte 			hash_size = MD5_LEN;
6253fcf3ce44SJohn Forte 			MD5Init(&mdctx);
6254fcf3ce44SJohn Forte 
6255fcf3ce44SJohn Forte 			MD5Update(&mdctx, (unsigned char *)&mytran_id, 1);
6256fcf3ce44SJohn Forte 
625782527734SSukumar Swaminathan 			if (ndlp->nlp_DID == FABRIC_DID) {
6258fcf3ce44SJohn Forte 				MD5Update(&mdctx,
6259fcf3ce44SJohn Forte 				    (unsigned char *)remote_key,
6260fcf3ce44SJohn Forte 				    node_dhc->auth_key.remote_password_length);
6261fcf3ce44SJohn Forte 			} else {
6262fcf3ce44SJohn Forte 				MD5Update(&mdctx,
6263fcf3ce44SJohn Forte 				    (unsigned char *)remote_key,
6264fcf3ce44SJohn Forte 				    node_dhc->auth_key.remote_password_length);
6265fcf3ce44SJohn Forte 			}
6266fcf3ce44SJohn Forte 
626782527734SSukumar Swaminathan 			if (ndlp->nlp_DID == FABRIC_DID) {
6268fcf3ce44SJohn Forte 				MD5Update(&mdctx,
6269fcf3ce44SJohn Forte 				    (unsigned char *)&node_dhc->hrsp_cval[0],
6270fcf3ce44SJohn Forte 				    MD5_LEN);
6271fcf3ce44SJohn Forte 			} else {
6272fcf3ce44SJohn Forte 		MD5Update(&mdctx,
6273fcf3ce44SJohn Forte 		    (unsigned char *)&node_dhc->nlp_auth_misc.hrsp_cval[0],
6274fcf3ce44SJohn Forte 		    MD5_LEN);
6275fcf3ce44SJohn Forte 			}
6276fcf3ce44SJohn Forte 
6277fcf3ce44SJohn Forte 			MD5Final((uint8_t *)md5_digest, &mdctx);
6278fcf3ce44SJohn Forte 
6279fcf3ce44SJohn Forte 			hash_val = (uint32_t *)kmem_alloc(hash_size,
6280fcf3ce44SJohn Forte 			    KM_NOSLEEP);
6281fcf3ce44SJohn Forte 			if (hash_val == NULL) {
6282fcf3ce44SJohn Forte 				EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
6283*8f23e9faSHans Rosenfeld 				    "hash_verification: alloc failed");
6284fcf3ce44SJohn Forte 
6285fcf3ce44SJohn Forte 				return (NULL);
6286fcf3ce44SJohn Forte 			} else {
6287fcf3ce44SJohn Forte 				bcopy((void *)md5_digest,
6288fcf3ce44SJohn Forte 				    (void *)hash_val, MD5_LEN);
6289fcf3ce44SJohn Forte 			}
6290fcf3ce44SJohn Forte 		}
6291fcf3ce44SJohn Forte 		if (hash_id == AUTH_SHA1) {
6292fcf3ce44SJohn Forte 			bzero(&sha1ctx, sizeof (SHA1_CTX));
6293fcf3ce44SJohn Forte 			hash_size = SHA1_LEN;
6294fcf3ce44SJohn Forte 			SHA1Init(&sha1ctx);
6295fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx, (void *)&mytran_id, 1);
6296fcf3ce44SJohn Forte 
629782527734SSukumar Swaminathan 			if (ndlp->nlp_DID == FABRIC_DID) {
6298fcf3ce44SJohn Forte 				SHA1Update(&sha1ctx, (void *)remote_key,
6299fcf3ce44SJohn Forte 				    node_dhc->auth_key.remote_password_length);
6300fcf3ce44SJohn Forte 			} else {
6301fcf3ce44SJohn Forte 				SHA1Update(&sha1ctx, (void *)remote_key,
6302fcf3ce44SJohn Forte 				    node_dhc->auth_key.remote_password_length);
6303fcf3ce44SJohn Forte 			}
6304fcf3ce44SJohn Forte 
630582527734SSukumar Swaminathan 			if (ndlp->nlp_DID == FABRIC_DID) {
6306fcf3ce44SJohn Forte 				SHA1Update(&sha1ctx,
6307fcf3ce44SJohn Forte 				    (void *)&node_dhc->hrsp_cval[0],
6308fcf3ce44SJohn Forte 				    SHA1_LEN);
6309fcf3ce44SJohn Forte 			} else {
6310fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx,
6311fcf3ce44SJohn Forte 			    (void *)&node_dhc->nlp_auth_misc.hrsp_cval[0],
6312fcf3ce44SJohn Forte 			    SHA1_LEN);
6313fcf3ce44SJohn Forte 			}
6314fcf3ce44SJohn Forte 
6315fcf3ce44SJohn Forte 			SHA1Final((void *)sha1_digest, &sha1ctx);
6316fcf3ce44SJohn Forte 			hash_val = (uint32_t *)kmem_zalloc(hash_size,
6317fcf3ce44SJohn Forte 			    KM_NOSLEEP);
6318fcf3ce44SJohn Forte 			if (hash_val == NULL) {
6319fcf3ce44SJohn Forte 				EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
6320*8f23e9faSHans Rosenfeld 				    "hash_verification: alloc failed");
6321fcf3ce44SJohn Forte 
6322fcf3ce44SJohn Forte 				return (NULL);
6323fcf3ce44SJohn Forte 			} else {
6324fcf3ce44SJohn Forte 				bcopy((void *)sha1_digest,
6325fcf3ce44SJohn Forte 				    (void *)hash_val, SHA1_LEN);
6326fcf3ce44SJohn Forte 			}
6327fcf3ce44SJohn Forte 		}
6328fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
6329*8f23e9faSHans Rosenfeld 		    "hash_verification: hash_val=0x%x",
6330fcf3ce44SJohn Forte 		    *(uint32_t *)hash_val);
6331fcf3ce44SJohn Forte 
6332fcf3ce44SJohn Forte 		return ((uint32_t *)hash_val);
6333fcf3ce44SJohn Forte 	} else {
6334fcf3ce44SJohn Forte 
6335fcf3ce44SJohn Forte 		/* DHCHAP group 1,2,3,4 */
6336fcf3ce44SJohn Forte 		/*
6337fcf3ce44SJohn Forte 		 * host received (g^x mod p) as dhval host has its own
6338fcf3ce44SJohn Forte 		 * private key y as node_dhc->hrsp_priv_key[] host has its
6339fcf3ce44SJohn Forte 		 * original challenge c as node_dhc->hrsp_cval[]
6340fcf3ce44SJohn Forte 		 *
6341fcf3ce44SJohn Forte 		 * H(c || (g^x mod p)^y mod p) = Cai H(Ti || Km || Cai) =
6342fcf3ce44SJohn Forte 		 * hash_val returned. Ti : tran_id, Km : shared secret, Cai:
6343fcf3ce44SJohn Forte 		 * obtained above.
6344fcf3ce44SJohn Forte 		 */
6345fcf3ce44SJohn Forte 		if (hash_id == AUTH_MD5) {
634682527734SSukumar Swaminathan 			if (ndlp->nlp_DID == FABRIC_DID) {
6347fcf3ce44SJohn Forte 				bcopy((void *)node_dhc->hrsp_priv_key,
6348fcf3ce44SJohn Forte 				    (void *)key, MD5_LEN);
6349fcf3ce44SJohn Forte 			} else {
6350fcf3ce44SJohn Forte 			bcopy(
6351fcf3ce44SJohn Forte 			    (void *)node_dhc->nlp_auth_misc.hrsp_priv_key,
6352fcf3ce44SJohn Forte 			    (void *)key, MD5_LEN);
6353fcf3ce44SJohn Forte 			}
6354fcf3ce44SJohn Forte 		}
6355fcf3ce44SJohn Forte 		if (hash_id == AUTH_SHA1) {
635682527734SSukumar Swaminathan 			if (ndlp->nlp_DID == FABRIC_DID) {
6357fcf3ce44SJohn Forte 				bcopy((void *)node_dhc->hrsp_priv_key,
6358fcf3ce44SJohn Forte 				    (void *)key, SHA1_LEN);
6359fcf3ce44SJohn Forte 			} else {
6360fcf3ce44SJohn Forte 			bcopy(
6361fcf3ce44SJohn Forte 			    (void *)node_dhc->nlp_auth_misc.hrsp_priv_key,
6362fcf3ce44SJohn Forte 			    (void *)key, SHA1_LEN);
6363fcf3ce44SJohn Forte 			}
6364fcf3ce44SJohn Forte 		}
636582527734SSukumar Swaminathan 		if (ndlp->nlp_DID == FABRIC_DID) {
6366fcf3ce44SJohn Forte 			bcopy((void *)node_dhc->hrsp_cval,
6367fcf3ce44SJohn Forte 			    (void *)cval, node_dhc->hrsp_cval_len);
6368fcf3ce44SJohn Forte 			cval_len = node_dhc->hrsp_cval_len;
6369fcf3ce44SJohn Forte 		} else {
6370fcf3ce44SJohn Forte 			bcopy((void *)node_dhc->nlp_auth_misc.hrsp_cval,
6371fcf3ce44SJohn Forte 			    (void *)cval,
6372fcf3ce44SJohn Forte 			    node_dhc->nlp_auth_misc.hrsp_cval_len);
6373fcf3ce44SJohn Forte 			cval_len = node_dhc->nlp_auth_misc.hrsp_cval_len;
6374fcf3ce44SJohn Forte 		}
6375fcf3ce44SJohn Forte 
6376fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
6377*8f23e9faSHans Rosenfeld 		    "hash_verification: N-Null gp. 0x%x 0x%x",
6378fcf3ce44SJohn Forte 		    ndlp->nlp_DID, cval_len);
6379fcf3ce44SJohn Forte 
6380fcf3ce44SJohn Forte 		err = emlxs_hash_Cai(port, port_dhc, ndlp, (void *)Cai,
6381fcf3ce44SJohn Forte 		    hash_id, dhgp_id,
6382fcf3ce44SJohn Forte 		    tran_id, cval, cval_len,
6383fcf3ce44SJohn Forte 		    key, dhval, dhval_len);
6384fcf3ce44SJohn Forte 
6385fcf3ce44SJohn Forte 		if (err != BIG_OK) {
6386fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
6387*8f23e9faSHans Rosenfeld 			    "hash_verification: Cai error. ret=0x%x",
6388fcf3ce44SJohn Forte 			    err);
6389fcf3ce44SJohn Forte 
6390fcf3ce44SJohn Forte 			return (NULL);
6391fcf3ce44SJohn Forte 		}
6392fcf3ce44SJohn Forte 		if (hash_id == AUTH_MD5) {
6393fcf3ce44SJohn Forte 			bzero(&mdctx, sizeof (MD5_CTX));
6394fcf3ce44SJohn Forte 			hash_size = MD5_LEN;
6395fcf3ce44SJohn Forte 
6396fcf3ce44SJohn Forte 			MD5Init(&mdctx);
6397fcf3ce44SJohn Forte 			MD5Update(&mdctx, (unsigned char *)&mytran_id, 1);
6398fcf3ce44SJohn Forte 
639982527734SSukumar Swaminathan 			if (ndlp->nlp_DID == FABRIC_DID) {
6400fcf3ce44SJohn Forte 				MD5Update(&mdctx,
6401fcf3ce44SJohn Forte 				    (unsigned char *)remote_key,
6402fcf3ce44SJohn Forte 				    node_dhc->auth_key.remote_password_length);
6403fcf3ce44SJohn Forte 			} else {
6404fcf3ce44SJohn Forte 				MD5Update(&mdctx,
6405fcf3ce44SJohn Forte 				    (unsigned char *)remote_key,
6406fcf3ce44SJohn Forte 				    node_dhc->auth_key.remote_password_length);
6407fcf3ce44SJohn Forte 			}
6408fcf3ce44SJohn Forte 
6409fcf3ce44SJohn Forte 			MD5Update(&mdctx, (unsigned char *)Cai, MD5_LEN);
6410fcf3ce44SJohn Forte 			MD5Final((uint8_t *)md5_digest, &mdctx);
6411fcf3ce44SJohn Forte 
6412fcf3ce44SJohn Forte 			hash_val = (uint32_t *)kmem_zalloc(hash_size,
6413fcf3ce44SJohn Forte 			    KM_NOSLEEP);
6414fcf3ce44SJohn Forte 			if (hash_val == NULL) {
6415fcf3ce44SJohn Forte 				EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
6416*8f23e9faSHans Rosenfeld 				    "hash_vf: alloc failed(Non-NULL dh)");
6417fcf3ce44SJohn Forte 
6418fcf3ce44SJohn Forte 				return (NULL);
6419fcf3ce44SJohn Forte 			} else {
6420fcf3ce44SJohn Forte 				bcopy((void *)&md5_digest,
6421fcf3ce44SJohn Forte 				    (void *)hash_val, MD5_LEN);
6422fcf3ce44SJohn Forte 			}
6423fcf3ce44SJohn Forte 		}
6424fcf3ce44SJohn Forte 		if (hash_id == AUTH_SHA1) {
6425fcf3ce44SJohn Forte 			bzero(&sha1ctx, sizeof (SHA1_CTX));
6426fcf3ce44SJohn Forte 			hash_size = SHA1_LEN;
6427fcf3ce44SJohn Forte 
6428fcf3ce44SJohn Forte 			SHA1Init(&sha1ctx);
6429fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx, (void *)&mytran_id, 1);
6430fcf3ce44SJohn Forte 
643182527734SSukumar Swaminathan 			if (ndlp->nlp_DID == FABRIC_DID) {
6432fcf3ce44SJohn Forte 				SHA1Update(&sha1ctx, (void *)remote_key,
6433fcf3ce44SJohn Forte 				    node_dhc->auth_key.remote_password_length);
6434fcf3ce44SJohn Forte 			} else {
6435fcf3ce44SJohn Forte 				SHA1Update(&sha1ctx, (void *)remote_key,
6436fcf3ce44SJohn Forte 				    node_dhc->auth_key.remote_password_length);
6437fcf3ce44SJohn Forte 			}
6438fcf3ce44SJohn Forte 
6439fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx, (void *)Cai, SHA1_LEN);
6440fcf3ce44SJohn Forte 			SHA1Final((void *)sha1_digest, &sha1ctx);
6441fcf3ce44SJohn Forte 
6442fcf3ce44SJohn Forte 			hash_val = (uint32_t *)kmem_zalloc(hash_size,
6443fcf3ce44SJohn Forte 			    KM_NOSLEEP);
6444fcf3ce44SJohn Forte 			if (hash_val == NULL) {
6445fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
6446*8f23e9faSHans Rosenfeld 			    "hash_vf: val alloc failed (Non-NULL dh)");
6447fcf3ce44SJohn Forte 
6448fcf3ce44SJohn Forte 				return (NULL);
6449fcf3ce44SJohn Forte 			} else {
6450fcf3ce44SJohn Forte 				bcopy((void *)&sha1_digest,
6451fcf3ce44SJohn Forte 				    (void *)hash_val, SHA1_LEN);
6452fcf3ce44SJohn Forte 			}
6453fcf3ce44SJohn Forte 		}
6454fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
6455*8f23e9faSHans Rosenfeld 		    "hash_verification: hash_val=0x%x",
6456fcf3ce44SJohn Forte 		    *(uint32_t *)hash_val);
6457fcf3ce44SJohn Forte 
6458fcf3ce44SJohn Forte 		return ((uint32_t *)hash_val);
6459fcf3ce44SJohn Forte 	}
6460fcf3ce44SJohn Forte 
6461fcf3ce44SJohn Forte } /* emlxs_hash_verification */
6462fcf3ce44SJohn Forte 
6463fcf3ce44SJohn Forte 
6464fcf3ce44SJohn Forte 
6465fcf3ce44SJohn Forte /*
6466fcf3ce44SJohn Forte  * When DHCHAP_Success msg was sent from responder to the initiator,
6467fcf3ce44SJohn Forte  * with bi-directional authentication requested, the
6468fcf3ce44SJohn Forte  * DHCHAP_Success contains the response R2 to the challenge C2 received.
6469fcf3ce44SJohn Forte  *
6470fcf3ce44SJohn Forte  * DHCHAP response R2: The value of R2 is computed using the hash function
6471fcf3ce44SJohn Forte  * H() selected by the HashID parameter of the
6472fcf3ce44SJohn Forte  * DHCHAP_Challenge msg, and the augmented challenge Ca2.
6473fcf3ce44SJohn Forte  *
6474fcf3ce44SJohn Forte  * NULL DH group: Ca2 = C2 Non NULL DH group: Ca2 = H(C2 ||
6475fcf3ce44SJohn Forte  * (g^y mod p)^x mod p)) x is selected by the authentication responder
6476fcf3ce44SJohn Forte  * which is the node_dhc->hrsp_priv_key[] (g^y mod p) is dhval received
6477fcf3ce44SJohn Forte  * from authentication initiator.
6478fcf3ce44SJohn Forte  *
6479fcf3ce44SJohn Forte  * R2 = H(Ti || Km || Ca2) Ti is the least significant byte of the
6480fcf3ce44SJohn Forte  * transaction id. Km is the secret associated with the
6481fcf3ce44SJohn Forte  * authentication responder.
6482fcf3ce44SJohn Forte  *
6483fcf3ce44SJohn Forte  * emlxs_hash_get_R2 and emlxs_hash_verification could be mergerd into one
6484fcf3ce44SJohn Forte  * function later.
6485fcf3ce44SJohn Forte  *
6486fcf3ce44SJohn Forte  */
6487fcf3ce44SJohn Forte static uint32_t *
emlxs_hash_get_R2(emlxs_port_t * port,emlxs_port_dhc_t * port_dhc,NODELIST * ndlp,uint32_t tran_id,uint8_t * dhval,uint32_t dhval_len,uint32_t flag,uint8_t * bi_cval)6488fcf3ce44SJohn Forte emlxs_hash_get_R2(
6489fcf3ce44SJohn Forte 	emlxs_port_t *port,
6490fcf3ce44SJohn Forte 	emlxs_port_dhc_t *port_dhc,
6491fcf3ce44SJohn Forte 	NODELIST *ndlp,
6492fcf3ce44SJohn Forte 	uint32_t tran_id,
6493fcf3ce44SJohn Forte 	uint8_t *dhval,
6494fcf3ce44SJohn Forte 	uint32_t dhval_len,
6495fcf3ce44SJohn Forte 	uint32_t flag,	/* flag 1 rsponder or 0 initiator */
6496fcf3ce44SJohn Forte 	uint8_t *bi_cval)
6497fcf3ce44SJohn Forte {
6498fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
6499fcf3ce44SJohn Forte 
6500fcf3ce44SJohn Forte 	uint32_t dhgp_id;
6501fcf3ce44SJohn Forte 	uint32_t hash_id;
6502fcf3ce44SJohn Forte 	uint32_t *hash_val = NULL;
6503fcf3ce44SJohn Forte 	uint32_t hash_size;
6504fcf3ce44SJohn Forte 	MD5_CTX mdctx;
6505fcf3ce44SJohn Forte 	SHA1_CTX sha1ctx;
6506fcf3ce44SJohn Forte 	uint8_t sha1_digest[20];
6507fcf3ce44SJohn Forte 	uint8_t md5_digest[16];
6508fcf3ce44SJohn Forte 	uint8_t Cai[20];
6509fcf3ce44SJohn Forte 	/* union challenge_val un_cval; */
6510fcf3ce44SJohn Forte 	uint8_t key[20];
6511fcf3ce44SJohn Forte 	uint32_t cval_len;
6512fcf3ce44SJohn Forte 	uint8_t mytran_id = 0x00;
6513fcf3ce44SJohn Forte 
6514fcf3ce44SJohn Forte 	char *mykey;
6515fcf3ce44SJohn Forte 	BIG_ERR_CODE err = BIG_OK;
6516fcf3ce44SJohn Forte 
651782527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
6518fcf3ce44SJohn Forte 		dhgp_id = node_dhc->nlp_auth_dhgpid;
6519fcf3ce44SJohn Forte 		hash_id = node_dhc->nlp_auth_hashid;
6520fcf3ce44SJohn Forte 	} else {
6521fcf3ce44SJohn Forte 		if (flag == 0) {
6522fcf3ce44SJohn Forte 			dhgp_id = node_dhc->dhgp_id;
6523fcf3ce44SJohn Forte 			hash_id = node_dhc->hash_id;
6524fcf3ce44SJohn Forte 		} else {
6525fcf3ce44SJohn Forte 			dhgp_id = node_dhc->nlp_auth_dhgpid;
6526fcf3ce44SJohn Forte 			hash_id = node_dhc->nlp_auth_hashid;
6527fcf3ce44SJohn Forte 		}
6528fcf3ce44SJohn Forte 	}
6529fcf3ce44SJohn Forte 
6530fcf3ce44SJohn Forte 	tran_id = (AUTH_TRAN_ID_MASK & tran_id);
653182527734SSukumar Swaminathan 	mytran_id = (uint8_t)(LE_SWAP32(tran_id));
6532fcf3ce44SJohn Forte 
6533fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_detail_msg,
6534*8f23e9faSHans Rosenfeld 	    "hash_get_R2:0x%x 0x%x dhgp_id=0x%x mytran_id=0x%x",
6535fcf3ce44SJohn Forte 	    ndlp->nlp_DID, hash_id, dhgp_id, mytran_id);
6536fcf3ce44SJohn Forte 
653782527734SSukumar Swaminathan 	if (ndlp->nlp_DID == FABRIC_DID) {
6538fcf3ce44SJohn Forte 		mykey = (char *)node_dhc->auth_key.local_password;
6539fcf3ce44SJohn Forte 
6540fcf3ce44SJohn Forte 	} else {
6541fcf3ce44SJohn Forte 		/* in case of end-to-end mykey should be remote_password */
6542fcf3ce44SJohn Forte 		mykey = (char *)node_dhc->auth_key.remote_password;
6543fcf3ce44SJohn Forte 	}
6544fcf3ce44SJohn Forte 
6545fcf3ce44SJohn Forte 	if (dhval_len == 0) {
6546fcf3ce44SJohn Forte 		/* NULL DHCHAP group */
6547fcf3ce44SJohn Forte 		if (hash_id == AUTH_MD5) {
6548fcf3ce44SJohn Forte 			bzero(&mdctx, sizeof (MD5_CTX));
6549fcf3ce44SJohn Forte 			hash_size = MD5_LEN;
6550fcf3ce44SJohn Forte 			MD5Init(&mdctx);
6551fcf3ce44SJohn Forte 
6552fcf3ce44SJohn Forte 			MD5Update(&mdctx, (unsigned char *)&mytran_id, 1);
6553fcf3ce44SJohn Forte 
655482527734SSukumar Swaminathan 			if (ndlp->nlp_DID == FABRIC_DID) {
6555fcf3ce44SJohn Forte 				MD5Update(&mdctx, (unsigned char *)mykey,
6556fcf3ce44SJohn Forte 				    node_dhc->auth_key.local_password_length);
6557fcf3ce44SJohn Forte 			} else {
6558fcf3ce44SJohn Forte 				MD5Update(&mdctx, (unsigned char *)mykey,
6559fcf3ce44SJohn Forte 				    node_dhc->auth_key.remote_password_length);
6560fcf3ce44SJohn Forte 			}
6561fcf3ce44SJohn Forte 
6562fcf3ce44SJohn Forte 			MD5Update(&mdctx, (unsigned char *)bi_cval, MD5_LEN);
6563fcf3ce44SJohn Forte 
6564fcf3ce44SJohn Forte 			MD5Final((uint8_t *)md5_digest, &mdctx);
6565fcf3ce44SJohn Forte 
6566fcf3ce44SJohn Forte 			hash_val = (uint32_t *)kmem_alloc(hash_size,
6567fcf3ce44SJohn Forte 			    KM_NOSLEEP);
6568fcf3ce44SJohn Forte 			if (hash_val == NULL) {
6569fcf3ce44SJohn Forte 				return (NULL);
6570fcf3ce44SJohn Forte 			} else {
6571fcf3ce44SJohn Forte 				bcopy((void *)md5_digest,
6572fcf3ce44SJohn Forte 				    (void *)hash_val, MD5_LEN);
6573fcf3ce44SJohn Forte 			}
6574fcf3ce44SJohn Forte 		}
6575fcf3ce44SJohn Forte 		if (hash_id == AUTH_SHA1) {
6576fcf3ce44SJohn Forte 			bzero(&sha1ctx, sizeof (SHA1_CTX));
6577fcf3ce44SJohn Forte 			hash_size = SHA1_LEN;
6578fcf3ce44SJohn Forte 			SHA1Init(&sha1ctx);
6579fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx, (void *)&mytran_id, 1);
6580fcf3ce44SJohn Forte 
658182527734SSukumar Swaminathan 			if (ndlp->nlp_DID == FABRIC_DID) {
6582fcf3ce44SJohn Forte 				SHA1Update(&sha1ctx, (void *)mykey,
6583fcf3ce44SJohn Forte 				    node_dhc->auth_key.local_password_length);
6584fcf3ce44SJohn Forte 			} else {
6585fcf3ce44SJohn Forte 				SHA1Update(&sha1ctx, (void *)mykey,
6586fcf3ce44SJohn Forte 				    node_dhc->auth_key.remote_password_length);
6587fcf3ce44SJohn Forte 			}
6588fcf3ce44SJohn Forte 
6589fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx, (void *)bi_cval, SHA1_LEN);
6590fcf3ce44SJohn Forte 			SHA1Final((void *)sha1_digest, &sha1ctx);
6591fcf3ce44SJohn Forte 			hash_val = (uint32_t *)kmem_alloc(hash_size,
6592fcf3ce44SJohn Forte 			    KM_NOSLEEP);
6593fcf3ce44SJohn Forte 			if (hash_val == NULL) {
6594fcf3ce44SJohn Forte 				return (NULL);
6595fcf3ce44SJohn Forte 			} else {
6596fcf3ce44SJohn Forte 				bcopy((void *)sha1_digest,
6597fcf3ce44SJohn Forte 				    (void *)hash_val, SHA1_LEN);
6598fcf3ce44SJohn Forte 			}
6599fcf3ce44SJohn Forte 		}
6600fcf3ce44SJohn Forte 	} else {
6601fcf3ce44SJohn Forte 		/* NON-NULL DHCHAP */
660282527734SSukumar Swaminathan 		if (ndlp->nlp_DID == FABRIC_DID) {
6603fcf3ce44SJohn Forte 			if (hash_id == AUTH_MD5) {
6604fcf3ce44SJohn Forte 				bcopy((void *)node_dhc->hrsp_priv_key,
6605fcf3ce44SJohn Forte 				    (void *)key, MD5_LEN);
6606fcf3ce44SJohn Forte 			}
6607fcf3ce44SJohn Forte 			if (hash_id == AUTH_SHA1) {
6608fcf3ce44SJohn Forte 				bcopy((void *)node_dhc->hrsp_priv_key,
6609fcf3ce44SJohn Forte 				    (void *)key, SHA1_LEN);
6610fcf3ce44SJohn Forte 			}
6611fcf3ce44SJohn Forte 			cval_len = node_dhc->hrsp_cval_len;
6612fcf3ce44SJohn Forte 		} else {
6613fcf3ce44SJohn Forte 			if (hash_id == AUTH_MD5) {
6614fcf3ce44SJohn Forte 			bcopy(
6615fcf3ce44SJohn Forte 			    (void *)node_dhc->nlp_auth_misc.hrsp_priv_key,
6616fcf3ce44SJohn Forte 			    (void *)key, MD5_LEN);
6617fcf3ce44SJohn Forte 			}
6618fcf3ce44SJohn Forte 			if (hash_id == AUTH_SHA1) {
6619fcf3ce44SJohn Forte 			bcopy(
6620fcf3ce44SJohn Forte 			    (void *)node_dhc->nlp_auth_misc.hrsp_priv_key,
6621fcf3ce44SJohn Forte 			    (void *)key, SHA1_LEN);
6622fcf3ce44SJohn Forte 			}
6623fcf3ce44SJohn Forte 			cval_len = node_dhc->nlp_auth_misc.hrsp_cval_len;
6624fcf3ce44SJohn Forte 		}
6625fcf3ce44SJohn Forte 
6626fcf3ce44SJohn Forte 		/* use bi_cval here */
6627fcf3ce44SJohn Forte 		/*
6628fcf3ce44SJohn Forte 		 * key: x dhval: (g^y mod p) tran_id: Ti bi_cval: C2 hash_id:
6629fcf3ce44SJohn Forte 		 * H dhgp_id: p/g
6630fcf3ce44SJohn Forte 		 *
6631fcf3ce44SJohn Forte 		 * Cai = H (C2 || ((g^y mod p)^x mod p) )
6632fcf3ce44SJohn Forte 		 *
6633fcf3ce44SJohn Forte 		 * R2 = H (Ti || Km || Cai)
6634fcf3ce44SJohn Forte 		 */
6635fcf3ce44SJohn Forte 		err = emlxs_hash_Cai(port, port_dhc, ndlp, (void *)Cai,
6636fcf3ce44SJohn Forte 		    hash_id, dhgp_id, tran_id, bi_cval, cval_len,
6637fcf3ce44SJohn Forte 		    key, dhval, dhval_len);
6638fcf3ce44SJohn Forte 
6639fcf3ce44SJohn Forte 		if (err != BIG_OK) {
6640fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
6641*8f23e9faSHans Rosenfeld 			    "hash_get_R2: hash_Cai error. ret=0x%x",
6642fcf3ce44SJohn Forte 			    err);
6643fcf3ce44SJohn Forte 
6644fcf3ce44SJohn Forte 			return (NULL);
6645fcf3ce44SJohn Forte 		}
6646fcf3ce44SJohn Forte 		if (hash_id == AUTH_MD5) {
6647fcf3ce44SJohn Forte 			bzero(&mdctx, sizeof (MD5_CTX));
6648fcf3ce44SJohn Forte 			hash_size = MD5_LEN;
6649fcf3ce44SJohn Forte 
6650fcf3ce44SJohn Forte 			MD5Init(&mdctx);
6651fcf3ce44SJohn Forte 			MD5Update(&mdctx, (unsigned char *) &mytran_id, 1);
6652fcf3ce44SJohn Forte 
6653fcf3ce44SJohn Forte 			/*
6654fcf3ce44SJohn Forte 			 * Here we use the same key: mykey, note: this mykey
6655fcf3ce44SJohn Forte 			 * should be the key associated with the
6656fcf3ce44SJohn Forte 			 * authentication responder i.e. the remote key.
6657fcf3ce44SJohn Forte 			 */
665882527734SSukumar Swaminathan 			if (ndlp->nlp_DID == FABRIC_DID)
6659fcf3ce44SJohn Forte 				MD5Update(&mdctx, (unsigned char *)mykey,
6660fcf3ce44SJohn Forte 				    node_dhc->auth_key.local_password_length);
6661fcf3ce44SJohn Forte 			else
6662fcf3ce44SJohn Forte 				MD5Update(&mdctx, (unsigned char *)mykey,
6663fcf3ce44SJohn Forte 				    node_dhc->auth_key.remote_password_length);
6664fcf3ce44SJohn Forte 
6665fcf3ce44SJohn Forte 			MD5Update(&mdctx, (unsigned char *)Cai, MD5_LEN);
6666fcf3ce44SJohn Forte 			MD5Final((uint8_t *)md5_digest, &mdctx);
6667fcf3ce44SJohn Forte 
6668fcf3ce44SJohn Forte 			hash_val = (uint32_t *)kmem_alloc(hash_size,
6669fcf3ce44SJohn Forte 			    KM_NOSLEEP);
6670fcf3ce44SJohn Forte 			if (hash_val == NULL) {
6671fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
6672*8f23e9faSHans Rosenfeld 			    "hash_get_R2: hash_val MD5 alloc failed.");
6673fcf3ce44SJohn Forte 
6674fcf3ce44SJohn Forte 				return (NULL);
6675fcf3ce44SJohn Forte 			} else {
6676fcf3ce44SJohn Forte 				bcopy((void *)md5_digest,
6677fcf3ce44SJohn Forte 				    (void *)hash_val, MD5_LEN);
6678fcf3ce44SJohn Forte 			}
6679fcf3ce44SJohn Forte 		}
6680fcf3ce44SJohn Forte 		if (hash_id == AUTH_SHA1) {
6681fcf3ce44SJohn Forte 			bzero(&sha1ctx, sizeof (SHA1_CTX));
6682fcf3ce44SJohn Forte 			hash_size = SHA1_LEN;
6683fcf3ce44SJohn Forte 
6684fcf3ce44SJohn Forte 			SHA1Init(&sha1ctx);
6685fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx, (void *)&mytran_id, 1);
6686fcf3ce44SJohn Forte 
668782527734SSukumar Swaminathan 			if (ndlp->nlp_DID == FABRIC_DID) {
6688fcf3ce44SJohn Forte 				SHA1Update(&sha1ctx, (void *)mykey,
6689fcf3ce44SJohn Forte 				    node_dhc->auth_key.local_password_length);
6690fcf3ce44SJohn Forte 			} else {
6691fcf3ce44SJohn Forte 				SHA1Update(&sha1ctx, (void *)mykey,
6692fcf3ce44SJohn Forte 				    node_dhc->auth_key.remote_password_length);
6693fcf3ce44SJohn Forte 			}
6694fcf3ce44SJohn Forte 
6695fcf3ce44SJohn Forte 			SHA1Update(&sha1ctx, (void *)Cai, SHA1_LEN);
6696fcf3ce44SJohn Forte 			SHA1Final((void *)sha1_digest, &sha1ctx);
6697fcf3ce44SJohn Forte 
6698fcf3ce44SJohn Forte 			hash_val = (uint32_t *)kmem_alloc(hash_size,
6699fcf3ce44SJohn Forte 			    KM_NOSLEEP);
6700fcf3ce44SJohn Forte 			if (hash_val == NULL) {
6701fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_error_msg,
6702*8f23e9faSHans Rosenfeld 			    "hash_get_R2: hash_val SHA1 alloc failed.");
6703fcf3ce44SJohn Forte 
6704fcf3ce44SJohn Forte 				return (NULL);
6705fcf3ce44SJohn Forte 			} else {
6706fcf3ce44SJohn Forte 				bcopy((void *)sha1_digest,
6707fcf3ce44SJohn Forte 				    (void *)hash_val, SHA1_LEN);
6708fcf3ce44SJohn Forte 			}
6709fcf3ce44SJohn Forte 		}
6710fcf3ce44SJohn Forte 	}
6711fcf3ce44SJohn Forte 
6712fcf3ce44SJohn Forte 	return ((uint32_t *)hash_val);
6713fcf3ce44SJohn Forte 
6714fcf3ce44SJohn Forte } /* emlxs_hash_get_R2 */
6715fcf3ce44SJohn Forte 
6716fcf3ce44SJohn Forte 
6717fcf3ce44SJohn Forte static void
emlxs_log_auth_event(emlxs_port_t * port,NODELIST * ndlp,char * subclass,char * info)6718fcf3ce44SJohn Forte emlxs_log_auth_event(
6719fcf3ce44SJohn Forte 	emlxs_port_t *port,
6720fcf3ce44SJohn Forte 	NODELIST *ndlp,
6721fcf3ce44SJohn Forte 	char *subclass,
6722fcf3ce44SJohn Forte 	char *info)
6723fcf3ce44SJohn Forte {
6724fcf3ce44SJohn Forte 	emlxs_hba_t *hba = HBA;
6725fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
6726fcf3ce44SJohn Forte 	nvlist_t *attr_list = NULL;
6727fcf3ce44SJohn Forte 	dev_info_t *dip = hba->dip;
6728fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *auth_cfg;
6729fcf3ce44SJohn Forte 	char *tmp = "No_more_logging_information_available";
6730fcf3ce44SJohn Forte 	uint8_t lwwn[8];
6731fcf3ce44SJohn Forte 	uint8_t rwwn[8];
6732*8f23e9faSHans Rosenfeld 	char *lwwn_str = NULL;
6733*8f23e9faSHans Rosenfeld 	char *rwwn_str = NULL;
6734*8f23e9faSHans Rosenfeld 	char ext_subclass[128];
6735*8f23e9faSHans Rosenfeld 	char ext_class[32];
6736fcf3ce44SJohn Forte 
6737fcf3ce44SJohn Forte 	auth_cfg = &(node_dhc->auth_cfg);
6738fcf3ce44SJohn Forte 
6739fcf3ce44SJohn Forte 	if (info == NULL) {
6740fcf3ce44SJohn Forte 		info = tmp;
6741fcf3ce44SJohn Forte 	}
6742fcf3ce44SJohn Forte 	bcopy((void *) &auth_cfg->local_entity, (void *)lwwn, 8);
6743*8f23e9faSHans Rosenfeld 	lwwn_str = (char *)kmem_zalloc(32, KM_NOSLEEP);
6744*8f23e9faSHans Rosenfeld 	if (lwwn_str == NULL) {
6745fcf3ce44SJohn Forte 		return;
6746fcf3ce44SJohn Forte 	}
6747*8f23e9faSHans Rosenfeld 	(void) snprintf(lwwn_str, 32, "%02X%02X%02X%02X%02X%02X%02X%02X",
6748*8f23e9faSHans Rosenfeld 	    lwwn[0], lwwn[1], lwwn[2], lwwn[3], lwwn[4], lwwn[5], lwwn[6],
6749*8f23e9faSHans Rosenfeld 	    lwwn[7]);
6750fcf3ce44SJohn Forte 
6751fcf3ce44SJohn Forte 	bcopy((void *)&auth_cfg->remote_entity, (void *)rwwn, 8);
6752*8f23e9faSHans Rosenfeld 	rwwn_str = (char *)kmem_zalloc(32, KM_NOSLEEP);
6753*8f23e9faSHans Rosenfeld 	if (rwwn_str == NULL) {
6754*8f23e9faSHans Rosenfeld 		kmem_free(lwwn_str, 32);
6755fcf3ce44SJohn Forte 		return;
6756fcf3ce44SJohn Forte 	}
6757*8f23e9faSHans Rosenfeld 
6758*8f23e9faSHans Rosenfeld 	(void) snprintf(rwwn_str, 32, "%02X%02X%02X%02X%02X%02X%02X%02X",
6759*8f23e9faSHans Rosenfeld 	    rwwn[0], rwwn[1], rwwn[2], rwwn[3], rwwn[4], rwwn[5], rwwn[6],
6760*8f23e9faSHans Rosenfeld 	    rwwn[7]);
6761*8f23e9faSHans Rosenfeld 
6762*8f23e9faSHans Rosenfeld 	(void) snprintf(ext_subclass, sizeof (ext_subclass),
6763*8f23e9faSHans Rosenfeld 	    "ESC_%s_%s", DRIVER_NAME, subclass);
6764*8f23e9faSHans Rosenfeld 	(void) snprintf(ext_class, sizeof (ext_class),
6765*8f23e9faSHans Rosenfeld 	    "EC_%s", DRIVER_NAME);
6766fcf3ce44SJohn Forte 
6767fcf3ce44SJohn Forte 	if (nvlist_alloc(&attr_list, NV_UNIQUE_NAME_TYPE, KM_NOSLEEP)
6768fcf3ce44SJohn Forte 	    == DDI_SUCCESS) {
6769fcf3ce44SJohn Forte 		if ((nvlist_add_uint32(attr_list, "instance",
6770fcf3ce44SJohn Forte 		    ddi_get_instance(dip)) == DDI_SUCCESS) &&
6771fcf3ce44SJohn Forte 		    (nvlist_add_string(attr_list, "lwwn",
6772*8f23e9faSHans Rosenfeld 		    lwwn_str) == DDI_SUCCESS) &&
6773fcf3ce44SJohn Forte 		    (nvlist_add_string(attr_list, "rwwn",
6774*8f23e9faSHans Rosenfeld 		    rwwn_str) == DDI_SUCCESS) &&
6775fcf3ce44SJohn Forte 		    (nvlist_add_string(attr_list, "Info",
6776fcf3ce44SJohn Forte 		    info) == DDI_SUCCESS) &&
6777fcf3ce44SJohn Forte 		    (nvlist_add_string(attr_list, "Class",
6778*8f23e9faSHans Rosenfeld 		    ext_class) == DDI_SUCCESS) &&
6779fcf3ce44SJohn Forte 		    (nvlist_add_string(attr_list, "SubClass",
6780*8f23e9faSHans Rosenfeld 		    ext_subclass) == DDI_SUCCESS)) {
6781fcf3ce44SJohn Forte 
6782fcf3ce44SJohn Forte 			(void) ddi_log_sysevent(dip,
6783*8f23e9faSHans Rosenfeld 			    emlxs_strtoupper(DRIVER_NAME),
6784*8f23e9faSHans Rosenfeld 			    ext_class,
6785*8f23e9faSHans Rosenfeld 			    ext_subclass,
6786fcf3ce44SJohn Forte 			    attr_list,
6787fcf3ce44SJohn Forte 			    NULL,
6788fcf3ce44SJohn Forte 			    DDI_NOSLEEP);
6789fcf3ce44SJohn Forte 		}
6790fcf3ce44SJohn Forte 		nvlist_free(attr_list);
6791fcf3ce44SJohn Forte 		attr_list = NULL;
6792fcf3ce44SJohn Forte 	}
6793*8f23e9faSHans Rosenfeld 	kmem_free(lwwn_str, 32);
6794*8f23e9faSHans Rosenfeld 	kmem_free(rwwn_str, 32);
6795fcf3ce44SJohn Forte 
6796fcf3ce44SJohn Forte 	return;
6797fcf3ce44SJohn Forte 
6798fcf3ce44SJohn Forte } /* emlxs_log_auth_event() */
6799fcf3ce44SJohn Forte 
6800fcf3ce44SJohn Forte 
6801fcf3ce44SJohn Forte /* **************************** AUTH DHC INTERFACE ************************* */
6802fcf3ce44SJohn Forte 
6803fcf3ce44SJohn Forte extern int
emlxs_dhc_auth_start(emlxs_port_t * port,emlxs_node_t * ndlp,uint8_t * deferred_sbp,uint8_t * deferred_ubp)6804fcf3ce44SJohn Forte emlxs_dhc_auth_start(
6805fcf3ce44SJohn Forte 	emlxs_port_t *port,
6806fcf3ce44SJohn Forte 	emlxs_node_t *ndlp,
6807fcf3ce44SJohn Forte 	uint8_t *deferred_sbp,
6808fcf3ce44SJohn Forte 	uint8_t *deferred_ubp)
6809fcf3ce44SJohn Forte {
6810fcf3ce44SJohn Forte 	emlxs_hba_t *hba = HBA;
6811fcf3ce44SJohn Forte 	emlxs_config_t *cfg = &CFG;
6812fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
6813fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *auth_cfg;
6814fcf3ce44SJohn Forte 	emlxs_auth_key_t *auth_key;
6815fcf3ce44SJohn Forte 	uint32_t i;
6816fcf3ce44SJohn Forte 	uint32_t fabric;
6817fcf3ce44SJohn Forte 	uint32_t fabric_switch;
6818fcf3ce44SJohn Forte 
6819fcf3ce44SJohn Forte 	/* The ubp represents an unsolicted PLOGI */
6820fcf3ce44SJohn Forte 	/* The sbp represents a solicted PLOGI    */
6821fcf3ce44SJohn Forte 
682282527734SSukumar Swaminathan 	fabric = ((ndlp->nlp_DID & FABRIC_DID_MASK) == FABRIC_DID_MASK) ? 1 : 0;
682382527734SSukumar Swaminathan 	fabric_switch = ((ndlp->nlp_DID == FABRIC_DID) ? 1 : 0);
6824fcf3ce44SJohn Forte 
6825fcf3ce44SJohn Forte 	/* Return is authentication is not enabled */
6826fcf3ce44SJohn Forte 	if (cfg[CFG_AUTH_ENABLE].current == 0) {
6827fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
6828fcf3ce44SJohn Forte 		    &emlxs_fcsp_start_msg,
6829fcf3ce44SJohn Forte 		    "Not started. Auth disabled. did=0x%x", ndlp->nlp_DID);
6830fcf3ce44SJohn Forte 
6831fcf3ce44SJohn Forte 		emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_DISABLED, 0, 0);
6832fcf3ce44SJohn Forte 
6833fcf3ce44SJohn Forte 		return (1);
6834fcf3ce44SJohn Forte 	}
6835fcf3ce44SJohn Forte 	if (port->vpi != 0 && cfg[CFG_AUTH_NPIV].current == 0) {
6836fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
6837fcf3ce44SJohn Forte 		    &emlxs_fcsp_start_msg,
6838fcf3ce44SJohn Forte 		    "Not started. NPIV auth disabled. did=0x%x", ndlp->nlp_DID);
6839fcf3ce44SJohn Forte 
6840fcf3ce44SJohn Forte 		emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_DISABLED, 0, 0);
6841fcf3ce44SJohn Forte 
6842fcf3ce44SJohn Forte 		return (1);
6843fcf3ce44SJohn Forte 	}
6844fcf3ce44SJohn Forte 	if (!fabric_switch && fabric) {
6845fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
6846fcf3ce44SJohn Forte 		    &emlxs_fcsp_start_msg,
6847fcf3ce44SJohn Forte 		    "Not started. FS auth disabled. did=0x%x", ndlp->nlp_DID);
6848fcf3ce44SJohn Forte 
6849fcf3ce44SJohn Forte 		emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_DISABLED, 0, 0);
6850fcf3ce44SJohn Forte 
6851fcf3ce44SJohn Forte 		return (1);
6852fcf3ce44SJohn Forte 	}
6853fcf3ce44SJohn Forte 	/* Return if fcsp support to this node is not enabled */
6854fcf3ce44SJohn Forte 	if (!fabric_switch && cfg[CFG_AUTH_E2E].current == 0) {
6855fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
6856fcf3ce44SJohn Forte 		    &emlxs_fcsp_start_msg,
6857fcf3ce44SJohn Forte 		    "Not started. E2E auth disabled. did=0x%x", ndlp->nlp_DID);
6858fcf3ce44SJohn Forte 
6859fcf3ce44SJohn Forte 		emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_DISABLED, 0, 0);
6860fcf3ce44SJohn Forte 
6861fcf3ce44SJohn Forte 		return (1);
6862fcf3ce44SJohn Forte 	}
6863fcf3ce44SJohn Forte 	if ((deferred_sbp && node_dhc->deferred_sbp) ||
6864fcf3ce44SJohn Forte 	    (deferred_ubp && node_dhc->deferred_ubp)) {
6865fcf3ce44SJohn Forte 		/* Clear previous authentication */
6866fcf3ce44SJohn Forte 		emlxs_dhc_auth_stop(port, ndlp);
6867fcf3ce44SJohn Forte 	}
6868fcf3ce44SJohn Forte 	mutex_enter(&hba->auth_lock);
6869fcf3ce44SJohn Forte 
6870fcf3ce44SJohn Forte 	/* Intialize node */
6871fcf3ce44SJohn Forte 	node_dhc->parent_auth_cfg = NULL;
6872fcf3ce44SJohn Forte 	node_dhc->parent_auth_key = NULL;
6873fcf3ce44SJohn Forte 
6874fcf3ce44SJohn Forte 	/* Acquire auth configuration */
6875fcf3ce44SJohn Forte 	if (fabric_switch) {
6876fcf3ce44SJohn Forte 		auth_cfg = emlxs_auth_cfg_find(port,
6877fcf3ce44SJohn Forte 		    (uint8_t *)emlxs_fabric_wwn);
6878fcf3ce44SJohn Forte 		auth_key = emlxs_auth_key_find(port,
6879fcf3ce44SJohn Forte 		    (uint8_t *)emlxs_fabric_wwn);
6880fcf3ce44SJohn Forte 	} else {
6881fcf3ce44SJohn Forte 		auth_cfg = emlxs_auth_cfg_find(port,
6882fcf3ce44SJohn Forte 		    (uint8_t *)&ndlp->nlp_portname);
6883fcf3ce44SJohn Forte 		auth_key = emlxs_auth_key_find(port,
6884fcf3ce44SJohn Forte 		    (uint8_t *)&ndlp->nlp_portname);
6885fcf3ce44SJohn Forte 	}
6886fcf3ce44SJohn Forte 
6887fcf3ce44SJohn Forte 	if (!auth_cfg) {
6888fcf3ce44SJohn Forte 		mutex_exit(&hba->auth_lock);
6889fcf3ce44SJohn Forte 
6890fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
6891fcf3ce44SJohn Forte 		    &emlxs_fcsp_start_msg,
6892fcf3ce44SJohn Forte 		    "Not started. No auth cfg entry found. did=0x%x",
6893fcf3ce44SJohn Forte 		    ndlp->nlp_DID);
6894fcf3ce44SJohn Forte 
6895fcf3ce44SJohn Forte 		emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_DISABLED, 0, 0);
6896fcf3ce44SJohn Forte 
6897fcf3ce44SJohn Forte 		return (1);
6898fcf3ce44SJohn Forte 	}
6899fcf3ce44SJohn Forte 	if (fabric_switch) {
6900fcf3ce44SJohn Forte 		auth_cfg->node = NULL;
6901fcf3ce44SJohn Forte 	} else {
6902fcf3ce44SJohn Forte 		node_dhc->parent_auth_cfg = auth_cfg;
6903fcf3ce44SJohn Forte 		auth_cfg->node = ndlp;
6904fcf3ce44SJohn Forte 	}
6905fcf3ce44SJohn Forte 
6906fcf3ce44SJohn Forte 	if (!auth_key) {
6907fcf3ce44SJohn Forte 		mutex_exit(&hba->auth_lock);
6908fcf3ce44SJohn Forte 
6909fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
6910fcf3ce44SJohn Forte 		    &emlxs_fcsp_start_msg,
6911fcf3ce44SJohn Forte 		    "Not started. No auth key entry found. did=0x%x",
6912fcf3ce44SJohn Forte 		    ndlp->nlp_DID);
6913fcf3ce44SJohn Forte 
6914fcf3ce44SJohn Forte 		emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_DISABLED, 0, 0);
6915fcf3ce44SJohn Forte 
6916fcf3ce44SJohn Forte 		return (1);
6917fcf3ce44SJohn Forte 	}
6918fcf3ce44SJohn Forte 	if (fabric_switch) {
6919fcf3ce44SJohn Forte 		auth_key->node = NULL;
6920fcf3ce44SJohn Forte 	} else {
6921fcf3ce44SJohn Forte 		node_dhc->parent_auth_key = auth_key;
6922fcf3ce44SJohn Forte 		auth_key->node = ndlp;
6923fcf3ce44SJohn Forte 	}
6924fcf3ce44SJohn Forte 
6925fcf3ce44SJohn Forte 	/* Remote port does not support fcsp */
6926fcf3ce44SJohn Forte 	if (ndlp->sparm.cmn.fcsp_support == 0) {
6927fcf3ce44SJohn Forte 		switch (auth_cfg->authentication_mode) {
6928fcf3ce44SJohn Forte 		case AUTH_MODE_PASSIVE:
6929fcf3ce44SJohn Forte 			mutex_exit(&hba->auth_lock);
6930fcf3ce44SJohn Forte 
6931fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
6932fcf3ce44SJohn Forte 			    &emlxs_fcsp_start_msg,
6933fcf3ce44SJohn Forte 			    "Not started. Auth unsupported. did=0x%x",
6934fcf3ce44SJohn Forte 			    ndlp->nlp_DID);
6935fcf3ce44SJohn Forte 
6936fcf3ce44SJohn Forte 			emlxs_dhc_state(port, ndlp,
6937fcf3ce44SJohn Forte 			    NODE_STATE_AUTH_DISABLED, 0, 0);
6938fcf3ce44SJohn Forte 			return (1);
6939fcf3ce44SJohn Forte 
6940fcf3ce44SJohn Forte 		case AUTH_MODE_ACTIVE:
6941fcf3ce44SJohn Forte 			mutex_exit(&hba->auth_lock);
6942fcf3ce44SJohn Forte 
6943fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
6944fcf3ce44SJohn Forte 			    &emlxs_fcsp_start_msg,
6945fcf3ce44SJohn Forte 			    "Failed. Auth unsupported. did=0x%x",
6946fcf3ce44SJohn Forte 			    ndlp->nlp_DID);
6947fcf3ce44SJohn Forte 
6948fcf3ce44SJohn Forte 			/*
6949fcf3ce44SJohn Forte 			 * Save packet for deferred completion until
6950fcf3ce44SJohn Forte 			 * authentication is complete
6951fcf3ce44SJohn Forte 			 */
6952fcf3ce44SJohn Forte 			ndlp->node_dhc.deferred_sbp = deferred_sbp;
6953fcf3ce44SJohn Forte 			ndlp->node_dhc.deferred_ubp = deferred_ubp;
6954fcf3ce44SJohn Forte 
6955fcf3ce44SJohn Forte 			goto failed;
6956fcf3ce44SJohn Forte 
6957fcf3ce44SJohn Forte 		case AUTH_MODE_DISABLED:
6958fcf3ce44SJohn Forte 		default:
6959fcf3ce44SJohn Forte 			mutex_exit(&hba->auth_lock);
6960fcf3ce44SJohn Forte 
6961fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
6962fcf3ce44SJohn Forte 			    &emlxs_fcsp_start_msg,
6963fcf3ce44SJohn Forte 			    "Not started. Auth mode=disabled. did=0x%x",
6964fcf3ce44SJohn Forte 			    ndlp->nlp_DID);
6965fcf3ce44SJohn Forte 
6966fcf3ce44SJohn Forte 			emlxs_dhc_state(port, ndlp,
6967fcf3ce44SJohn Forte 			    NODE_STATE_AUTH_DISABLED, 0, 0);
6968fcf3ce44SJohn Forte 			return (1);
6969fcf3ce44SJohn Forte 		}
6970fcf3ce44SJohn Forte 	} else {	/* Remote port supports fcsp */
6971fcf3ce44SJohn Forte 		switch (auth_cfg->authentication_mode) {
6972fcf3ce44SJohn Forte 		case AUTH_MODE_PASSIVE:
6973fcf3ce44SJohn Forte 		case AUTH_MODE_ACTIVE:
6974fcf3ce44SJohn Forte 			/* start auth */
6975fcf3ce44SJohn Forte 			break;
6976fcf3ce44SJohn Forte 
6977fcf3ce44SJohn Forte 		case AUTH_MODE_DISABLED:
6978fcf3ce44SJohn Forte 		default:
6979fcf3ce44SJohn Forte 			mutex_exit(&hba->auth_lock);
6980fcf3ce44SJohn Forte 
6981fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
6982fcf3ce44SJohn Forte 			    &emlxs_fcsp_start_msg,
6983fcf3ce44SJohn Forte 			    "Failed. Auth mode=disabled. did=0x%x",
6984fcf3ce44SJohn Forte 			    ndlp->nlp_DID);
6985fcf3ce44SJohn Forte 
6986fcf3ce44SJohn Forte 			/*
6987fcf3ce44SJohn Forte 			 * Save packet for deferred completion until
6988fcf3ce44SJohn Forte 			 * authentication is complete
6989fcf3ce44SJohn Forte 			 */
6990fcf3ce44SJohn Forte 			ndlp->node_dhc.deferred_sbp = deferred_sbp;
6991fcf3ce44SJohn Forte 			ndlp->node_dhc.deferred_ubp = deferred_ubp;
6992fcf3ce44SJohn Forte 
6993fcf3ce44SJohn Forte 			goto failed;
6994fcf3ce44SJohn Forte 		}
6995fcf3ce44SJohn Forte 	}
6996fcf3ce44SJohn Forte 
6997fcf3ce44SJohn Forte 	/* We have a GO for authentication */
6998fcf3ce44SJohn Forte 
6999fcf3ce44SJohn Forte 	/*
7000fcf3ce44SJohn Forte 	 * Save pointers for deferred completion until authentication is
7001fcf3ce44SJohn Forte 	 * complete
7002fcf3ce44SJohn Forte 	 */
7003fcf3ce44SJohn Forte 	node_dhc->deferred_sbp = deferred_sbp;
7004fcf3ce44SJohn Forte 	node_dhc->deferred_ubp = deferred_ubp;
7005fcf3ce44SJohn Forte 
7006fcf3ce44SJohn Forte 	bzero(&node_dhc->auth_cfg, sizeof (node_dhc->auth_cfg));
7007fcf3ce44SJohn Forte 	bzero(&node_dhc->auth_key, sizeof (node_dhc->auth_key));
7008fcf3ce44SJohn Forte 
7009fcf3ce44SJohn Forte 	/* Program node's auth cfg */
7010fcf3ce44SJohn Forte 	bcopy((uint8_t *)&port->wwpn,
7011fcf3ce44SJohn Forte 	    (uint8_t *)&node_dhc->auth_cfg.local_entity, 8);
7012fcf3ce44SJohn Forte 	bcopy((uint8_t *)&ndlp->nlp_portname,
7013fcf3ce44SJohn Forte 	    (uint8_t *)&node_dhc->auth_cfg.remote_entity, 8);
7014fcf3ce44SJohn Forte 
7015fcf3ce44SJohn Forte 	node_dhc->auth_cfg.authentication_timeout =
7016fcf3ce44SJohn Forte 	    auth_cfg->authentication_timeout;
7017fcf3ce44SJohn Forte 	node_dhc->auth_cfg.authentication_mode =
7018fcf3ce44SJohn Forte 	    auth_cfg->authentication_mode;
7019fcf3ce44SJohn Forte 
7020fcf3ce44SJohn Forte 	/*
7021fcf3ce44SJohn Forte 	 * If remote password type is "ignore", then only unidirectional auth
7022fcf3ce44SJohn Forte 	 * is allowed
7023fcf3ce44SJohn Forte 	 */
7024fcf3ce44SJohn Forte 	if (auth_key->remote_password_type == 3) {
7025fcf3ce44SJohn Forte 		node_dhc->auth_cfg.bidirectional = 0;
7026fcf3ce44SJohn Forte 	} else {
7027fcf3ce44SJohn Forte 		node_dhc->auth_cfg.bidirectional = auth_cfg->bidirectional;
7028fcf3ce44SJohn Forte 	}
7029fcf3ce44SJohn Forte 
7030fcf3ce44SJohn Forte 	node_dhc->auth_cfg.reauthenticate_time_interval =
7031fcf3ce44SJohn Forte 	    auth_cfg->reauthenticate_time_interval;
7032fcf3ce44SJohn Forte 
7033fcf3ce44SJohn Forte 	for (i = 0; i < 4; i++) {
7034fcf3ce44SJohn Forte 		switch (auth_cfg->authentication_type_priority[i]) {
7035fcf3ce44SJohn Forte 		case ELX_DHCHAP:
7036fcf3ce44SJohn Forte 			node_dhc->auth_cfg.authentication_type_priority[i] =
7037fcf3ce44SJohn Forte 			    AUTH_DHCHAP;
7038fcf3ce44SJohn Forte 			break;
7039fcf3ce44SJohn Forte 
7040fcf3ce44SJohn Forte 		case ELX_FCAP:
7041fcf3ce44SJohn Forte 			node_dhc->auth_cfg.authentication_type_priority[i] =
7042fcf3ce44SJohn Forte 			    AUTH_FCAP;
7043fcf3ce44SJohn Forte 			break;
7044fcf3ce44SJohn Forte 
7045fcf3ce44SJohn Forte 		case ELX_FCPAP:
7046fcf3ce44SJohn Forte 			node_dhc->auth_cfg.authentication_type_priority[i] =
7047fcf3ce44SJohn Forte 			    AUTH_FCPAP;
7048fcf3ce44SJohn Forte 			break;
7049fcf3ce44SJohn Forte 
7050fcf3ce44SJohn Forte 		case ELX_KERBEROS:
7051fcf3ce44SJohn Forte 			node_dhc->auth_cfg.authentication_type_priority[i] =
7052fcf3ce44SJohn Forte 			    AUTH_KERBEROS;
7053fcf3ce44SJohn Forte 			break;
7054fcf3ce44SJohn Forte 
7055fcf3ce44SJohn Forte 		default:
7056fcf3ce44SJohn Forte 			node_dhc->auth_cfg.authentication_type_priority[i] =
7057fcf3ce44SJohn Forte 			    0;
7058fcf3ce44SJohn Forte 			break;
7059fcf3ce44SJohn Forte 		}
7060fcf3ce44SJohn Forte 
7061fcf3ce44SJohn Forte 		switch (auth_cfg->hash_priority[i]) {
7062fcf3ce44SJohn Forte 		case ELX_SHA1:
7063fcf3ce44SJohn Forte 			node_dhc->auth_cfg.hash_priority[i] = AUTH_SHA1;
7064fcf3ce44SJohn Forte 			break;
7065fcf3ce44SJohn Forte 
7066fcf3ce44SJohn Forte 		case ELX_MD5:
7067fcf3ce44SJohn Forte 			node_dhc->auth_cfg.hash_priority[i] = AUTH_MD5;
7068fcf3ce44SJohn Forte 			break;
7069fcf3ce44SJohn Forte 
7070fcf3ce44SJohn Forte 		default:
7071fcf3ce44SJohn Forte 			node_dhc->auth_cfg.hash_priority[i] = 0;
7072fcf3ce44SJohn Forte 			break;
7073fcf3ce44SJohn Forte 		}
7074fcf3ce44SJohn Forte 	}
7075fcf3ce44SJohn Forte 
7076fcf3ce44SJohn Forte 	for (i = 0; i < 8; i++) {
7077fcf3ce44SJohn Forte 		switch (auth_cfg->dh_group_priority[i]) {
7078fcf3ce44SJohn Forte 		case ELX_GROUP_NULL:
7079fcf3ce44SJohn Forte 			node_dhc->auth_cfg.dh_group_priority[i] = GROUP_NULL;
7080fcf3ce44SJohn Forte 			break;
7081fcf3ce44SJohn Forte 
7082fcf3ce44SJohn Forte 		case ELX_GROUP_1024:
7083fcf3ce44SJohn Forte 			node_dhc->auth_cfg.dh_group_priority[i] = GROUP_1024;
7084fcf3ce44SJohn Forte 			break;
7085fcf3ce44SJohn Forte 
7086fcf3ce44SJohn Forte 		case ELX_GROUP_1280:
7087fcf3ce44SJohn Forte 			node_dhc->auth_cfg.dh_group_priority[i] = GROUP_1280;
7088fcf3ce44SJohn Forte 			break;
7089fcf3ce44SJohn Forte 
7090fcf3ce44SJohn Forte 		case ELX_GROUP_1536:
7091fcf3ce44SJohn Forte 			node_dhc->auth_cfg.dh_group_priority[i] = GROUP_1536;
7092fcf3ce44SJohn Forte 			break;
7093fcf3ce44SJohn Forte 
7094fcf3ce44SJohn Forte 		case ELX_GROUP_2048:
7095fcf3ce44SJohn Forte 			node_dhc->auth_cfg.dh_group_priority[i] = GROUP_2048;
7096fcf3ce44SJohn Forte 			break;
7097fcf3ce44SJohn Forte 
7098fcf3ce44SJohn Forte 		default:
7099fcf3ce44SJohn Forte 			node_dhc->auth_cfg.dh_group_priority[i] = 0xF;
7100fcf3ce44SJohn Forte 			break;
7101fcf3ce44SJohn Forte 		}
7102fcf3ce44SJohn Forte 	}
7103fcf3ce44SJohn Forte 
7104fcf3ce44SJohn Forte 	/* Program the node's key */
7105fcf3ce44SJohn Forte 	if (auth_key) {
7106fcf3ce44SJohn Forte 		bcopy((uint8_t *)auth_key,
7107fcf3ce44SJohn Forte 		    (uint8_t *)&node_dhc->auth_key,
7108fcf3ce44SJohn Forte 		    sizeof (emlxs_auth_key_t));
7109fcf3ce44SJohn Forte 		node_dhc->auth_key.next = NULL;
7110fcf3ce44SJohn Forte 		node_dhc->auth_key.prev = NULL;
7111fcf3ce44SJohn Forte 
7112fcf3ce44SJohn Forte 		bcopy((uint8_t *)&port->wwpn,
7113fcf3ce44SJohn Forte 		    (uint8_t *)&node_dhc->auth_key.local_entity, 8);
7114fcf3ce44SJohn Forte 		bcopy((uint8_t *)&ndlp->nlp_portname,
7115fcf3ce44SJohn Forte 		    (uint8_t *)&node_dhc->auth_key.remote_entity,
7116fcf3ce44SJohn Forte 		    8);
7117fcf3ce44SJohn Forte 	}
7118fcf3ce44SJohn Forte 	mutex_exit(&hba->auth_lock);
7119fcf3ce44SJohn Forte 
7120fcf3ce44SJohn Forte 	node_dhc->nlp_auth_limit = 2;
7121fcf3ce44SJohn Forte 	node_dhc->nlp_fb_vendor = 1;
7122fcf3ce44SJohn Forte 
7123fcf3ce44SJohn Forte 	node_dhc->nlp_authrsp_tmocnt = 0;
7124fcf3ce44SJohn Forte 	node_dhc->nlp_authrsp_tmo = 0;
7125fcf3ce44SJohn Forte 
7126fcf3ce44SJohn Forte 	if (deferred_ubp) {
7127fcf3ce44SJohn Forte 		/* Acknowledge the unsolicited PLOGI */
7128fcf3ce44SJohn Forte 		/* This should trigger the other port to start authentication */
7129fcf3ce44SJohn Forte 		if (emlxs_ub_send_login_acc(port,
7130fcf3ce44SJohn Forte 		    (fc_unsol_buf_t *)deferred_ubp) != FC_SUCCESS) {
7131fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
7132fcf3ce44SJohn Forte 			    &emlxs_fcsp_start_msg,
7133fcf3ce44SJohn Forte 			    "Not started. Unable to send PLOGI ACC. did=0x%x",
7134fcf3ce44SJohn Forte 			    ndlp->nlp_DID);
7135fcf3ce44SJohn Forte 
7136fcf3ce44SJohn Forte 			goto failed;
7137fcf3ce44SJohn Forte 		}
7138fcf3ce44SJohn Forte 		/* Start the auth rsp timer */
7139fcf3ce44SJohn Forte 		node_dhc->nlp_authrsp_tmo = DRV_TIME +
7140fcf3ce44SJohn Forte 		    node_dhc->auth_cfg.authentication_timeout;
7141fcf3ce44SJohn Forte 
7142fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
7143fcf3ce44SJohn Forte 		    &emlxs_fcsp_start_msg,
7144fcf3ce44SJohn Forte 		    "Authrsp timer activated. did=0x%x",
7145fcf3ce44SJohn Forte 		    ndlp->nlp_DID);
7146fcf3ce44SJohn Forte 
7147fcf3ce44SJohn Forte 		/* The next state should be emlxs_rcv_auth_msg_unmapped_node */
7148fcf3ce44SJohn Forte 		emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_SUCCESS, 0, 0);
7149fcf3ce44SJohn Forte 	} else {
7150fcf3ce44SJohn Forte 		node_dhc->nlp_auth_flag = 1;	/* host is the initiator */
7151fcf3ce44SJohn Forte 
7152fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
7153fcf3ce44SJohn Forte 		    &emlxs_fcsp_start_msg,
7154fcf3ce44SJohn Forte 		    "Auth initiated. did=0x%x limit=%d sbp=%p",
7155fcf3ce44SJohn Forte 		    ndlp->nlp_DID, node_dhc->nlp_auth_limit, deferred_sbp);
7156fcf3ce44SJohn Forte 
7157fcf3ce44SJohn Forte 		if (emlxs_issue_auth_negotiate(port, ndlp, 0)) {
7158fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_start_msg,
7159fcf3ce44SJohn Forte 			    "Failed. Auth initiation failed. did=0x%x",
7160fcf3ce44SJohn Forte 			    ndlp->nlp_DID);
7161fcf3ce44SJohn Forte 
7162fcf3ce44SJohn Forte 			goto failed;
7163fcf3ce44SJohn Forte 		}
7164fcf3ce44SJohn Forte 	}
7165fcf3ce44SJohn Forte 
7166fcf3ce44SJohn Forte 	return (0);
7167fcf3ce44SJohn Forte 
7168fcf3ce44SJohn Forte failed:
7169fcf3ce44SJohn Forte 
7170fcf3ce44SJohn Forte 	emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_FAILED, 0, 0);
7171fcf3ce44SJohn Forte 
7172fcf3ce44SJohn Forte 	/* Complete authentication with failed status */
7173fcf3ce44SJohn Forte 	emlxs_dhc_auth_complete(port, ndlp, 1);
7174fcf3ce44SJohn Forte 
7175fcf3ce44SJohn Forte 	return (0);
7176fcf3ce44SJohn Forte 
7177fcf3ce44SJohn Forte } /* emlxs_dhc_auth_start() */
7178fcf3ce44SJohn Forte 
7179fcf3ce44SJohn Forte 
7180fcf3ce44SJohn Forte 
7181fcf3ce44SJohn Forte /* This is called to indicate the driver has lost connection with this node */
7182fcf3ce44SJohn Forte extern void
emlxs_dhc_auth_stop(emlxs_port_t * port,emlxs_node_t * ndlp)7183fcf3ce44SJohn Forte emlxs_dhc_auth_stop(
7184fcf3ce44SJohn Forte 	emlxs_port_t *port,
7185fcf3ce44SJohn Forte 	emlxs_node_t *ndlp)
7186fcf3ce44SJohn Forte {
7187fcf3ce44SJohn Forte 	emlxs_port_dhc_t *port_dhc = &port->port_dhc;
7188fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc;
7189fcf3ce44SJohn Forte 	uint32_t i;
7190fcf3ce44SJohn Forte 
7191fcf3ce44SJohn Forte 	if (port_dhc->state == ELX_FABRIC_STATE_UNKNOWN) {
7192fcf3ce44SJohn Forte 		/* Nothing to stop */
7193fcf3ce44SJohn Forte 		return;
7194fcf3ce44SJohn Forte 	}
7195fcf3ce44SJohn Forte 	if (ndlp) {
7196fcf3ce44SJohn Forte 		node_dhc = &ndlp->node_dhc;
7197fcf3ce44SJohn Forte 
7198fcf3ce44SJohn Forte 		if (node_dhc->state == NODE_STATE_UNKNOWN) {
7199fcf3ce44SJohn Forte 			/* Nothing to stop */
7200fcf3ce44SJohn Forte 			return;
7201fcf3ce44SJohn Forte 		}
720282527734SSukumar Swaminathan 		if (ndlp->nlp_DID != FABRIC_DID) {
7203fcf3ce44SJohn Forte 			emlxs_dhc_state(port, ndlp, NODE_STATE_UNKNOWN, 0, 0);
7204fcf3ce44SJohn Forte 		}
7205fcf3ce44SJohn Forte 		emlxs_dhc_auth_complete(port, ndlp, 2);
7206fcf3ce44SJohn Forte 	} else {	/* Lost connection to all nodes for this port */
7207fcf3ce44SJohn Forte 		rw_enter(&port->node_rwlock, RW_READER);
7208fcf3ce44SJohn Forte 		for (i = 0; i < EMLXS_NUM_HASH_QUES; i++) {
7209fcf3ce44SJohn Forte 			ndlp = port->node_table[i];
7210fcf3ce44SJohn Forte 
7211fcf3ce44SJohn Forte 			if (!ndlp) {
7212fcf3ce44SJohn Forte 				continue;
7213fcf3ce44SJohn Forte 			}
7214fcf3ce44SJohn Forte 			node_dhc = &ndlp->node_dhc;
7215fcf3ce44SJohn Forte 
7216fcf3ce44SJohn Forte 			if (node_dhc->state == NODE_STATE_UNKNOWN) {
7217fcf3ce44SJohn Forte 				continue;
7218fcf3ce44SJohn Forte 			}
721982527734SSukumar Swaminathan 			if (ndlp->nlp_DID != FABRIC_DID) {
7220fcf3ce44SJohn Forte 				emlxs_dhc_state(port, ndlp,
7221fcf3ce44SJohn Forte 				    NODE_STATE_UNKNOWN, 0, 0);
7222fcf3ce44SJohn Forte 			}
7223fcf3ce44SJohn Forte 			emlxs_dhc_auth_complete(port, ndlp, 2);
7224fcf3ce44SJohn Forte 		}
7225fcf3ce44SJohn Forte 		rw_exit(&port->node_rwlock);
7226fcf3ce44SJohn Forte 	}
7227fcf3ce44SJohn Forte 
7228fcf3ce44SJohn Forte 	return;
7229fcf3ce44SJohn Forte 
7230fcf3ce44SJohn Forte } /* emlxs_dhc_auth_stop */
7231fcf3ce44SJohn Forte 
7232fcf3ce44SJohn Forte 
7233fcf3ce44SJohn Forte /* state = 0   - Successful completion. Continue connection to node */
7234fcf3ce44SJohn Forte /* state = 1   - Failed completion. Do not continue with connection to node */
7235fcf3ce44SJohn Forte /* state = 2   - Stopped completion. Do not continue with connection to node */
7236fcf3ce44SJohn Forte 
7237fcf3ce44SJohn Forte static void
emlxs_dhc_auth_complete(emlxs_port_t * port,emlxs_node_t * ndlp,uint32_t status)7238fcf3ce44SJohn Forte emlxs_dhc_auth_complete(
7239fcf3ce44SJohn Forte 			emlxs_port_t *port,
7240fcf3ce44SJohn Forte 			emlxs_node_t *ndlp,
7241fcf3ce44SJohn Forte 			uint32_t status)
7242fcf3ce44SJohn Forte {
7243fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
7244fcf3ce44SJohn Forte 	uint32_t fabric;
7245fcf3ce44SJohn Forte 	uint32_t fabric_switch;
7246fcf3ce44SJohn Forte 
724782527734SSukumar Swaminathan 	fabric = ((ndlp->nlp_DID & FABRIC_DID_MASK) == FABRIC_DID_MASK) ? 1 : 0;
724882527734SSukumar Swaminathan 	fabric_switch = ((ndlp->nlp_DID == FABRIC_DID) ? 1 : 0);
7249fcf3ce44SJohn Forte 
7250fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT,
7251fcf3ce44SJohn Forte 	    &emlxs_fcsp_complete_msg,
7252fcf3ce44SJohn Forte 	    "did=0x%x status=%d sbp=%p ubp=%p",
7253fcf3ce44SJohn Forte 	    ndlp->nlp_DID, status, node_dhc->deferred_sbp,
7254fcf3ce44SJohn Forte 	    node_dhc->deferred_ubp);
7255fcf3ce44SJohn Forte 
7256fcf3ce44SJohn Forte 	if (status == 1) {
7257fcf3ce44SJohn Forte 		if (fabric_switch) {
7258fcf3ce44SJohn Forte 			/* Virtual link down */
7259fcf3ce44SJohn Forte 			(void) emlxs_port_offline(port, 0xfeffffff);
7260fcf3ce44SJohn Forte 		} else if (!fabric) {
7261fcf3ce44SJohn Forte 			/* Port offline */
7262fcf3ce44SJohn Forte 			(void) emlxs_port_offline(port, ndlp->nlp_DID);
7263fcf3ce44SJohn Forte 		}
7264fcf3ce44SJohn Forte 	}
7265fcf3ce44SJohn Forte 	/* Send a LOGO if authentication was not successful */
7266fcf3ce44SJohn Forte 	if (status == 1) {
7267fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
7268fcf3ce44SJohn Forte 		    &emlxs_fcsp_complete_msg,
7269fcf3ce44SJohn Forte 		    "Sending LOGO to did=0x%x...",
7270fcf3ce44SJohn Forte 		    ndlp->nlp_DID);
7271fcf3ce44SJohn Forte 		emlxs_send_logo(port, ndlp->nlp_DID);
7272fcf3ce44SJohn Forte 	}
7273fcf3ce44SJohn Forte 
7274a9800bebSGarrett D'Amore 	/* Process deferred cmpl now */
7275a9800bebSGarrett D'Amore 	emlxs_mb_deferred_cmpl(port, status,
7276a9800bebSGarrett D'Amore 	    (emlxs_buf_t *)node_dhc->deferred_sbp,
7277a9800bebSGarrett D'Amore 	    (fc_unsol_buf_t *)node_dhc->deferred_ubp, 0);
7278a9800bebSGarrett D'Amore 
7279a9800bebSGarrett D'Amore 	node_dhc->deferred_sbp = 0;
7280fcf3ce44SJohn Forte 	node_dhc->deferred_ubp = 0;
7281fcf3ce44SJohn Forte 
7282fcf3ce44SJohn Forte 	return;
7283fcf3ce44SJohn Forte 
7284fcf3ce44SJohn Forte } /* emlxs_dhc_auth_complete */
7285fcf3ce44SJohn Forte 
7286fcf3ce44SJohn Forte 
7287fcf3ce44SJohn Forte extern void
emlxs_dhc_attach(emlxs_hba_t * hba)7288fcf3ce44SJohn Forte emlxs_dhc_attach(emlxs_hba_t *hba)
7289fcf3ce44SJohn Forte {
7290*8f23e9faSHans Rosenfeld 	mutex_init(&hba->auth_lock, NULL, MUTEX_DRIVER, NULL);
7291fcf3ce44SJohn Forte 
7292*8f23e9faSHans Rosenfeld 	mutex_init(&hba->dhc_lock, NULL, MUTEX_DRIVER, NULL);
7293fcf3ce44SJohn Forte 
7294fcf3ce44SJohn Forte 	emlxs_auth_cfg_init(hba);
7295fcf3ce44SJohn Forte 
7296fcf3ce44SJohn Forte 	emlxs_auth_key_init(hba);
7297fcf3ce44SJohn Forte 
7298fcf3ce44SJohn Forte 	hba->rdn_flag = 1;
7299fcf3ce44SJohn Forte 
7300fcf3ce44SJohn Forte 	return;
7301fcf3ce44SJohn Forte 
7302fcf3ce44SJohn Forte } /* emlxs_dhc_attach() */
7303fcf3ce44SJohn Forte 
7304fcf3ce44SJohn Forte 
7305fcf3ce44SJohn Forte extern void
emlxs_dhc_detach(emlxs_hba_t * hba)7306fcf3ce44SJohn Forte emlxs_dhc_detach(emlxs_hba_t *hba)
7307fcf3ce44SJohn Forte {
7308fcf3ce44SJohn Forte 	emlxs_auth_cfg_fini(hba);
7309fcf3ce44SJohn Forte 
7310fcf3ce44SJohn Forte 	emlxs_auth_key_fini(hba);
7311fcf3ce44SJohn Forte 
7312fcf3ce44SJohn Forte 	mutex_destroy(&hba->dhc_lock);
7313fcf3ce44SJohn Forte 	mutex_destroy(&hba->auth_lock);
7314fcf3ce44SJohn Forte 
7315fcf3ce44SJohn Forte 	return;
7316fcf3ce44SJohn Forte 
7317fcf3ce44SJohn Forte } /* emlxs_dhc_detach() */
7318fcf3ce44SJohn Forte 
7319fcf3ce44SJohn Forte 
7320fcf3ce44SJohn Forte extern void
emlxs_dhc_init_sp(emlxs_port_t * port,uint32_t did,SERV_PARM * sp,char ** msg)7321728bdc9bSSukumar Swaminathan emlxs_dhc_init_sp(emlxs_port_t *port, uint32_t did, SERV_PARM *sp, char **msg)
7322fcf3ce44SJohn Forte {
7323fcf3ce44SJohn Forte 	emlxs_hba_t *hba = HBA;
7324fcf3ce44SJohn Forte 	emlxs_config_t *cfg = &CFG;
7325fcf3ce44SJohn Forte 	uint32_t fabric;
7326fcf3ce44SJohn Forte 	uint32_t fabric_switch;
7327728bdc9bSSukumar Swaminathan 	emlxs_auth_cfg_t *auth_cfg = NULL;
7328728bdc9bSSukumar Swaminathan 	emlxs_auth_key_t *auth_key = NULL;
7329fcf3ce44SJohn Forte 
733082527734SSukumar Swaminathan 	fabric = ((did & FABRIC_DID_MASK) == FABRIC_DID_MASK) ? 1 : 0;
733182527734SSukumar Swaminathan 	fabric_switch = ((did == FABRIC_DID) ? 1 : 0);
7332fcf3ce44SJohn Forte 
7333fcf3ce44SJohn Forte 	/* Return is authentication is not enabled */
7334fcf3ce44SJohn Forte 	if (cfg[CFG_AUTH_ENABLE].current == 0) {
7335fcf3ce44SJohn Forte 		sp->cmn.fcsp_support = 0;
7336728bdc9bSSukumar Swaminathan 		bcopy("fcsp:Disabled (0)", (void *) &msg[0],
7337728bdc9bSSukumar Swaminathan 		    sizeof ("fcsp:Disabled (0)"));
7338fcf3ce44SJohn Forte 		return;
7339fcf3ce44SJohn Forte 	}
7340291a2b48SSukumar Swaminathan 
7341fcf3ce44SJohn Forte 	if (port->vpi != 0 && cfg[CFG_AUTH_NPIV].current == 0) {
7342fcf3ce44SJohn Forte 		sp->cmn.fcsp_support = 0;
7343728bdc9bSSukumar Swaminathan 		bcopy("fcsp:Disabled (npiv)", (void *) &msg[0],
7344291a2b48SSukumar Swaminathan 		    sizeof ("fcsp:Disabled (npiv)"));
7345fcf3ce44SJohn Forte 		return;
7346fcf3ce44SJohn Forte 	}
7347fcf3ce44SJohn Forte 	if (!fabric_switch && fabric) {
7348fcf3ce44SJohn Forte 		sp->cmn.fcsp_support = 0;
7349728bdc9bSSukumar Swaminathan 		bcopy("fcsp:Disabled (fs)", (void *) &msg[0],
7350728bdc9bSSukumar Swaminathan 		    sizeof ("fcsp:Disabled (fs)"));
7351fcf3ce44SJohn Forte 		return;
7352fcf3ce44SJohn Forte 	}
7353fcf3ce44SJohn Forte 	/* Return if fcsp support to this node is not enabled */
7354fcf3ce44SJohn Forte 	if (!fabric_switch && cfg[CFG_AUTH_E2E].current == 0) {
7355fcf3ce44SJohn Forte 		sp->cmn.fcsp_support = 0;
7356728bdc9bSSukumar Swaminathan 		bcopy("fcsp:Disabled (e2e)", (void *) &msg[0],
7357728bdc9bSSukumar Swaminathan 		    sizeof ("fcsp:Disabled (e2e)"));
7358fcf3ce44SJohn Forte 		return;
7359fcf3ce44SJohn Forte 	}
7360fcf3ce44SJohn Forte 
7361728bdc9bSSukumar Swaminathan 	mutex_enter(&hba->auth_lock);
7362728bdc9bSSukumar Swaminathan 	if (fabric_switch) {
7363728bdc9bSSukumar Swaminathan 		auth_cfg = emlxs_auth_cfg_find(port,
7364728bdc9bSSukumar Swaminathan 		    (uint8_t *)emlxs_fabric_wwn);
7365728bdc9bSSukumar Swaminathan 		auth_key = emlxs_auth_key_find(port,
7366728bdc9bSSukumar Swaminathan 		    (uint8_t *)emlxs_fabric_wwn);
7367728bdc9bSSukumar Swaminathan 		if ((!auth_cfg) || (!auth_key)) {
7368728bdc9bSSukumar Swaminathan 			sp->cmn.fcsp_support = 0;
7369728bdc9bSSukumar Swaminathan 			bcopy("fcsp:Disabled (1)", (void *) &msg[0],
7370728bdc9bSSukumar Swaminathan 			    sizeof ("fcsp:Disabled (1)"));
7371728bdc9bSSukumar Swaminathan 			mutex_exit(&hba->auth_lock);
7372728bdc9bSSukumar Swaminathan 			return;
7373728bdc9bSSukumar Swaminathan 		}
7374728bdc9bSSukumar Swaminathan 	}
7375728bdc9bSSukumar Swaminathan 	mutex_exit(&hba->auth_lock);
7376728bdc9bSSukumar Swaminathan 
7377728bdc9bSSukumar Swaminathan 	sp->cmn.fcsp_support = 1;
7378fcf3ce44SJohn Forte 
7379fcf3ce44SJohn Forte 	return;
7380fcf3ce44SJohn Forte 
7381fcf3ce44SJohn Forte } /* emlxs_dhc_init_sp() */
7382fcf3ce44SJohn Forte 
7383fcf3ce44SJohn Forte 
7384fcf3ce44SJohn Forte extern uint32_t
emlxs_dhc_verify_login(emlxs_port_t * port,uint32_t sid,SERV_PARM * sp)7385fcf3ce44SJohn Forte emlxs_dhc_verify_login(emlxs_port_t *port, uint32_t sid, SERV_PARM *sp)
7386fcf3ce44SJohn Forte {
7387fcf3ce44SJohn Forte 	emlxs_hba_t *hba = HBA;
7388fcf3ce44SJohn Forte 	emlxs_config_t *cfg = &CFG;
7389fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *auth_cfg;
7390fcf3ce44SJohn Forte 	emlxs_auth_key_t *auth_key;
7391fcf3ce44SJohn Forte 	uint32_t fabric;
7392fcf3ce44SJohn Forte 	uint32_t fabric_switch;
7393fcf3ce44SJohn Forte 
739482527734SSukumar Swaminathan 	fabric = ((sid & FABRIC_DID_MASK) == FABRIC_DID_MASK) ? 1 : 0;
739582527734SSukumar Swaminathan 	fabric_switch = ((sid == FABRIC_DID) ? 1 : 0);
7396fcf3ce44SJohn Forte 
7397fcf3ce44SJohn Forte 	if (port->port_dhc.state == ELX_FABRIC_AUTH_FAILED) {
7398fcf3ce44SJohn Forte 		/* Reject login */
7399fcf3ce44SJohn Forte 		return (1);
7400fcf3ce44SJohn Forte 	}
7401fcf3ce44SJohn Forte 	/* Remote host supports FCSP */
7402fcf3ce44SJohn Forte 	if (sp->cmn.fcsp_support) {
7403fcf3ce44SJohn Forte 		/* Continue login */
7404fcf3ce44SJohn Forte 		return (0);
7405fcf3ce44SJohn Forte 	}
7406fcf3ce44SJohn Forte 	/* Auth disabled in host */
7407fcf3ce44SJohn Forte 	if (cfg[CFG_AUTH_ENABLE].current == 0) {
7408fcf3ce44SJohn Forte 		/* Continue login */
7409fcf3ce44SJohn Forte 		return (0);
7410fcf3ce44SJohn Forte 	}
7411fcf3ce44SJohn Forte 	/* Auth disabled for npiv */
7412fcf3ce44SJohn Forte 	if (port->vpi != 0 && cfg[CFG_AUTH_NPIV].current == 0) {
7413fcf3ce44SJohn Forte 		/* Continue login */
7414fcf3ce44SJohn Forte 		return (0);
7415fcf3ce44SJohn Forte 	}
7416fcf3ce44SJohn Forte 	if (!fabric_switch && fabric) {
7417fcf3ce44SJohn Forte 		/* Continue login */
7418fcf3ce44SJohn Forte 		return (0);
7419fcf3ce44SJohn Forte 	}
7420fcf3ce44SJohn Forte 	/* Auth disabled for p2p */
7421fcf3ce44SJohn Forte 	if (!fabric_switch && cfg[CFG_AUTH_E2E].current == 0) {
7422fcf3ce44SJohn Forte 		/* Continue login */
7423fcf3ce44SJohn Forte 		return (0);
7424fcf3ce44SJohn Forte 	}
7425fcf3ce44SJohn Forte 
7426fcf3ce44SJohn Forte 	/* Remote port does NOT support FCSP */
7427fcf3ce44SJohn Forte 	/* Host has FCSP enabled */
7428fcf3ce44SJohn Forte 	/* Now check to make sure auth mode for this port is also enabled */
7429fcf3ce44SJohn Forte 
7430fcf3ce44SJohn Forte 	mutex_enter(&hba->auth_lock);
7431fcf3ce44SJohn Forte 
7432fcf3ce44SJohn Forte 	/* Acquire auth configuration */
7433fcf3ce44SJohn Forte 	if (fabric_switch) {
7434fcf3ce44SJohn Forte 		auth_cfg = emlxs_auth_cfg_find(port,
7435fcf3ce44SJohn Forte 		    (uint8_t *)emlxs_fabric_wwn);
7436fcf3ce44SJohn Forte 		auth_key = emlxs_auth_key_find(port,
7437fcf3ce44SJohn Forte 		    (uint8_t *)emlxs_fabric_wwn);
7438fcf3ce44SJohn Forte 	} else {
7439fcf3ce44SJohn Forte 		auth_cfg = emlxs_auth_cfg_find(port,
7440fcf3ce44SJohn Forte 		    (uint8_t *)&sp->portName);
7441fcf3ce44SJohn Forte 		auth_key = emlxs_auth_key_find(port,
7442fcf3ce44SJohn Forte 		    (uint8_t *)&sp->portName);
7443fcf3ce44SJohn Forte 	}
7444fcf3ce44SJohn Forte 
7445fcf3ce44SJohn Forte 	if (auth_key && auth_cfg &&
7446fcf3ce44SJohn Forte 	    (auth_cfg->authentication_mode == AUTH_MODE_ACTIVE)) {
7447fcf3ce44SJohn Forte 		mutex_exit(&hba->auth_lock);
7448fcf3ce44SJohn Forte 
7449fcf3ce44SJohn Forte 		/* Reject login */
7450fcf3ce44SJohn Forte 		return (1);
7451fcf3ce44SJohn Forte 	}
7452fcf3ce44SJohn Forte 	mutex_exit(&hba->auth_lock);
7453fcf3ce44SJohn Forte 
7454fcf3ce44SJohn Forte 	return (0);
7455fcf3ce44SJohn Forte 
7456fcf3ce44SJohn Forte } /* emlxs_dhc_verify_login() */
7457fcf3ce44SJohn Forte 
7458fcf3ce44SJohn Forte 
7459fcf3ce44SJohn Forte /*
7460fcf3ce44SJohn Forte  * ! emlxs_dhc_reauth_timeout
7461fcf3ce44SJohn Forte  *
7462fcf3ce44SJohn Forte  * \pre \post \param phba \param arg1: \param arg2: ndlp to which the host
7463fcf3ce44SJohn Forte  * is to be authenticated. \return void
7464fcf3ce44SJohn Forte  *
7465fcf3ce44SJohn Forte  * \b Description:
7466fcf3ce44SJohn Forte  *
7467fcf3ce44SJohn Forte  * Timeout handler for reauthentication heartbeat.
7468fcf3ce44SJohn Forte  *
7469fcf3ce44SJohn Forte  * The reauthentication heart beat will be triggered 1 min by default after
7470fcf3ce44SJohn Forte  * the first authentication success. reauth_intval is
7471fcf3ce44SJohn Forte  * configurable. if reauth_intval is set to zero, it means no reauth heart
7472fcf3ce44SJohn Forte  * beat anymore.
7473fcf3ce44SJohn Forte  *
7474fcf3ce44SJohn Forte  * reauth heart beat will be triggered by IOCTL call from user space. Reauth
7475fcf3ce44SJohn Forte  * heart beat will go through the authentication process
7476fcf3ce44SJohn Forte  * all over again without causing IO traffic disruption. Initially it should
7477fcf3ce44SJohn Forte  * be triggered after authentication success.
7478fcf3ce44SJohn Forte  * Subsequently disable/enable reauth heart beat will be performed by
7479fcf3ce44SJohn Forte  * HBAnyware or other utility.
7480fcf3ce44SJohn Forte  *
7481fcf3ce44SJohn Forte  */
7482fcf3ce44SJohn Forte /* ARGSUSED */
7483fcf3ce44SJohn Forte extern void
emlxs_dhc_reauth_timeout(emlxs_port_t * port,void * arg1,void * arg2)7484fcf3ce44SJohn Forte emlxs_dhc_reauth_timeout(
7485fcf3ce44SJohn Forte 	emlxs_port_t *port,
7486fcf3ce44SJohn Forte 	void *arg1,
7487fcf3ce44SJohn Forte 	void *arg2)
7488fcf3ce44SJohn Forte {
7489fcf3ce44SJohn Forte 	emlxs_port_dhc_t *port_dhc = &port->port_dhc;
7490fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *) arg2;
7491fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
7492fcf3ce44SJohn Forte 
7493fcf3ce44SJohn Forte 	if (node_dhc->auth_cfg.reauthenticate_time_interval == 0) {
7494fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
7495fcf3ce44SJohn Forte 		    &emlxs_fcsp_debug_msg,
7496fcf3ce44SJohn Forte 		    "Reauth timeout. Reauth no longer enabled. 0x%x %x",
7497fcf3ce44SJohn Forte 		    ndlp->nlp_DID, node_dhc->state);
7498fcf3ce44SJohn Forte 
7499fcf3ce44SJohn Forte 		emlxs_dhc_set_reauth_time(port, ndlp, DISABLE);
7500fcf3ce44SJohn Forte 
7501fcf3ce44SJohn Forte 		return;
7502fcf3ce44SJohn Forte 	}
7503fcf3ce44SJohn Forte 	/* This should not happen!! */
7504fcf3ce44SJohn Forte 	if (port_dhc->state == ELX_FABRIC_IN_AUTH) {
7505fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
7506fcf3ce44SJohn Forte 		    &emlxs_fcsp_error_msg,
7507fcf3ce44SJohn Forte 		    "Reauth timeout. Fabric in auth. Quiting. 0x%x %x",
7508fcf3ce44SJohn Forte 		    ndlp->nlp_DID, node_dhc->state);
7509fcf3ce44SJohn Forte 
7510fcf3ce44SJohn Forte 		emlxs_dhc_set_reauth_time(port, ndlp, DISABLE);
7511fcf3ce44SJohn Forte 
7512fcf3ce44SJohn Forte 		return;
7513fcf3ce44SJohn Forte 	}
7514fcf3ce44SJohn Forte 	if (node_dhc->state != NODE_STATE_AUTH_SUCCESS) {
7515fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
7516fcf3ce44SJohn Forte 		    &emlxs_fcsp_debug_msg,
7517fcf3ce44SJohn Forte 		    "Reauth timeout. Auth not done. Restarting. 0x%x %x",
7518fcf3ce44SJohn Forte 		    ndlp->nlp_DID, node_dhc->state);
7519fcf3ce44SJohn Forte 
7520fcf3ce44SJohn Forte 		goto restart;
7521fcf3ce44SJohn Forte 	}
7522fcf3ce44SJohn Forte 	/*
7523fcf3ce44SJohn Forte 	 * This might happen, the ndlp is doing reauthencation. meaning ndlp
7524fcf3ce44SJohn Forte 	 * is being re-authenticated to the host. Thus not necessary to have
7525fcf3ce44SJohn Forte 	 * host re-authenticated to the ndlp at this point because ndlp might
7526fcf3ce44SJohn Forte 	 * support bi-directional auth. we can just simply donothing and
7527fcf3ce44SJohn Forte 	 * restart the timer.
7528fcf3ce44SJohn Forte 	 */
7529fcf3ce44SJohn Forte 	if (port_dhc->state == ELX_FABRIC_IN_REAUTH) {
7530fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
7531fcf3ce44SJohn Forte 		    &emlxs_fcsp_debug_msg,
7532fcf3ce44SJohn Forte 		    "Reauth timeout. Fabric in reauth. Restarting. 0x%x %x",
7533fcf3ce44SJohn Forte 		    ndlp->nlp_DID, node_dhc->state);
7534fcf3ce44SJohn Forte 
7535fcf3ce44SJohn Forte 		goto restart;
7536fcf3ce44SJohn Forte 	}
7537fcf3ce44SJohn Forte 	/*
7538fcf3ce44SJohn Forte 	 * node's reauth heart beat is running already, cancel it first and
7539fcf3ce44SJohn Forte 	 * then restart
7540fcf3ce44SJohn Forte 	 */
7541fcf3ce44SJohn Forte 	if (node_dhc->nlp_reauth_status == NLP_HOST_REAUTH_IN_PROGRESS) {
7542fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
7543fcf3ce44SJohn Forte 		    &emlxs_fcsp_debug_msg,
7544fcf3ce44SJohn Forte 		    "Reauth timeout. Fabric in reauth. Restarting. 0x%x %x",
7545fcf3ce44SJohn Forte 		    ndlp->nlp_DID, node_dhc->state);
7546fcf3ce44SJohn Forte 
7547fcf3ce44SJohn Forte 		goto restart;
7548fcf3ce44SJohn Forte 	}
7549fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT,
7550fcf3ce44SJohn Forte 	    &emlxs_fcsp_debug_msg,
7551fcf3ce44SJohn Forte 	    "Reauth timeout. Auth initiated. did=0x%x",
7552fcf3ce44SJohn Forte 	    ndlp->nlp_DID);
7553fcf3ce44SJohn Forte 
7554fcf3ce44SJohn Forte 	emlxs_dhc_set_reauth_time(port, ndlp, ENABLE);
7555fcf3ce44SJohn Forte 	node_dhc->nlp_reauth_status = NLP_HOST_REAUTH_IN_PROGRESS;
7556fcf3ce44SJohn Forte 
7557fcf3ce44SJohn Forte 	/* Attempt to restart authentication */
7558fcf3ce44SJohn Forte 	if (emlxs_dhc_auth_start(port, ndlp, NULL, NULL) != 0) {
7559fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
7560fcf3ce44SJohn Forte 		    &emlxs_fcsp_debug_msg,
7561fcf3ce44SJohn Forte 		    "Reauth timeout. Auth initiation failed. 0x%x %x",
7562fcf3ce44SJohn Forte 		    ndlp->nlp_DID, node_dhc->state);
7563fcf3ce44SJohn Forte 
7564fcf3ce44SJohn Forte 		return;
7565fcf3ce44SJohn Forte 	}
7566fcf3ce44SJohn Forte 	return;
7567fcf3ce44SJohn Forte 
7568fcf3ce44SJohn Forte restart:
7569fcf3ce44SJohn Forte 
7570fcf3ce44SJohn Forte 	emlxs_dhc_set_reauth_time(port, ndlp, ENABLE);
7571fcf3ce44SJohn Forte 
7572fcf3ce44SJohn Forte 	return;
7573fcf3ce44SJohn Forte 
7574fcf3ce44SJohn Forte } /* emlxs_dhc_reauth_timeout */
7575fcf3ce44SJohn Forte 
7576fcf3ce44SJohn Forte 
7577fcf3ce44SJohn Forte static void
emlxs_dhc_set_reauth_time(emlxs_port_t * port,emlxs_node_t * ndlp,uint32_t status)7578fcf3ce44SJohn Forte emlxs_dhc_set_reauth_time(
7579fcf3ce44SJohn Forte 	emlxs_port_t *port,
7580fcf3ce44SJohn Forte 	emlxs_node_t *ndlp,
7581fcf3ce44SJohn Forte 	uint32_t status)
7582fcf3ce44SJohn Forte {
7583fcf3ce44SJohn Forte 	emlxs_port_dhc_t *port_dhc = &port->port_dhc;
7584fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
7585fcf3ce44SJohn Forte 	uint32_t drv_time;
7586fcf3ce44SJohn Forte 	uint32_t timeout;
7587fcf3ce44SJohn Forte 	uint32_t reauth_tmo;
7588fcf3ce44SJohn Forte 	time_t last_auth_time;
7589fcf3ce44SJohn Forte 
7590fcf3ce44SJohn Forte 	node_dhc->flag &= ~NLP_SET_REAUTH_TIME;
7591fcf3ce44SJohn Forte 
7592fcf3ce44SJohn Forte 	if ((status == ENABLE) &&
7593fcf3ce44SJohn Forte 	    node_dhc->auth_cfg.reauthenticate_time_interval) {
7594fcf3ce44SJohn Forte 
7595fcf3ce44SJohn Forte 		timeout =
7596fcf3ce44SJohn Forte 		    (60 * node_dhc->auth_cfg.reauthenticate_time_interval);
7597fcf3ce44SJohn Forte 		drv_time = DRV_TIME;
7598fcf3ce44SJohn Forte 
7599fcf3ce44SJohn Forte 		/* Get last successful auth time */
760082527734SSukumar Swaminathan 		if (ndlp->nlp_DID == FABRIC_DID) {
7601fcf3ce44SJohn Forte 			last_auth_time = port_dhc->auth_time;
7602fcf3ce44SJohn Forte 		} else if (node_dhc->parent_auth_cfg) {
7603fcf3ce44SJohn Forte 			last_auth_time = node_dhc->parent_auth_cfg->auth_time;
7604fcf3ce44SJohn Forte 		} else {
7605fcf3ce44SJohn Forte 			last_auth_time = 0;
7606fcf3ce44SJohn Forte 		}
7607fcf3ce44SJohn Forte 
7608fcf3ce44SJohn Forte 		if (last_auth_time) {
7609fcf3ce44SJohn Forte 			reauth_tmo = last_auth_time + timeout;
7610fcf3ce44SJohn Forte 
7611fcf3ce44SJohn Forte 			/* Validate reauth_tmo */
7612fcf3ce44SJohn Forte 			if ((reauth_tmo < drv_time) ||
7613fcf3ce44SJohn Forte 			    (reauth_tmo > drv_time + timeout)) {
7614fcf3ce44SJohn Forte 				reauth_tmo = drv_time + timeout;
7615fcf3ce44SJohn Forte 			}
7616fcf3ce44SJohn Forte 		} else {
7617fcf3ce44SJohn Forte 			reauth_tmo = drv_time + timeout;
7618fcf3ce44SJohn Forte 		}
7619fcf3ce44SJohn Forte 
7620fcf3ce44SJohn Forte 		node_dhc->nlp_reauth_tmo = reauth_tmo;
7621fcf3ce44SJohn Forte 		node_dhc->nlp_reauth_status = NLP_HOST_REAUTH_ENABLED;
7622fcf3ce44SJohn Forte 
7623fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
7624fcf3ce44SJohn Forte 		    &emlxs_fcsp_debug_msg,
7625fcf3ce44SJohn Forte 		    "Reauth enabled. did=0x%x state=%x tmo=%d,%d",
7626fcf3ce44SJohn Forte 		    ndlp->nlp_DID, node_dhc->state,
7627fcf3ce44SJohn Forte 		    node_dhc->auth_cfg.reauthenticate_time_interval,
7628fcf3ce44SJohn Forte 		    (reauth_tmo - drv_time));
7629fcf3ce44SJohn Forte 
7630fcf3ce44SJohn Forte 	} else {
7631fcf3ce44SJohn Forte 		node_dhc->nlp_reauth_tmo = 0;
7632fcf3ce44SJohn Forte 		node_dhc->nlp_reauth_status = NLP_HOST_REAUTH_DISABLED;
7633fcf3ce44SJohn Forte 
7634fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
7635fcf3ce44SJohn Forte 		    &emlxs_fcsp_debug_msg,
7636fcf3ce44SJohn Forte 		    "Reauth disabled. did=0x%x state=%x",
7637fcf3ce44SJohn Forte 		    ndlp->nlp_DID, node_dhc->state);
7638fcf3ce44SJohn Forte 	}
7639fcf3ce44SJohn Forte 
7640fcf3ce44SJohn Forte 	return;
7641fcf3ce44SJohn Forte 
7642fcf3ce44SJohn Forte } /* emlxs_dhc_set_reauth_time */
7643fcf3ce44SJohn Forte 
7644fcf3ce44SJohn Forte 
7645fcf3ce44SJohn Forte /* ARGSUSED */
7646fcf3ce44SJohn Forte extern void
emlxs_dhc_authrsp_timeout(emlxs_port_t * port,void * arg1,void * arg2)7647fcf3ce44SJohn Forte emlxs_dhc_authrsp_timeout(
7648fcf3ce44SJohn Forte 	emlxs_port_t *port,
7649fcf3ce44SJohn Forte 	void *arg1,
7650fcf3ce44SJohn Forte 	void *arg2)
7651fcf3ce44SJohn Forte {
7652fcf3ce44SJohn Forte 	NODELIST *ndlp = (NODELIST *)arg1;
7653fcf3ce44SJohn Forte 	emlxs_node_dhc_t *node_dhc = &ndlp->node_dhc;
7654fcf3ce44SJohn Forte 	uint8_t ReasonCode;
7655fcf3ce44SJohn Forte 	uint8_t ReasonCodeExplanation;
7656fcf3ce44SJohn Forte 
7657fcf3ce44SJohn Forte 	node_dhc->nlp_authrsp_tmo = 0;
7658fcf3ce44SJohn Forte 	node_dhc->nlp_authrsp_tmocnt++;
7659fcf3ce44SJohn Forte 
7660fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_debug_msg,
7661fcf3ce44SJohn Forte 	    "Authrsp timeout. did=0x%x count=%d",
7662fcf3ce44SJohn Forte 	    ndlp->nlp_DID, node_dhc->nlp_authrsp_tmocnt);
7663fcf3ce44SJohn Forte 
7664fcf3ce44SJohn Forte 	/*
7665fcf3ce44SJohn Forte 	 * According to the FC-SP spec v1.8 pp76.
7666fcf3ce44SJohn Forte 	 *
7667fcf3ce44SJohn Forte 	 * When the AUTH_TMO error is detected, the entity may: 1. Act as if the
7668fcf3ce44SJohn Forte 	 * authentication transaction has failed and terminate the
7669fcf3ce44SJohn Forte 	 * communication; or 2. Restart a new authentication transaction, by
7670fcf3ce44SJohn Forte 	 * sending an AUTH_Reject msg with Reason Code `Logical Error' and
7671fcf3ce44SJohn Forte 	 * Reason Code Explanation 'Restart Authentication Protocol', The
7672fcf3ce44SJohn Forte 	 * action performed by the entity receiving such a AUTH_Reject should
7673fcf3ce44SJohn Forte 	 * restart the authentication Transaction by sending a new
7674fcf3ce44SJohn Forte 	 * AUTH_Negotiate. We plan to use 2 as the action for now.
7675fcf3ce44SJohn Forte 	 *
7676fcf3ce44SJohn Forte 	 */
7677fcf3ce44SJohn Forte 
7678fcf3ce44SJohn Forte 	if (node_dhc->nlp_authrsp_tmocnt > 3) {
7679fcf3ce44SJohn Forte 		/* Generate a remove event for the nodelist entry */
7680fcf3ce44SJohn Forte 		(void) emlxs_dhchap_state_machine(port, NULL, NULL,
7681fcf3ce44SJohn Forte 		    NULL, ndlp, NODE_EVENT_DEVICE_RM);
7682fcf3ce44SJohn Forte 
7683fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_FAILURE;
7684fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_AUTH_FAILED;
7685fcf3ce44SJohn Forte 	} else {
7686fcf3ce44SJohn Forte 		/* Generate a recovery event for the nodelist entry */
7687fcf3ce44SJohn Forte 		(void) emlxs_dhchap_state_machine(port, NULL, NULL,
7688fcf3ce44SJohn Forte 		    NULL, ndlp, NODE_EVENT_DEVICE_RECOVERY);
7689fcf3ce44SJohn Forte 
7690fcf3ce44SJohn Forte 		ReasonCode = AUTHRJT_LOGIC_ERR;
7691fcf3ce44SJohn Forte 		ReasonCodeExplanation = AUTHEXP_RESTART_AUTH;
7692fcf3ce44SJohn Forte 	}
7693fcf3ce44SJohn Forte 
7694fcf3ce44SJohn Forte 	emlxs_dhc_state(port, ndlp, NODE_STATE_AUTH_FAILED, ReasonCode,
7695fcf3ce44SJohn Forte 	    ReasonCodeExplanation);
7696fcf3ce44SJohn Forte 	(void) emlxs_issue_auth_reject(port, ndlp, 0, 0, ReasonCode,
7697fcf3ce44SJohn Forte 	    ReasonCodeExplanation);
7698fcf3ce44SJohn Forte 	emlxs_dhc_auth_complete(port, ndlp, 1);
7699fcf3ce44SJohn Forte 
7700fcf3ce44SJohn Forte 	/*
7701fcf3ce44SJohn Forte 	 * It is expected the other party should restart the authentication
7702fcf3ce44SJohn Forte 	 * transaction
7703fcf3ce44SJohn Forte 	 */
7704fcf3ce44SJohn Forte 
7705fcf3ce44SJohn Forte 	return;
7706fcf3ce44SJohn Forte 
7707fcf3ce44SJohn Forte } /* emlxs_dhc_authrsp_timeout() */
7708fcf3ce44SJohn Forte 
7709fcf3ce44SJohn Forte 
7710fcf3ce44SJohn Forte /* **************************** AUTH CFG MANAGEMENT ************************ */
7711fcf3ce44SJohn Forte 
7712fcf3ce44SJohn Forte /* auth_lock must be held */
7713fcf3ce44SJohn Forte static emlxs_auth_cfg_t *
emlxs_auth_cfg_find(emlxs_port_t * port,uint8_t * rwwpn)7714fcf3ce44SJohn Forte emlxs_auth_cfg_find(emlxs_port_t *port, uint8_t *rwwpn)
7715fcf3ce44SJohn Forte {
7716fcf3ce44SJohn Forte 	emlxs_hba_t *hba = HBA;
7717fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *auth_cfg;
7718fcf3ce44SJohn Forte 
7719fcf3ce44SJohn Forte 	if (rwwpn) {
7720fcf3ce44SJohn Forte 		/* lwwpn, rwwpn */
7721fcf3ce44SJohn Forte 		auth_cfg = emlxs_auth_cfg_get(hba,
7722fcf3ce44SJohn Forte 		    (uint8_t *)&port->wwpn, (uint8_t *)rwwpn);
7723fcf3ce44SJohn Forte 
7724fcf3ce44SJohn Forte 		if (auth_cfg) {
7725fcf3ce44SJohn Forte 			emlxs_auth_cfg_print(hba, auth_cfg);
7726fcf3ce44SJohn Forte 			return (auth_cfg);
7727fcf3ce44SJohn Forte 		}
7728fcf3ce44SJohn Forte 		/* null, rwwpn */
7729fcf3ce44SJohn Forte 		auth_cfg = emlxs_auth_cfg_get(hba,
7730fcf3ce44SJohn Forte 		    (uint8_t *)emlxs_null_wwn, (uint8_t *)rwwpn);
7731fcf3ce44SJohn Forte 
7732fcf3ce44SJohn Forte 		if (auth_cfg) {
7733fcf3ce44SJohn Forte 			emlxs_auth_cfg_print(hba, auth_cfg);
7734fcf3ce44SJohn Forte 			return (auth_cfg);
7735fcf3ce44SJohn Forte 		}
7736fcf3ce44SJohn Forte 	}
7737fcf3ce44SJohn Forte 	/* lwwpn, null */
7738fcf3ce44SJohn Forte 	auth_cfg = emlxs_auth_cfg_get(hba,
7739fcf3ce44SJohn Forte 	    (uint8_t *)&port->wwpn, (uint8_t *)emlxs_null_wwn);
7740fcf3ce44SJohn Forte 
7741fcf3ce44SJohn Forte 	if (auth_cfg) {
7742fcf3ce44SJohn Forte 		emlxs_auth_cfg_print(hba, auth_cfg);
7743fcf3ce44SJohn Forte 		return (auth_cfg);
7744fcf3ce44SJohn Forte 	}
7745fcf3ce44SJohn Forte 	/* null, null */
7746fcf3ce44SJohn Forte 	return (&hba->auth_cfg);
7747fcf3ce44SJohn Forte 
7748fcf3ce44SJohn Forte } /* emlxs_auth_cfg_find() */
7749fcf3ce44SJohn Forte 
7750fcf3ce44SJohn Forte static void
emlxs_auth_cfg_init(emlxs_hba_t * hba)7751fcf3ce44SJohn Forte emlxs_auth_cfg_init(emlxs_hba_t *hba)
7752fcf3ce44SJohn Forte {
7753fcf3ce44SJohn Forte 	emlxs_config_t *cfg = &CFG;
7754fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *auth_cfg;
7755fcf3ce44SJohn Forte 
7756fcf3ce44SJohn Forte 	/* Destroy old table if one exists */
7757fcf3ce44SJohn Forte 	emlxs_auth_cfg_fini(hba);
7758fcf3ce44SJohn Forte 
7759fcf3ce44SJohn Forte 	mutex_enter(&hba->auth_lock);
7760fcf3ce44SJohn Forte 
7761fcf3ce44SJohn Forte 	/* Zero default entry */
7762fcf3ce44SJohn Forte 	auth_cfg = &hba->auth_cfg;
7763fcf3ce44SJohn Forte 	bzero(auth_cfg, sizeof (emlxs_auth_cfg_t));
7764fcf3ce44SJohn Forte 	auth_cfg->next = auth_cfg;
7765fcf3ce44SJohn Forte 	auth_cfg->prev = auth_cfg;
7766fcf3ce44SJohn Forte 
7767fcf3ce44SJohn Forte 	/* Configure the default entry */
7768fcf3ce44SJohn Forte 	auth_cfg->authentication_timeout =
7769fcf3ce44SJohn Forte 	    cfg[CFG_AUTH_TMO].current;
7770fcf3ce44SJohn Forte 	auth_cfg->authentication_mode =
7771fcf3ce44SJohn Forte 	    cfg[CFG_AUTH_MODE].current;
7772fcf3ce44SJohn Forte 	auth_cfg->bidirectional =
7773fcf3ce44SJohn Forte 	    cfg[CFG_AUTH_BIDIR].current;
7774fcf3ce44SJohn Forte 	auth_cfg->authentication_type_priority[0] =
7775fcf3ce44SJohn Forte 	    (cfg[CFG_AUTH_TYPE].current & 0xF000) >> 12;
7776fcf3ce44SJohn Forte 	auth_cfg->authentication_type_priority[1] =
7777fcf3ce44SJohn Forte 	    (cfg[CFG_AUTH_TYPE].current & 0x0F00) >> 8;
7778fcf3ce44SJohn Forte 	auth_cfg->authentication_type_priority[2] =
7779fcf3ce44SJohn Forte 	    (cfg[CFG_AUTH_TYPE].current & 0x00F0) >> 4;
7780fcf3ce44SJohn Forte 	auth_cfg->authentication_type_priority[3] =
7781fcf3ce44SJohn Forte 	    (cfg[CFG_AUTH_TYPE].current & 0x000F);
7782fcf3ce44SJohn Forte 	auth_cfg->hash_priority[0] =
7783fcf3ce44SJohn Forte 	    (cfg[CFG_AUTH_HASH].current & 0xF000) >> 12;
7784fcf3ce44SJohn Forte 	auth_cfg->hash_priority[1] =
7785fcf3ce44SJohn Forte 	    (cfg[CFG_AUTH_HASH].current & 0x0F00) >> 8;
7786fcf3ce44SJohn Forte 	auth_cfg->hash_priority[2] =
7787fcf3ce44SJohn Forte 	    (cfg[CFG_AUTH_HASH].current & 0x00F0) >> 4;
7788fcf3ce44SJohn Forte 	auth_cfg->hash_priority[3] =
7789fcf3ce44SJohn Forte 	    (cfg[CFG_AUTH_HASH].current & 0x000F);
7790fcf3ce44SJohn Forte 	auth_cfg->dh_group_priority[0] =
7791fcf3ce44SJohn Forte 	    (cfg[CFG_AUTH_GROUP].current & 0xF0000000) >> 28;
7792fcf3ce44SJohn Forte 	auth_cfg->dh_group_priority[1] =
7793fcf3ce44SJohn Forte 	    (cfg[CFG_AUTH_GROUP].current & 0x0F000000) >> 24;
7794fcf3ce44SJohn Forte 	auth_cfg->dh_group_priority[2] =
7795fcf3ce44SJohn Forte 	    (cfg[CFG_AUTH_GROUP].current & 0x00F00000) >> 20;
7796fcf3ce44SJohn Forte 	auth_cfg->dh_group_priority[3] =
7797fcf3ce44SJohn Forte 	    (cfg[CFG_AUTH_GROUP].current & 0x000F0000) >> 16;
7798fcf3ce44SJohn Forte 	auth_cfg->dh_group_priority[4] =
7799fcf3ce44SJohn Forte 	    (cfg[CFG_AUTH_GROUP].current & 0x0000F000) >> 12;
7800fcf3ce44SJohn Forte 	auth_cfg->dh_group_priority[5] =
7801fcf3ce44SJohn Forte 	    (cfg[CFG_AUTH_GROUP].current & 0x00000F00) >> 8;
7802fcf3ce44SJohn Forte 	auth_cfg->dh_group_priority[6] =
7803fcf3ce44SJohn Forte 	    (cfg[CFG_AUTH_GROUP].current & 0x000000F0) >> 4;
7804fcf3ce44SJohn Forte 	auth_cfg->dh_group_priority[7] =
7805fcf3ce44SJohn Forte 	    (cfg[CFG_AUTH_GROUP].current & 0x0000000F);
7806fcf3ce44SJohn Forte 	auth_cfg->reauthenticate_time_interval =
7807fcf3ce44SJohn Forte 	    cfg[CFG_AUTH_INTERVAL].current;
7808fcf3ce44SJohn Forte 
7809fcf3ce44SJohn Forte 	emlxs_auth_cfg_read(hba);
7810fcf3ce44SJohn Forte 
7811fcf3ce44SJohn Forte 	mutex_exit(&hba->auth_lock);
7812fcf3ce44SJohn Forte 
7813fcf3ce44SJohn Forte 	return;
7814fcf3ce44SJohn Forte 
7815fcf3ce44SJohn Forte } /* emlxs_auth_cfg_init() */
7816fcf3ce44SJohn Forte 
7817fcf3ce44SJohn Forte 
7818fcf3ce44SJohn Forte static void
emlxs_auth_cfg_fini(emlxs_hba_t * hba)7819fcf3ce44SJohn Forte emlxs_auth_cfg_fini(emlxs_hba_t *hba)
7820fcf3ce44SJohn Forte {
7821fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *auth_cfg = hba->auth_cfg.next;
7822fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *next;
7823fcf3ce44SJohn Forte 
7824fcf3ce44SJohn Forte 	mutex_enter(&hba->auth_lock);
7825fcf3ce44SJohn Forte 
7826fcf3ce44SJohn Forte 	while (auth_cfg && auth_cfg != &hba->auth_cfg) {
7827fcf3ce44SJohn Forte 		next = auth_cfg->next;
7828fcf3ce44SJohn Forte 		emlxs_auth_cfg_destroy(hba, auth_cfg);
7829fcf3ce44SJohn Forte 		auth_cfg = next;
7830fcf3ce44SJohn Forte 	}
7831fcf3ce44SJohn Forte 
7832fcf3ce44SJohn Forte 	mutex_exit(&hba->auth_lock);
7833fcf3ce44SJohn Forte 
7834fcf3ce44SJohn Forte 	return;
7835fcf3ce44SJohn Forte 
7836fcf3ce44SJohn Forte } /* emlxs_auth_cfg_fini() */
7837fcf3ce44SJohn Forte 
7838fcf3ce44SJohn Forte 
7839fcf3ce44SJohn Forte static void
emlxs_auth_cfg_print(emlxs_hba_t * hba,emlxs_auth_cfg_t * auth_cfg)7840fcf3ce44SJohn Forte emlxs_auth_cfg_print(emlxs_hba_t *hba, emlxs_auth_cfg_t *auth_cfg)
7841fcf3ce44SJohn Forte {
7842fcf3ce44SJohn Forte 	emlxs_port_t *port = &PPORT;
7843fcf3ce44SJohn Forte 
7844fcf3ce44SJohn Forte 	char s_lwwpn[32];
7845fcf3ce44SJohn Forte 	char s_rwwpn[32];
7846fcf3ce44SJohn Forte 
7847fcf3ce44SJohn Forte 	/* Create and add new entry */
7848fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT,
7849fcf3ce44SJohn Forte 	    &emlxs_fcsp_detail_msg,
7850fcf3ce44SJohn Forte 	    "%s:%s:%x:%x:%x:%x%x%x%x:%x%x%x%x:%x%x%x%x%x%x%x%x:%x",
7851*8f23e9faSHans Rosenfeld 	    emlxs_wwn_xlate(s_lwwpn, sizeof (s_lwwpn),
7852*8f23e9faSHans Rosenfeld 	    (uint8_t *)&auth_cfg->local_entity),
7853*8f23e9faSHans Rosenfeld 	    emlxs_wwn_xlate(s_rwwpn, sizeof (s_rwwpn),
7854*8f23e9faSHans Rosenfeld 	    (uint8_t *)&auth_cfg->remote_entity),
7855fcf3ce44SJohn Forte 	    auth_cfg->authentication_timeout,
7856fcf3ce44SJohn Forte 	    auth_cfg->authentication_mode,
7857fcf3ce44SJohn Forte 	    auth_cfg->bidirectional,
7858fcf3ce44SJohn Forte 	    auth_cfg->authentication_type_priority[0],
7859fcf3ce44SJohn Forte 	    auth_cfg->authentication_type_priority[1],
7860fcf3ce44SJohn Forte 	    auth_cfg->authentication_type_priority[2],
7861fcf3ce44SJohn Forte 	    auth_cfg->authentication_type_priority[3],
7862fcf3ce44SJohn Forte 	    auth_cfg->hash_priority[0],
7863fcf3ce44SJohn Forte 	    auth_cfg->hash_priority[1],
7864fcf3ce44SJohn Forte 	    auth_cfg->hash_priority[2],
7865fcf3ce44SJohn Forte 	    auth_cfg->hash_priority[3],
7866fcf3ce44SJohn Forte 	    auth_cfg->dh_group_priority[0],
7867fcf3ce44SJohn Forte 	    auth_cfg->dh_group_priority[1],
7868fcf3ce44SJohn Forte 	    auth_cfg->dh_group_priority[2],
7869fcf3ce44SJohn Forte 	    auth_cfg->dh_group_priority[3],
7870fcf3ce44SJohn Forte 	    auth_cfg->dh_group_priority[4],
7871fcf3ce44SJohn Forte 	    auth_cfg->dh_group_priority[5],
7872fcf3ce44SJohn Forte 	    auth_cfg->dh_group_priority[6],
7873fcf3ce44SJohn Forte 	    auth_cfg->dh_group_priority[7],
7874fcf3ce44SJohn Forte 	    auth_cfg->reauthenticate_time_interval);
7875fcf3ce44SJohn Forte 
7876fcf3ce44SJohn Forte } /* emlxs_auth_cfg_print() */
7877fcf3ce44SJohn Forte 
7878fcf3ce44SJohn Forte 
7879fcf3ce44SJohn Forte /* auth_lock must be held */
7880fcf3ce44SJohn Forte static emlxs_auth_cfg_t *
emlxs_auth_cfg_get(emlxs_hba_t * hba,uint8_t * lwwpn,uint8_t * rwwpn)7881fcf3ce44SJohn Forte emlxs_auth_cfg_get(emlxs_hba_t *hba, uint8_t *lwwpn, uint8_t *rwwpn)
7882fcf3ce44SJohn Forte {
7883fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *auth_cfg;
7884fcf3ce44SJohn Forte 
7885fcf3ce44SJohn Forte 	if (!lwwpn || !rwwpn) {
7886fcf3ce44SJohn Forte 		return (NULL);
7887fcf3ce44SJohn Forte 	}
7888fcf3ce44SJohn Forte 
7889fcf3ce44SJohn Forte 	/* Check for default entry */
7890fcf3ce44SJohn Forte 	if ((bcmp(lwwpn, emlxs_null_wwn, 8) == 0) &&
7891fcf3ce44SJohn Forte 	    (bcmp(rwwpn, emlxs_null_wwn, 8) == 0)) {
7892fcf3ce44SJohn Forte 		return (&hba->auth_cfg);
7893fcf3ce44SJohn Forte 	}
7894fcf3ce44SJohn Forte 
7895fcf3ce44SJohn Forte 	for (auth_cfg = hba->auth_cfg.next;
7896fcf3ce44SJohn Forte 	    auth_cfg != &hba->auth_cfg; auth_cfg = auth_cfg->next) {
7897fcf3ce44SJohn Forte 		/* Find pwd entry for this local port */
7898fcf3ce44SJohn Forte 
7899fcf3ce44SJohn Forte 		/* Check for exact wwpn match */
7900fcf3ce44SJohn Forte 		if (bcmp((void *)&auth_cfg->local_entity,
7901fcf3ce44SJohn Forte 		    (void *)lwwpn, 8) != 0) {
7902fcf3ce44SJohn Forte 			continue;
7903fcf3ce44SJohn Forte 		}
7904fcf3ce44SJohn Forte 		/* Find pwd entry for remote port */
7905fcf3ce44SJohn Forte 
7906fcf3ce44SJohn Forte 		/* Check for exact wwpn match */
7907fcf3ce44SJohn Forte 		if (bcmp((void *)&auth_cfg->remote_entity,
7908fcf3ce44SJohn Forte 		    (void *)rwwpn, 8) != 0) {
7909fcf3ce44SJohn Forte 			continue;
7910fcf3ce44SJohn Forte 		}
7911fcf3ce44SJohn Forte 		return (auth_cfg);
7912fcf3ce44SJohn Forte 	}
7913fcf3ce44SJohn Forte 
7914fcf3ce44SJohn Forte 	return (NULL);
7915fcf3ce44SJohn Forte 
7916fcf3ce44SJohn Forte } /* emlxs_auth_cfg_get() */
7917fcf3ce44SJohn Forte 
7918fcf3ce44SJohn Forte 
7919fcf3ce44SJohn Forte /* auth_lock must be held */
7920fcf3ce44SJohn Forte static emlxs_auth_cfg_t *
emlxs_auth_cfg_create(emlxs_hba_t * hba,uint8_t * lwwpn,uint8_t * rwwpn)7921fcf3ce44SJohn Forte emlxs_auth_cfg_create(emlxs_hba_t *hba, uint8_t *lwwpn, uint8_t *rwwpn)
7922fcf3ce44SJohn Forte {
7923fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *auth_cfg;
7924fcf3ce44SJohn Forte 
7925fcf3ce44SJohn Forte 	/* First check if entry already exists */
7926fcf3ce44SJohn Forte 	auth_cfg = emlxs_auth_cfg_get(hba, lwwpn, rwwpn);
7927fcf3ce44SJohn Forte 
7928fcf3ce44SJohn Forte 	if (auth_cfg) {
7929fcf3ce44SJohn Forte 		return (auth_cfg);
7930fcf3ce44SJohn Forte 	}
7931fcf3ce44SJohn Forte 	/* Allocate entry */
7932fcf3ce44SJohn Forte 	auth_cfg = (emlxs_auth_cfg_t *)kmem_zalloc(sizeof (emlxs_auth_cfg_t),
7933fcf3ce44SJohn Forte 	    KM_NOSLEEP);
7934fcf3ce44SJohn Forte 
7935fcf3ce44SJohn Forte 	if (!auth_cfg) {
7936fcf3ce44SJohn Forte 		return (NULL);
7937fcf3ce44SJohn Forte 	}
7938fcf3ce44SJohn Forte 	/* Add to list */
7939fcf3ce44SJohn Forte 	auth_cfg->next = &hba->auth_cfg;
7940fcf3ce44SJohn Forte 	auth_cfg->prev = hba->auth_cfg.prev;
7941fcf3ce44SJohn Forte 	hba->auth_cfg.prev->next = auth_cfg;
7942fcf3ce44SJohn Forte 	hba->auth_cfg.prev = auth_cfg;
7943fcf3ce44SJohn Forte 	hba->auth_cfg_count++;
7944fcf3ce44SJohn Forte 
7945fcf3ce44SJohn Forte 	/* Initialize name pair */
7946fcf3ce44SJohn Forte 	if (lwwpn) {
7947fcf3ce44SJohn Forte 		bcopy((void *)lwwpn, (void *)&auth_cfg->local_entity, 8);
7948fcf3ce44SJohn Forte 	}
7949fcf3ce44SJohn Forte 	if (rwwpn) {
7950fcf3ce44SJohn Forte 		bcopy((void *)rwwpn, (void *)&auth_cfg->remote_entity, 8);
7951fcf3ce44SJohn Forte 	}
7952fcf3ce44SJohn Forte 	auth_cfg->auth_status.auth_state = DFC_AUTH_STATE_OFF;
7953fcf3ce44SJohn Forte 
7954fcf3ce44SJohn Forte 	return (auth_cfg);
7955fcf3ce44SJohn Forte 
7956fcf3ce44SJohn Forte } /* emlxs_auth_cfg_create() */
7957fcf3ce44SJohn Forte 
7958fcf3ce44SJohn Forte 
7959fcf3ce44SJohn Forte /* auth_lock must be held */
7960fcf3ce44SJohn Forte static void
emlxs_auth_cfg_destroy(emlxs_hba_t * hba,emlxs_auth_cfg_t * auth_cfg)7961fcf3ce44SJohn Forte emlxs_auth_cfg_destroy(emlxs_hba_t *hba, emlxs_auth_cfg_t *auth_cfg)
7962fcf3ce44SJohn Forte {
7963fcf3ce44SJohn Forte 
7964fcf3ce44SJohn Forte 	if (!auth_cfg) {
7965fcf3ce44SJohn Forte 		return;
7966fcf3ce44SJohn Forte 	}
7967fcf3ce44SJohn Forte 	if (auth_cfg == &hba->auth_cfg) {
7968fcf3ce44SJohn Forte 		return;
7969fcf3ce44SJohn Forte 	}
7970fcf3ce44SJohn Forte 	/* Remove from  list */
7971fcf3ce44SJohn Forte 	auth_cfg->next->prev = auth_cfg->prev;
7972fcf3ce44SJohn Forte 	auth_cfg->prev->next = auth_cfg->next;
7973fcf3ce44SJohn Forte 	hba->auth_cfg_count--;
7974fcf3ce44SJohn Forte 
7975fcf3ce44SJohn Forte 	/* Remove node binding */
7976fcf3ce44SJohn Forte 	if (auth_cfg->node &&
7977fcf3ce44SJohn Forte 	    auth_cfg->node->nlp_active &&
7978fcf3ce44SJohn Forte 	    (auth_cfg->node->node_dhc.parent_auth_cfg == auth_cfg)) {
7979fcf3ce44SJohn Forte 		auth_cfg->node->node_dhc.parent_auth_cfg = NULL;
7980fcf3ce44SJohn Forte 	}
7981fcf3ce44SJohn Forte 	bzero(auth_cfg, sizeof (emlxs_auth_cfg_t));
7982fcf3ce44SJohn Forte 	kmem_free(auth_cfg, sizeof (emlxs_auth_cfg_t));
7983fcf3ce44SJohn Forte 
7984fcf3ce44SJohn Forte 	return;
7985fcf3ce44SJohn Forte 
7986fcf3ce44SJohn Forte } /* emlxs_auth_cfg_destroy() */
7987fcf3ce44SJohn Forte 
7988fcf3ce44SJohn Forte 
7989fcf3ce44SJohn Forte /* auth_lock must be held */
7990fcf3ce44SJohn Forte static void
emlxs_auth_cfg_read(emlxs_hba_t * hba)7991fcf3ce44SJohn Forte emlxs_auth_cfg_read(emlxs_hba_t *hba)
7992fcf3ce44SJohn Forte {
7993fcf3ce44SJohn Forte 	emlxs_port_t *port = &PPORT;
7994fcf3ce44SJohn Forte 	char **arrayp;
7995fcf3ce44SJohn Forte 	emlxs_auth_cfg_t auth_cfg;
7996fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *auth_cfg2;
7997fcf3ce44SJohn Forte 	uint32_t cnt;
7998fcf3ce44SJohn Forte 	uint32_t rval;
7999fcf3ce44SJohn Forte 	char buffer[64];
8000fcf3ce44SJohn Forte 	char *prop_str;
8001fcf3ce44SJohn Forte 	uint32_t i;
8002fcf3ce44SJohn Forte 
8003fcf3ce44SJohn Forte 	/* Check for the per adapter setting */
8004*8f23e9faSHans Rosenfeld 	(void) snprintf(buffer, sizeof (buffer), "%s%d-auth-cfgs", DRIVER_NAME,
8005*8f23e9faSHans Rosenfeld 	    hba->ddiinst);
8006fcf3ce44SJohn Forte 	cnt = 0;
8007fcf3ce44SJohn Forte 	arrayp = NULL;
8008fcf3ce44SJohn Forte 	rval = ddi_prop_lookup_string_array(DDI_DEV_T_ANY, hba->dip,
8009fcf3ce44SJohn Forte 	    (DDI_PROP_DONTPASS),
8010fcf3ce44SJohn Forte 	    buffer, &arrayp, &cnt);
8011fcf3ce44SJohn Forte 
8012fcf3ce44SJohn Forte 	if ((rval != DDI_PROP_SUCCESS) || !cnt || !arrayp) {
8013fcf3ce44SJohn Forte 		/* Check for the global setting */
8014fcf3ce44SJohn Forte 		cnt = 0;
8015fcf3ce44SJohn Forte 		arrayp = NULL;
8016fcf3ce44SJohn Forte 		rval = ddi_prop_lookup_string_array(DDI_DEV_T_ANY,
8017fcf3ce44SJohn Forte 		    hba->dip, (DDI_PROP_DONTPASS),
8018fcf3ce44SJohn Forte 		    "auth-cfgs", &arrayp, &cnt);
8019fcf3ce44SJohn Forte 	}
8020fcf3ce44SJohn Forte 	if ((rval != DDI_PROP_SUCCESS) || !cnt || !arrayp) {
8021fcf3ce44SJohn Forte 		return;
8022fcf3ce44SJohn Forte 	}
8023fcf3ce44SJohn Forte 	for (i = 0; i < cnt; i++) {
8024fcf3ce44SJohn Forte 		prop_str = arrayp[i];
8025fcf3ce44SJohn Forte 		if (prop_str == NULL) {
8026fcf3ce44SJohn Forte 			break;
8027fcf3ce44SJohn Forte 		}
8028fcf3ce44SJohn Forte 		/* parse the string */
8029fcf3ce44SJohn Forte 		if (emlxs_auth_cfg_parse(hba, &auth_cfg, prop_str) == 0) {
8030fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8031fcf3ce44SJohn Forte 			    &emlxs_attach_msg,
8032fcf3ce44SJohn Forte 			    "Error parsing auth_cfgs property. entry=%d", i);
8033fcf3ce44SJohn Forte 			continue;
8034fcf3ce44SJohn Forte 		}
8035fcf3ce44SJohn Forte 		auth_cfg2 = emlxs_auth_cfg_create(hba,
8036fcf3ce44SJohn Forte 		    (uint8_t *)&auth_cfg.local_entity,
8037fcf3ce44SJohn Forte 		    (uint8_t *)&auth_cfg.remote_entity);
8038fcf3ce44SJohn Forte 
8039fcf3ce44SJohn Forte 		if (!auth_cfg2) {
8040fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8041fcf3ce44SJohn Forte 			    &emlxs_attach_msg,
8042fcf3ce44SJohn Forte 			    "Out of memory parsing auth_cfgs property. ey=%d",
8043fcf3ce44SJohn Forte 			    i);
8044fcf3ce44SJohn Forte 			return;
8045fcf3ce44SJohn Forte 		}
8046fcf3ce44SJohn Forte 		auth_cfg.next = auth_cfg2->next;
8047fcf3ce44SJohn Forte 		auth_cfg.prev = auth_cfg2->prev;
8048fcf3ce44SJohn Forte 		bcopy((uint8_t *)&auth_cfg,
8049fcf3ce44SJohn Forte 		    (uint8_t *)auth_cfg2,
8050fcf3ce44SJohn Forte 		    sizeof (emlxs_auth_cfg_t));
8051fcf3ce44SJohn Forte 	}
8052fcf3ce44SJohn Forte 
8053fcf3ce44SJohn Forte 	return;
8054fcf3ce44SJohn Forte 
8055fcf3ce44SJohn Forte } /* emlxs_auth_cfg_read() */
8056fcf3ce44SJohn Forte 
8057fcf3ce44SJohn Forte 
8058fcf3ce44SJohn Forte /* auth_lock must be held */
8059fcf3ce44SJohn Forte static uint32_t
emlxs_auth_cfg_parse(emlxs_hba_t * hba,emlxs_auth_cfg_t * auth_cfg,char * prop_str)8060fcf3ce44SJohn Forte emlxs_auth_cfg_parse(
8061fcf3ce44SJohn Forte 	emlxs_hba_t *hba,
8062fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *auth_cfg,
8063fcf3ce44SJohn Forte 	char *prop_str)
8064fcf3ce44SJohn Forte {
8065fcf3ce44SJohn Forte 	emlxs_port_t *port = &PPORT;
8066fcf3ce44SJohn Forte 	emlxs_config_t *cfg = &CFG;
8067fcf3ce44SJohn Forte 	uint32_t errors = 0;
8068fcf3ce44SJohn Forte 	uint32_t c1;
8069fcf3ce44SJohn Forte 	uint8_t *np;
8070fcf3ce44SJohn Forte 	uint32_t j;
8071fcf3ce44SJohn Forte 	uint32_t i;
8072fcf3ce44SJohn Forte 	uint32_t sum;
8073fcf3ce44SJohn Forte 	char *s;
8074fcf3ce44SJohn Forte 
8075fcf3ce44SJohn Forte 	s = prop_str;
8076fcf3ce44SJohn Forte 	bzero(auth_cfg, sizeof (emlxs_auth_cfg_t));
8077fcf3ce44SJohn Forte 
8078fcf3ce44SJohn Forte 	/* Read local wwpn */
8079fcf3ce44SJohn Forte 	np = (uint8_t *)&auth_cfg->local_entity;
8080fcf3ce44SJohn Forte 	for (j = 0; j < 8; j++) {
8081fcf3ce44SJohn Forte 		c1 = *s++;
8082fcf3ce44SJohn Forte 		if ((c1 >= '0') && (c1 <= '9')) {
8083fcf3ce44SJohn Forte 			sum = ((c1 - '0') << 4);
8084fcf3ce44SJohn Forte 		} else if ((c1 >= 'a') && (c1 <= 'f')) {
8085fcf3ce44SJohn Forte 			sum = ((c1 - 'a' + 10) << 4);
8086fcf3ce44SJohn Forte 		} else if ((c1 >= 'A') && (c1 <= 'F')) {
8087fcf3ce44SJohn Forte 			sum = ((c1 - 'A' + 10) << 4);
8088fcf3ce44SJohn Forte 		} else {
8089fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8090fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8091fcf3ce44SJohn Forte 			    "Cfg err:Invalid LWWPN found. byte=%d hi_nibble=%c",
8092fcf3ce44SJohn Forte 			    j, c1);
8093fcf3ce44SJohn Forte 			errors++;
8094fcf3ce44SJohn Forte 		}
8095fcf3ce44SJohn Forte 
8096fcf3ce44SJohn Forte 		c1 = *s++;
8097fcf3ce44SJohn Forte 		if ((c1 >= '0') && (c1 <= '9')) {
8098fcf3ce44SJohn Forte 			sum |= (c1 - '0');
8099fcf3ce44SJohn Forte 		} else if ((c1 >= 'a') && (c1 <= 'f')) {
8100fcf3ce44SJohn Forte 			sum |= (c1 - 'a' + 10);
8101fcf3ce44SJohn Forte 		} else if ((c1 >= 'A') && (c1 <= 'F')) {
8102fcf3ce44SJohn Forte 			sum |= (c1 - 'A' + 10);
8103fcf3ce44SJohn Forte 		} else {
8104fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8105fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8106fcf3ce44SJohn Forte 			    "Cfg err: Invalid LWWPN found. %d %c",
8107fcf3ce44SJohn Forte 			    j, c1);
8108fcf3ce44SJohn Forte 			errors++;
8109fcf3ce44SJohn Forte 		}
8110fcf3ce44SJohn Forte 
8111a9800bebSGarrett D'Amore 		*np++ = (uint8_t)sum;
8112fcf3ce44SJohn Forte 	}
8113fcf3ce44SJohn Forte 
8114fcf3ce44SJohn Forte 	if (*s++ != ':') {
8115fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
8116fcf3ce44SJohn Forte 		    &emlxs_attach_debug_msg,
8117fcf3ce44SJohn Forte 		    "Cfg err: Invalid delimiter after LWWPN.");
8118fcf3ce44SJohn Forte 		goto out;
8119fcf3ce44SJohn Forte 	}
8120fcf3ce44SJohn Forte 	/* Read remote wwpn */
8121fcf3ce44SJohn Forte 	np = (uint8_t *)&auth_cfg->remote_entity;
8122fcf3ce44SJohn Forte 	for (j = 0; j < 8; j++) {
8123fcf3ce44SJohn Forte 		c1 = *s++;
8124fcf3ce44SJohn Forte 		if ((c1 >= '0') && (c1 <= '9')) {
8125fcf3ce44SJohn Forte 			sum = ((c1 - '0') << 4);
8126fcf3ce44SJohn Forte 		} else if ((c1 >= 'a') && (c1 <= 'f')) {
8127fcf3ce44SJohn Forte 			sum = ((c1 - 'a' + 10) << 4);
8128fcf3ce44SJohn Forte 		} else if ((c1 >= 'A') && (c1 <= 'F')) {
8129fcf3ce44SJohn Forte 			sum = ((c1 - 'A' + 10) << 4);
8130fcf3ce44SJohn Forte 		} else {
8131fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8132fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8133fcf3ce44SJohn Forte 			    "Cfg err: Invalid RWWPN found.byte=%d hi_nibble=%c",
8134fcf3ce44SJohn Forte 			    j, c1);
8135fcf3ce44SJohn Forte 			errors++;
8136fcf3ce44SJohn Forte 		}
8137fcf3ce44SJohn Forte 
8138fcf3ce44SJohn Forte 		c1 = *s++;
8139fcf3ce44SJohn Forte 		if ((c1 >= '0') && (c1 <= '9')) {
8140fcf3ce44SJohn Forte 			sum |= (c1 - '0');
8141fcf3ce44SJohn Forte 		} else if ((c1 >= 'a') && (c1 <= 'f')) {
8142fcf3ce44SJohn Forte 			sum |= (c1 - 'a' + 10);
8143fcf3ce44SJohn Forte 		} else if ((c1 >= 'A') && (c1 <= 'F')) {
8144fcf3ce44SJohn Forte 			sum |= (c1 - 'A' + 10);
8145fcf3ce44SJohn Forte 		} else {
8146fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8147fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8148fcf3ce44SJohn Forte 			    "Cfg err: Invalid RWWPN found. %d %c",
8149fcf3ce44SJohn Forte 			    j, c1);
8150fcf3ce44SJohn Forte 			errors++;
8151fcf3ce44SJohn Forte 		}
8152fcf3ce44SJohn Forte 
8153a9800bebSGarrett D'Amore 		*np++ = (uint8_t)sum;
8154fcf3ce44SJohn Forte 	}
8155fcf3ce44SJohn Forte 
8156fcf3ce44SJohn Forte 	if (*s++ != ':') {
8157fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
8158fcf3ce44SJohn Forte 		    &emlxs_attach_debug_msg,
8159fcf3ce44SJohn Forte 		    "Cfg err: Invalid delimiter after RWWPN.");
8160fcf3ce44SJohn Forte 		goto out;
8161fcf3ce44SJohn Forte 	}
8162fcf3ce44SJohn Forte 	/* Read auth_tov (%x) */
8163fcf3ce44SJohn Forte 	sum = 0;
8164fcf3ce44SJohn Forte 	do {
8165fcf3ce44SJohn Forte 		c1 = *s++;
8166fcf3ce44SJohn Forte 		if ((c1 >= '0') && (c1 <= '9')) {
8167fcf3ce44SJohn Forte 			sum = (sum << 4) + (c1 - '0');
8168fcf3ce44SJohn Forte 		} else if ((c1 >= 'a') && (c1 <= 'f')) {
8169fcf3ce44SJohn Forte 			sum = (sum << 4) + (c1 - 'a' + 10);
8170fcf3ce44SJohn Forte 		} else if ((c1 >= 'A') && (c1 <= 'F')) {
8171fcf3ce44SJohn Forte 			sum = (sum << 4) + (c1 - 'A' + 10);
8172fcf3ce44SJohn Forte 		} else {
8173fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8174fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8175fcf3ce44SJohn Forte 			    "Cfg err: Invalid auth_tov found. c=%c sum=%d",
8176fcf3ce44SJohn Forte 			    c1, sum);
8177fcf3ce44SJohn Forte 
8178fcf3ce44SJohn Forte 			errors++;
8179fcf3ce44SJohn Forte 		}
8180fcf3ce44SJohn Forte 
8181fcf3ce44SJohn Forte 	} while (*s != ':' && *s != 0);
8182fcf3ce44SJohn Forte 	auth_cfg->authentication_timeout = sum;
8183fcf3ce44SJohn Forte 
8184fcf3ce44SJohn Forte 	if (*s++ != ':') {
8185fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
8186fcf3ce44SJohn Forte 		    &emlxs_attach_debug_msg,
8187fcf3ce44SJohn Forte 		    "Cfg err: Invalid delimiter after auth_tov.");
8188fcf3ce44SJohn Forte 		goto out;
8189fcf3ce44SJohn Forte 	}
8190fcf3ce44SJohn Forte 	/* Read auth_mode */
8191fcf3ce44SJohn Forte 	sum = 0;
8192fcf3ce44SJohn Forte 	do {
8193fcf3ce44SJohn Forte 		c1 = *s++;
8194fcf3ce44SJohn Forte 		if ((c1 >= '0') && (c1 <= '9')) {
8195fcf3ce44SJohn Forte 			sum = (sum << 4) + (c1 - '0');
8196fcf3ce44SJohn Forte 		} else if ((c1 >= 'a') && (c1 <= 'f')) {
8197fcf3ce44SJohn Forte 			sum = (sum << 4) + (c1 - 'a' + 10);
8198fcf3ce44SJohn Forte 		} else if ((c1 >= 'A') && (c1 <= 'F')) {
8199fcf3ce44SJohn Forte 			sum = (sum << 4) + (c1 - 'A' + 10);
8200fcf3ce44SJohn Forte 		} else {
8201fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8202fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8203fcf3ce44SJohn Forte 			    "Cfg err: Invalid auth_mode found. c=%c sum=%d",
8204fcf3ce44SJohn Forte 			    c1, sum);
8205fcf3ce44SJohn Forte 
8206fcf3ce44SJohn Forte 			errors++;
8207fcf3ce44SJohn Forte 		}
8208fcf3ce44SJohn Forte 
8209fcf3ce44SJohn Forte 	} while (*s != ':' && *s != 0);
8210fcf3ce44SJohn Forte 	auth_cfg->authentication_mode = sum;
8211fcf3ce44SJohn Forte 
8212fcf3ce44SJohn Forte 	if (*s++ != ':') {
8213fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
8214fcf3ce44SJohn Forte 		    &emlxs_attach_debug_msg,
8215fcf3ce44SJohn Forte 		    "Config error: Invalid delimiter after auth_mode.");
8216fcf3ce44SJohn Forte 		goto out;
8217fcf3ce44SJohn Forte 	}
8218fcf3ce44SJohn Forte 	/* Read auth_bidir */
8219fcf3ce44SJohn Forte 	sum = 0;
8220fcf3ce44SJohn Forte 	do {
8221fcf3ce44SJohn Forte 		c1 = *s++;
8222fcf3ce44SJohn Forte 		if ((c1 >= '0') && (c1 <= '9')) {
8223fcf3ce44SJohn Forte 			sum = (sum << 4) + (c1 - '0');
8224fcf3ce44SJohn Forte 		} else if ((c1 >= 'a') && (c1 <= 'f')) {
8225fcf3ce44SJohn Forte 			sum = (sum << 4) + (c1 - 'a' + 10);
8226fcf3ce44SJohn Forte 		} else if ((c1 >= 'A') && (c1 <= 'F')) {
8227fcf3ce44SJohn Forte 			sum = (sum << 4) + (c1 - 'A' + 10);
8228fcf3ce44SJohn Forte 		} else {
8229fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8230fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8231fcf3ce44SJohn Forte 			    "Cfg err: Invalid auth_bidir found. c=%c sum=%d",
8232fcf3ce44SJohn Forte 			    c1, sum);
8233fcf3ce44SJohn Forte 
8234fcf3ce44SJohn Forte 			errors++;
8235fcf3ce44SJohn Forte 		}
8236fcf3ce44SJohn Forte 
8237fcf3ce44SJohn Forte 	} while (*s != ':' && *s != 0);
8238fcf3ce44SJohn Forte 	auth_cfg->bidirectional = sum;
8239fcf3ce44SJohn Forte 
8240fcf3ce44SJohn Forte 	if (*s++ != ':') {
8241fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
8242fcf3ce44SJohn Forte 		    &emlxs_attach_debug_msg,
8243fcf3ce44SJohn Forte 		    "Cfg err: Invalid delimiter after auth_bidir.");
8244fcf3ce44SJohn Forte 		goto out;
8245fcf3ce44SJohn Forte 	}
8246fcf3ce44SJohn Forte 	/* Read type_priority[4] */
8247fcf3ce44SJohn Forte 	for (i = 0; i < 4; i++) {
8248fcf3ce44SJohn Forte 		c1 = *s++;
8249fcf3ce44SJohn Forte 		if ((c1 >= '0') && (c1 <= '9')) {
8250fcf3ce44SJohn Forte 			sum = (c1 - '0');
8251fcf3ce44SJohn Forte 		} else if ((c1 >= 'a') && (c1 <= 'f')) {
8252fcf3ce44SJohn Forte 			sum = (c1 - 'a' + 10);
8253fcf3ce44SJohn Forte 		} else if ((c1 >= 'A') && (c1 <= 'F')) {
8254fcf3ce44SJohn Forte 			sum = (c1 - 'A' + 10);
8255fcf3ce44SJohn Forte 		} else {
8256fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8257fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8258fcf3ce44SJohn Forte 			    "Cfg err: Invalid type_pty[%d] found. c=%c sum=%d",
8259fcf3ce44SJohn Forte 			    i, c1, sum);
8260fcf3ce44SJohn Forte 
8261fcf3ce44SJohn Forte 			errors++;
8262fcf3ce44SJohn Forte 		}
8263fcf3ce44SJohn Forte 
8264fcf3ce44SJohn Forte 		auth_cfg->authentication_type_priority[i] = sum;
8265fcf3ce44SJohn Forte 	}
8266fcf3ce44SJohn Forte 
8267fcf3ce44SJohn Forte 	if (*s++ != ':') {
8268fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
8269fcf3ce44SJohn Forte 		    &emlxs_attach_debug_msg,
8270fcf3ce44SJohn Forte 		    "Cfg err: Invalid delimiter after type_priority.");
8271fcf3ce44SJohn Forte 
8272fcf3ce44SJohn Forte 		goto out;
8273fcf3ce44SJohn Forte 	}
8274fcf3ce44SJohn Forte 	/* Read hash_priority[4] */
8275fcf3ce44SJohn Forte 	for (i = 0; i < 4; i++) {
8276fcf3ce44SJohn Forte 		c1 = *s++;
8277fcf3ce44SJohn Forte 		if ((c1 >= '0') && (c1 <= '9')) {
8278fcf3ce44SJohn Forte 			sum = (c1 - '0');
8279fcf3ce44SJohn Forte 		} else if ((c1 >= 'a') && (c1 <= 'f')) {
8280fcf3ce44SJohn Forte 			sum = (c1 - 'a' + 10);
8281fcf3ce44SJohn Forte 		} else if ((c1 >= 'A') && (c1 <= 'F')) {
8282fcf3ce44SJohn Forte 			sum = (c1 - 'A' + 10);
8283fcf3ce44SJohn Forte 		} else {
8284fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8285fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8286fcf3ce44SJohn Forte 			    "Cfg err: Invalid hash_priority[%d] fd. %c %d",
8287fcf3ce44SJohn Forte 			    i, c1, sum);
8288fcf3ce44SJohn Forte 
8289fcf3ce44SJohn Forte 			errors++;
8290fcf3ce44SJohn Forte 		}
8291fcf3ce44SJohn Forte 
8292fcf3ce44SJohn Forte 		auth_cfg->hash_priority[i] = sum;
8293fcf3ce44SJohn Forte 	}
8294fcf3ce44SJohn Forte 
8295fcf3ce44SJohn Forte 	if (*s++ != ':') {
8296fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
8297fcf3ce44SJohn Forte 		    &emlxs_attach_debug_msg,
8298fcf3ce44SJohn Forte 		    "Cfg err: Invalid delimiter after hash_priority.");
8299fcf3ce44SJohn Forte 
8300fcf3ce44SJohn Forte 		goto out;
8301fcf3ce44SJohn Forte 	}
8302fcf3ce44SJohn Forte 	/* Read group_priority[8] */
8303fcf3ce44SJohn Forte 	for (i = 0; i < 8; i++) {
8304fcf3ce44SJohn Forte 		c1 = *s++;
8305fcf3ce44SJohn Forte 		if ((c1 >= '0') && (c1 <= '9')) {
8306fcf3ce44SJohn Forte 			sum = (c1 - '0');
8307fcf3ce44SJohn Forte 		} else if ((c1 >= 'a') && (c1 <= 'f')) {
8308fcf3ce44SJohn Forte 			sum = (c1 - 'a' + 10);
8309fcf3ce44SJohn Forte 		} else if ((c1 >= 'A') && (c1 <= 'F')) {
8310fcf3ce44SJohn Forte 			sum = (c1 - 'A' + 10);
8311fcf3ce44SJohn Forte 		} else {
8312fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8313fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8314fcf3ce44SJohn Forte 			    "Cfg err: Invalid group_priority[%d] fd. %c %d",
8315fcf3ce44SJohn Forte 			    i, c1, sum);
8316fcf3ce44SJohn Forte 
8317fcf3ce44SJohn Forte 			errors++;
8318fcf3ce44SJohn Forte 		}
8319fcf3ce44SJohn Forte 
8320fcf3ce44SJohn Forte 		auth_cfg->dh_group_priority[i] = sum;
8321fcf3ce44SJohn Forte 	}
8322fcf3ce44SJohn Forte 
8323fcf3ce44SJohn Forte 	if (*s++ != ':') {
8324fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
8325fcf3ce44SJohn Forte 		    &emlxs_attach_debug_msg,
8326fcf3ce44SJohn Forte 		    "Cfg err: Invalid delimiter after group_priority.");
8327fcf3ce44SJohn Forte 		goto out;
8328fcf3ce44SJohn Forte 	}
8329fcf3ce44SJohn Forte 	/* Read reauth_tov */
8330fcf3ce44SJohn Forte 	sum = 0;
8331fcf3ce44SJohn Forte 	do {
8332fcf3ce44SJohn Forte 		c1 = *s++;
8333fcf3ce44SJohn Forte 		if ((c1 >= '0') && (c1 <= '9')) {
8334fcf3ce44SJohn Forte 			sum = (sum << 4) + (c1 - '0');
8335fcf3ce44SJohn Forte 		} else if ((c1 >= 'a') && (c1 <= 'f')) {
8336fcf3ce44SJohn Forte 			sum = (sum << 4) + (c1 - 'a' + 10);
8337fcf3ce44SJohn Forte 		} else if ((c1 >= 'A') && (c1 <= 'F')) {
8338fcf3ce44SJohn Forte 			sum = (sum << 4) + (c1 - 'A' + 10);
8339fcf3ce44SJohn Forte 		} else {
8340fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8341fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8342fcf3ce44SJohn Forte 			    "Cfg err: Invalid reauth_tov found. c=%c sum=%d",
8343fcf3ce44SJohn Forte 			    c1, sum);
8344fcf3ce44SJohn Forte 
8345fcf3ce44SJohn Forte 			errors++;
8346fcf3ce44SJohn Forte 		}
8347fcf3ce44SJohn Forte 
8348fcf3ce44SJohn Forte 	} while (*s != ':' && *s != 0);
8349fcf3ce44SJohn Forte 	auth_cfg->reauthenticate_time_interval = sum;
8350fcf3ce44SJohn Forte 
8351fcf3ce44SJohn Forte 	if (errors) {
8352fcf3ce44SJohn Forte 		goto out;
8353fcf3ce44SJohn Forte 	}
8354fcf3ce44SJohn Forte 	/* Verify values */
8355fcf3ce44SJohn Forte 
8356fcf3ce44SJohn Forte 	/* Check authentication_timeout */
8357fcf3ce44SJohn Forte 	if (auth_cfg->authentication_timeout < cfg[CFG_AUTH_TMO].low) {
8358fcf3ce44SJohn Forte 		auth_cfg->authentication_timeout = cfg[CFG_AUTH_TMO].current;
8359fcf3ce44SJohn Forte 	} else if (auth_cfg->authentication_timeout > cfg[CFG_AUTH_TMO].hi) {
8360fcf3ce44SJohn Forte 		auth_cfg->authentication_timeout = cfg[CFG_AUTH_TMO].current;
8361fcf3ce44SJohn Forte 	}
8362fcf3ce44SJohn Forte 	/* Check authentication_mode */
8363fcf3ce44SJohn Forte 	if (auth_cfg->authentication_mode < cfg[CFG_AUTH_MODE].low) {
8364fcf3ce44SJohn Forte 		auth_cfg->authentication_mode = cfg[CFG_AUTH_MODE].current;
8365fcf3ce44SJohn Forte 	} else if (auth_cfg->authentication_mode > cfg[CFG_AUTH_MODE].hi) {
8366fcf3ce44SJohn Forte 		auth_cfg->authentication_mode = cfg[CFG_AUTH_MODE].current;
8367fcf3ce44SJohn Forte 	}
8368fcf3ce44SJohn Forte 	/* Check bidirectional */
8369fcf3ce44SJohn Forte 	if (auth_cfg->bidirectional < cfg[CFG_AUTH_BIDIR].low) {
8370fcf3ce44SJohn Forte 		auth_cfg->bidirectional = cfg[CFG_AUTH_BIDIR].current;
8371fcf3ce44SJohn Forte 	} else if (auth_cfg->bidirectional > cfg[CFG_AUTH_BIDIR].hi) {
8372fcf3ce44SJohn Forte 		auth_cfg->bidirectional = cfg[CFG_AUTH_BIDIR].current;
8373fcf3ce44SJohn Forte 	}
8374fcf3ce44SJohn Forte 	/* Check authentication_type_priority and hash_priority */
8375fcf3ce44SJohn Forte 	for (i = 0; i < 4; i++) {
8376fcf3ce44SJohn Forte 		if (auth_cfg->authentication_type_priority[i] >
8377fcf3ce44SJohn Forte 		    DFC_AUTH_TYPE_MAX) {
8378fcf3ce44SJohn Forte 			/* Set to current default */
8379fcf3ce44SJohn Forte 			auth_cfg->authentication_type_priority[i] =
8380fcf3ce44SJohn Forte 			    hba->auth_cfg.authentication_type_priority[i];
8381fcf3ce44SJohn Forte 		}
8382fcf3ce44SJohn Forte 		if (auth_cfg->hash_priority[i] > DFC_AUTH_HASH_MAX) {
8383fcf3ce44SJohn Forte 			/* Set to current default */
8384fcf3ce44SJohn Forte 			auth_cfg->hash_priority[i] =
8385fcf3ce44SJohn Forte 			    hba->auth_cfg.hash_priority[i];
8386fcf3ce44SJohn Forte 		}
8387fcf3ce44SJohn Forte 	}
8388fcf3ce44SJohn Forte 
8389fcf3ce44SJohn Forte 	/* Check dh_group_priority */
8390fcf3ce44SJohn Forte 	for (i = 0; i < 8; i++) {
8391fcf3ce44SJohn Forte 		if (auth_cfg->dh_group_priority[i] > DFC_AUTH_GROUP_MAX) {
8392fcf3ce44SJohn Forte 			/* Set to current default */
8393fcf3ce44SJohn Forte 			auth_cfg->dh_group_priority[i] =
8394fcf3ce44SJohn Forte 			    hba->auth_cfg.dh_group_priority[i];
8395fcf3ce44SJohn Forte 		}
8396fcf3ce44SJohn Forte 	}
8397fcf3ce44SJohn Forte 
8398fcf3ce44SJohn Forte 	/* Check reauthenticate_time_interval */
8399fcf3ce44SJohn Forte 	if (auth_cfg->reauthenticate_time_interval <
8400fcf3ce44SJohn Forte 	    cfg[CFG_AUTH_INTERVAL].low) {
8401fcf3ce44SJohn Forte 		auth_cfg->reauthenticate_time_interval =
8402fcf3ce44SJohn Forte 		    cfg[CFG_AUTH_INTERVAL].current;
8403fcf3ce44SJohn Forte 	} else if (auth_cfg->reauthenticate_time_interval >
8404fcf3ce44SJohn Forte 	    cfg[CFG_AUTH_INTERVAL].hi) {
8405fcf3ce44SJohn Forte 		auth_cfg->reauthenticate_time_interval =
8406fcf3ce44SJohn Forte 		    cfg[CFG_AUTH_INTERVAL].current;
8407fcf3ce44SJohn Forte 	}
8408fcf3ce44SJohn Forte 	emlxs_auth_cfg_print(hba, auth_cfg);
8409fcf3ce44SJohn Forte 
8410fcf3ce44SJohn Forte out:
8411fcf3ce44SJohn Forte 
8412fcf3ce44SJohn Forte 	if (errors) {
8413fcf3ce44SJohn Forte 		bzero(auth_cfg, sizeof (emlxs_auth_cfg_t));
8414fcf3ce44SJohn Forte 		return (0);
8415fcf3ce44SJohn Forte 	}
8416fcf3ce44SJohn Forte 	return (1);
8417fcf3ce44SJohn Forte 
8418fcf3ce44SJohn Forte } /* emlxs_auth_cfg_parse() */
8419fcf3ce44SJohn Forte 
8420fcf3ce44SJohn Forte 
8421fcf3ce44SJohn Forte /* **************************** AUTH KEY MANAGEMENT ************************* */
8422fcf3ce44SJohn Forte 
8423fcf3ce44SJohn Forte /* auth_lock must be held */
8424fcf3ce44SJohn Forte extern emlxs_auth_key_t *
emlxs_auth_key_find(emlxs_port_t * port,uint8_t * rwwpn)8425fcf3ce44SJohn Forte emlxs_auth_key_find(emlxs_port_t *port, uint8_t *rwwpn)
8426fcf3ce44SJohn Forte {
8427fcf3ce44SJohn Forte 	emlxs_hba_t *hba = HBA;
8428fcf3ce44SJohn Forte 	emlxs_auth_key_t *auth_key;
8429fcf3ce44SJohn Forte 
8430fcf3ce44SJohn Forte 	if (rwwpn) {
8431fcf3ce44SJohn Forte 		/* lwwpn, rwwpn */
8432fcf3ce44SJohn Forte 		auth_key = emlxs_auth_key_get(hba,
8433fcf3ce44SJohn Forte 		    (uint8_t *)&port->wwpn, (uint8_t *)rwwpn);
8434fcf3ce44SJohn Forte 
8435fcf3ce44SJohn Forte 		if (auth_key) {
8436fcf3ce44SJohn Forte 			emlxs_auth_key_print(hba, auth_key);
8437fcf3ce44SJohn Forte 			return (auth_key);
8438fcf3ce44SJohn Forte 		}
8439fcf3ce44SJohn Forte 		/* null, rwwpn */
8440fcf3ce44SJohn Forte 		auth_key = emlxs_auth_key_get(hba,
8441fcf3ce44SJohn Forte 		    (uint8_t *)emlxs_null_wwn, (uint8_t *)rwwpn);
8442fcf3ce44SJohn Forte 
8443fcf3ce44SJohn Forte 		if (auth_key) {
8444fcf3ce44SJohn Forte 			emlxs_auth_key_print(hba, auth_key);
8445fcf3ce44SJohn Forte 			return (auth_key);
8446fcf3ce44SJohn Forte 		}
8447fcf3ce44SJohn Forte 	}
8448fcf3ce44SJohn Forte 	/* lwwpn, null */
8449fcf3ce44SJohn Forte 	auth_key = emlxs_auth_key_get(hba,
8450fcf3ce44SJohn Forte 	    (uint8_t *)&port->wwpn, (uint8_t *)emlxs_null_wwn);
8451fcf3ce44SJohn Forte 
8452fcf3ce44SJohn Forte 	if (auth_key) {
8453fcf3ce44SJohn Forte 		emlxs_auth_key_print(hba, auth_key);
8454fcf3ce44SJohn Forte 		return (auth_key);
8455fcf3ce44SJohn Forte 	}
8456fcf3ce44SJohn Forte 	return (NULL);
8457fcf3ce44SJohn Forte 
8458fcf3ce44SJohn Forte } /* emlxs_auth_key_find() */
8459fcf3ce44SJohn Forte 
8460fcf3ce44SJohn Forte 
8461fcf3ce44SJohn Forte static void
emlxs_auth_key_init(emlxs_hba_t * hba)8462fcf3ce44SJohn Forte emlxs_auth_key_init(emlxs_hba_t *hba)
8463fcf3ce44SJohn Forte {
8464fcf3ce44SJohn Forte 	emlxs_auth_key_t *auth_key;
8465fcf3ce44SJohn Forte 
8466fcf3ce44SJohn Forte 	/* Destroy old table if one exists */
8467fcf3ce44SJohn Forte 	emlxs_auth_key_fini(hba);
8468fcf3ce44SJohn Forte 
8469fcf3ce44SJohn Forte 	mutex_enter(&hba->auth_lock);
8470fcf3ce44SJohn Forte 
8471fcf3ce44SJohn Forte 	/* Zero default entry */
8472fcf3ce44SJohn Forte 	auth_key = &hba->auth_key;
8473fcf3ce44SJohn Forte 	bzero(auth_key, sizeof (emlxs_auth_key_t));
8474fcf3ce44SJohn Forte 	auth_key->next = auth_key;
8475fcf3ce44SJohn Forte 	auth_key->prev = auth_key;
8476fcf3ce44SJohn Forte 
8477fcf3ce44SJohn Forte 	/* Configure the default entry */
8478fcf3ce44SJohn Forte 	auth_key->local_password_type = PASSWORD_TYPE_IGNORE;
8479fcf3ce44SJohn Forte 	auth_key->remote_password_type = PASSWORD_TYPE_IGNORE;
8480fcf3ce44SJohn Forte 
8481fcf3ce44SJohn Forte 	emlxs_auth_key_read(hba);
8482fcf3ce44SJohn Forte 
8483fcf3ce44SJohn Forte 	mutex_exit(&hba->auth_lock);
8484fcf3ce44SJohn Forte 
8485fcf3ce44SJohn Forte 	return;
8486fcf3ce44SJohn Forte 
8487fcf3ce44SJohn Forte } /* emlxs_auth_key_init() */
8488fcf3ce44SJohn Forte 
8489fcf3ce44SJohn Forte 
8490fcf3ce44SJohn Forte static void
emlxs_auth_key_fini(emlxs_hba_t * hba)8491fcf3ce44SJohn Forte emlxs_auth_key_fini(emlxs_hba_t *hba)
8492fcf3ce44SJohn Forte {
8493fcf3ce44SJohn Forte 	emlxs_auth_key_t *auth_key = hba->auth_key.next;
8494fcf3ce44SJohn Forte 	emlxs_auth_key_t *next;
8495fcf3ce44SJohn Forte 
8496fcf3ce44SJohn Forte 	mutex_enter(&hba->auth_lock);
8497fcf3ce44SJohn Forte 
8498fcf3ce44SJohn Forte 	while (auth_key && auth_key != &hba->auth_key) {
8499fcf3ce44SJohn Forte 		next = auth_key->next;
8500fcf3ce44SJohn Forte 		emlxs_auth_key_destroy(hba, auth_key);
8501fcf3ce44SJohn Forte 		auth_key = next;
8502fcf3ce44SJohn Forte 	}
8503fcf3ce44SJohn Forte 
8504fcf3ce44SJohn Forte 	mutex_exit(&hba->auth_lock);
8505fcf3ce44SJohn Forte 
8506fcf3ce44SJohn Forte 	return;
8507fcf3ce44SJohn Forte 
8508fcf3ce44SJohn Forte } /* emlxs_auth_key_fini() */
8509fcf3ce44SJohn Forte 
8510fcf3ce44SJohn Forte 
8511fcf3ce44SJohn Forte static void
emlxs_auth_key_print(emlxs_hba_t * hba,emlxs_auth_key_t * auth_key)8512fcf3ce44SJohn Forte emlxs_auth_key_print(emlxs_hba_t *hba, emlxs_auth_key_t *auth_key)
8513fcf3ce44SJohn Forte {
8514fcf3ce44SJohn Forte 	emlxs_port_t *port = &PPORT;
8515fcf3ce44SJohn Forte 	char s_lwwpn[32];
8516fcf3ce44SJohn Forte 	char s_rwwpn[32];
8517fcf3ce44SJohn Forte 
8518fcf3ce44SJohn Forte 	EMLXS_MSGF(EMLXS_CONTEXT,
8519fcf3ce44SJohn Forte 	    &emlxs_fcsp_detail_msg,
8520fcf3ce44SJohn Forte 	    "auth-key> %s:%s:%x:*%d chars*:%x:*%d chars*",
8521*8f23e9faSHans Rosenfeld 	    emlxs_wwn_xlate(s_lwwpn, sizeof (s_lwwpn),
8522*8f23e9faSHans Rosenfeld 	    (uint8_t *)&auth_key->local_entity),
8523*8f23e9faSHans Rosenfeld 	    emlxs_wwn_xlate(s_rwwpn, sizeof (s_rwwpn),
8524*8f23e9faSHans Rosenfeld 	    (uint8_t *)&auth_key->remote_entity),
8525fcf3ce44SJohn Forte 	    auth_key->local_password_type, auth_key->local_password_length,
8526fcf3ce44SJohn Forte 	    auth_key->remote_password_type, auth_key->remote_password_length);
8527fcf3ce44SJohn Forte 
8528fcf3ce44SJohn Forte 	return;
8529fcf3ce44SJohn Forte 
8530fcf3ce44SJohn Forte } /* emlxs_auth_key_print() */
8531fcf3ce44SJohn Forte 
8532fcf3ce44SJohn Forte 
8533fcf3ce44SJohn Forte /* auth_lock must be held */
8534fcf3ce44SJohn Forte static emlxs_auth_key_t *
emlxs_auth_key_get(emlxs_hba_t * hba,uint8_t * lwwpn,uint8_t * rwwpn)8535fcf3ce44SJohn Forte emlxs_auth_key_get(emlxs_hba_t *hba, uint8_t *lwwpn, uint8_t *rwwpn)
8536fcf3ce44SJohn Forte {
8537fcf3ce44SJohn Forte 	emlxs_auth_key_t *auth_key;
8538fcf3ce44SJohn Forte 
8539fcf3ce44SJohn Forte 	if (!lwwpn || !rwwpn) {
8540fcf3ce44SJohn Forte 		return (NULL);
8541fcf3ce44SJohn Forte 	}
8542fcf3ce44SJohn Forte 	/* Check for default entry */
8543fcf3ce44SJohn Forte 	if ((bcmp(lwwpn, emlxs_null_wwn, 8) == 0) &&
8544fcf3ce44SJohn Forte 	    (bcmp(rwwpn, emlxs_null_wwn, 8) == 0)) {
8545fcf3ce44SJohn Forte 		return (&hba->auth_key);
8546fcf3ce44SJohn Forte 	}
8547fcf3ce44SJohn Forte 	for (auth_key = hba->auth_key.next; auth_key !=
8548fcf3ce44SJohn Forte 	    &hba->auth_key; auth_key = auth_key->next) {
8549fcf3ce44SJohn Forte 		/* Find pwd entry for this local port */
8550fcf3ce44SJohn Forte 
8551fcf3ce44SJohn Forte 		/* Check for exact wwpn match */
8552fcf3ce44SJohn Forte 		if (bcmp((void *)&auth_key->local_entity,
8553fcf3ce44SJohn Forte 		    (void *)lwwpn, 8) != 0) {
8554fcf3ce44SJohn Forte 			continue;
8555fcf3ce44SJohn Forte 		}
8556fcf3ce44SJohn Forte 		/* Find pwd entry for remote port */
8557fcf3ce44SJohn Forte 
8558fcf3ce44SJohn Forte 		/* Check for exact wwpn match */
8559fcf3ce44SJohn Forte 		if (bcmp((void *)&auth_key->remote_entity,
8560fcf3ce44SJohn Forte 		    (void *)rwwpn, 8) != 0) {
8561fcf3ce44SJohn Forte 			continue;
8562fcf3ce44SJohn Forte 		}
8563fcf3ce44SJohn Forte 		return (auth_key);
8564fcf3ce44SJohn Forte 	}
8565fcf3ce44SJohn Forte 
8566fcf3ce44SJohn Forte 	return (NULL);
8567fcf3ce44SJohn Forte 
8568fcf3ce44SJohn Forte } /* emlxs_auth_key_get() */
8569fcf3ce44SJohn Forte 
8570fcf3ce44SJohn Forte 
8571fcf3ce44SJohn Forte /* auth_lock must be held */
8572fcf3ce44SJohn Forte static emlxs_auth_key_t *
emlxs_auth_key_create(emlxs_hba_t * hba,uint8_t * lwwpn,uint8_t * rwwpn)8573fcf3ce44SJohn Forte emlxs_auth_key_create(emlxs_hba_t *hba, uint8_t *lwwpn, uint8_t *rwwpn)
8574fcf3ce44SJohn Forte {
8575fcf3ce44SJohn Forte 	emlxs_auth_key_t *auth_key;
8576fcf3ce44SJohn Forte 
8577fcf3ce44SJohn Forte 	/* First check if entry already exists */
8578fcf3ce44SJohn Forte 	auth_key = emlxs_auth_key_get(hba, lwwpn, rwwpn);
8579fcf3ce44SJohn Forte 
8580fcf3ce44SJohn Forte 	if (auth_key) {
8581fcf3ce44SJohn Forte 		return (auth_key);
8582fcf3ce44SJohn Forte 	}
8583fcf3ce44SJohn Forte 	/* Allocate entry */
8584fcf3ce44SJohn Forte 	auth_key = (emlxs_auth_key_t *)kmem_zalloc(sizeof (emlxs_auth_key_t),
8585fcf3ce44SJohn Forte 	    KM_NOSLEEP);
8586fcf3ce44SJohn Forte 
8587fcf3ce44SJohn Forte 	if (!auth_key) {
8588fcf3ce44SJohn Forte 		return (NULL);
8589fcf3ce44SJohn Forte 	}
8590fcf3ce44SJohn Forte 	/* Initialize name pair */
8591fcf3ce44SJohn Forte 	if (lwwpn) {
8592fcf3ce44SJohn Forte 		bcopy((void *)lwwpn, (void *)&auth_key->local_entity, 8);
8593fcf3ce44SJohn Forte 	}
8594fcf3ce44SJohn Forte 	if (rwwpn) {
8595fcf3ce44SJohn Forte 		bcopy((void *)rwwpn, (void *)&auth_key->remote_entity, 8);
8596fcf3ce44SJohn Forte 	}
8597fcf3ce44SJohn Forte 	/* Initialize type */
8598fcf3ce44SJohn Forte 	auth_key->local_password_type = PASSWORD_TYPE_IGNORE;
8599fcf3ce44SJohn Forte 	auth_key->remote_password_type = PASSWORD_TYPE_IGNORE;
8600fcf3ce44SJohn Forte 
8601fcf3ce44SJohn Forte 	/* Add to list */
8602fcf3ce44SJohn Forte 	auth_key->next = &hba->auth_key;
8603fcf3ce44SJohn Forte 	auth_key->prev = hba->auth_key.prev;
8604fcf3ce44SJohn Forte 	hba->auth_key.prev->next = auth_key;
8605fcf3ce44SJohn Forte 	hba->auth_key.prev = auth_key;
8606fcf3ce44SJohn Forte 	hba->auth_key_count++;
8607fcf3ce44SJohn Forte 
8608fcf3ce44SJohn Forte 	return (auth_key);
8609fcf3ce44SJohn Forte 
8610fcf3ce44SJohn Forte } /* emlxs_auth_key_create() */
8611fcf3ce44SJohn Forte 
8612fcf3ce44SJohn Forte 
8613fcf3ce44SJohn Forte /* auth_lock must be held */
8614fcf3ce44SJohn Forte static void
emlxs_auth_key_destroy(emlxs_hba_t * hba,emlxs_auth_key_t * auth_key)8615fcf3ce44SJohn Forte emlxs_auth_key_destroy(emlxs_hba_t *hba, emlxs_auth_key_t *auth_key)
8616fcf3ce44SJohn Forte {
8617fcf3ce44SJohn Forte 
8618fcf3ce44SJohn Forte 	if (!auth_key) {
8619fcf3ce44SJohn Forte 		return;
8620fcf3ce44SJohn Forte 	}
8621fcf3ce44SJohn Forte 	if (auth_key == &hba->auth_key) {
8622fcf3ce44SJohn Forte 		return;
8623fcf3ce44SJohn Forte 	}
8624fcf3ce44SJohn Forte 	/* Remove from  list */
8625fcf3ce44SJohn Forte 	auth_key->next->prev = auth_key->prev;
8626fcf3ce44SJohn Forte 	auth_key->prev->next = auth_key->next;
8627fcf3ce44SJohn Forte 	hba->auth_key_count--;
8628fcf3ce44SJohn Forte 
8629fcf3ce44SJohn Forte 	/* Remove node binding */
8630fcf3ce44SJohn Forte 	if (auth_key->node &&
8631fcf3ce44SJohn Forte 	    auth_key->node->nlp_active &&
8632fcf3ce44SJohn Forte 	    (auth_key->node->node_dhc.parent_auth_key == auth_key)) {
8633fcf3ce44SJohn Forte 		auth_key->node->node_dhc.parent_auth_key = NULL;
8634fcf3ce44SJohn Forte 	}
8635fcf3ce44SJohn Forte 	bzero(auth_key, sizeof (emlxs_auth_key_t));
8636fcf3ce44SJohn Forte 	kmem_free(auth_key, sizeof (emlxs_auth_key_t));
8637fcf3ce44SJohn Forte 
8638fcf3ce44SJohn Forte 	return;
8639fcf3ce44SJohn Forte 
8640fcf3ce44SJohn Forte } /* emlxs_auth_key_destroy() */
8641fcf3ce44SJohn Forte 
8642fcf3ce44SJohn Forte 
8643fcf3ce44SJohn Forte /* auth_lock must be held */
8644fcf3ce44SJohn Forte static void
emlxs_auth_key_read(emlxs_hba_t * hba)8645fcf3ce44SJohn Forte emlxs_auth_key_read(emlxs_hba_t *hba)
8646fcf3ce44SJohn Forte {
8647fcf3ce44SJohn Forte 	emlxs_port_t *port = &PPORT;
8648fcf3ce44SJohn Forte 	char **arrayp;
8649fcf3ce44SJohn Forte 	emlxs_auth_key_t auth_key;
8650fcf3ce44SJohn Forte 	emlxs_auth_key_t *auth_key2;
8651fcf3ce44SJohn Forte 	uint32_t cnt;
8652fcf3ce44SJohn Forte 	uint32_t rval;
8653fcf3ce44SJohn Forte 	char buffer[64];
8654fcf3ce44SJohn Forte 	char *prop_str;
8655fcf3ce44SJohn Forte 	uint32_t i;
8656fcf3ce44SJohn Forte 
8657fcf3ce44SJohn Forte 	/* Check for the per adapter setting */
8658*8f23e9faSHans Rosenfeld 	(void) snprintf(buffer, sizeof (buffer), "%s%d-auth-keys", DRIVER_NAME,
8659*8f23e9faSHans Rosenfeld 	    hba->ddiinst);
8660fcf3ce44SJohn Forte 	cnt = 0;
8661fcf3ce44SJohn Forte 	arrayp = NULL;
8662fcf3ce44SJohn Forte 	rval = ddi_prop_lookup_string_array(DDI_DEV_T_ANY, hba->dip,
8663fcf3ce44SJohn Forte 	    (DDI_PROP_DONTPASS),
8664fcf3ce44SJohn Forte 	    buffer, &arrayp, &cnt);
8665fcf3ce44SJohn Forte 
8666fcf3ce44SJohn Forte 	if ((rval != DDI_PROP_SUCCESS) || !cnt || !arrayp) {
8667fcf3ce44SJohn Forte 		/* Check for the global setting */
8668fcf3ce44SJohn Forte 		cnt = 0;
8669fcf3ce44SJohn Forte 		arrayp = NULL;
8670fcf3ce44SJohn Forte 		rval = ddi_prop_lookup_string_array(DDI_DEV_T_ANY, hba->dip,
8671fcf3ce44SJohn Forte 		    (DDI_PROP_DONTPASS),
8672fcf3ce44SJohn Forte 		    "auth-keys", &arrayp, &cnt);
8673fcf3ce44SJohn Forte 	}
8674fcf3ce44SJohn Forte 	if ((rval != DDI_PROP_SUCCESS) || !cnt || !arrayp) {
8675fcf3ce44SJohn Forte 		return;
8676fcf3ce44SJohn Forte 	}
8677fcf3ce44SJohn Forte 	for (i = 0; i < cnt; i++) {
8678fcf3ce44SJohn Forte 		prop_str = arrayp[i];
8679fcf3ce44SJohn Forte 		if (prop_str == NULL) {
8680fcf3ce44SJohn Forte 			break;
8681fcf3ce44SJohn Forte 		}
8682fcf3ce44SJohn Forte 		/* parse the string */
8683fcf3ce44SJohn Forte 		if (emlxs_auth_key_parse(hba, &auth_key, prop_str) == 0) {
8684fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8685fcf3ce44SJohn Forte 			    &emlxs_attach_msg,
8686fcf3ce44SJohn Forte 			    "Error parsing auth_keys property. entry=%d", i);
8687fcf3ce44SJohn Forte 			continue;
8688fcf3ce44SJohn Forte 		}
8689fcf3ce44SJohn Forte 		auth_key2 = emlxs_auth_key_create(hba,
8690fcf3ce44SJohn Forte 		    (uint8_t *)&auth_key.local_entity,
8691fcf3ce44SJohn Forte 		    (uint8_t *)&auth_key.remote_entity);
8692fcf3ce44SJohn Forte 
8693fcf3ce44SJohn Forte 		if (!auth_key2) {
8694fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8695fcf3ce44SJohn Forte 			    &emlxs_attach_msg,
8696fcf3ce44SJohn Forte 			    "Out of memory parsing auth_keys property. %d",
8697fcf3ce44SJohn Forte 			    i);
8698fcf3ce44SJohn Forte 			return;
8699fcf3ce44SJohn Forte 		}
8700fcf3ce44SJohn Forte 		auth_key.next = auth_key2->next;
8701fcf3ce44SJohn Forte 		auth_key.prev = auth_key2->prev;
8702fcf3ce44SJohn Forte 		bcopy((uint8_t *)&auth_key,
8703fcf3ce44SJohn Forte 		    (uint8_t *)auth_key2, sizeof (emlxs_auth_key_t));
8704fcf3ce44SJohn Forte 	}
8705fcf3ce44SJohn Forte 
8706fcf3ce44SJohn Forte 	return;
8707fcf3ce44SJohn Forte 
8708fcf3ce44SJohn Forte } /* emlxs_auth_key_read() */
8709fcf3ce44SJohn Forte 
8710fcf3ce44SJohn Forte 
8711fcf3ce44SJohn Forte /* auth_lock must be held */
8712fcf3ce44SJohn Forte static uint32_t
emlxs_auth_key_parse(emlxs_hba_t * hba,emlxs_auth_key_t * auth_key,char * prop_str)8713fcf3ce44SJohn Forte emlxs_auth_key_parse(
8714fcf3ce44SJohn Forte 	emlxs_hba_t *hba,
8715fcf3ce44SJohn Forte 	emlxs_auth_key_t *auth_key,
8716fcf3ce44SJohn Forte 	char *prop_str)
8717fcf3ce44SJohn Forte {
8718fcf3ce44SJohn Forte 	emlxs_port_t *port = &PPORT;
8719fcf3ce44SJohn Forte 	uint32_t errors = 0;
8720fcf3ce44SJohn Forte 	uint32_t c1;
8721fcf3ce44SJohn Forte 	uint8_t *np;
8722fcf3ce44SJohn Forte 	uint32_t j;
8723fcf3ce44SJohn Forte 	uint32_t sum;
8724fcf3ce44SJohn Forte 	char *s;
8725fcf3ce44SJohn Forte 
8726fcf3ce44SJohn Forte 	s = prop_str;
8727fcf3ce44SJohn Forte 	bzero(auth_key, sizeof (emlxs_auth_key_t));
8728fcf3ce44SJohn Forte 
8729fcf3ce44SJohn Forte 	/* Read local wwpn */
8730fcf3ce44SJohn Forte 	np = (uint8_t *)&auth_key->local_entity;
8731fcf3ce44SJohn Forte 	for (j = 0; j < 8; j++) {
8732fcf3ce44SJohn Forte 		c1 = *s++;
8733fcf3ce44SJohn Forte 		if ((c1 >= '0') && (c1 <= '9')) {
8734fcf3ce44SJohn Forte 			sum = ((c1 - '0') << 4);
8735fcf3ce44SJohn Forte 		} else if ((c1 >= 'a') && (c1 <= 'f')) {
8736fcf3ce44SJohn Forte 			sum = ((c1 - 'a' + 10) << 4);
8737fcf3ce44SJohn Forte 		} else if ((c1 >= 'A') && (c1 <= 'F')) {
8738fcf3ce44SJohn Forte 			sum = ((c1 - 'A' + 10) << 4);
8739fcf3ce44SJohn Forte 		} else {
8740fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8741fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8742fcf3ce44SJohn Forte 			    "Cfg err: Invalid LWWPN found. %d %c",
8743fcf3ce44SJohn Forte 			    j, c1);
8744fcf3ce44SJohn Forte 			errors++;
8745fcf3ce44SJohn Forte 		}
8746fcf3ce44SJohn Forte 
8747fcf3ce44SJohn Forte 		c1 = *s++;
8748fcf3ce44SJohn Forte 		if ((c1 >= '0') && (c1 <= '9')) {
8749fcf3ce44SJohn Forte 			sum |= (c1 - '0');
8750fcf3ce44SJohn Forte 		} else if ((c1 >= 'a') && (c1 <= 'f')) {
8751fcf3ce44SJohn Forte 			sum |= (c1 - 'a' + 10);
8752fcf3ce44SJohn Forte 		} else if ((c1 >= 'A') && (c1 <= 'F')) {
8753fcf3ce44SJohn Forte 			sum |= (c1 - 'A' + 10);
8754fcf3ce44SJohn Forte 		} else {
8755fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8756fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8757fcf3ce44SJohn Forte 			    "Cfg err: Invalid LWWPN found. %d %c",
8758fcf3ce44SJohn Forte 			    j, c1);
8759fcf3ce44SJohn Forte 			errors++;
8760fcf3ce44SJohn Forte 		}
8761fcf3ce44SJohn Forte 
8762a9800bebSGarrett D'Amore 		*np++ = (uint8_t)sum;
8763fcf3ce44SJohn Forte 	}
8764fcf3ce44SJohn Forte 
8765fcf3ce44SJohn Forte 	if (*s++ != ':') {
8766fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
8767fcf3ce44SJohn Forte 		    &emlxs_attach_debug_msg,
8768fcf3ce44SJohn Forte 		    "Cfg err: Invalid delimiter after LWWPN.");
8769fcf3ce44SJohn Forte 		goto out;
8770fcf3ce44SJohn Forte 	}
8771fcf3ce44SJohn Forte 	/* Read remote wwpn */
8772fcf3ce44SJohn Forte 	np = (uint8_t *)&auth_key->remote_entity;
8773fcf3ce44SJohn Forte 	for (j = 0; j < 8; j++) {
8774fcf3ce44SJohn Forte 		c1 = *s++;
8775fcf3ce44SJohn Forte 		if ((c1 >= '0') && (c1 <= '9')) {
8776fcf3ce44SJohn Forte 			sum = ((c1 - '0') << 4);
8777fcf3ce44SJohn Forte 		} else if ((c1 >= 'a') && (c1 <= 'f')) {
8778fcf3ce44SJohn Forte 			sum = ((c1 - 'a' + 10) << 4);
8779fcf3ce44SJohn Forte 		} else if ((c1 >= 'A') && (c1 <= 'F')) {
8780fcf3ce44SJohn Forte 			sum = ((c1 - 'A' + 10) << 4);
8781fcf3ce44SJohn Forte 		} else {
8782fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8783fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8784fcf3ce44SJohn Forte 			    "Cfg err: Invalid RWWPN found.%d %c",
8785fcf3ce44SJohn Forte 			    j, c1);
8786fcf3ce44SJohn Forte 			errors++;
8787fcf3ce44SJohn Forte 		}
8788fcf3ce44SJohn Forte 
8789fcf3ce44SJohn Forte 		c1 = *s++;
8790fcf3ce44SJohn Forte 		if ((c1 >= '0') && (c1 <= '9')) {
8791fcf3ce44SJohn Forte 			sum |= (c1 - '0');
8792fcf3ce44SJohn Forte 		} else if ((c1 >= 'a') && (c1 <= 'f')) {
8793fcf3ce44SJohn Forte 			sum |= (c1 - 'a' + 10);
8794fcf3ce44SJohn Forte 		} else if ((c1 >= 'A') && (c1 <= 'F')) {
8795fcf3ce44SJohn Forte 			sum |= (c1 - 'A' + 10);
8796fcf3ce44SJohn Forte 		} else {
8797fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8798fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8799fcf3ce44SJohn Forte 			    "Cfg err: Invalid RWWPN found. %d %c",
8800fcf3ce44SJohn Forte 			    j, c1);
8801fcf3ce44SJohn Forte 			errors++;
8802fcf3ce44SJohn Forte 		}
8803fcf3ce44SJohn Forte 
8804a9800bebSGarrett D'Amore 		*np++ = (uint8_t)sum;
8805fcf3ce44SJohn Forte 	}
8806fcf3ce44SJohn Forte 
8807fcf3ce44SJohn Forte 	if (*s++ != ':') {
8808fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
8809fcf3ce44SJohn Forte 		    &emlxs_attach_debug_msg,
8810fcf3ce44SJohn Forte 		    "Cfg err: Invalid delimiter after RWWPN.");
8811fcf3ce44SJohn Forte 		goto out;
8812fcf3ce44SJohn Forte 	}
8813fcf3ce44SJohn Forte 	/* Read lpwd type (%x) */
8814fcf3ce44SJohn Forte 	sum = 0;
8815fcf3ce44SJohn Forte 	do {
8816fcf3ce44SJohn Forte 		c1 = *s++;
8817fcf3ce44SJohn Forte 		if ((c1 >= '0') && (c1 <= '9')) {
8818fcf3ce44SJohn Forte 			sum = (sum << 4) + (c1 - '0');
8819fcf3ce44SJohn Forte 		} else if ((c1 >= 'a') && (c1 <= 'f')) {
8820fcf3ce44SJohn Forte 			sum = (sum << 4) + (c1 - 'a' + 10);
8821fcf3ce44SJohn Forte 		} else if ((c1 >= 'A') && (c1 <= 'F')) {
8822fcf3ce44SJohn Forte 			sum = (sum << 4) + (c1 - 'A' + 10);
8823fcf3ce44SJohn Forte 		} else {
8824fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8825fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8826fcf3ce44SJohn Forte 			    "Cfg err: Invalid lpwd type found. %c %d",
8827fcf3ce44SJohn Forte 			    c1, sum);
8828fcf3ce44SJohn Forte 
8829fcf3ce44SJohn Forte 			errors++;
8830fcf3ce44SJohn Forte 		}
8831fcf3ce44SJohn Forte 
8832fcf3ce44SJohn Forte 	} while (*s != ':' && *s != 0);
8833a9800bebSGarrett D'Amore 	auth_key->local_password_type = (uint16_t)sum;
8834fcf3ce44SJohn Forte 
8835fcf3ce44SJohn Forte 	if (*s++ != ':') {
8836fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
8837fcf3ce44SJohn Forte 		    &emlxs_attach_debug_msg,
8838fcf3ce44SJohn Forte 		    "Cfg err: Invalid delimiter after lpwd type.");
8839fcf3ce44SJohn Forte 		goto out;
8840fcf3ce44SJohn Forte 	}
8841fcf3ce44SJohn Forte 	/* Read lpwd */
8842fcf3ce44SJohn Forte 	np = (uint8_t *)&auth_key->local_password;
8843fcf3ce44SJohn Forte 	j = 0;
8844fcf3ce44SJohn Forte 	switch (auth_key->local_password_type) {
8845fcf3ce44SJohn Forte 	case 1:	/* ACSII */
8846fcf3ce44SJohn Forte 		while (*s != ':' && *s != 0) {
8847fcf3ce44SJohn Forte 			*np++ = *s++;
8848fcf3ce44SJohn Forte 			j++;
8849fcf3ce44SJohn Forte 		}
8850fcf3ce44SJohn Forte 		break;
8851fcf3ce44SJohn Forte 
8852fcf3ce44SJohn Forte 	case 2:	/* Hex */
8853fcf3ce44SJohn Forte 		do {
8854fcf3ce44SJohn Forte 			c1 = *s++;
8855fcf3ce44SJohn Forte 			if ((c1 >= '0') && (c1 <= '9')) {
8856fcf3ce44SJohn Forte 				sum = ((c1 - '0') << 4);
8857fcf3ce44SJohn Forte 			} else if ((c1 >= 'a') && (c1 <= 'f')) {
8858fcf3ce44SJohn Forte 				sum = ((c1 - 'a' + 10) << 4);
8859fcf3ce44SJohn Forte 			} else if ((c1 >= 'A') && (c1 <= 'F')) {
8860fcf3ce44SJohn Forte 				sum = ((c1 - 'A' + 10) << 4);
8861fcf3ce44SJohn Forte 			} else {
8862fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8863fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8864fcf3ce44SJohn Forte 			    "Cfg err: Invalid lpwd found. %d %c",
8865fcf3ce44SJohn Forte 			    j, c1);
8866fcf3ce44SJohn Forte 				errors++;
8867fcf3ce44SJohn Forte 			}
8868fcf3ce44SJohn Forte 
8869fcf3ce44SJohn Forte 			c1 = *s++;
8870fcf3ce44SJohn Forte 			if ((c1 >= '0') && (c1 <= '9')) {
8871fcf3ce44SJohn Forte 				sum |= (c1 - '0');
8872fcf3ce44SJohn Forte 			} else if ((c1 >= 'a') && (c1 <= 'f')) {
8873fcf3ce44SJohn Forte 				sum |= (c1 - 'a' + 10);
8874fcf3ce44SJohn Forte 			} else if ((c1 >= 'A') && (c1 <= 'F')) {
8875fcf3ce44SJohn Forte 				sum |= (c1 - 'A' + 10);
8876fcf3ce44SJohn Forte 			} else {
8877fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8878fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8879fcf3ce44SJohn Forte 			    "Cfg err: Invalid lpwd found. %d %c",
8880fcf3ce44SJohn Forte 			    j, c1);
8881fcf3ce44SJohn Forte 				errors++;
8882fcf3ce44SJohn Forte 			}
8883fcf3ce44SJohn Forte 
8884a9800bebSGarrett D'Amore 			*np++ = (uint8_t)sum;
8885fcf3ce44SJohn Forte 			j++;
8886fcf3ce44SJohn Forte 
8887fcf3ce44SJohn Forte 		} while (*s != ':' && *s != 0);
8888fcf3ce44SJohn Forte 
8889fcf3ce44SJohn Forte 		break;
8890fcf3ce44SJohn Forte 
8891fcf3ce44SJohn Forte 	case 0:	/* Ignore */
8892fcf3ce44SJohn Forte 	case 3:	/* Ignore */
8893fcf3ce44SJohn Forte 		break;
8894fcf3ce44SJohn Forte 
8895fcf3ce44SJohn Forte 	default:
8896fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
8897fcf3ce44SJohn Forte 		    &emlxs_attach_debug_msg,
8898fcf3ce44SJohn Forte 		    "Config error: Invalid lpwd type found. type=%x",
8899fcf3ce44SJohn Forte 		    auth_key->local_password_type);
8900fcf3ce44SJohn Forte 
8901fcf3ce44SJohn Forte 		errors++;
8902fcf3ce44SJohn Forte 		goto out;
8903fcf3ce44SJohn Forte 	}
8904a9800bebSGarrett D'Amore 	auth_key->local_password_length = (uint16_t)j;
8905fcf3ce44SJohn Forte 
8906fcf3ce44SJohn Forte 	if (*s++ != ':') {
8907fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
8908fcf3ce44SJohn Forte 		    &emlxs_attach_debug_msg,
8909fcf3ce44SJohn Forte 		    "Config error: Invalid delimiter after lpwd.");
8910fcf3ce44SJohn Forte 		goto out;
8911fcf3ce44SJohn Forte 	}
8912fcf3ce44SJohn Forte 	/* Read rpwd type (%x) */
8913fcf3ce44SJohn Forte 	sum = 0;
8914fcf3ce44SJohn Forte 	do {
8915fcf3ce44SJohn Forte 		c1 = *s++;
8916fcf3ce44SJohn Forte 		if ((c1 >= '0') && (c1 <= '9')) {
8917fcf3ce44SJohn Forte 			sum = (sum << 4) + (c1 - '0');
8918fcf3ce44SJohn Forte 		} else if ((c1 >= 'a') && (c1 <= 'f')) {
8919fcf3ce44SJohn Forte 			sum = (sum << 4) + (c1 - 'a' + 10);
8920fcf3ce44SJohn Forte 		} else if ((c1 >= 'A') && (c1 <= 'F')) {
8921fcf3ce44SJohn Forte 			sum = (sum << 4) + (c1 - 'A' + 10);
8922fcf3ce44SJohn Forte 		} else {
8923fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8924fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8925fcf3ce44SJohn Forte 			    "Config error: Invalid rpwd type found. %c %d",
8926fcf3ce44SJohn Forte 			    c1, sum);
8927fcf3ce44SJohn Forte 
8928fcf3ce44SJohn Forte 			errors++;
8929fcf3ce44SJohn Forte 		}
8930fcf3ce44SJohn Forte 
8931fcf3ce44SJohn Forte 	} while (*s != ':' && *s != 0);
8932a9800bebSGarrett D'Amore 	auth_key->remote_password_type = (uint16_t)sum;
8933fcf3ce44SJohn Forte 
8934fcf3ce44SJohn Forte 	if (*s++ != ':') {
8935fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
8936fcf3ce44SJohn Forte 		    &emlxs_attach_debug_msg,
8937fcf3ce44SJohn Forte 		    "Config error: Invalid delimiter after rpwd type.");
8938fcf3ce44SJohn Forte 		goto out;
8939fcf3ce44SJohn Forte 	}
8940fcf3ce44SJohn Forte 	/* Read rpwd */
8941fcf3ce44SJohn Forte 	np = (uint8_t *)&auth_key->remote_password;
8942fcf3ce44SJohn Forte 	j = 0;
8943fcf3ce44SJohn Forte 	switch (auth_key->remote_password_type) {
8944fcf3ce44SJohn Forte 	case 1:	/* ACSII */
8945fcf3ce44SJohn Forte 		while (*s != ':' && *s != 0) {
8946fcf3ce44SJohn Forte 			*np++ = *s++;
8947fcf3ce44SJohn Forte 			j++;
8948fcf3ce44SJohn Forte 		}
8949fcf3ce44SJohn Forte 		break;
8950fcf3ce44SJohn Forte 
8951fcf3ce44SJohn Forte 	case 2:	/* Hex */
8952fcf3ce44SJohn Forte 		do {
8953fcf3ce44SJohn Forte 			c1 = *s++;
8954fcf3ce44SJohn Forte 			if ((c1 >= '0') && (c1 <= '9')) {
8955fcf3ce44SJohn Forte 				sum = ((c1 - '0') << 4);
8956fcf3ce44SJohn Forte 			} else if ((c1 >= 'a') && (c1 <= 'f')) {
8957fcf3ce44SJohn Forte 				sum = ((c1 - 'a' + 10) << 4);
8958fcf3ce44SJohn Forte 			} else if ((c1 >= 'A') && (c1 <= 'F')) {
8959fcf3ce44SJohn Forte 				sum = ((c1 - 'A' + 10) << 4);
8960fcf3ce44SJohn Forte 			} else {
8961fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8962fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8963fcf3ce44SJohn Forte 			    "Cfg err: Invalid rpwd found. %d %c",
8964fcf3ce44SJohn Forte 			    j, c1);
8965fcf3ce44SJohn Forte 				errors++;
8966fcf3ce44SJohn Forte 			}
8967fcf3ce44SJohn Forte 
8968fcf3ce44SJohn Forte 			c1 = *s++;
8969fcf3ce44SJohn Forte 			if ((c1 >= '0') && (c1 <= '9')) {
8970fcf3ce44SJohn Forte 				sum |= (c1 - '0');
8971fcf3ce44SJohn Forte 			} else if ((c1 >= 'a') && (c1 <= 'f')) {
8972fcf3ce44SJohn Forte 				sum |= (c1 - 'a' + 10);
8973fcf3ce44SJohn Forte 			} else if ((c1 >= 'A') && (c1 <= 'F')) {
8974fcf3ce44SJohn Forte 				sum |= (c1 - 'A' + 10);
8975fcf3ce44SJohn Forte 			} else {
8976fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
8977fcf3ce44SJohn Forte 			    &emlxs_attach_debug_msg,
8978fcf3ce44SJohn Forte 			    "Cfg err: Invalid rpwd found. %d %c",
8979fcf3ce44SJohn Forte 			    j, c1);
8980fcf3ce44SJohn Forte 				errors++;
8981fcf3ce44SJohn Forte 			}
8982fcf3ce44SJohn Forte 
8983a9800bebSGarrett D'Amore 			*np++ = (uint8_t)sum;
8984fcf3ce44SJohn Forte 			j++;
8985fcf3ce44SJohn Forte 
8986fcf3ce44SJohn Forte 		} while (*s != ':' && *s != 0);
8987fcf3ce44SJohn Forte 
8988fcf3ce44SJohn Forte 		break;
8989fcf3ce44SJohn Forte 
8990fcf3ce44SJohn Forte 	case 0:	/* Ignore */
8991fcf3ce44SJohn Forte 	case 3:	/* Ignore */
8992fcf3ce44SJohn Forte 		break;
8993fcf3ce44SJohn Forte 
8994fcf3ce44SJohn Forte 	default:
8995fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
8996fcf3ce44SJohn Forte 		    &emlxs_attach_debug_msg,
8997fcf3ce44SJohn Forte 		    "Cfg error: Invalid rpwd type found. type=%x",
8998fcf3ce44SJohn Forte 		    auth_key->remote_password_type);
8999fcf3ce44SJohn Forte 
9000fcf3ce44SJohn Forte 		errors++;
9001fcf3ce44SJohn Forte 		goto out;
9002fcf3ce44SJohn Forte 	}
9003a9800bebSGarrett D'Amore 	auth_key->remote_password_length = (uint16_t)j;
9004fcf3ce44SJohn Forte 
9005fcf3ce44SJohn Forte 	if (errors) {
9006fcf3ce44SJohn Forte 		goto out;
9007fcf3ce44SJohn Forte 	}
9008fcf3ce44SJohn Forte 	/* Verify values */
9009fcf3ce44SJohn Forte 	if (auth_key->local_password_type == 0 ||
9010fcf3ce44SJohn Forte 	    auth_key->local_password_type > 3 ||
9011fcf3ce44SJohn Forte 	    auth_key->local_password_length == 0) {
9012fcf3ce44SJohn Forte 
9013fcf3ce44SJohn Forte 		auth_key->local_password_type = 3;
9014fcf3ce44SJohn Forte 		auth_key->local_password_length = 0;
9015fcf3ce44SJohn Forte 		bzero(auth_key->local_password,
9016fcf3ce44SJohn Forte 		    sizeof (auth_key->local_password));
9017fcf3ce44SJohn Forte 	}
9018fcf3ce44SJohn Forte 	if (auth_key->remote_password_type == 0 ||
9019fcf3ce44SJohn Forte 	    auth_key->remote_password_type > 3 ||
9020fcf3ce44SJohn Forte 	    auth_key->remote_password_length == 0) {
9021fcf3ce44SJohn Forte 
9022fcf3ce44SJohn Forte 		auth_key->remote_password_type = 3;
9023fcf3ce44SJohn Forte 		auth_key->remote_password_length = 0;
9024fcf3ce44SJohn Forte 		bzero(auth_key->remote_password,
9025fcf3ce44SJohn Forte 		    sizeof (auth_key->remote_password));
9026fcf3ce44SJohn Forte 	}
9027fcf3ce44SJohn Forte 	/* Display entry */
9028fcf3ce44SJohn Forte 	emlxs_auth_key_print(hba, auth_key);
9029fcf3ce44SJohn Forte 
9030fcf3ce44SJohn Forte out:
9031fcf3ce44SJohn Forte 	if (errors) {
9032fcf3ce44SJohn Forte 		bzero(auth_key, sizeof (emlxs_auth_key_t));
9033fcf3ce44SJohn Forte 		return (0);
9034fcf3ce44SJohn Forte 	}
9035fcf3ce44SJohn Forte 	return (1);
9036fcf3ce44SJohn Forte 
9037fcf3ce44SJohn Forte } /* emlxs_auth_key_parse() */
9038fcf3ce44SJohn Forte 
9039fcf3ce44SJohn Forte 
9040fcf3ce44SJohn Forte /* ************************** AUTH DFCLIB SUPPORT *********************** */
9041fcf3ce44SJohn Forte 
9042fcf3ce44SJohn Forte /* Provides DFC support for emlxs_dfc_init_auth() */
9043fcf3ce44SJohn Forte extern uint32_t
emlxs_dhc_init_auth(emlxs_hba_t * hba,uint8_t * lwwpn,uint8_t * rwwpn)9044fcf3ce44SJohn Forte emlxs_dhc_init_auth(emlxs_hba_t *hba, uint8_t *lwwpn, uint8_t *rwwpn)
9045fcf3ce44SJohn Forte {
9046fcf3ce44SJohn Forte 	emlxs_port_t *port = &PPORT;
9047fcf3ce44SJohn Forte 	emlxs_config_t *cfg = &CFG;
9048fcf3ce44SJohn Forte 	NODELIST *ndlp;
9049fcf3ce44SJohn Forte 	uint32_t vpi;
9050fcf3ce44SJohn Forte 	char s_wwpn[64];
9051fcf3ce44SJohn Forte 
9052fcf3ce44SJohn Forte 	/* Return is authentication is not enabled */
9053fcf3ce44SJohn Forte 	if (cfg[CFG_AUTH_ENABLE].current == 0) {
9054fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
9055fcf3ce44SJohn Forte 		    &emlxs_fcsp_debug_msg,
9056*8f23e9faSHans Rosenfeld 		    "dhc_init_auth. Auth disabled.");
9057fcf3ce44SJohn Forte 
9058fcf3ce44SJohn Forte 		return (DFC_AUTH_AUTHENTICATION_DISABLED);
9059fcf3ce44SJohn Forte 	}
9060fcf3ce44SJohn Forte 	/* Scan for lwwpn match */
9061fcf3ce44SJohn Forte 	for (vpi = 0; vpi < MAX_VPORTS; vpi++) {
9062fcf3ce44SJohn Forte 		port = &VPORT(vpi);
9063fcf3ce44SJohn Forte 
9064fcf3ce44SJohn Forte 		if (!(port->flag & EMLXS_PORT_BOUND)) {
9065fcf3ce44SJohn Forte 			continue;
9066fcf3ce44SJohn Forte 		}
9067728bdc9bSSukumar Swaminathan 		if (bcmp((uint8_t *)&port->wwpn, lwwpn, 8) == 0) {
9068fcf3ce44SJohn Forte 			break;
9069fcf3ce44SJohn Forte 		}
9070fcf3ce44SJohn Forte 	}
9071fcf3ce44SJohn Forte 
9072fcf3ce44SJohn Forte 	if (vpi == MAX_VPORTS) {
9073fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
9074fcf3ce44SJohn Forte 		    &emlxs_dfc_error_msg,
9075*8f23e9faSHans Rosenfeld 		    "dhc_init_auth: lwwpn not found. %s",
9076*8f23e9faSHans Rosenfeld 		    emlxs_wwn_xlate(s_wwpn, sizeof (s_wwpn), lwwpn));
9077fcf3ce44SJohn Forte 
9078fcf3ce44SJohn Forte 		return (DFC_AUTH_WWN_NOT_FOUND);
9079fcf3ce44SJohn Forte 	}
9080728bdc9bSSukumar Swaminathan 	if (bcmp(rwwpn, emlxs_fabric_wwn, 8) == 0) {
9081fcf3ce44SJohn Forte 		/* Scan for fabric node */
9082*8f23e9faSHans Rosenfeld 		if ((ndlp = emlxs_node_find_did(port, FABRIC_DID, 1)) == NULL) {
9083fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
9084fcf3ce44SJohn Forte 			    &emlxs_dfc_error_msg,
9085*8f23e9faSHans Rosenfeld 			    "dhc_init_auth: fabric node not found.");
9086fcf3ce44SJohn Forte 
9087fcf3ce44SJohn Forte 			return (DFC_AUTH_WWN_NOT_FOUND);
9088fcf3ce44SJohn Forte 		}
9089fcf3ce44SJohn Forte 	} else {
9090fcf3ce44SJohn Forte 		/* Scan for rwwpn match */
9091*8f23e9faSHans Rosenfeld 		if ((ndlp = emlxs_node_find_wwpn(port, rwwpn, 1)) == NULL) {
9092fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
9093fcf3ce44SJohn Forte 			    &emlxs_dfc_error_msg,
9094*8f23e9faSHans Rosenfeld 			    "dhc_init_auth: rwwpn not found. %s",
9095*8f23e9faSHans Rosenfeld 			    emlxs_wwn_xlate(s_wwpn, sizeof (s_wwpn), rwwpn));
9096fcf3ce44SJohn Forte 
9097fcf3ce44SJohn Forte 			return (DFC_AUTH_WWN_NOT_FOUND);
9098fcf3ce44SJohn Forte 		}
9099fcf3ce44SJohn Forte 	}
9100fcf3ce44SJohn Forte 
910182527734SSukumar Swaminathan 	if ((ndlp->nlp_DID != FABRIC_DID) &&
9102fcf3ce44SJohn Forte 	    ((port->port_dhc.state != ELX_FABRIC_AUTH_SUCCESS))) {
9103fcf3ce44SJohn Forte 		return (DFC_IO_ERROR);
9104fcf3ce44SJohn Forte 	}
9105fcf3ce44SJohn Forte 	if (ndlp->node_dhc.state >= NODE_STATE_AUTH_NEGOTIATE_ISSUE) {
9106fcf3ce44SJohn Forte 		return (DFC_AUTH_AUTHENTICATION_GOINGON);
9107fcf3ce44SJohn Forte 	}
9108fcf3ce44SJohn Forte 	if (ndlp->node_dhc.state == NODE_STATE_AUTH_SUCCESS) {
9109fcf3ce44SJohn Forte 		ndlp->node_dhc.nlp_reauth_status = NLP_HOST_REAUTH_IN_PROGRESS;
9110fcf3ce44SJohn Forte 	}
9111fcf3ce44SJohn Forte 	/* Attempt to start authentication */
9112fcf3ce44SJohn Forte 	if (emlxs_dhc_auth_start(port, ndlp, NULL, NULL) != 0) {
9113fcf3ce44SJohn Forte 		return (DFC_IO_ERROR);
9114fcf3ce44SJohn Forte 	}
9115fcf3ce44SJohn Forte 	return (0);
9116fcf3ce44SJohn Forte 
9117fcf3ce44SJohn Forte } /* emlxs_dhc_init_auth() */
9118fcf3ce44SJohn Forte 
9119fcf3ce44SJohn Forte 
9120fcf3ce44SJohn Forte /* Provides DFC support for emlxs_dfc_get_auth_cfg() */
9121fcf3ce44SJohn Forte extern uint32_t
emlxs_dhc_get_auth_cfg(emlxs_hba_t * hba,dfc_fcsp_config_t * fcsp_cfg)9122fcf3ce44SJohn Forte emlxs_dhc_get_auth_cfg(emlxs_hba_t *hba, dfc_fcsp_config_t *fcsp_cfg)
9123fcf3ce44SJohn Forte {
9124fcf3ce44SJohn Forte 	emlxs_port_t *port = &PPORT;
9125fcf3ce44SJohn Forte 	emlxs_config_t *cfg = &CFG;
9126fcf3ce44SJohn Forte 	char s_lwwpn[64];
9127fcf3ce44SJohn Forte 	char s_rwwpn[64];
9128fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *auth_cfg;
9129fcf3ce44SJohn Forte 	uint32_t i;
9130fcf3ce44SJohn Forte 
9131fcf3ce44SJohn Forte 	/* Return is authentication is not enabled */
9132fcf3ce44SJohn Forte 	if (cfg[CFG_AUTH_ENABLE].current == 0) {
9133fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
9134fcf3ce44SJohn Forte 		    &emlxs_fcsp_debug_msg,
9135*8f23e9faSHans Rosenfeld 		    "dhc_get_auth_cfg. Auth disabled.");
9136fcf3ce44SJohn Forte 
9137fcf3ce44SJohn Forte 		return (DFC_AUTH_AUTHENTICATION_DISABLED);
9138fcf3ce44SJohn Forte 	}
9139fcf3ce44SJohn Forte 	mutex_enter(&hba->auth_lock);
9140fcf3ce44SJohn Forte 
9141fcf3ce44SJohn Forte 	auth_cfg = emlxs_auth_cfg_get(hba,
9142fcf3ce44SJohn Forte 	    (uint8_t *)&fcsp_cfg->lwwpn, (uint8_t *)&fcsp_cfg->rwwpn);
9143fcf3ce44SJohn Forte 
9144fcf3ce44SJohn Forte 	if (!auth_cfg) {
9145fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
9146fcf3ce44SJohn Forte 		    &emlxs_dfc_error_msg,
9147*8f23e9faSHans Rosenfeld 		    "dhc_get_auth_cfg: entry not found. %s:%s",
9148*8f23e9faSHans Rosenfeld 		    emlxs_wwn_xlate(s_lwwpn, sizeof (s_lwwpn),
9149fcf3ce44SJohn Forte 		    (uint8_t *)&fcsp_cfg->lwwpn),
9150*8f23e9faSHans Rosenfeld 		    emlxs_wwn_xlate(s_rwwpn, sizeof (s_rwwpn),
9151fcf3ce44SJohn Forte 		    (uint8_t *)&fcsp_cfg->rwwpn));
9152fcf3ce44SJohn Forte 
9153fcf3ce44SJohn Forte 		mutex_exit(&hba->auth_lock);
9154fcf3ce44SJohn Forte 
9155fcf3ce44SJohn Forte 		return (DFC_AUTH_NOT_CONFIGURED);
9156fcf3ce44SJohn Forte 	}
9157fcf3ce44SJohn Forte 	fcsp_cfg->auth_tov = auth_cfg->authentication_timeout;
9158fcf3ce44SJohn Forte 	fcsp_cfg->auth_mode = auth_cfg->authentication_mode;
9159fcf3ce44SJohn Forte 	fcsp_cfg->auth_bidir = auth_cfg->bidirectional;
9160fcf3ce44SJohn Forte 
9161fcf3ce44SJohn Forte 	for (i = 0; i < 4; i++) {
9162fcf3ce44SJohn Forte 		fcsp_cfg->type_priority[i] =
9163fcf3ce44SJohn Forte 		    auth_cfg->authentication_type_priority[i];
9164fcf3ce44SJohn Forte 		fcsp_cfg->hash_priority[i] =
9165fcf3ce44SJohn Forte 		    auth_cfg->hash_priority[i];
9166fcf3ce44SJohn Forte 	}
9167fcf3ce44SJohn Forte 
9168fcf3ce44SJohn Forte 	for (i = 0; i < 8; i++) {
9169fcf3ce44SJohn Forte 		fcsp_cfg->group_priority[i] = auth_cfg->dh_group_priority[i];
9170fcf3ce44SJohn Forte 	}
9171fcf3ce44SJohn Forte 
9172fcf3ce44SJohn Forte 	fcsp_cfg->reauth_tov = auth_cfg->reauthenticate_time_interval;
9173fcf3ce44SJohn Forte 
9174fcf3ce44SJohn Forte 	mutex_exit(&hba->auth_lock);
9175fcf3ce44SJohn Forte 
9176fcf3ce44SJohn Forte 	return (0);
9177fcf3ce44SJohn Forte 
9178fcf3ce44SJohn Forte } /* emlxs_dhc_get_auth_cfg() */
9179fcf3ce44SJohn Forte 
9180fcf3ce44SJohn Forte 
9181fcf3ce44SJohn Forte /* Provides DFC support for emlxs_dfc_set_auth_cfg() */
9182fcf3ce44SJohn Forte extern uint32_t
emlxs_dhc_add_auth_cfg(emlxs_hba_t * hba,dfc_fcsp_config_t * fcsp_cfg,dfc_password_t * dfc_pwd)9183fcf3ce44SJohn Forte emlxs_dhc_add_auth_cfg(
9184fcf3ce44SJohn Forte 	emlxs_hba_t *hba,
9185fcf3ce44SJohn Forte 	dfc_fcsp_config_t *fcsp_cfg,
9186fcf3ce44SJohn Forte 	dfc_password_t *dfc_pwd)
9187fcf3ce44SJohn Forte {
9188fcf3ce44SJohn Forte 	emlxs_port_t *port = &PPORT;
9189fcf3ce44SJohn Forte 	emlxs_config_t *cfg = &CFG;
9190fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *auth_cfg;
9191fcf3ce44SJohn Forte 	emlxs_auth_key_t *auth_key;
9192fcf3ce44SJohn Forte 	uint32_t i;
9193fcf3ce44SJohn Forte 	NODELIST *ndlp;
9194fcf3ce44SJohn Forte 
9195fcf3ce44SJohn Forte 	/* Return if authentication is not enabled */
9196fcf3ce44SJohn Forte 	if (cfg[CFG_AUTH_ENABLE].current == 0) {
9197fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
9198fcf3ce44SJohn Forte 		    &emlxs_fcsp_debug_msg,
9199*8f23e9faSHans Rosenfeld 		    "dhc_add_auth_cfg. Auth disabled.");
9200fcf3ce44SJohn Forte 
9201fcf3ce44SJohn Forte 		return (DFC_AUTH_AUTHENTICATION_DISABLED);
9202fcf3ce44SJohn Forte 	}
9203fcf3ce44SJohn Forte 	mutex_enter(&hba->auth_lock);
9204fcf3ce44SJohn Forte 
9205fcf3ce44SJohn Forte 	auth_key = emlxs_auth_key_get(hba,
9206fcf3ce44SJohn Forte 	    (uint8_t *)&fcsp_cfg->lwwpn, (uint8_t *)&fcsp_cfg->rwwpn);
9207fcf3ce44SJohn Forte 
9208fcf3ce44SJohn Forte 	if (auth_key &&
9209fcf3ce44SJohn Forte 	    (auth_key->local_password_type == PASSWORD_TYPE_ASCII ||
9210fcf3ce44SJohn Forte 	    auth_key->local_password_type == PASSWORD_TYPE_BINARY)) {
9211fcf3ce44SJohn Forte 
9212fcf3ce44SJohn Forte 		/* Verify local password */
9213fcf3ce44SJohn Forte 		if ((auth_key->local_password_length != dfc_pwd->length) ||
9214fcf3ce44SJohn Forte 		    (auth_key->local_password_type != dfc_pwd->type) ||
9215fcf3ce44SJohn Forte 		    bcmp(dfc_pwd->password, auth_key->local_password,
9216fcf3ce44SJohn Forte 		    dfc_pwd->length)) {
9217fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
9218fcf3ce44SJohn Forte 			    &emlxs_dfc_error_msg,
9219*8f23e9faSHans Rosenfeld 			    "dhc_add_auth_cfg: Invalid local password.");
9220fcf3ce44SJohn Forte 
9221fcf3ce44SJohn Forte 			mutex_exit(&hba->auth_lock);
9222fcf3ce44SJohn Forte 
9223291a2b48SSukumar Swaminathan 			return (DFC_AUTH_COMPARE_FAILED);
9224fcf3ce44SJohn Forte 		}
9225fcf3ce44SJohn Forte 	}
9226fcf3ce44SJohn Forte 	/* Create entry */
9227fcf3ce44SJohn Forte 	auth_cfg = emlxs_auth_cfg_create(hba,
9228fcf3ce44SJohn Forte 	    (uint8_t *)&fcsp_cfg->lwwpn,
9229fcf3ce44SJohn Forte 	    (uint8_t *)&fcsp_cfg->rwwpn);
9230fcf3ce44SJohn Forte 
9231fcf3ce44SJohn Forte 	if (!auth_cfg) {
9232fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
9233fcf3ce44SJohn Forte 		    &emlxs_dfc_error_msg,
9234*8f23e9faSHans Rosenfeld 		    "dhc_add_auth_cfg: Out of memory.");
9235fcf3ce44SJohn Forte 
9236fcf3ce44SJohn Forte 		mutex_exit(&hba->auth_lock);
9237fcf3ce44SJohn Forte 
9238fcf3ce44SJohn Forte 		return (DFC_SYSRES_ERROR);
9239fcf3ce44SJohn Forte 	}
9240fcf3ce44SJohn Forte 	/* Init entry */
9241fcf3ce44SJohn Forte 	auth_cfg->authentication_timeout = fcsp_cfg->auth_tov;
9242fcf3ce44SJohn Forte 	auth_cfg->authentication_mode = fcsp_cfg->auth_mode;
9243fcf3ce44SJohn Forte 	auth_cfg->bidirectional = fcsp_cfg->auth_bidir;
9244fcf3ce44SJohn Forte 
9245fcf3ce44SJohn Forte 	for (i = 0; i < 4; i++) {
9246fcf3ce44SJohn Forte 		auth_cfg->authentication_type_priority[i] =
9247fcf3ce44SJohn Forte 		    fcsp_cfg->type_priority[i];
9248fcf3ce44SJohn Forte 		auth_cfg->hash_priority[i] =
9249fcf3ce44SJohn Forte 		    fcsp_cfg->hash_priority[i];
9250fcf3ce44SJohn Forte 	}
9251fcf3ce44SJohn Forte 
9252fcf3ce44SJohn Forte 	for (i = 0; i < 8; i++) {
9253fcf3ce44SJohn Forte 		auth_cfg->dh_group_priority[i] = fcsp_cfg->group_priority[i];
9254fcf3ce44SJohn Forte 	}
9255fcf3ce44SJohn Forte 
9256fcf3ce44SJohn Forte 	auth_cfg->reauthenticate_time_interval = fcsp_cfg->reauth_tov;
9257fcf3ce44SJohn Forte 
9258fcf3ce44SJohn Forte 	emlxs_auth_cfg_print(hba, auth_cfg);
9259fcf3ce44SJohn Forte 
9260fcf3ce44SJohn Forte 	/* Cancel old reauth to restart the new one if necessary */
9261fcf3ce44SJohn Forte 
9262fcf3ce44SJohn Forte 	/* Scan for lwwpn match */
9263fcf3ce44SJohn Forte 	for (i = 0; i < MAX_VPORTS; i++) {
9264fcf3ce44SJohn Forte 		port = &VPORT(i);
9265fcf3ce44SJohn Forte 
9266fcf3ce44SJohn Forte 		if (!(port->flag & EMLXS_PORT_BOUND)) {
9267fcf3ce44SJohn Forte 			continue;
9268fcf3ce44SJohn Forte 		}
9269fcf3ce44SJohn Forte 		if (bcmp((uint8_t *)&fcsp_cfg->lwwpn,
9270fcf3ce44SJohn Forte 		    (uint8_t *)&port->wwpn, 8)) {
9271fcf3ce44SJohn Forte 			continue;
9272fcf3ce44SJohn Forte 		}
9273fcf3ce44SJohn Forte 		/* Port match found */
9274fcf3ce44SJohn Forte 
9275fcf3ce44SJohn Forte 		if (bcmp((uint8_t *)&fcsp_cfg->rwwpn,
9276728bdc9bSSukumar Swaminathan 		    emlxs_fabric_wwn, 8) == 0) {
9277fcf3ce44SJohn Forte 			/* Scan for fabric node */
9278fcf3ce44SJohn Forte 			if ((ndlp = emlxs_node_find_did(port,
9279*8f23e9faSHans Rosenfeld 			    FABRIC_DID, 1)) == NULL) {
9280fcf3ce44SJohn Forte 				break;
9281fcf3ce44SJohn Forte 			}
9282fcf3ce44SJohn Forte 		} else {
9283fcf3ce44SJohn Forte 			/* Scan for rwwpn match */
9284fcf3ce44SJohn Forte 			if ((ndlp = emlxs_node_find_wwpn(port,
9285*8f23e9faSHans Rosenfeld 			    (uint8_t *)&fcsp_cfg->rwwpn, 1)) == NULL) {
9286fcf3ce44SJohn Forte 				break;
9287fcf3ce44SJohn Forte 			}
9288fcf3ce44SJohn Forte 		}
9289fcf3ce44SJohn Forte 
9290fcf3ce44SJohn Forte 		emlxs_dhc_set_reauth_time(port, ndlp, ENABLE);
9291fcf3ce44SJohn Forte 
9292fcf3ce44SJohn Forte 		break;
9293fcf3ce44SJohn Forte 	}
9294fcf3ce44SJohn Forte 
9295fcf3ce44SJohn Forte 	mutex_exit(&hba->auth_lock);
9296fcf3ce44SJohn Forte 
9297fcf3ce44SJohn Forte 	return (0);
9298fcf3ce44SJohn Forte 
9299fcf3ce44SJohn Forte } /* emlxs_dhc_add_auth_cfg() */
9300fcf3ce44SJohn Forte 
9301fcf3ce44SJohn Forte 
9302fcf3ce44SJohn Forte /* Provides DFC support for emlxs_dfc_set_auth_cfg() */
9303fcf3ce44SJohn Forte extern uint32_t
emlxs_dhc_delete_auth_cfg(emlxs_hba_t * hba,dfc_fcsp_config_t * fcsp_cfg,dfc_password_t * dfc_pwd)9304fcf3ce44SJohn Forte emlxs_dhc_delete_auth_cfg(
9305fcf3ce44SJohn Forte 	emlxs_hba_t *hba,
9306fcf3ce44SJohn Forte 	dfc_fcsp_config_t *fcsp_cfg,
9307fcf3ce44SJohn Forte 	dfc_password_t *dfc_pwd)
9308fcf3ce44SJohn Forte {
9309fcf3ce44SJohn Forte 	emlxs_port_t *port = &PPORT;
9310fcf3ce44SJohn Forte 	emlxs_config_t *cfg = &CFG;
9311fcf3ce44SJohn Forte 	char s_lwwpn[64];
9312fcf3ce44SJohn Forte 	char s_rwwpn[64];
9313fcf3ce44SJohn Forte 	emlxs_auth_key_t *auth_key;
9314fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *auth_cfg;
9315fcf3ce44SJohn Forte 
9316fcf3ce44SJohn Forte 	/* Return is authentication is not enabled */
9317fcf3ce44SJohn Forte 	if (cfg[CFG_AUTH_ENABLE].current == 0) {
9318fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
9319fcf3ce44SJohn Forte 		    &emlxs_fcsp_debug_msg,
9320*8f23e9faSHans Rosenfeld 		    "dhc_delete_auth_cfg. Auth disabled.");
9321fcf3ce44SJohn Forte 
9322fcf3ce44SJohn Forte 		return (DFC_AUTH_AUTHENTICATION_DISABLED);
9323fcf3ce44SJohn Forte 	}
9324fcf3ce44SJohn Forte 	mutex_enter(&hba->auth_lock);
9325fcf3ce44SJohn Forte 
9326fcf3ce44SJohn Forte 	auth_key = emlxs_auth_key_get(hba,
9327fcf3ce44SJohn Forte 	    (uint8_t *)&fcsp_cfg->lwwpn,
9328fcf3ce44SJohn Forte 	    (uint8_t *)&fcsp_cfg->rwwpn);
9329fcf3ce44SJohn Forte 
9330fcf3ce44SJohn Forte 	if (auth_key &&
9331fcf3ce44SJohn Forte 	    (auth_key->local_password_type == PASSWORD_TYPE_ASCII ||
9332fcf3ce44SJohn Forte 	    auth_key->local_password_type ==
9333fcf3ce44SJohn Forte 	    PASSWORD_TYPE_BINARY)) {
9334fcf3ce44SJohn Forte 		/* Verify local password */
9335fcf3ce44SJohn Forte 		if ((auth_key->local_password_length != dfc_pwd->length) ||
9336fcf3ce44SJohn Forte 		    (auth_key->local_password_type != dfc_pwd->type) ||
9337fcf3ce44SJohn Forte 		    bcmp(dfc_pwd->password,
9338fcf3ce44SJohn Forte 		    auth_key->local_password,
9339fcf3ce44SJohn Forte 		    dfc_pwd->length)) {
9340fcf3ce44SJohn Forte 
9341fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
9342fcf3ce44SJohn Forte 			    &emlxs_dfc_error_msg,
9343*8f23e9faSHans Rosenfeld 			    "dhc_delete_auth_cfg: Ivld local pwd.");
9344fcf3ce44SJohn Forte 
9345fcf3ce44SJohn Forte 			mutex_exit(&hba->auth_lock);
9346fcf3ce44SJohn Forte 
9347291a2b48SSukumar Swaminathan 			return (DFC_AUTH_COMPARE_FAILED);
9348fcf3ce44SJohn Forte 		}
9349fcf3ce44SJohn Forte 	}
9350fcf3ce44SJohn Forte 	auth_cfg = emlxs_auth_cfg_get(hba,
9351fcf3ce44SJohn Forte 	    (uint8_t *)&fcsp_cfg->lwwpn, (uint8_t *)&fcsp_cfg->rwwpn);
9352fcf3ce44SJohn Forte 
9353fcf3ce44SJohn Forte 	if (!auth_cfg) {
9354fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
9355fcf3ce44SJohn Forte 		    &emlxs_dfc_error_msg,
9356*8f23e9faSHans Rosenfeld 		    "dhc_delete_auth_cfg: entry not found. %s:%s",
9357*8f23e9faSHans Rosenfeld 		    emlxs_wwn_xlate(s_lwwpn, sizeof (s_lwwpn),
9358*8f23e9faSHans Rosenfeld 		    (uint8_t *)&fcsp_cfg->lwwpn),
9359*8f23e9faSHans Rosenfeld 		    emlxs_wwn_xlate(s_rwwpn, sizeof (s_rwwpn),
9360*8f23e9faSHans Rosenfeld 		    (uint8_t *)&fcsp_cfg->rwwpn));
9361fcf3ce44SJohn Forte 
9362fcf3ce44SJohn Forte 		mutex_exit(&hba->auth_lock);
9363fcf3ce44SJohn Forte 
9364fcf3ce44SJohn Forte 		return (DFC_AUTH_WWN_NOT_FOUND);
9365fcf3ce44SJohn Forte 	}
9366fcf3ce44SJohn Forte 	/* Destroy cfg entry */
9367fcf3ce44SJohn Forte 	emlxs_auth_cfg_destroy(hba, auth_cfg);
9368fcf3ce44SJohn Forte 
9369fcf3ce44SJohn Forte 	/* Destroy pwd entry */
9370fcf3ce44SJohn Forte 	emlxs_auth_key_destroy(hba, auth_key);
9371fcf3ce44SJohn Forte 
9372fcf3ce44SJohn Forte 	mutex_exit(&hba->auth_lock);
9373fcf3ce44SJohn Forte 
9374fcf3ce44SJohn Forte 	return (0);
9375fcf3ce44SJohn Forte 
9376fcf3ce44SJohn Forte } /* emlxs_dhc_delete_auth_cfg() */
9377fcf3ce44SJohn Forte 
9378fcf3ce44SJohn Forte 
9379fcf3ce44SJohn Forte /* Provides DFC support for emlxs_dfc_get_auth_key() */
9380fcf3ce44SJohn Forte extern uint32_t
emlxs_dhc_get_auth_key(emlxs_hba_t * hba,dfc_auth_password_t * dfc_auth_pwd)9381fcf3ce44SJohn Forte emlxs_dhc_get_auth_key(emlxs_hba_t *hba, dfc_auth_password_t *dfc_auth_pwd)
9382fcf3ce44SJohn Forte {
9383fcf3ce44SJohn Forte 	emlxs_port_t *port = &PPORT;
9384fcf3ce44SJohn Forte 	emlxs_config_t *cfg = &CFG;
9385fcf3ce44SJohn Forte 	char s_lwwpn[64];
9386fcf3ce44SJohn Forte 	char s_rwwpn[64];
9387fcf3ce44SJohn Forte 	emlxs_auth_key_t *auth_key;
9388fcf3ce44SJohn Forte 
9389fcf3ce44SJohn Forte 	/* Return is authentication is not enabled */
9390fcf3ce44SJohn Forte 	if (cfg[CFG_AUTH_ENABLE].current == 0) {
9391fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
9392fcf3ce44SJohn Forte 		    &emlxs_fcsp_debug_msg,
9393*8f23e9faSHans Rosenfeld 		    "dhc_get_auth_key. Auth disabled.");
9394fcf3ce44SJohn Forte 
9395fcf3ce44SJohn Forte 		return (DFC_AUTH_AUTHENTICATION_DISABLED);
9396fcf3ce44SJohn Forte 	}
9397fcf3ce44SJohn Forte 	mutex_enter(&hba->auth_lock);
9398fcf3ce44SJohn Forte 
9399fcf3ce44SJohn Forte 	auth_key = emlxs_auth_key_get(hba,
9400fcf3ce44SJohn Forte 	    (uint8_t *)&dfc_auth_pwd->lwwpn,
9401fcf3ce44SJohn Forte 	    (uint8_t *)&dfc_auth_pwd->rwwpn);
9402fcf3ce44SJohn Forte 
9403fcf3ce44SJohn Forte 	if (!auth_key) {
9404fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
9405fcf3ce44SJohn Forte 		    &emlxs_dfc_error_msg,
9406*8f23e9faSHans Rosenfeld 		    "dhc_get_auth_key: entry not found. %s:%s",
9407*8f23e9faSHans Rosenfeld 		    emlxs_wwn_xlate(s_lwwpn, sizeof (s_lwwpn),
9408*8f23e9faSHans Rosenfeld 		    (uint8_t *)&dfc_auth_pwd->lwwpn),
9409*8f23e9faSHans Rosenfeld 		    emlxs_wwn_xlate(s_rwwpn, sizeof (s_rwwpn),
9410*8f23e9faSHans Rosenfeld 		    (uint8_t *)&dfc_auth_pwd->rwwpn));
9411fcf3ce44SJohn Forte 
9412fcf3ce44SJohn Forte 		mutex_exit(&hba->auth_lock);
9413fcf3ce44SJohn Forte 
9414fcf3ce44SJohn Forte 		return (DFC_AUTH_NOT_CONFIGURED);
9415fcf3ce44SJohn Forte 	}
9416fcf3ce44SJohn Forte 	dfc_auth_pwd->lpw.length = auth_key->local_password_length;
9417fcf3ce44SJohn Forte 	dfc_auth_pwd->lpw.type = auth_key->local_password_type;
9418fcf3ce44SJohn Forte 	/*
9419fcf3ce44SJohn Forte 	 * bcopy(auth_key->local_password, dfc_auth_pwd->lpw.password,
9420fcf3ce44SJohn Forte 	 * dfc_auth_pwd->lpw.length);
9421fcf3ce44SJohn Forte 	 */
9422fcf3ce44SJohn Forte 
9423fcf3ce44SJohn Forte 	dfc_auth_pwd->rpw.length = auth_key->remote_password_length;
9424fcf3ce44SJohn Forte 	dfc_auth_pwd->rpw.type = auth_key->remote_password_type;
9425fcf3ce44SJohn Forte 	/*
9426fcf3ce44SJohn Forte 	 * bcopy(auth_key->remote_password, dfc_auth_pwd->rpw.password,
9427fcf3ce44SJohn Forte 	 * dfc_auth_pwd->rpw.length);
9428fcf3ce44SJohn Forte 	 */
9429fcf3ce44SJohn Forte 
9430fcf3ce44SJohn Forte 	dfc_auth_pwd->lpw_new.length = auth_key->local_password_length;
9431fcf3ce44SJohn Forte 	dfc_auth_pwd->lpw_new.type = auth_key->local_password_type;
9432fcf3ce44SJohn Forte 	/*
9433fcf3ce44SJohn Forte 	 * bcopy(auth_key->local_password, dfc_auth_pwd->lpw_new.password,
9434fcf3ce44SJohn Forte 	 * dfc_auth_pwd->lpw_new.length);
9435fcf3ce44SJohn Forte 	 */
9436fcf3ce44SJohn Forte 
9437fcf3ce44SJohn Forte 	dfc_auth_pwd->rpw_new.length = auth_key->remote_password_length;
9438fcf3ce44SJohn Forte 	dfc_auth_pwd->rpw_new.type = auth_key->remote_password_type;
9439fcf3ce44SJohn Forte 	/*
9440fcf3ce44SJohn Forte 	 * bcopy(auth_key->remote_password, dfc_auth_pwd->rpw_new.password,
9441fcf3ce44SJohn Forte 	 * dfc_auth_pwd->rpw_new.length);
9442fcf3ce44SJohn Forte 	 */
9443fcf3ce44SJohn Forte 
9444fcf3ce44SJohn Forte 	mutex_exit(&hba->auth_lock);
9445fcf3ce44SJohn Forte 
9446fcf3ce44SJohn Forte 	return (0);
9447fcf3ce44SJohn Forte 
9448fcf3ce44SJohn Forte } /* emlxs_dhc_get_auth_key() */
9449fcf3ce44SJohn Forte 
9450fcf3ce44SJohn Forte 
9451fcf3ce44SJohn Forte /* Provides DFC support for emlxs_dfc_set_auth_key() */
9452fcf3ce44SJohn Forte extern uint32_t
emlxs_dhc_set_auth_key(emlxs_hba_t * hba,dfc_auth_password_t * dfc_pwd)9453fcf3ce44SJohn Forte emlxs_dhc_set_auth_key(emlxs_hba_t *hba, dfc_auth_password_t *dfc_pwd)
9454fcf3ce44SJohn Forte {
9455fcf3ce44SJohn Forte 	emlxs_port_t *port = &PPORT;
9456fcf3ce44SJohn Forte 	emlxs_config_t *cfg = &CFG;
9457fcf3ce44SJohn Forte 	emlxs_auth_key_t *auth_key;
9458fcf3ce44SJohn Forte 	uint32_t length;
9459fcf3ce44SJohn Forte 
9460fcf3ce44SJohn Forte 	/* Return is authentication is not enabled */
9461fcf3ce44SJohn Forte 	if (cfg[CFG_AUTH_ENABLE].current == 0) {
9462fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
9463fcf3ce44SJohn Forte 		    &emlxs_fcsp_debug_msg,
9464*8f23e9faSHans Rosenfeld 		    "dhc_set_auth_key. Auth disabled.");
9465fcf3ce44SJohn Forte 
9466fcf3ce44SJohn Forte 		return (DFC_AUTH_AUTHENTICATION_DISABLED);
9467fcf3ce44SJohn Forte 	}
9468291a2b48SSukumar Swaminathan 
9469291a2b48SSukumar Swaminathan 	/* Check to make sure localpwd does not equal to remotepwd */
9470291a2b48SSukumar Swaminathan 	/* if they are given in the same time, if not, see below  */
9471291a2b48SSukumar Swaminathan 	if ((dfc_pwd->lpw_new.type == PASSWORD_TYPE_ASCII ||
9472291a2b48SSukumar Swaminathan 	    dfc_pwd->lpw_new.type == PASSWORD_TYPE_BINARY) &&
9473291a2b48SSukumar Swaminathan 	    (dfc_pwd->rpw_new.type == PASSWORD_TYPE_ASCII ||
9474291a2b48SSukumar Swaminathan 	    dfc_pwd->rpw_new.type == PASSWORD_TYPE_BINARY)) {
9475291a2b48SSukumar Swaminathan 		if (bcmp(dfc_pwd->lpw_new.password,
9476291a2b48SSukumar Swaminathan 		    dfc_pwd->rpw_new.password,
9477291a2b48SSukumar Swaminathan 		    dfc_pwd->lpw_new.length) == 0) {
9478291a2b48SSukumar Swaminathan 			EMLXS_MSGF(EMLXS_CONTEXT,
9479291a2b48SSukumar Swaminathan 			    &emlxs_fcsp_debug_msg,
9480*8f23e9faSHans Rosenfeld 			    "dhc_set_auth_key. nlpwd==nrpwd");
9481291a2b48SSukumar Swaminathan 
9482291a2b48SSukumar Swaminathan 			return (DFC_AUTH_LOCAL_REMOTE_PWD_EQUAL);
9483291a2b48SSukumar Swaminathan 		}
9484291a2b48SSukumar Swaminathan 	}
9485291a2b48SSukumar Swaminathan 
9486fcf3ce44SJohn Forte 	mutex_enter(&hba->auth_lock);
9487fcf3ce44SJohn Forte 
9488fcf3ce44SJohn Forte 	auth_key = emlxs_auth_key_get(hba,
9489fcf3ce44SJohn Forte 	    (uint8_t *)&dfc_pwd->lwwpn,
9490fcf3ce44SJohn Forte 	    (uint8_t *)&dfc_pwd->rwwpn);
9491fcf3ce44SJohn Forte 
9492fcf3ce44SJohn Forte 	/* If entry does not exist, then create entry */
9493fcf3ce44SJohn Forte 	if (!auth_key) {
9494fcf3ce44SJohn Forte 		auth_key = emlxs_auth_key_create(hba,
9495fcf3ce44SJohn Forte 		    (uint8_t *)&dfc_pwd->lwwpn,
9496fcf3ce44SJohn Forte 		    (uint8_t *)&dfc_pwd->rwwpn);
9497fcf3ce44SJohn Forte 
9498fcf3ce44SJohn Forte 		if (!auth_key) {
9499fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
9500fcf3ce44SJohn Forte 			    &emlxs_dfc_error_msg,
9501*8f23e9faSHans Rosenfeld 			    "dhc_set_auth_key: Out of memory.");
9502fcf3ce44SJohn Forte 
9503fcf3ce44SJohn Forte 			mutex_exit(&hba->auth_lock);
9504fcf3ce44SJohn Forte 
9505fcf3ce44SJohn Forte 			return (DFC_SYSRES_ERROR);
9506fcf3ce44SJohn Forte 		}
9507fcf3ce44SJohn Forte 	}
9508291a2b48SSukumar Swaminathan 
9509fcf3ce44SJohn Forte 	/* Check if a new local password is provided */
9510fcf3ce44SJohn Forte 	if (dfc_pwd->lpw_new.type == PASSWORD_TYPE_ASCII ||
9511fcf3ce44SJohn Forte 	    dfc_pwd->lpw_new.type == PASSWORD_TYPE_BINARY) {
9512fcf3ce44SJohn Forte 		/* Check if current password should be checked */
9513fcf3ce44SJohn Forte 		if (auth_key->local_password_type == PASSWORD_TYPE_ASCII ||
9514fcf3ce44SJohn Forte 		    auth_key->local_password_type == PASSWORD_TYPE_BINARY) {
9515fcf3ce44SJohn Forte 			/* Verify current local password */
9516fcf3ce44SJohn Forte 			if ((auth_key->local_password_length !=
9517fcf3ce44SJohn Forte 			    dfc_pwd->lpw.length) ||
9518fcf3ce44SJohn Forte 			    (auth_key->local_password_type !=
9519fcf3ce44SJohn Forte 			    dfc_pwd->lpw.type) ||
9520fcf3ce44SJohn Forte 			    bcmp(dfc_pwd->lpw.password,
9521fcf3ce44SJohn Forte 			    auth_key->local_password,
9522fcf3ce44SJohn Forte 			    dfc_pwd->lpw.length)) {
9523fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
9524fcf3ce44SJohn Forte 			    &emlxs_dfc_error_msg,
9525*8f23e9faSHans Rosenfeld 			    "dhc_set_auth_key: Invalid local password.");
9526fcf3ce44SJohn Forte 
9527fcf3ce44SJohn Forte 				mutex_exit(&hba->auth_lock);
9528fcf3ce44SJohn Forte 
9529fcf3ce44SJohn Forte 				return (DFC_AUTH_COMPARE_FAILED);
9530fcf3ce44SJohn Forte 			}
9531fcf3ce44SJohn Forte 		}
9532291a2b48SSukumar Swaminathan 
9533291a2b48SSukumar Swaminathan 		/*
9534291a2b48SSukumar Swaminathan 		 * Make sure the new local pwd is not equal to the current
9535291a2b48SSukumar Swaminathan 		 * remote pwd if any
9536291a2b48SSukumar Swaminathan 		 */
9537291a2b48SSukumar Swaminathan 		if (auth_key->remote_password_type == PASSWORD_TYPE_ASCII ||
9538291a2b48SSukumar Swaminathan 		    auth_key->remote_password_type == PASSWORD_TYPE_BINARY) {
9539291a2b48SSukumar Swaminathan 			if ((auth_key->remote_password_length ==
9540291a2b48SSukumar Swaminathan 			    dfc_pwd->lpw_new.length) &&
9541291a2b48SSukumar Swaminathan 			    (bcmp(dfc_pwd->lpw_new.password,
9542291a2b48SSukumar Swaminathan 			    auth_key->remote_password,
9543291a2b48SSukumar Swaminathan 			    dfc_pwd->lpw_new.length) == 0)) {
9544291a2b48SSukumar Swaminathan 			EMLXS_MSGF(EMLXS_CONTEXT,
9545291a2b48SSukumar Swaminathan 			    &emlxs_dfc_error_msg,
9546*8f23e9faSHans Rosenfeld 			    "dhc_set_auth_key: nlpwd==crpwd");
9547291a2b48SSukumar Swaminathan 
9548291a2b48SSukumar Swaminathan 				mutex_exit(&hba->auth_lock);
9549291a2b48SSukumar Swaminathan 
9550291a2b48SSukumar Swaminathan 				return (DFC_AUTH_LOCAL_REMOTE_PWD_EQUAL);
9551291a2b48SSukumar Swaminathan 			}
9552291a2b48SSukumar Swaminathan 		}
9553fcf3ce44SJohn Forte 		/* Update local entry */
9554fcf3ce44SJohn Forte 		auth_key->local_password_length = dfc_pwd->lpw_new.length;
9555fcf3ce44SJohn Forte 		auth_key->local_password_type = dfc_pwd->lpw_new.type;
9556fcf3ce44SJohn Forte 		bzero(auth_key->local_password,
9557fcf3ce44SJohn Forte 		    sizeof (auth_key->local_password));
9558fcf3ce44SJohn Forte 		length = min(dfc_pwd->lpw_new.length,
9559fcf3ce44SJohn Forte 		    sizeof (auth_key->local_password));
9560fcf3ce44SJohn Forte 		bcopy(dfc_pwd->lpw_new.password,
9561fcf3ce44SJohn Forte 		    auth_key->local_password, length);
9562fcf3ce44SJohn Forte 	}
9563fcf3ce44SJohn Forte 	/* Check if a new remote password is provided */
9564fcf3ce44SJohn Forte 	if (dfc_pwd->rpw_new.type == PASSWORD_TYPE_ASCII ||
9565fcf3ce44SJohn Forte 	    dfc_pwd->rpw_new.type == PASSWORD_TYPE_BINARY) {
9566fcf3ce44SJohn Forte 		/* Check if current password should be checked */
9567fcf3ce44SJohn Forte 		if (auth_key->remote_password_type == PASSWORD_TYPE_ASCII ||
9568fcf3ce44SJohn Forte 		    auth_key->remote_password_type == PASSWORD_TYPE_BINARY) {
9569fcf3ce44SJohn Forte 			/* Verify current remote password */
9570fcf3ce44SJohn Forte 			if ((auth_key->remote_password_length !=
9571fcf3ce44SJohn Forte 			    dfc_pwd->rpw.length) ||
9572fcf3ce44SJohn Forte 			    (auth_key->remote_password_type !=
9573fcf3ce44SJohn Forte 			    dfc_pwd->rpw.type) ||
9574fcf3ce44SJohn Forte 			    bcmp(dfc_pwd->rpw.password,
9575fcf3ce44SJohn Forte 			    auth_key->remote_password,
9576fcf3ce44SJohn Forte 			    dfc_pwd->rpw.length)) {
9577fcf3ce44SJohn Forte 			EMLXS_MSGF(EMLXS_CONTEXT,
9578fcf3ce44SJohn Forte 			    &emlxs_dfc_error_msg,
9579*8f23e9faSHans Rosenfeld 			    "dhc_set_auth_key: Invalid remote password.");
9580fcf3ce44SJohn Forte 
9581fcf3ce44SJohn Forte 				mutex_exit(&hba->auth_lock);
9582fcf3ce44SJohn Forte 
9583fcf3ce44SJohn Forte 				return (DFC_AUTH_COMPARE_FAILED);
9584fcf3ce44SJohn Forte 			}
9585fcf3ce44SJohn Forte 		}
9586291a2b48SSukumar Swaminathan 
9587291a2b48SSukumar Swaminathan 		/*
9588291a2b48SSukumar Swaminathan 		 * Make sure the new remote pwd is not equal to the current
9589291a2b48SSukumar Swaminathan 		 * local pwd if any
9590291a2b48SSukumar Swaminathan 		 */
9591291a2b48SSukumar Swaminathan 		if (auth_key->local_password_type == PASSWORD_TYPE_ASCII ||
9592291a2b48SSukumar Swaminathan 		    auth_key->local_password_type == PASSWORD_TYPE_BINARY) {
9593291a2b48SSukumar Swaminathan 			if ((auth_key->local_password_length ==
9594291a2b48SSukumar Swaminathan 			    dfc_pwd->rpw_new.length) &&
9595291a2b48SSukumar Swaminathan 			    (bcmp(dfc_pwd->rpw_new.password,
9596291a2b48SSukumar Swaminathan 			    auth_key->local_password,
9597291a2b48SSukumar Swaminathan 			    dfc_pwd->rpw_new.length) == 0)) {
9598291a2b48SSukumar Swaminathan 			EMLXS_MSGF(EMLXS_CONTEXT,
9599291a2b48SSukumar Swaminathan 			    &emlxs_dfc_error_msg,
9600*8f23e9faSHans Rosenfeld 			    "dhc_set_auth_key: nrpwd==clpwd");
9601291a2b48SSukumar Swaminathan 
9602291a2b48SSukumar Swaminathan 				mutex_exit(&hba->auth_lock);
9603291a2b48SSukumar Swaminathan 
9604291a2b48SSukumar Swaminathan 				return (DFC_AUTH_LOCAL_REMOTE_PWD_EQUAL);
9605291a2b48SSukumar Swaminathan 			}
9606291a2b48SSukumar Swaminathan 		}
9607fcf3ce44SJohn Forte 		/* Update remote entry */
9608fcf3ce44SJohn Forte 		auth_key->remote_password_length = dfc_pwd->rpw_new.length;
9609fcf3ce44SJohn Forte 		auth_key->remote_password_type = dfc_pwd->rpw_new.type;
9610fcf3ce44SJohn Forte 		bzero(auth_key->remote_password,
9611fcf3ce44SJohn Forte 		    sizeof (auth_key->remote_password));
9612fcf3ce44SJohn Forte 		length = min(dfc_pwd->rpw_new.length, 128);
9613fcf3ce44SJohn Forte 		bcopy(dfc_pwd->rpw_new.password,
9614fcf3ce44SJohn Forte 		    auth_key->remote_password, length);
9615fcf3ce44SJohn Forte 	}
9616fcf3ce44SJohn Forte 	/* Update dfc local entry */
9617fcf3ce44SJohn Forte 	dfc_pwd->lpw.length = auth_key->local_password_length;
9618fcf3ce44SJohn Forte 	dfc_pwd->lpw.type = auth_key->local_password_type;
9619fcf3ce44SJohn Forte 	bzero(dfc_pwd->lpw.password, sizeof (dfc_pwd->lpw.password));
9620fcf3ce44SJohn Forte 	length = min(auth_key->local_password_length,
9621fcf3ce44SJohn Forte 	    sizeof (dfc_pwd->lpw.password));
9622fcf3ce44SJohn Forte 	bcopy(auth_key->local_password, dfc_pwd->lpw.password, length);
9623fcf3ce44SJohn Forte 
9624fcf3ce44SJohn Forte 	/* Update dfc remote entry */
9625fcf3ce44SJohn Forte 	dfc_pwd->rpw.length = auth_key->remote_password_length;
9626fcf3ce44SJohn Forte 	dfc_pwd->rpw.type = auth_key->remote_password_type;
9627fcf3ce44SJohn Forte 	bzero(dfc_pwd->rpw.password, sizeof (dfc_pwd->rpw.password));
9628fcf3ce44SJohn Forte 	length = min(auth_key->remote_password_length,
9629fcf3ce44SJohn Forte 	    sizeof (dfc_pwd->rpw.password));
9630fcf3ce44SJohn Forte 	bcopy(auth_key->remote_password, dfc_pwd->rpw.password, length);
9631fcf3ce44SJohn Forte 
9632fcf3ce44SJohn Forte 	emlxs_auth_key_print(hba, auth_key);
9633fcf3ce44SJohn Forte 
9634fcf3ce44SJohn Forte 	mutex_exit(&hba->auth_lock);
9635fcf3ce44SJohn Forte 
9636fcf3ce44SJohn Forte 	return (0);
9637fcf3ce44SJohn Forte 
9638fcf3ce44SJohn Forte } /* emlxs_dhc_set_auth_key() */
9639fcf3ce44SJohn Forte 
9640fcf3ce44SJohn Forte 
9641fcf3ce44SJohn Forte /* Provides DFC support for emlxs_dfc_get_auth_status() */
9642fcf3ce44SJohn Forte extern uint32_t
emlxs_dhc_get_auth_status(emlxs_hba_t * hba,dfc_auth_status_t * fcsp_status)9643fcf3ce44SJohn Forte emlxs_dhc_get_auth_status(emlxs_hba_t *hba, dfc_auth_status_t *fcsp_status)
9644fcf3ce44SJohn Forte {
9645fcf3ce44SJohn Forte 	emlxs_port_t *port = &PPORT;
9646fcf3ce44SJohn Forte 	emlxs_config_t *cfg = &CFG;
9647fcf3ce44SJohn Forte 	char s_lwwpn[64];
9648fcf3ce44SJohn Forte 	char s_rwwpn[64];
9649fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *auth_cfg;
9650fcf3ce44SJohn Forte 	dfc_auth_status_t *auth_status;
9651fcf3ce44SJohn Forte 	NODELIST *ndlp;
9652fcf3ce44SJohn Forte 	uint32_t rc;
9653fcf3ce44SJohn Forte 	time_t auth_time;
9654fcf3ce44SJohn Forte 	uint32_t update;
9655fcf3ce44SJohn Forte 
9656fcf3ce44SJohn Forte 	/* Return is authentication is not enabled */
9657fcf3ce44SJohn Forte 	if (cfg[CFG_AUTH_ENABLE].current == 0) {
9658fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_fcsp_debug_msg,
9659*8f23e9faSHans Rosenfeld 		    "dhc_get_auth_status. Auth disabled.");
9660fcf3ce44SJohn Forte 
9661fcf3ce44SJohn Forte 		return (DFC_AUTH_AUTHENTICATION_DISABLED);
9662fcf3ce44SJohn Forte 	}
9663fcf3ce44SJohn Forte 	mutex_enter(&hba->auth_lock);
9664fcf3ce44SJohn Forte 
9665fcf3ce44SJohn Forte 	auth_cfg = emlxs_auth_cfg_get(hba, (uint8_t *)&fcsp_status->lwwpn,
9666fcf3ce44SJohn Forte 	    (uint8_t *)&fcsp_status->rwwpn);
9667fcf3ce44SJohn Forte 
9668fcf3ce44SJohn Forte 	if (!auth_cfg) {
9669fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_dfc_error_msg,
9670*8f23e9faSHans Rosenfeld 		    "dhc_get_auth_status: entry not found. %s:%s",
9671*8f23e9faSHans Rosenfeld 		    emlxs_wwn_xlate(s_lwwpn, sizeof (s_lwwpn),
9672*8f23e9faSHans Rosenfeld 		    (uint8_t *)&fcsp_status->lwwpn),
9673*8f23e9faSHans Rosenfeld 		    emlxs_wwn_xlate(s_rwwpn, sizeof (s_rwwpn),
9674*8f23e9faSHans Rosenfeld 		    (uint8_t *)&fcsp_status->rwwpn));
9675fcf3ce44SJohn Forte 
9676fcf3ce44SJohn Forte 		mutex_exit(&hba->auth_lock);
9677fcf3ce44SJohn Forte 
9678fcf3ce44SJohn Forte 		return (DFC_AUTH_NOT_CONFIGURED);
9679fcf3ce44SJohn Forte 	}
9680fcf3ce44SJohn Forte 	if (bcmp((uint8_t *)&fcsp_status->rwwpn,
9681728bdc9bSSukumar Swaminathan 	    (uint8_t *)emlxs_fabric_wwn, 8) == 0) {
9682fcf3ce44SJohn Forte 		auth_status = &port->port_dhc.auth_status;
9683fcf3ce44SJohn Forte 		auth_time = port->port_dhc.auth_time;
9684*8f23e9faSHans Rosenfeld 		ndlp = emlxs_node_find_did(port, FABRIC_DID, 1);
9685fcf3ce44SJohn Forte 	} else {
9686fcf3ce44SJohn Forte 		auth_status = &auth_cfg->auth_status;
9687fcf3ce44SJohn Forte 		auth_time = auth_cfg->auth_time;
9688fcf3ce44SJohn Forte 		ndlp = auth_cfg->node;
9689fcf3ce44SJohn Forte 	}
9690fcf3ce44SJohn Forte 
9691fcf3ce44SJohn Forte 	update = 0;
9692fcf3ce44SJohn Forte 
9693fcf3ce44SJohn Forte 	/* Check if node is still available */
9694fcf3ce44SJohn Forte 	if (ndlp && ndlp->nlp_active) {
9695fcf3ce44SJohn Forte 		emlxs_dhc_status(port, ndlp, 0, 0);
9696fcf3ce44SJohn Forte 		update = 1;
9697fcf3ce44SJohn Forte 	} else {
9698fcf3ce44SJohn Forte 		rc = DFC_AUTH_WWN_NOT_FOUND;
9699fcf3ce44SJohn Forte 	}
9700fcf3ce44SJohn Forte 
9701fcf3ce44SJohn Forte 
9702fcf3ce44SJohn Forte 	if (update) {
9703fcf3ce44SJohn Forte 		fcsp_status->auth_state = auth_status->auth_state;
9704fcf3ce44SJohn Forte 		fcsp_status->auth_failReason = auth_status->auth_failReason;
9705fcf3ce44SJohn Forte 		fcsp_status->type_priority = auth_status->type_priority;
9706fcf3ce44SJohn Forte 		fcsp_status->group_priority = auth_status->group_priority;
9707fcf3ce44SJohn Forte 		fcsp_status->hash_priority = auth_status->hash_priority;
9708fcf3ce44SJohn Forte 		fcsp_status->localAuth = auth_status->localAuth;
9709fcf3ce44SJohn Forte 		fcsp_status->remoteAuth = auth_status->remoteAuth;
9710fcf3ce44SJohn Forte 		fcsp_status->time_from_last_auth = DRV_TIME - auth_time;
9711fcf3ce44SJohn Forte 		fcsp_status->time_until_next_auth =
9712fcf3ce44SJohn Forte 		    auth_status->time_until_next_auth;
9713fcf3ce44SJohn Forte 
9714fcf3ce44SJohn Forte 		rc = 0;
9715fcf3ce44SJohn Forte 	} else {
9716fcf3ce44SJohn Forte 		rc = DFC_AUTH_WWN_NOT_FOUND;
9717fcf3ce44SJohn Forte 	}
9718fcf3ce44SJohn Forte 
9719fcf3ce44SJohn Forte 	mutex_exit(&hba->auth_lock);
9720fcf3ce44SJohn Forte 
9721fcf3ce44SJohn Forte 	return (rc);
9722fcf3ce44SJohn Forte 
9723fcf3ce44SJohn Forte } /* emlxs_dhc_get_auth_status() */
9724fcf3ce44SJohn Forte 
9725fcf3ce44SJohn Forte 
9726fcf3ce44SJohn Forte /* Provides DFC support for emlxs_dfc_get_auth_list() */
9727fcf3ce44SJohn Forte /* auth_lock must be held when calling. */
9728fcf3ce44SJohn Forte /* fcsp_cfg must be large enough to hold hba->auth_cfg_count entries */
9729fcf3ce44SJohn Forte extern uint32_t
emlxs_dhc_get_auth_cfg_table(emlxs_hba_t * hba,dfc_fcsp_config_t * fcsp_cfg)9730fcf3ce44SJohn Forte emlxs_dhc_get_auth_cfg_table(emlxs_hba_t *hba, dfc_fcsp_config_t *fcsp_cfg)
9731fcf3ce44SJohn Forte {
9732fcf3ce44SJohn Forte 	emlxs_port_t *port = &PPORT;
9733fcf3ce44SJohn Forte 	emlxs_config_t *cfg = &CFG;
9734fcf3ce44SJohn Forte 	emlxs_auth_cfg_t *auth_cfg;
9735fcf3ce44SJohn Forte 	uint32_t i;
9736fcf3ce44SJohn Forte 
9737fcf3ce44SJohn Forte 	/* Return if authentication is not enabled */
9738fcf3ce44SJohn Forte 	if (cfg[CFG_AUTH_ENABLE].current == 0) {
9739fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
9740fcf3ce44SJohn Forte 		    &emlxs_fcsp_debug_msg,
9741*8f23e9faSHans Rosenfeld 		    "dhc_get_auth_cfg_table. Auth disabled.");
9742fcf3ce44SJohn Forte 
9743fcf3ce44SJohn Forte 		return (DFC_AUTH_AUTHENTICATION_DISABLED);
9744fcf3ce44SJohn Forte 	}
9745fcf3ce44SJohn Forte 	for (auth_cfg = hba->auth_cfg.next;
9746fcf3ce44SJohn Forte 	    auth_cfg != &hba->auth_cfg;
9747fcf3ce44SJohn Forte 	    auth_cfg = auth_cfg->next) {
9748fcf3ce44SJohn Forte 		bcopy((uint8_t *)&auth_cfg->local_entity,
9749fcf3ce44SJohn Forte 		    (uint8_t *)&fcsp_cfg->lwwpn, 8);
9750fcf3ce44SJohn Forte 		bcopy((uint8_t *)&auth_cfg->remote_entity,
9751fcf3ce44SJohn Forte 		    (uint8_t *)&fcsp_cfg->rwwpn, 8);
9752fcf3ce44SJohn Forte 
9753fcf3ce44SJohn Forte 		fcsp_cfg->auth_tov = auth_cfg->authentication_timeout;
9754fcf3ce44SJohn Forte 		fcsp_cfg->auth_mode = auth_cfg->authentication_mode;
9755fcf3ce44SJohn Forte 		fcsp_cfg->auth_bidir = auth_cfg->bidirectional;
9756fcf3ce44SJohn Forte 
9757fcf3ce44SJohn Forte 		for (i = 0; i < 4; i++) {
9758fcf3ce44SJohn Forte 			fcsp_cfg->type_priority[i] =
9759fcf3ce44SJohn Forte 			    auth_cfg->authentication_type_priority[i];
9760fcf3ce44SJohn Forte 			fcsp_cfg->hash_priority[i] =
9761fcf3ce44SJohn Forte 			    auth_cfg->hash_priority[i];
9762fcf3ce44SJohn Forte 		}
9763fcf3ce44SJohn Forte 
9764fcf3ce44SJohn Forte 		for (i = 0; i < 8; i++) {
9765fcf3ce44SJohn Forte 			fcsp_cfg->group_priority[i] =
9766fcf3ce44SJohn Forte 			    auth_cfg->dh_group_priority[i];
9767fcf3ce44SJohn Forte 		}
9768fcf3ce44SJohn Forte 
9769fcf3ce44SJohn Forte 		fcsp_cfg->reauth_tov = auth_cfg->reauthenticate_time_interval;
9770fcf3ce44SJohn Forte 
9771fcf3ce44SJohn Forte 		fcsp_cfg++;
9772fcf3ce44SJohn Forte 	}
9773fcf3ce44SJohn Forte 
9774fcf3ce44SJohn Forte 	return (0);
9775fcf3ce44SJohn Forte 
9776fcf3ce44SJohn Forte } /* emlxs_dhc_get_auth_cfg_table() */
9777fcf3ce44SJohn Forte 
9778fcf3ce44SJohn Forte 
9779fcf3ce44SJohn Forte 
9780fcf3ce44SJohn Forte /* Provides DFC support for emlxs_dfc_get_auth_list() */
9781fcf3ce44SJohn Forte /* auth_lock must be held when calling. */
9782fcf3ce44SJohn Forte /* auth_pwd must be large enough to hold hba->auth_key_count entries */
9783fcf3ce44SJohn Forte extern uint32_t
emlxs_dhc_get_auth_key_table(emlxs_hba_t * hba,dfc_auth_password_t * auth_pwd)9784fcf3ce44SJohn Forte emlxs_dhc_get_auth_key_table(emlxs_hba_t *hba, dfc_auth_password_t *auth_pwd)
9785fcf3ce44SJohn Forte {
9786fcf3ce44SJohn Forte 	emlxs_port_t *port = &PPORT;
9787fcf3ce44SJohn Forte 	emlxs_config_t *cfg = &CFG;
9788fcf3ce44SJohn Forte 	emlxs_auth_key_t *auth_key;
9789fcf3ce44SJohn Forte 
9790fcf3ce44SJohn Forte 	/* Return if authentication is not enabled */
9791fcf3ce44SJohn Forte 	if (cfg[CFG_AUTH_ENABLE].current == 0) {
9792fcf3ce44SJohn Forte 		EMLXS_MSGF(EMLXS_CONTEXT,
9793fcf3ce44SJohn Forte 		    &emlxs_fcsp_debug_msg,
9794*8f23e9faSHans Rosenfeld 		    "dhc_get_auth_key_table. Auth disabled.");
9795fcf3ce44SJohn Forte 
9796fcf3ce44SJohn Forte 		return (DFC_AUTH_AUTHENTICATION_DISABLED);
9797fcf3ce44SJohn Forte 	}
9798fcf3ce44SJohn Forte 	for (auth_key = hba->auth_key.next;
9799fcf3ce44SJohn Forte 	    auth_key != &hba->auth_key;
9800fcf3ce44SJohn Forte 	    auth_key = auth_key->next) {
9801fcf3ce44SJohn Forte 		bcopy((uint8_t *)&auth_key->local_entity,
9802fcf3ce44SJohn Forte 		    (uint8_t *)&auth_pwd->lwwpn, 8);
9803fcf3ce44SJohn Forte 		bcopy((uint8_t *)&auth_key->remote_entity,
9804fcf3ce44SJohn Forte 		    (uint8_t *)&auth_pwd->rwwpn, 8);
9805fcf3ce44SJohn Forte 
9806fcf3ce44SJohn Forte 		auth_pwd->lpw.length = auth_key->local_password_length;
9807fcf3ce44SJohn Forte 		auth_pwd->lpw.type = auth_key->local_password_type;
9808fcf3ce44SJohn Forte 		/*
9809fcf3ce44SJohn Forte 		 * bcopy(auth_key->local_password, auth_pwd->lpw.password,
9810fcf3ce44SJohn Forte 		 * auth_pwd->lpw.length);
9811fcf3ce44SJohn Forte 		 */
9812fcf3ce44SJohn Forte 
9813fcf3ce44SJohn Forte 		auth_pwd->rpw.length = auth_key->remote_password_length;
9814fcf3ce44SJohn Forte 		auth_pwd->rpw.type = auth_key->remote_password_type;
9815fcf3ce44SJohn Forte 		/*
9816fcf3ce44SJohn Forte 		 * bcopy(auth_key->remote_password, auth_pwd->rpw.password,
9817fcf3ce44SJohn Forte 		 * auth_pwd->rpw.length);
9818fcf3ce44SJohn Forte 		 */
9819fcf3ce44SJohn Forte 
9820fcf3ce44SJohn Forte 		auth_pwd->lpw_new.length = auth_key->local_password_length;
9821fcf3ce44SJohn Forte 		auth_pwd->lpw_new.type = auth_key->local_password_type;
9822fcf3ce44SJohn Forte 		/*
9823fcf3ce44SJohn Forte 		 * bcopy(auth_key->local_password,
9824fcf3ce44SJohn Forte 		 * auth_pwd->lpw_new.password, auth_pwd->lpw_new.length);
9825fcf3ce44SJohn Forte 		 */
9826fcf3ce44SJohn Forte 
9827fcf3ce44SJohn Forte 		auth_pwd->rpw_new.length = auth_key->remote_password_length;
9828fcf3ce44SJohn Forte 		auth_pwd->rpw_new.type = auth_key->remote_password_type;
9829fcf3ce44SJohn Forte 		/*
9830fcf3ce44SJohn Forte 		 * bcopy(auth_key->remote_password,
9831fcf3ce44SJohn Forte 		 * auth_pwd->rpw_new.password, auth_pwd->rpw_new.length);
9832fcf3ce44SJohn Forte 		 */
9833fcf3ce44SJohn Forte 
9834fcf3ce44SJohn Forte 		auth_pwd++;
9835fcf3ce44SJohn Forte 	}
9836fcf3ce44SJohn Forte 
9837fcf3ce44SJohn Forte 	return (0);
9838fcf3ce44SJohn Forte 
9839fcf3ce44SJohn Forte } /* emlxs_dhc_get_auth_key_table() */
9840fcf3ce44SJohn Forte 
9841fcf3ce44SJohn Forte #endif	/* DHCHAP_SUPPORT */
9842