xref: /dflybsd-src/share/examples/ses/srcs/eltsub.c (revision 86d7f5d305c6adaa56ff4582ece9859d73106103)
1*86d7f5d3SJohn Marino /* $FreeBSD: src/share/examples/ses/srcs/eltsub.c,v 1.1 2000/02/29 05:44:17 mjacob Exp $ */
2*86d7f5d3SJohn Marino /* $DragonFly: src/share/examples/ses/srcs/eltsub.c,v 1.2 2003/06/17 04:36:58 dillon Exp $ */
3*86d7f5d3SJohn Marino /*
4*86d7f5d3SJohn Marino  * Copyright (c) 2000 by Matthew Jacob
5*86d7f5d3SJohn Marino  * All rights reserved.
6*86d7f5d3SJohn Marino  *
7*86d7f5d3SJohn Marino  * Redistribution and use in source and binary forms, with or without
8*86d7f5d3SJohn Marino  * modification, are permitted provided that the following conditions
9*86d7f5d3SJohn Marino  * are met:
10*86d7f5d3SJohn Marino  * 1. Redistributions of source code must retain the above copyright
11*86d7f5d3SJohn Marino  *    notice, this list of conditions, and the following disclaimer,
12*86d7f5d3SJohn Marino  *    without modification, immediately at the beginning of the file.
13*86d7f5d3SJohn Marino  * 2. The name of the author may not be used to endorse or promote products
14*86d7f5d3SJohn Marino  *    derived from this software without specific prior written permission.
15*86d7f5d3SJohn Marino  *
16*86d7f5d3SJohn Marino  * Alternatively, this software may be distributed under the terms of the
17*86d7f5d3SJohn Marino  * the GNU Public License ("GPL").
18*86d7f5d3SJohn Marino  *
19*86d7f5d3SJohn Marino  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20*86d7f5d3SJohn Marino  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*86d7f5d3SJohn Marino  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*86d7f5d3SJohn Marino  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
23*86d7f5d3SJohn Marino  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*86d7f5d3SJohn Marino  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*86d7f5d3SJohn Marino  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*86d7f5d3SJohn Marino  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*86d7f5d3SJohn Marino  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*86d7f5d3SJohn Marino  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*86d7f5d3SJohn Marino  * SUCH DAMAGE.
30*86d7f5d3SJohn Marino  *
31*86d7f5d3SJohn Marino  * Matthew Jacob
32*86d7f5d3SJohn Marino  * Feral Software
33*86d7f5d3SJohn Marino  * mjacob@feral.com
34*86d7f5d3SJohn Marino  */
35*86d7f5d3SJohn Marino 
36*86d7f5d3SJohn Marino #include <unistd.h>
37*86d7f5d3SJohn Marino #include <stdlib.h>
38*86d7f5d3SJohn Marino #include <stdio.h>
39*86d7f5d3SJohn Marino #include <sys/ioctl.h>
40*86d7f5d3SJohn Marino #include SESINC
41*86d7f5d3SJohn Marino 
42*86d7f5d3SJohn Marino char *
geteltnm(type)43*86d7f5d3SJohn Marino geteltnm(type)
44*86d7f5d3SJohn Marino 	int type;
45*86d7f5d3SJohn Marino {
46*86d7f5d3SJohn Marino 	static char rbuf[132];
47*86d7f5d3SJohn Marino 
48*86d7f5d3SJohn Marino 	switch (type) {
49*86d7f5d3SJohn Marino 	case SESTYP_UNSPECIFIED:
50*86d7f5d3SJohn Marino 		sprintf(rbuf, "Unspecified");
51*86d7f5d3SJohn Marino 		break;
52*86d7f5d3SJohn Marino 	case SESTYP_DEVICE:
53*86d7f5d3SJohn Marino 		sprintf(rbuf, "Device");
54*86d7f5d3SJohn Marino 		break;
55*86d7f5d3SJohn Marino 	case SESTYP_POWER:
56*86d7f5d3SJohn Marino 		sprintf(rbuf, "Power supply");
57*86d7f5d3SJohn Marino 		break;
58*86d7f5d3SJohn Marino 	case SESTYP_FAN:
59*86d7f5d3SJohn Marino 		sprintf(rbuf, "Cooling element");
60*86d7f5d3SJohn Marino 		break;
61*86d7f5d3SJohn Marino 	case SESTYP_THERM:
62*86d7f5d3SJohn Marino 		sprintf(rbuf, "Temperature sensors");
63*86d7f5d3SJohn Marino 		break;
64*86d7f5d3SJohn Marino 	case SESTYP_DOORLOCK:
65*86d7f5d3SJohn Marino 		sprintf(rbuf, "Door Lock");
66*86d7f5d3SJohn Marino 		break;
67*86d7f5d3SJohn Marino 	case SESTYP_ALARM:
68*86d7f5d3SJohn Marino 		sprintf(rbuf, "Audible alarm");
69*86d7f5d3SJohn Marino 		break;
70*86d7f5d3SJohn Marino 	case SESTYP_ESCC:
71*86d7f5d3SJohn Marino 		sprintf(rbuf, "Enclosure services controller electronics");
72*86d7f5d3SJohn Marino 		break;
73*86d7f5d3SJohn Marino 	case SESTYP_SCC:
74*86d7f5d3SJohn Marino 		sprintf(rbuf, "SCC controller electronics");
75*86d7f5d3SJohn Marino 		break;
76*86d7f5d3SJohn Marino 	case SESTYP_NVRAM:
77*86d7f5d3SJohn Marino 		sprintf(rbuf, "Nonvolatile cache");
78*86d7f5d3SJohn Marino 		break;
79*86d7f5d3SJohn Marino 	case SESTYP_UPS:
80*86d7f5d3SJohn Marino 		sprintf(rbuf, "Uninterruptible power supply");
81*86d7f5d3SJohn Marino 		break;
82*86d7f5d3SJohn Marino 	case SESTYP_DISPLAY:
83*86d7f5d3SJohn Marino 		sprintf(rbuf, "Display");
84*86d7f5d3SJohn Marino 		break;
85*86d7f5d3SJohn Marino 	case SESTYP_KEYPAD:
86*86d7f5d3SJohn Marino 		sprintf(rbuf, "Key pad entry device");
87*86d7f5d3SJohn Marino 		break;
88*86d7f5d3SJohn Marino 	case SESTYP_SCSIXVR:
89*86d7f5d3SJohn Marino 		sprintf(rbuf, "SCSI port/transceiver");
90*86d7f5d3SJohn Marino 		break;
91*86d7f5d3SJohn Marino 	case SESTYP_LANGUAGE:
92*86d7f5d3SJohn Marino 		sprintf(rbuf, "Language");
93*86d7f5d3SJohn Marino 		break;
94*86d7f5d3SJohn Marino 	case SESTYP_COMPORT:
95*86d7f5d3SJohn Marino 		sprintf(rbuf, "Communication Port");
96*86d7f5d3SJohn Marino 		break;
97*86d7f5d3SJohn Marino 	case SESTYP_VOM:
98*86d7f5d3SJohn Marino 		sprintf(rbuf, "Voltage Sensor");
99*86d7f5d3SJohn Marino 		break;
100*86d7f5d3SJohn Marino 	case SESTYP_AMMETER:
101*86d7f5d3SJohn Marino 		sprintf(rbuf, "Current Sensor");
102*86d7f5d3SJohn Marino 		break;
103*86d7f5d3SJohn Marino 	case SESTYP_SCSI_TGT:
104*86d7f5d3SJohn Marino 		sprintf(rbuf, "SCSI target port");
105*86d7f5d3SJohn Marino 		break;
106*86d7f5d3SJohn Marino 	case SESTYP_SCSI_INI:
107*86d7f5d3SJohn Marino 		sprintf(rbuf, "SCSI initiator port");
108*86d7f5d3SJohn Marino 		break;
109*86d7f5d3SJohn Marino 	case SESTYP_SUBENC:
110*86d7f5d3SJohn Marino 		sprintf(rbuf, "Simple sub-enclosure");
111*86d7f5d3SJohn Marino 		break;
112*86d7f5d3SJohn Marino 	default:
113*86d7f5d3SJohn Marino 		(void) sprintf(rbuf, "<Type 0x%x>", type);
114*86d7f5d3SJohn Marino 		break;
115*86d7f5d3SJohn Marino 	}
116*86d7f5d3SJohn Marino 	return (rbuf);
117*86d7f5d3SJohn Marino }
118*86d7f5d3SJohn Marino 
119*86d7f5d3SJohn Marino static char *
scode2ascii(code)120*86d7f5d3SJohn Marino scode2ascii(code)
121*86d7f5d3SJohn Marino 	u_char code;
122*86d7f5d3SJohn Marino {
123*86d7f5d3SJohn Marino 	static char rbuf[32];
124*86d7f5d3SJohn Marino 	switch (code & 0xf) {
125*86d7f5d3SJohn Marino 	case SES_OBJSTAT_UNSUPPORTED:
126*86d7f5d3SJohn Marino 		sprintf(rbuf, "status not supported");
127*86d7f5d3SJohn Marino 		break;
128*86d7f5d3SJohn Marino 	case SES_OBJSTAT_OK:
129*86d7f5d3SJohn Marino 		sprintf(rbuf, "ok");
130*86d7f5d3SJohn Marino 		break;
131*86d7f5d3SJohn Marino 	case SES_OBJSTAT_CRIT:
132*86d7f5d3SJohn Marino 		sprintf(rbuf, "critical");
133*86d7f5d3SJohn Marino 		break;
134*86d7f5d3SJohn Marino 	case SES_OBJSTAT_NONCRIT:
135*86d7f5d3SJohn Marino 		sprintf(rbuf, "non-critical");
136*86d7f5d3SJohn Marino 		break;
137*86d7f5d3SJohn Marino 	case SES_OBJSTAT_UNRECOV:
138*86d7f5d3SJohn Marino 		sprintf(rbuf, "unrecoverable");
139*86d7f5d3SJohn Marino 		break;
140*86d7f5d3SJohn Marino 	case SES_OBJSTAT_NOTINSTALLED:
141*86d7f5d3SJohn Marino 		sprintf(rbuf, "not installed");
142*86d7f5d3SJohn Marino 		break;
143*86d7f5d3SJohn Marino 	case SES_OBJSTAT_UNKNOWN:
144*86d7f5d3SJohn Marino 		sprintf(rbuf, "unknown status");
145*86d7f5d3SJohn Marino 		break;
146*86d7f5d3SJohn Marino 	case SES_OBJSTAT_NOTAVAIL:
147*86d7f5d3SJohn Marino 		sprintf(rbuf, "status not available");
148*86d7f5d3SJohn Marino 		break;
149*86d7f5d3SJohn Marino 	default:
150*86d7f5d3SJohn Marino 		sprintf(rbuf, "unknown status code %x", code & 0xf);
151*86d7f5d3SJohn Marino 		break;
152*86d7f5d3SJohn Marino 	}
153*86d7f5d3SJohn Marino 	return (rbuf);
154*86d7f5d3SJohn Marino }
155*86d7f5d3SJohn Marino 
156*86d7f5d3SJohn Marino 
157*86d7f5d3SJohn Marino char *
stat2ascii(eletype,cstat)158*86d7f5d3SJohn Marino stat2ascii(eletype, cstat)
159*86d7f5d3SJohn Marino 	int eletype;
160*86d7f5d3SJohn Marino 	u_char *cstat;
161*86d7f5d3SJohn Marino {
162*86d7f5d3SJohn Marino 	static char ebuf[256], *scode;
163*86d7f5d3SJohn Marino 
164*86d7f5d3SJohn Marino 	scode = scode2ascii(cstat[0]);
165*86d7f5d3SJohn Marino 	sprintf(ebuf, "Status=%s (bytes=0x%02x 0x%02x 0x%02x 0x%02x)",
166*86d7f5d3SJohn Marino 	    scode, cstat[0], cstat[1], cstat[2], cstat[3]);
167*86d7f5d3SJohn Marino 	return (ebuf);
168*86d7f5d3SJohn Marino }
169