xref: /openbmc/ipmitool/include/ipmitool/ipmi.h (revision 0caa6811)
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 #ifndef IPMI_H
34 #define IPMI_H
35 
36 #include <stdlib.h>
37 #include <stdio.h>
38 #include <inttypes.h>
39 #include <sys/types.h>
40 #include <netinet/in.h>
41 #include <ipmitool/helper.h>
42 #include <ipmitool/ipmi_cc.h>
43 
44 #if HAVE_CONFIG_H
45 # include <config.h>
46 #endif
47 
48 #define IPMI_BUF_SIZE 1024
49 
50 #if HAVE_PRAGMA_PACK
51 #define ATTRIBUTE_PACKING
52 #else
53 #define ATTRIBUTE_PACKING __attribute__ ((packed))
54 #endif
55 
56 
57 /* From table 13.16 of the IPMI v2 specification */
58 #define IPMI_PAYLOAD_TYPE_IPMI               0x00
59 #define IPMI_PAYLOAD_TYPE_SOL                0x01
60 #define IPMI_PAYLOAD_TYPE_OEM                0x02
61 #define IPMI_PAYLOAD_TYPE_RMCP_OPEN_REQUEST  0x10
62 #define IPMI_PAYLOAD_TYPE_RMCP_OPEN_RESPONSE 0x11
63 #define IPMI_PAYLOAD_TYPE_RAKP_1             0x12
64 #define IPMI_PAYLOAD_TYPE_RAKP_2             0x13
65 #define IPMI_PAYLOAD_TYPE_RAKP_3             0x14
66 #define IPMI_PAYLOAD_TYPE_RAKP_4             0x15
67 
68 extern int verbose;
69 extern int csv_output;
70 
71 struct ipmi_rq {
72 	struct {
73 		uint8_t netfn:6;
74 		uint8_t lun:2;
75 		uint8_t cmd;
76 		uint8_t target_cmd;
77 		uint16_t data_len;
78 		uint8_t *data;
79 	} msg;
80 };
81 
82 /*
83  * This is what the sendrcv_v2() function would take as an argument. The common case
84  * is for payload_type to be IPMI_PAYLOAD_TYPE_IPMI.
85  */
86 struct ipmi_v2_payload {
87 	uint16_t payload_length;
88 	uint8_t payload_type;
89 
90 	union {
91 
92 		struct {
93 			uint8_t rq_seq;
94 			struct ipmi_rq *request;
95 		} ipmi_request;
96 
97 		struct {
98 			uint8_t rs_seq;
99 			struct ipmi_rs *response;
100 		} ipmi_response;
101 
102 		/* Only used internally by the lanplus interface */
103 		struct {
104 			uint8_t *request;
105 		} open_session_request;
106 
107 		/* Only used internally by the lanplus interface */
108 		struct {
109 			uint8_t *message;
110 		} rakp_1_message;
111 
112 		/* Only used internally by the lanplus interface */
113 		struct {
114 			uint8_t *message;
115 		} rakp_2_message;
116 
117 		/* Only used internally by the lanplus interface */
118 		struct {
119 			uint8_t *message;
120 		} rakp_3_message;
121 
122 		/* Only used internally by the lanplus interface */
123 		struct {
124 			uint8_t *message;
125 		} rakp_4_message;
126 
127 		struct {
128 			uint8_t data[IPMI_BUF_SIZE];
129 			uint16_t character_count;
130 			uint8_t packet_sequence_number;
131 			uint8_t acked_packet_number;
132 			uint8_t accepted_character_count;
133 			uint8_t is_nack;	/* bool */
134 			uint8_t assert_ring_wor;	/* bool */
135 			uint8_t generate_break;	/* bool */
136 			uint8_t deassert_cts;	/* bool */
137 			uint8_t deassert_dcd_dsr;	/* bool */
138 			uint8_t flush_inbound;	/* bool */
139 			uint8_t flush_outbound;	/* bool */
140 		} sol_packet;
141 
142 	} payload;
143 };
144 
145 struct ipmi_rq_entry {
146 	struct ipmi_rq req;
147 	struct ipmi_intf *intf;
148 	uint8_t rq_seq;
149 	uint8_t *msg_data;
150 	int msg_len;
151 	int bridging_level;
152 	struct ipmi_rq_entry *next;
153 };
154 
155 struct ipmi_rs {
156 	uint8_t ccode;
157 	uint8_t data[IPMI_BUF_SIZE];
158 
159 	/*
160 	 * Looks like this is the length of the entire packet, including the RMCP
161 	 * stuff, then modified to be the length of the extra IPMI message data
162 	 */
163 	int data_len;
164 
165 	struct {
166 		uint8_t netfn;
167 		uint8_t cmd;
168 		uint8_t seq;
169 		uint8_t lun;
170 	} msg;
171 
172 	struct {
173 		uint8_t authtype;
174 		uint32_t seq;
175 		uint32_t id;
176 		uint8_t bEncrypted;	/* IPMI v2 only */
177 		uint8_t bAuthenticated;	/* IPMI v2 only */
178 		uint8_t payloadtype;	/* IPMI v2 only */
179 		/* This is the total length of the payload or
180 		   IPMI message.  IPMI v2.0 requires this to
181 		   be 2 bytes.  Not really used for much. */
182 		uint16_t msglen;
183 	} session;
184 
185 	/*
186 	 * A union of the different possible payload meta-data
187 	 */
188 	union {
189 		struct {
190 			uint8_t rq_addr;
191 			uint8_t netfn;
192 			uint8_t rq_lun;
193 			uint8_t rs_addr;
194 			uint8_t rq_seq;
195 			uint8_t rs_lun;
196 			uint8_t cmd;
197 		} ipmi_response;
198 		struct {
199 			uint8_t message_tag;
200 			uint8_t rakp_return_code;
201 			uint8_t max_priv_level;
202 			uint32_t console_id;
203 			uint32_t bmc_id;
204 			uint8_t auth_alg;
205 			uint8_t integrity_alg;
206 			uint8_t crypt_alg;
207 		} open_session_response;
208 		struct {
209 			uint8_t message_tag;
210 			uint8_t rakp_return_code;
211 			uint32_t console_id;
212 			uint8_t bmc_rand[16];	/* Random number generated by the BMC */
213 			uint8_t bmc_guid[16];
214 			uint8_t key_exchange_auth_code[20];
215 		} rakp2_message;
216 		struct {
217 			uint8_t message_tag;
218 			uint8_t rakp_return_code;
219 			uint32_t console_id;
220 			uint8_t integrity_check_value[20];
221 		} rakp4_message;
222 		struct {
223 			uint8_t packet_sequence_number;
224 			uint8_t acked_packet_number;
225 			uint8_t accepted_character_count;
226 			uint8_t is_nack;	/* bool */
227 			uint8_t transfer_unavailable;	/* bool */
228 			uint8_t sol_inactive;	/* bool */
229 			uint8_t transmit_overrun;	/* bool */
230 			uint8_t break_detected;	/* bool */
231 		} sol_packet;
232 
233 	} payload;
234 };
235 
236 #define IPMI_NETFN_CHASSIS		0x0
237 #define IPMI_NETFN_BRIDGE		0x2
238 #define IPMI_NETFN_SE			0x4
239 #define IPMI_NETFN_APP			0x6
240 #define IPMI_NETFN_FIRMWARE		0x8
241 #define IPMI_NETFN_STORAGE		0xa
242 #define IPMI_NETFN_TRANSPORT	0xc
243 #define IPMI_NETFN_PICMG		0x2C
244 #define IPMI_NETFN_DCGRP		0x2C
245 #define IPMI_NETFN_OEM		0x2E
246 #define IPMI_NETFN_ISOL			0x34
247 #define IPMI_NETFN_TSOL			0x30
248 
249 #define IPMI_BMC_SLAVE_ADDR		0x20
250 #define IPMI_REMOTE_SWID		0x81
251 
252 
253 /* These values are IANA numbers */
254 typedef enum IPMI_OEM {
255      IPMI_OEM_UNKNOWN    = 0,
256      IPMI_OEM_HP         = 11,
257      IPMI_OEM_SUN        = 42,
258      IPMI_OEM_NOKIA      = 94,
259      IPMI_OEM_BULL       = 107,
260      IPMI_OEM_HITACHI_116 = 116,
261      IPMI_OEM_NEC        = 119,
262      IPMI_OEM_TOSHIBA    = 186,
263      IPMI_OEM_ERICSSON   = 193,
264      IPMI_OEM_INTEL      = 343,
265      IPMI_OEM_TATUNG     = 373,
266      IPMI_OEM_HITACHI_399 = 399,
267      IPMI_OEM_DELL       = 674,
268      IPMI_OEM_LMC        = 2168,
269      IPMI_OEM_RADISYS    = 4337,
270      IPMI_OEM_BROADCOM   = 4413,
271      IPMI_OEM_MAGNUM     = 5593,
272      IPMI_OEM_TYAN       = 6653,
273      IPMI_OEM_QUANTA     = 7244,
274      IPMI_OEM_NEWISYS    = 9237,
275      IPMI_OEM_ADVANTECH  = 10297,
276      IPMI_OEM_FUJITSU_SIEMENS = 10368,
277      IPMI_OEM_AVOCENT    = 10418,
278      IPMI_OEM_PEPPERCON  = 10437,
279      IPMI_OEM_SUPERMICRO = 10876,
280      IPMI_OEM_OSA        = 11102,
281      IPMI_OEM_GOOGLE     = 11129,
282      IPMI_OEM_PICMG      = 12634,
283      IPMI_OEM_RARITAN    = 13742,
284      IPMI_OEM_KONTRON    = 15000,
285      IPMI_OEM_PPS        = 16394,
286      IPMI_OEM_AMI        = 20974,
287      IPMI_OEM_NOKIA_SIEMENS_NETWORKS = 28458,
288      IPMI_OEM_SUPERMICRO_47488 = 47488
289 } IPMI_OEM;
290 
291 extern const struct valstr completion_code_vals[];
292 
293 #endif				/* IPMI_H */
294