1 /*
2  * Copyright (c) 2003 Sun Microsystems, Inc.  All Rights Reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions
6  * are met:
7  *
8  * Redistribution of source code must retain the above copyright
9  * notice, this list of conditions and the following disclaimer.
10  *
11  * Redistribution in binary form must reproduce the above copyright
12  * notice, this list of conditions and the following disclaimer in the
13  * documentation and/or other materials provided with the distribution.
14  *
15  * Neither the name of Sun Microsystems, Inc. or the names of
16  * contributors may be used to endorse or promote products derived
17  * from this software without specific prior written permission.
18  *
19  * This software is provided "AS IS," without a warranty of any kind.
20  * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
21  * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
22  * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
23  * SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
24  * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
25  * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.  IN NO EVENT WILL
26  * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
27  * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
28  * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
29  * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
30  * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
31  */
32 
33 #include "lanplus.h"
34 #include "lanplus_dump.h"
35 
36 extern const struct valstr ipmi_rakp_return_codes[];
37 extern const struct valstr ipmi_priv_levels[];
38 extern const struct valstr ipmi_auth_algorithms[];
39 extern const struct valstr ipmi_integrity_algorithms[];
40 extern const struct valstr ipmi_encryption_algorithms[];
41 
42 #define DUMP_PREFIX_INCOMING "<<"
43 
lanplus_dump_open_session_response(const struct ipmi_rs * rsp)44 void lanplus_dump_open_session_response(const struct ipmi_rs * rsp)
45 {
46 	if (verbose < 2)
47 		return;
48 
49  	printf("%sOPEN SESSION RESPONSE\n", DUMP_PREFIX_INCOMING);
50 
51 	printf("%s  Message tag                        : 0x%02x\n",
52 		   DUMP_PREFIX_INCOMING,
53 		   rsp->payload.open_session_response.message_tag);
54 	printf("%s  RMCP+ status                       : %s\n",
55 		   DUMP_PREFIX_INCOMING,
56 		   val2str(rsp->payload.open_session_response.rakp_return_code,
57 				   ipmi_rakp_return_codes));
58 	printf("%s  Maximum privilege level            : %s\n",
59 		   DUMP_PREFIX_INCOMING,
60 		   val2str(rsp->payload.open_session_response.max_priv_level,
61 				   ipmi_priv_levels));
62 	printf("%s  Console Session ID                 : 0x%08lx\n",
63 		   DUMP_PREFIX_INCOMING,
64 		   (long)rsp->payload.open_session_response.console_id);
65 
66 	/* only tag, status, privlvl, and console id are returned if error */
67 	if (rsp->payload.open_session_response.rakp_return_code !=
68 	    IPMI_RAKP_STATUS_NO_ERRORS)
69 		return;
70 
71 	printf("%s  BMC Session ID                     : 0x%08lx\n",
72 		   DUMP_PREFIX_INCOMING,
73 		   (long)rsp->payload.open_session_response.bmc_id);
74 	printf("%s  Negotiated authenticatin algorithm : %s\n",
75 		   DUMP_PREFIX_INCOMING,
76 		   val2str(rsp->payload.open_session_response.auth_alg,
77 				   ipmi_auth_algorithms));
78 	printf("%s  Negotiated integrity algorithm     : %s\n",
79 		   DUMP_PREFIX_INCOMING,
80 		   val2str(rsp->payload.open_session_response.integrity_alg,
81 				   ipmi_integrity_algorithms));
82 	printf("%s  Negotiated encryption algorithm    : %s\n",
83 		   DUMP_PREFIX_INCOMING,
84 		   val2str(rsp->payload.open_session_response.crypt_alg,
85 				   ipmi_encryption_algorithms));
86 	printf("\n");
87 }
88 
89 
90 
lanplus_dump_rakp2_message(const struct ipmi_rs * rsp,uint8_t auth_alg)91 void lanplus_dump_rakp2_message(const struct ipmi_rs * rsp, uint8_t auth_alg)
92 {
93 	int i;
94 
95 	if (verbose < 2)
96 		return;
97 
98 	printf("%sRAKP 2 MESSAGE\n", DUMP_PREFIX_INCOMING);
99 
100 	printf("%s  Message tag                   : 0x%02x\n",
101 		   DUMP_PREFIX_INCOMING,
102 		   rsp->payload.rakp2_message.message_tag);
103 
104 	printf("%s  RMCP+ status                  : %s\n",
105 		   DUMP_PREFIX_INCOMING,
106 		   val2str(rsp->payload.rakp2_message.rakp_return_code,
107 				   ipmi_rakp_return_codes));
108 
109 	printf("%s  Console Session ID            : 0x%08lx\n",
110 		   DUMP_PREFIX_INCOMING,
111 		   (long)rsp->payload.rakp2_message.console_id);
112 
113 	printf("%s  BMC random number             : 0x", DUMP_PREFIX_INCOMING);
114 	for (i = 0; i < 16; ++i)
115 		printf("%02x", rsp->payload.rakp2_message.bmc_rand[i]);
116 	printf("\n");
117 
118 	printf("%s  BMC GUID                      : 0x", DUMP_PREFIX_INCOMING);
119 	for (i = 0; i < 16; ++i)
120 		printf("%02x", rsp->payload.rakp2_message.bmc_guid[i]);
121 	printf("\n");
122 
123 	switch(auth_alg)
124 	{
125 	case IPMI_AUTH_RAKP_NONE:
126 		printf("%s  Key exchange auth code         : none\n", DUMP_PREFIX_INCOMING);
127 		break;
128 	case IPMI_AUTH_RAKP_HMAC_SHA1:
129 		printf("%s  Key exchange auth code [sha1] : 0x", DUMP_PREFIX_INCOMING);
130 		for (i = 0; i < 20; ++i)
131 			printf("%02x", rsp->payload.rakp2_message.key_exchange_auth_code[i]);
132 		printf("\n");
133 		break;
134 	case IPMI_AUTH_RAKP_HMAC_MD5:
135 		printf("%s  Key exchange auth code [md5]   : 0x", DUMP_PREFIX_INCOMING);
136 		for (i = 0; i < 16; ++i)
137 			printf("%02x", rsp->payload.rakp2_message.key_exchange_auth_code[i]);
138 		printf("\n");
139 		break;
140 	default:
141 		printf("%s  Key exchange auth code         : invalid", DUMP_PREFIX_INCOMING);
142 	}
143 	printf("\n");
144 }
145 
146 
147 
lanplus_dump_rakp4_message(const struct ipmi_rs * rsp,uint8_t auth_alg)148 void lanplus_dump_rakp4_message(const struct ipmi_rs * rsp, uint8_t auth_alg)
149 {
150 	int i;
151 
152 	if (verbose < 2)
153 		return;
154 
155 	printf("%sRAKP 4 MESSAGE\n", DUMP_PREFIX_INCOMING);
156 
157 	printf("%s  Message tag                   : 0x%02x\n",
158 		   DUMP_PREFIX_INCOMING,
159 		   rsp->payload.rakp4_message.message_tag);
160 
161 	printf("%s  RMCP+ status                  : %s\n",
162 		   DUMP_PREFIX_INCOMING,
163 		   val2str(rsp->payload.rakp4_message.rakp_return_code,
164 				   ipmi_rakp_return_codes));
165 
166 	printf("%s  Console Session ID            : 0x%08lx\n",
167 		   DUMP_PREFIX_INCOMING,
168 		   (long)rsp->payload.rakp4_message.console_id);
169 
170 	switch(auth_alg)
171 	{
172 	case IPMI_AUTH_RAKP_NONE:
173 		printf("%s  Key exchange auth code        : none\n", DUMP_PREFIX_INCOMING);
174 		break;
175 	case IPMI_AUTH_RAKP_HMAC_SHA1:
176 		printf("%s  Key exchange auth code [sha1] : 0x", DUMP_PREFIX_INCOMING);
177 		for (i = 0; i < 12; ++i)
178 			printf("%02x", rsp->payload.rakp4_message.integrity_check_value[i]);
179 		printf("\n");
180 		break;
181 	case IPMI_AUTH_RAKP_HMAC_MD5:
182 		printf("%s  Key exchange auth code [md5]   : 0x", DUMP_PREFIX_INCOMING);
183 		for (i = 0; i < 12; ++i)
184 			printf("%02x", rsp->payload.rakp4_message.integrity_check_value[i]);
185 		printf("\n");
186 		break;
187 	default:
188 		printf("%s  Key exchange auth code         : invalid", DUMP_PREFIX_INCOMING);
189 	}
190 	printf("\n");
191 }
192 
193