Add the DragonFly cvs id and perform general cleanups on cvs/rcs/sccs ids. Most
[dragonfly.git] / usr.sbin / dpt / dpt_led / dpt_led.c
1 /*
2  *       Copyright (c) 1997 by Simon Shapiro
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. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  * 3. 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  * 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  * $FreeBSD: src/usr.sbin/dpt/dpt_led/dpt_led.c,v 1.3 1999/08/28 01:16:08 peter Exp $
30  * $DragonFly: src/usr.sbin/dpt/dpt_led/dpt_led.c,v 1.2 2003/06/17 04:29:53 dillon Exp $
31  */
32
33 /* dpt_led.c:  Show the blinking LED array status of a DPT HBAs */
34
35 #include <fcntl.h>
36 #include <stdio.h>
37 #include <string.h>
38 #include <errno.h>
39 #include <sys/time.h>
40 #include <sys/stat.h>
41 #include <sys/queue.h>
42 #include <sys/ioctl.h>
43 #include <scsi/scsi_all.h>
44 #include <scsi/scsi_message.h>
45 #include <scsi/scsiconf.h>
46
47 #include <sys/dpt.h>
48
49 int
50 main(int argc, char **argv, char **argp)
51 {
52     eata_pt_t    pass_thru;
53     int                  led;
54     
55     int result;
56     int fd;
57
58     if ( (fd = open(argv[1], O_RDWR, S_IRUSR | S_IWUSR)) == -1 ) {
59                 (void)fprintf(stderr, "%s ERROR:  Failed to open \"%s\" - %s\n",
60                                           argv[0], argv[1], strerror(errno));
61                 exit(1);
62     }
63
64     pass_thru.eataID[0] = 'E';
65     pass_thru.eataID[1] = 'A';
66     pass_thru.eataID[2] = 'T';
67     pass_thru.eataID[3] = 'A';
68     pass_thru.command   = DPT_BLINKLED;
69     pass_thru.command_buffer = (u_int8_t *)&led;
70
71     if ( (result = ioctl(fd, DPT_IOCTL_SEND, &pass_thru)) != 0 ) {
72                 (void)fprintf(stderr, "%s ERROR:  Failed to send IOCTL %lx "
73                               "- %s\n",
74                               argv[0], DPT_IOCTL_SEND,
75                               strerror(errno));
76                 exit(1);
77     }
78
79         (void)fprintf(stdout, "%s\n", i2bin((unsigned int)led, 16));
80     return(0);
81 }
82
83 /*
84  * and this one presents an integer as ones and zeros
85  */
86 static char i2bin_bitmap[48];   /* Used for binary dump of registers */
87
88 char    *
89 i2bin(unsigned int no, int length)
90 {
91         int     ndx, rind;
92         
93         for (ndx = 0, rind = 0; ndx < 32; ndx++, rind++) {
94                 i2bin_bitmap[rind] = (((no << ndx) & 0x80000000) ? '1' : '0');
95         
96                 if (((ndx % 4) == 3))
97                         i2bin_bitmap[++rind] = ' ';
98         }
99         
100         if ((ndx % 4) == 3)
101                 i2bin_bitmap[rind - 1] = '\0';
102         else
103                 i2bin_bitmap[rind] = '\0';
104         
105         switch (length) {
106         case 8:
107                 return (i2bin_bitmap + 30);
108                 break;
109         case 16:
110                 return (i2bin_bitmap + 20);
111                 break;
112         case 24:
113                 return (i2bin_bitmap + 10);
114                 break;
115         case 32:
116                 return (i2bin_bitmap);
117         default:
118                 return ("i2bin: Invalid length Specs");
119                 break;
120         }
121 }
122