2 * Copyright (c) 1997 by Simon Shapiro
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
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.
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
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.3 2004/12/18 22:48:03 swildner Exp $
33 /* dpt_led.c: Show the blinking LED array status of a DPT HBAs */
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>
50 main(int argc, char **argv, char **argp)
58 if ( (fd = open(argv[1], O_RDWR, S_IRUSR | S_IWUSR)) == -1 ) {
59 fprintf(stderr, "%s ERROR: Failed to open \"%s\" - %s\n",
60 argv[0], argv[1], strerror(errno));
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;
71 if ( (result = ioctl(fd, DPT_IOCTL_SEND, &pass_thru)) != 0 ) {
72 fprintf(stderr, "%s ERROR: Failed to send IOCTL %lx "
74 argv[0], DPT_IOCTL_SEND,
79 fprintf(stdout, "%s\n", i2bin((unsigned int)led, 16));
84 * and this one presents an integer as ones and zeros
86 static char i2bin_bitmap[48]; /* Used for binary dump of registers */
89 i2bin(unsigned int no, int length)
93 for (ndx = 0, rind = 0; ndx < 32; ndx++, rind++) {
94 i2bin_bitmap[rind] = (((no << ndx) & 0x80000000) ? '1' : '0');
97 i2bin_bitmap[++rind] = ' ';
101 i2bin_bitmap[rind - 1] = '\0';
103 i2bin_bitmap[rind] = '\0';
107 return (i2bin_bitmap + 30);
110 return (i2bin_bitmap + 20);
113 return (i2bin_bitmap + 10);
116 return (i2bin_bitmap);
118 return ("i2bin: Invalid length Specs");