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