summaryrefslogtreecommitdiff
path: root/lib/ipmi_oem.c
blob: 04bbc8a45a17f2233983355a0eaf07c29fd3da04 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
/*
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 * 
 * Redistribution of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 * 
 * Redistribution in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * 
 * Neither the name of Sun Microsystems, Inc. or the names of
 * contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 * 
 * This software is provided "AS IS," without a warranty of any kind.
 * ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES,
 * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A
 * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED.
 * SUN MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE
 * FOR ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING
 * OR DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.  IN NO EVENT WILL
 * SUN OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA,
 * OR FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR
 * PUNITIVE DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF
 * LIABILITY, ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE,
 * EVEN IF SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
 */

#include <string.h>

#include <ipmitool/ipmi.h>
#include <ipmitool/ipmi_intf.h>
#include <ipmitool/ipmi_constants.h>
#include <ipmitool/log.h>
#include <ipmitool/helper.h>
#include <ipmitool/ipmi_sel.h>

static int ipmi_oem_supermicro(struct ipmi_intf *intf);
static int ipmi_oem_ibm(struct ipmi_intf *intf);
static int ipmi_oem_quanta(struct ipmi_intf *intf);

static struct ipmi_oem_handle ipmi_oem_list[] = {
	{
		.name = "supermicro",
		.desc = "Supermicro IPMIv1.5 BMC with OEM LAN authentication support",
		.setup = ipmi_oem_supermicro,
	},
	{
		.name = "intelwv2",
		.desc = "Intel SE7501WV2 IPMIv1.5 BMC with extra LAN communication support",
	},
	{
		.name = "intelplus",
		.desc = "Intel IPMI 2.0 BMC with RMCP+ communication support",
	},
	{
		.name = "icts",
		.desc = "IPMI 2.0 ICTS compliance support",
	},
	{
		.name = "ibm",
		.desc = "IBM OEM support",
		.setup = ipmi_oem_ibm,
	},
	{
		.name = "i82571spt",
		.desc = "Intel 82571 MAC with integrated RMCP+ support in super pass-through mode",
	},
	{
		.name = "kontron",
		.desc = "Kontron OEM big buffer support"
	},
	{
		.name = "quanta",
		.desc = "Quanta IPMIv1.5 BMC with OEM LAN authentication support",
		.setup = ipmi_oem_quanta,
	},
	{ 0 }
};

/* Supermicro IPMIv2 BMCs use OEM authtype */
static int
ipmi_oem_supermicro(struct ipmi_intf *intf)
{
	ipmi_intf_session_set_authtype(intf, IPMI_SESSION_AUTHTYPE_OEM);
	return 0;
}

static int
ipmi_oem_ibm(struct ipmi_intf *__UNUSED__(intf))
{
	char *filename = getenv("IPMI_OEM_IBM_DATAFILE");
	if (!filename) {
		lprintf(LOG_ERR, "Unable to read IPMI_OEM_IBM_DATAFILE from environment");
		return -1;
	}
	return ipmi_sel_oem_init((const char *)filename);
}

/* Quanta IPMIv2 BMCs use OEM authtype */
static int
ipmi_oem_quanta(struct ipmi_intf *intf)
{
	ipmi_intf_session_set_authtype(intf, IPMI_SESSION_AUTHTYPE_OEM);
	return 0;
}

/* ipmi_oem_print  -  print list of OEM handles
 */
void
ipmi_oem_print(void)
{
	struct ipmi_oem_handle *oem;
	lprintf(LOG_NOTICE, "\nOEM Support:");
	for (oem=ipmi_oem_list; oem->name && oem->desc; oem++) {
		lprintf(LOG_NOTICE, "\t%-12s %s", oem->name, oem->desc);
	}
	lprintf(LOG_NOTICE, "");
}

/* ipmi_oem_setup  -  do initial setup of OEM handle
 *
 * @intf:	ipmi interface
 * @oemtype:	OEM handle name
 *
 * returns 0 on success
 * returns -1 on error
 */
int
ipmi_oem_setup(struct ipmi_intf * intf, char * oemtype)
{
	struct ipmi_oem_handle * oem;
	int rc = 0;

	if (!oemtype
	    || strncmp(oemtype, "help", 4) == 0
	    || strncmp(oemtype, "list", 4) == 0)
	{
		ipmi_oem_print();
		return -1;
	}

	for (oem=ipmi_oem_list; oem->name; oem++) {
		if (strncmp(oemtype, oem->name, strlen(oem->name)) == 0)
			break;
	}

	if (!oem->name)
		return -1;

	/* save pointer for later use */
	intf->oem = oem;

	/* run optional setup function if it is defined */
	if (oem->setup) {
		lprintf(LOG_DEBUG, "Running OEM setup for \"%s\"", oem->desc);
		rc = oem->setup(intf);
	}

	return rc;
}

/* ipmi_oem_active  -  used to determine if a particular OEM type is set
 *
 * @intf:	ipmi interface
 * @oemtype:	string containing name of ipmi handle to check
 *
 * returns 1 if requested ipmi handle is active
 * returns 0 otherwise
 */
int
ipmi_oem_active(struct ipmi_intf * intf, const char * oemtype)
{
	if (!intf->oem)
		return 0;

	if (strncmp(intf->oem->name, oemtype, strlen(oemtype)) == 0)
		return 1;

	return 0;
}