1 /*
2 * Copyright (c) 2000 by Matthew Jacob
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions, and the following disclaimer,
10 * without modification, immediately at the beginning of the file.
11 * 2. The name of the author may not be used to endorse or promote products
12 * derived from this software without specific prior written permission.
13 *
14 * Alternatively, this software may be distributed under the terms of the
15 * the GNU Public License ("GPL").
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
21 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * Matthew Jacob
30 * Feral Software
31 * mjacob@feral.com
32 */
33
34 #include <unistd.h>
35 #include <stddef.h>
36 #include <stdint.h>
37 #include <stdlib.h>
38 #include <stdio.h>
39 #include <sys/ioctl.h>
40 #include <cam/scsi/scsi_all.h>
41 #include <cam/scsi/scsi_enc.h>
42
43 #include "eltsub.h"
44
45 char *
geteltnm(int type)46 geteltnm(int type)
47 {
48 static char rbuf[132];
49
50 switch (type) {
51 case ELMTYP_UNSPECIFIED:
52 sprintf(rbuf, "Unspecified");
53 break;
54 case ELMTYP_DEVICE:
55 sprintf(rbuf, "Device Slot");
56 break;
57 case ELMTYP_POWER:
58 sprintf(rbuf, "Power Supply");
59 break;
60 case ELMTYP_FAN:
61 sprintf(rbuf, "Cooling");
62 break;
63 case ELMTYP_THERM:
64 sprintf(rbuf, "Temperature Sensor");
65 break;
66 case ELMTYP_DOORLOCK:
67 sprintf(rbuf, "Door Lock");
68 break;
69 case ELMTYP_ALARM:
70 sprintf(rbuf, "Audible alarm");
71 break;
72 case ELMTYP_ESCC:
73 sprintf(rbuf, "Enclosure Services Controller Electronics");
74 break;
75 case ELMTYP_SCC:
76 sprintf(rbuf, "SCC Controller Electronics");
77 break;
78 case ELMTYP_NVRAM:
79 sprintf(rbuf, "Nonvolatile Cache");
80 break;
81 case ELMTYP_INV_OP_REASON:
82 sprintf(rbuf, "Invalid Operation Reason");
83 break;
84 case ELMTYP_UPS:
85 sprintf(rbuf, "Uninterruptible Power Supply");
86 break;
87 case ELMTYP_DISPLAY:
88 sprintf(rbuf, "Display");
89 break;
90 case ELMTYP_KEYPAD:
91 sprintf(rbuf, "Key Pad Entry");
92 break;
93 case ELMTYP_ENCLOSURE:
94 sprintf(rbuf, "Enclosure");
95 break;
96 case ELMTYP_SCSIXVR:
97 sprintf(rbuf, "SCSI Port/Transceiver");
98 break;
99 case ELMTYP_LANGUAGE:
100 sprintf(rbuf, "Language");
101 break;
102 case ELMTYP_COMPORT:
103 sprintf(rbuf, "Communication Port");
104 break;
105 case ELMTYP_VOM:
106 sprintf(rbuf, "Voltage Sensor");
107 break;
108 case ELMTYP_AMMETER:
109 sprintf(rbuf, "Current Sensor");
110 break;
111 case ELMTYP_SCSI_TGT:
112 sprintf(rbuf, "SCSI Target Port");
113 break;
114 case ELMTYP_SCSI_INI:
115 sprintf(rbuf, "SCSI Initiator Port");
116 break;
117 case ELMTYP_SUBENC:
118 sprintf(rbuf, "Simple Subenclosure");
119 break;
120 case ELMTYP_ARRAY_DEV:
121 sprintf(rbuf, "Array Device Slot");
122 break;
123 case ELMTYP_SAS_EXP:
124 sprintf(rbuf, "SAS Expander");
125 break;
126 case ELMTYP_SAS_CONN:
127 sprintf(rbuf, "SAS Connector");
128 break;
129 default:
130 (void) sprintf(rbuf, "<Type 0x%x>", type);
131 break;
132 }
133 return (rbuf);
134 }
135
136 static char *
scode2ascii(u_char code)137 scode2ascii(u_char code)
138 {
139 static char rbuf[32];
140 switch (code & 0xf) {
141 case SES_OBJSTAT_UNSUPPORTED:
142 sprintf(rbuf, "Unsupported");
143 break;
144 case SES_OBJSTAT_OK:
145 sprintf(rbuf, "OK");
146 break;
147 case SES_OBJSTAT_CRIT:
148 sprintf(rbuf, "Critical");
149 break;
150 case SES_OBJSTAT_NONCRIT:
151 sprintf(rbuf, "Noncritical");
152 break;
153 case SES_OBJSTAT_UNRECOV:
154 sprintf(rbuf, "Unrecoverable");
155 break;
156 case SES_OBJSTAT_NOTINSTALLED:
157 sprintf(rbuf, "Not Installed");
158 break;
159 case SES_OBJSTAT_UNKNOWN:
160 sprintf(rbuf, "Unknown");
161 break;
162 case SES_OBJSTAT_NOTAVAIL:
163 sprintf(rbuf, "Not Available");
164 break;
165 case SES_OBJSTAT_NOACCESS:
166 sprintf(rbuf, "No Access Allowed");
167 break;
168 default:
169 sprintf(rbuf, "<Status 0x%x>", code & 0xf);
170 break;
171 }
172 return (rbuf);
173 }
174
175
176 char *
stat2ascii(int eletype __unused,u_char * cstat)177 stat2ascii(int eletype __unused, u_char *cstat)
178 {
179 static char ebuf[256], *scode;
180
181 scode = scode2ascii(cstat[0]);
182 sprintf(ebuf, "status: %s%s%s%s (0x%02x 0x%02x 0x%02x 0x%02x)",
183 scode,
184 (cstat[0] & 0x40) ? ", Prd.Fail" : "",
185 (cstat[0] & 0x20) ? ", Disabled" : "",
186 (cstat[0] & 0x10) ? ", Swapped" : "",
187 cstat[0], cstat[1], cstat[2], cstat[3]);
188 return (ebuf);
189 }
190