1 /* $NetBSD: eltsub.c,v 1.4 2018/01/23 21:06:26 sevan 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(int);
44 static char *scode2ascii(u_char);
45 char *stat2ascii(int, u_char *);
46
47 char *
geteltnm(int type)48 geteltnm(int type)
49 {
50 static char rbuf[132];
51
52 switch (type) {
53 case SESTYP_UNSPECIFIED:
54 sprintf(rbuf, "Unspecified");
55 break;
56 case SESTYP_DEVICE:
57 sprintf(rbuf, "Device");
58 break;
59 case SESTYP_POWER:
60 sprintf(rbuf, "Power supply");
61 break;
62 case SESTYP_FAN:
63 sprintf(rbuf, "Cooling element");
64 break;
65 case SESTYP_THERM:
66 sprintf(rbuf, "Temperature sensors");
67 break;
68 case SESTYP_DOORLOCK:
69 sprintf(rbuf, "Door Lock");
70 break;
71 case SESTYP_ALARM:
72 sprintf(rbuf, "Audible alarm");
73 break;
74 case SESTYP_ESCC:
75 sprintf(rbuf, "Enclosure services controller electronics");
76 break;
77 case SESTYP_SCC:
78 sprintf(rbuf, "SCC controller electronics");
79 break;
80 case SESTYP_NVRAM:
81 sprintf(rbuf, "Nonvolatile cache");
82 break;
83 case SESTYP_UPS:
84 sprintf(rbuf, "Uninterruptible power supply");
85 break;
86 case SESTYP_DISPLAY:
87 sprintf(rbuf, "Display");
88 break;
89 case SESTYP_KEYPAD:
90 sprintf(rbuf, "Key pad entry device");
91 break;
92 case SESTYP_SCSIXVR:
93 sprintf(rbuf, "SCSI port/transceiver");
94 break;
95 case SESTYP_LANGUAGE:
96 sprintf(rbuf, "Language");
97 break;
98 case SESTYP_COMPORT:
99 sprintf(rbuf, "Communication Port");
100 break;
101 case SESTYP_VOM:
102 sprintf(rbuf, "Voltage Sensor");
103 break;
104 case SESTYP_AMMETER:
105 sprintf(rbuf, "Current Sensor");
106 break;
107 case SESTYP_SCSI_TGT:
108 sprintf(rbuf, "SCSI target port");
109 break;
110 case SESTYP_SCSI_INI:
111 sprintf(rbuf, "SCSI initiator port");
112 break;
113 case SESTYP_SUBENC:
114 sprintf(rbuf, "Simple sub-enclosure");
115 break;
116 default:
117 (void) sprintf(rbuf, "<Type 0x%x>", type);
118 break;
119 }
120 return (rbuf);
121 }
122
123 static char *
scode2ascii(u_char code)124 scode2ascii(u_char code)
125 {
126 static char rbuf[32];
127 switch (code & 0xf) {
128 case SES_OBJSTAT_UNSUPPORTED:
129 sprintf(rbuf, "status not supported");
130 break;
131 case SES_OBJSTAT_OK:
132 sprintf(rbuf, "ok");
133 break;
134 case SES_OBJSTAT_CRIT:
135 sprintf(rbuf, "critical");
136 break;
137 case SES_OBJSTAT_NONCRIT:
138 sprintf(rbuf, "non-critical");
139 break;
140 case SES_OBJSTAT_UNRECOV:
141 sprintf(rbuf, "unrecoverable");
142 break;
143 case SES_OBJSTAT_NOTINSTALLED:
144 sprintf(rbuf, "not installed");
145 break;
146 case SES_OBJSTAT_UNKNOWN:
147 sprintf(rbuf, "unknown status");
148 break;
149 case SES_OBJSTAT_NOTAVAIL:
150 sprintf(rbuf, "status not available");
151 break;
152 default:
153 sprintf(rbuf, "unknown status code %x", code & 0xf);
154 break;
155 }
156 return (rbuf);
157 }
158
159
160 char *
stat2ascii(int eletype,u_char * cstat)161 stat2ascii(int eletype, u_char *cstat)
162 {
163 static char ebuf[256], *scode;
164
165 scode = scode2ascii(cstat[0]);
166 sprintf(ebuf, "Status=%s (bytes=0x%02x 0x%02x 0x%02x 0x%02x)",
167 scode, cstat[0], cstat[1], cstat[2], cstat[3]);
168 return (ebuf);
169 }
170