1 /*
2  * ipmi_addr.h
3  *
4  * Addressing information for IPMI interfaces.
5  *
6  * Author: MontaVista Software, Inc.
7  *         Corey Minyard <minyard@mvista.com>
8  *         source@mvista.com
9  *
10  * Copyright 2002,2003,2004,2005 MontaVista Software Inc.
11  *
12  * This software is available to you under a choice of one of two
13  * licenses.  You may choose to be licensed under the terms of the GNU
14  * Lesser General Public License (GPL) Version 2 or the modified BSD
15  * license below.  The following disclamer applies to both licenses:
16  *
17  *  THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
18  *  WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19  *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20  *  IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21  *  INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
22  *  BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
23  *  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
24  *  ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
25  *  TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
26  *  USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27  *
28  * GNU Lesser General Public Licence
29  *
30  *  This program is free software; you can redistribute it and/or
31  *  modify it under the terms of the GNU Lesser General Public License
32  *  as published by the Free Software Foundation; either version 2 of
33  *  the License, or (at your option) any later version.
34  *
35  *  You should have received a copy of the GNU Lesser General Public
36  *  License along with this program; if not, write to the Free
37  *  Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
38  *
39  * Modified BSD Licence
40  *
41  * Redistribution and use in source and binary forms, with or without
42  * modification, are permitted provided that the following conditions
43  * are met:
44  *
45  *   1. Redistributions of source code must retain the above copyright
46  *      notice, this list of conditions and the following disclaimer.
47  *   2. Redistributions in binary form must reproduce the above
48  *      copyright notice, this list of conditions and the following
49  *      disclaimer in the documentation and/or other materials provided
50  *      with the distribution.
51  *   3. The name of the author may not be used to endorse or promote
52  *      products derived from this software without specific prior
53  *      written permission.
54  */
55 
56 #ifndef OPENIPMI_ADDR_H
57 #define OPENIPMI_ADDR_H
58 
59 /* To get a socket. */
60 #include <netinet/in.h>
61 
62 #ifdef __cplusplus
63 extern "C" {
64 #endif
65 
66 /* The formats of these MUST match the formats for the kernel. */
67 
68 #ifndef __LINUX_IPMI_H /* Don't include this if we are including the kernel */
69 
70 /* This is an overlay for all the address types, so it's easy to
71    determine the actual address type.  This is kind of like addresses
72    work for sockets. */
73 #define IPMI_MAX_ADDR_SIZE 32
74 struct ipmi_addr
75 {
76 	 /* Try to take these from the "Channel Medium Type" table
77 	    in section 6.5 of the IPMI 1.5 manual. */
78 	int   addr_type;
79 	short channel;
80 	char  data[IPMI_MAX_ADDR_SIZE];
81 };
82 
83 /* When the address is not used, the type will be set to this value.
84    The channel is the BMC's channel number for the channel (usually
85    0), or IPMC_BMC_CHANNEL if communicating directly with the BMC. */
86 #define IPMI_SYSTEM_INTERFACE_ADDR_TYPE	0xc
87 struct ipmi_system_interface_addr
88 {
89 	int           addr_type;
90 	short         channel;
91 	unsigned char lun;
92 };
93 
94 /* An IPMB Address. */
95 #define IPMI_IPMB_ADDR_TYPE	1
96 /* Used for broadcast get device id as described in section 17.9 of the
97    IPMI 1.5 manual. */
98 #define IPMI_IPMB_BROADCAST_ADDR_TYPE   0x41
99 struct ipmi_ipmb_addr
100 {
101 	int           addr_type;
102 	short         channel;
103 	unsigned char slave_addr;
104 	unsigned char lun;
105 };
106 
107 /*
108  * A LAN Address.  This is an address to/from a LAN interface bridged
109  * by the BMC, not an address actually out on the LAN.
110  *
111  * A concious decision was made here to deviate slightly from the IPMI
112  * spec.  We do not use rqSWID and rsSWID like it shows in the
113  * message.  Instead, we use remote_SWID and local_SWID.  This means
114  * that any message (a request or response) from another device will
115  * always have exactly the same address.  If you didn't do this,
116  * requests and responses from the same device would have different
117  * addresses, and that's not too cool.
118  *
119  * In this address, the remote_SWID is always the SWID the remote
120  * message came from, or the SWID we are sending the message to.
121  * local_SWID is always our SWID.  Note that having our SWID in the
122  * message is a little wierd, but this is required.
123  */
124 #define IPMI_LAN_ADDR_TYPE		0x04
125 struct ipmi_lan_addr
126 {
127 	int           addr_type;
128 	short         channel;
129 	unsigned char privilege;
130 	unsigned char session_handle;
131 	unsigned char remote_SWID;
132 	unsigned char local_SWID;
133 	unsigned char lun;
134 };
135 
136 /* Channel for talking directly with the BMC.  When using this
137    channel, This is for the system interface address type only.
138    FIXME - is this right, or should we use -1? */
139 #define IPMI_BMC_CHANNEL  0xf
140 
141 /* The channel that means "The channel we are talking on". */
142 #define IPMI_SELF_CHANNEL 0xe
143 
144 #define IPMI_NUM_CHANNELS 0x10
145 
146 #endif /* __LINUX_IPMI_H */
147 
148 /* RMCP+ address types are in this range.  These map to payloads.  Note
149    that 0x100 is specially used; it would be IPMI if there was no
150    special handling, but it is used for RMCP messages outside the
151    session. */
152 #define IPMI_RMCPP_ADDR_START		0x100
153 #define IPMI_RMCPP_ADDR_END		0x13f
154 typedef struct ipmi_rmcpp_addr
155 {
156 	int           addr_type;
157 
158         /* These fields are only used if this is a type 2 payload
159 	   (0x102 for the addr_type).  The IANA comes from the lan
160 	   challenge for the other oem payload types (0x20-0x27) */
161 	unsigned char oem_iana[3];
162 	uint16_t      oem_payload_id;
163 } ipmi_rmcpp_addr_t;
164 
165 /* This is outside the range of normal NETFNs, it is used for
166    registering for RMCP things. */
167 #define IPMI_RMCPP_DUMMY_NETFN		0x40
168 
169 /* Generate types for the kernel versions of these. */
170 typedef struct ipmi_addr ipmi_addr_t;
171 typedef struct ipmi_system_interface_addr ipmi_system_interface_addr_t;
172 typedef struct ipmi_ipmb_addr ipmi_ipmb_addr_t;
173 typedef struct ipmi_lan_addr ipmi_lan_addr_t;
174 
175 /* An 802.3 LAN address */
176 #define IPMI_802_3_ADDR_TYPE 4
177 typedef struct ipmi_802_3_addr_s
178 {
179 	int            addr_type;
180 	short          channel;
181 	struct in_addr addr;
182 	unsigned short port;
183 } ipmi_802_3_addr_t;
184 
185 /* Compare two IPMI addresses, and return false if they are equal and
186    true if they are not. */
187 int ipmi_addr_equal(const ipmi_addr_t *addr1,
188 		    int               addr1_len,
189 		    const ipmi_addr_t *addr2,
190 		    int               addr2_len);
191 unsigned int ipmi_addr_get_lun(const ipmi_addr_t *addr);
192 int ipmi_addr_set_lun(ipmi_addr_t *addr, unsigned int lun);
193 
194 /* Like the above, but do not use the LUN in the comparison. */
195 int ipmi_addr_equal_nolun(const ipmi_addr_t *addr1,
196 			  int               addr1_len,
197 			  const ipmi_addr_t *addr2,
198 			  int               addr2_len);
199 
200 /* Get the slave address from the address, returns 0 if the address
201    does not have a slave address. */
202 unsigned int ipmi_addr_get_slave_addr(const ipmi_addr_t *addr);
203 
204 #ifdef __cplusplus
205 }
206 #endif
207 
208 #endif /* OPENIPMI_ADDR_H */
209