eltsub.c revision 57580
1173147Srwatson/* $FreeBSD: head/share/examples/ses/srcs/eltsub.c 57580 2000-02-29 05:44:19Z mjacob $ */
2156287Srwatson/*
3156287Srwatson * Copyright (c) 2000 by Matthew Jacob
4156287Srwatson * All rights reserved.
5156287Srwatson *
6156287Srwatson * Redistribution and use in source and binary forms, with or without
7243750Srwatson * modification, are permitted provided that the following conditions
8243750Srwatson * are met:
9243750Srwatson * 1. Redistributions of source code must retain the above copyright
10243750Srwatson *    notice, this list of conditions, and the following disclaimer,
11243750Srwatson *    without modification, immediately at the beginning of the file.
12243750Srwatson * 2. The name of the author may not be used to endorse or promote products
13156287Srwatson *    derived from this software without specific prior written permission.
14195740Srwatson *
15156287Srwatson * Alternatively, this software may be distributed under the terms of the
16156287Srwatson * the GNU Public License ("GPL").
17156287Srwatson *
18156287Srwatson * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19243750Srwatson * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20243750Srwatson * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21243750Srwatson * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
22156287Srwatson * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23156287Srwatson * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24156287Srwatson * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25161634Srwatson * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26161634Srwatson * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27161634Srwatson * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28243750Srwatson * SUCH DAMAGE.
29243750Srwatson *
30243750Srwatson * Matthew Jacob
31156287Srwatson * Feral Software
32156287Srwatson * mjacob@feral.com
33156287Srwatson */
34156287Srwatson
35156287Srwatson#include <unistd.h>
36156287Srwatson#include <stdlib.h>
37243750Srwatson#include <stdio.h>
38243750Srwatson#include <sys/ioctl.h>
39243750Srwatson#include SESINC
40243750Srwatson
41243750Srwatsonchar *
42243750Srwatsongeteltnm(type)
43156287Srwatson	int type;
44156287Srwatson{
45156287Srwatson	static char rbuf[132];
46243750Srwatson
47243750Srwatson	switch (type) {
48243750Srwatson	case SESTYP_UNSPECIFIED:
49156287Srwatson		sprintf(rbuf, "Unspecified");
50156287Srwatson		break;
51156287Srwatson	case SESTYP_DEVICE:
52156287Srwatson		sprintf(rbuf, "Device");
53195740Srwatson		break;
54156287Srwatson	case SESTYP_POWER:
55243750Srwatson		sprintf(rbuf, "Power supply");
56243750Srwatson		break;
57243750Srwatson	case SESTYP_FAN:
58243750Srwatson		sprintf(rbuf, "Cooling element");
59243750Srwatson		break;
60243750Srwatson	case SESTYP_THERM:
61156287Srwatson		sprintf(rbuf, "Temperature sensors");
62156287Srwatson		break;
63156287Srwatson	case SESTYP_DOORLOCK:
64156287Srwatson		sprintf(rbuf, "Door Lock");
65156287Srwatson		break;
66156287Srwatson	case SESTYP_ALARM:
67156287Srwatson		sprintf(rbuf, "Audible alarm");
68156287Srwatson		break;
69156287Srwatson	case SESTYP_ESCC:
70185573Srwatson		sprintf(rbuf, "Enclosure services controller electronics");
71185573Srwatson		break;
72185573Srwatson	case SESTYP_SCC:
73185573Srwatson		sprintf(rbuf, "SCC controller electronics");
74185573Srwatson		break;
75185573Srwatson	case SESTYP_NVRAM:
76156287Srwatson		sprintf(rbuf, "Nonvolatile cache");
77156287Srwatson		break;
78156287Srwatson	case SESTYP_UPS:
79156287Srwatson		sprintf(rbuf, "Uninterruptible power supply");
80156287Srwatson		break;
81156287Srwatson	case SESTYP_DISPLAY:
82243750Srwatson		sprintf(rbuf, "Display");
83243750Srwatson		break;
84243750Srwatson	case SESTYP_KEYPAD:
85243750Srwatson		sprintf(rbuf, "Key pad entry device");
86243750Srwatson		break;
87243750Srwatson	case SESTYP_SCSIXVR:
88156287Srwatson		sprintf(rbuf, "SCSI port/transceiver");
89156287Srwatson		break;
90156287Srwatson	case SESTYP_LANGUAGE:
91156287Srwatson		sprintf(rbuf, "Language");
92156287Srwatson		break;
93156287Srwatson	case SESTYP_COMPORT:
94156287Srwatson		sprintf(rbuf, "Communication Port");
95156287Srwatson		break;
96156287Srwatson	case SESTYP_VOM:
97156287Srwatson		sprintf(rbuf, "Voltage Sensor");
98156287Srwatson		break;
99156287Srwatson	case SESTYP_AMMETER:
100156287Srwatson		sprintf(rbuf, "Current Sensor");
101156287Srwatson		break;
102156287Srwatson	case SESTYP_SCSI_TGT:
103156287Srwatson		sprintf(rbuf, "SCSI target port");
104243750Srwatson		break;
105243750Srwatson	case SESTYP_SCSI_INI:
106243750Srwatson		sprintf(rbuf, "SCSI initiator port");
107243750Srwatson		break;
108243750Srwatson	case SESTYP_SUBENC:
109243750Srwatson		sprintf(rbuf, "Simple sub-enclosure");
110243750Srwatson		break;
111243750Srwatson	default:
112243750Srwatson		(void) sprintf(rbuf, "<Type 0x%x>", type);
113243750Srwatson		break;
114243750Srwatson	}
115243750Srwatson	return (rbuf);
116243750Srwatson}
117186648Srwatson
118186648Srwatsonstatic char *
119186648Srwatsonscode2ascii(code)
120243750Srwatson	u_char code;
121243750Srwatson{
122243750Srwatson	static char rbuf[32];
123243750Srwatson	switch (code & 0xf) {
124243750Srwatson	case SES_OBJSTAT_UNSUPPORTED:
125243750Srwatson		sprintf(rbuf, "status not supported");
126243750Srwatson		break;
127243750Srwatson	case SES_OBJSTAT_OK:
128243750Srwatson		sprintf(rbuf, "ok");
129243750Srwatson		break;
130243750Srwatson	case SES_OBJSTAT_CRIT:
131243750Srwatson		sprintf(rbuf, "critical");
132243750Srwatson		break;
133243750Srwatson	case SES_OBJSTAT_NONCRIT:
134243750Srwatson		sprintf(rbuf, "non-critical");
135156287Srwatson		break;
136156287Srwatson	case SES_OBJSTAT_UNRECOV:
137156287Srwatson		sprintf(rbuf, "unrecoverable");
138156287Srwatson		break;
139156287Srwatson	case SES_OBJSTAT_NOTINSTALLED:
140156287Srwatson		sprintf(rbuf, "not installed");
141156287Srwatson		break;
142156287Srwatson	case SES_OBJSTAT_UNKNOWN:
143156287Srwatson		sprintf(rbuf, "unknown status");
144156287Srwatson		break;
145156287Srwatson	case SES_OBJSTAT_NOTAVAIL:
146156287Srwatson		sprintf(rbuf, "status not available");
147156287Srwatson		break;
148156287Srwatson	default:
149156287Srwatson		sprintf(rbuf, "unknown status code %x", code & 0xf);
150156287Srwatson		break;
151156287Srwatson	}
152156287Srwatson	return (rbuf);
153156287Srwatson}
154156287Srwatson
155156287Srwatson
156156287Srwatsonchar *
157156287Srwatsonstat2ascii(eletype, cstat)
158156287Srwatson	int eletype;
159156287Srwatson	u_char *cstat;
160162507Srwatson{
161162507Srwatson	static char ebuf[256], *scode;
162162507Srwatson
163185573Srwatson	scode = scode2ascii(cstat[0]);
164185573Srwatson	sprintf(ebuf, "Status=%s (bytes=0x%02x 0x%02x 0x%02x 0x%02x)",
165185573Srwatson	    scode, cstat[0], cstat[1], cstat[2], cstat[3]);
166243750Srwatson	return (ebuf);
167243750Srwatson}
168243750Srwatson