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