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"},
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 {
361fcf3ce44SJohn Forte 	{ELX_FABRIC_IN_AUTH, "FABRIC_IN_AUTH"},
363fcf3ce44SJohn Forte 
364fcf3ce44SJohn Forte };	/* emlxs_pstate_table() */
365fcf3ce44SJohn Forte 
366fcf3ce44SJohn Forte emlxs_table_t emlxs_nstate_table[] =
367fcf3ce44SJohn Forte {
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 
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 
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 
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