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