xref: /freebsd/usr.sbin/sesutil/eltsub.c (revision 59c8e88e72633afbc47a4ace0d2170d00d51f7dc)
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 <sys/types.h>
35 
36 #include <err.h>
37 #include <stddef.h>
38 #include <stdlib.h>
39 #include <stdio.h>
40 #include <cam/scsi/scsi_enc.h>
41 #include <libxo/xo.h>
42 
43 #include "eltsub.h"
44 
45 /*
46  * offset by +20 degrees.
47  * The range of the value expresses a temperature between -19 and +235 degrees
48  * Celsius. A value of 00h is reserved.
49  */
50 #define TEMPERATURE_OFFSET 20
51 
52 const char *
53 geteltnm(int type)
54 {
55 	static char rbuf[132];
56 
57 	switch (type) {
58 	case ELMTYP_UNSPECIFIED:
59 		return ("Unspecified");
60 	case ELMTYP_DEVICE:
61 		return ("Device Slot");
62 	case ELMTYP_POWER:
63 		return ("Power Supply");
64 	case ELMTYP_FAN:
65 		return ("Cooling");
66 	case ELMTYP_THERM:
67 		return ("Temperature Sensor");
68 	case ELMTYP_DOORLOCK:
69 		return ("Door Lock");
70 	case ELMTYP_ALARM:
71 		return ("Audible Alarm");
72 	case ELMTYP_ESCC:
73 		return ("Enclosure Services Controller Electronics");
74 	case ELMTYP_SCC:
75 		return ("SCC Controller Electronics");
76 	case ELMTYP_NVRAM:
77 		return ("Nonvolatile Cache");
78 	case ELMTYP_INV_OP_REASON:
79 		return ("Invalid Operation Reason");
80 	case ELMTYP_UPS:
81 		return ("Uninterruptible Power Supply");
82 	case ELMTYP_DISPLAY:
83 		return ("Display");
84 	case ELMTYP_KEYPAD:
85 		return ("Key Pad Entry");
86 	case ELMTYP_ENCLOSURE:
87 		return ("Enclosure");
88 	case ELMTYP_SCSIXVR:
89 		return ("SCSI Port/Transceiver");
90 	case ELMTYP_LANGUAGE:
91 		return ("Language");
92 	case ELMTYP_COMPORT:
93 		return ("Communication Port");
94 	case ELMTYP_VOM:
95 		return ("Voltage Sensor");
96 	case ELMTYP_AMMETER:
97 		return ("Current Sensor");
98 	case ELMTYP_SCSI_TGT:
99 		return ("SCSI Target Port");
100 	case ELMTYP_SCSI_INI:
101 		return ("SCSI Initiator Port");
102 	case ELMTYP_SUBENC:
103 		return ("Simple Subenclosure");
104 	case ELMTYP_ARRAY_DEV:
105 		return ("Array Device Slot");
106 	case ELMTYP_SAS_EXP:
107 		return ("SAS Expander");
108 	case ELMTYP_SAS_CONN:
109 		return ("SAS Connector");
110 	default:
111 		snprintf(rbuf, sizeof(rbuf), "<Type 0x%x>", type);
112 		return (rbuf);
113 	}
114 }
115 
116 const char *
117 scode2ascii(u_char code)
118 {
119 	static char rbuf[32];
120 	switch (code & 0xf) {
121 	case SES_OBJSTAT_UNSUPPORTED:
122 		return ("Unsupported");
123 	case SES_OBJSTAT_OK:
124 		return ("OK");
125 	case SES_OBJSTAT_CRIT:
126 		return ("Critical");
127 	case SES_OBJSTAT_NONCRIT:
128 		return ("Noncritical");
129 	case SES_OBJSTAT_UNRECOV:
130 		return ("Unrecoverable");
131 	case SES_OBJSTAT_NOTINSTALLED:
132 		return ("Not Installed");
133 	case SES_OBJSTAT_UNKNOWN:
134 		return ("Unknown");
135 	case SES_OBJSTAT_NOTAVAIL:
136 		return ("Not Available");
137 	case SES_OBJSTAT_NOACCESS:
138 		return ("No Access Allowed");
139 	default:
140 		snprintf(rbuf, sizeof(rbuf), "<Status 0x%x>", code & 0xf);
141 		return (rbuf);
142 	}
143 }
144