1 /* $NetBSD: lptctl.c,v 1.10 2004/02/03 21:46:39 jdolecek Exp $ */
4 * Copyright (c) 2004 The NetBSD Foundation, Inc.
7 * This code is derived from software contributed to The NetBSD Foundation
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
20 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
23 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
32 #include <sys/cdefs.h>
33 __RCSID("$NetBSD: lptctl.c,v 1.10 2004/02/03 21:46:39 jdolecek Exp $");
42 #include <sys/ioctl.h>
44 #include <dev/ppbus/lptio.h>
47 static void usage(int status
);
48 static void print_lpt_info(int, int);
51 main(const int argc
, const char * const * argv
) {
53 int omode
, mode
, oflags
, flags
;
57 /* N = command name + device name + number of command-arg pairs */
58 /* Check number of arguments: at least 2, always even */
59 if((argc
< 2) || (argc
% 2 != 0))
62 if ((fd
= open(argv
[1], O_RDONLY
, 0)) == -1)
63 err(2, "device open");
65 /* get current settings */
66 if (ioctl(fd
, LPTGFLAGS
, &flags
) == -1)
67 err(2, "ioctl(LPTGFLAGS)");
70 if (ioctl(fd
, LPTGMODE
, &mode
) == -1)
71 err(2, "ioctl(LPTGMODE)");
74 /* Get command and arg pairs (if any) and do an ioctl for each */
75 for(i
= 2; i
< argc
; i
+= 2) {
76 if (strcmp("dma", argv
[i
]) == 0) {
77 if (strcmp("yes", argv
[i
+ 1]) == 0)
79 else if (strcmp("no", argv
[i
+ 1]) == 0)
82 errx(2, "invalid '%s' command argument '%s'",
83 argv
[i
], argv
[i
+ 1]);
85 } else if (strcmp("mode", argv
[i
]) == 0) {
86 if (strcmp("standard", argv
[i
+ 1]) == 0)
88 else if (strcmp("ps2", argv
[i
+ 1]) == 0)
90 else if (strcmp("nibble", argv
[i
+ 1]) == 0)
92 else if (strcmp("fast", argv
[i
+ 1]) == 0)
94 else if (strcmp("ecp", argv
[i
+ 1]) == 0)
96 else if (strcmp("epp", argv
[i
+ 1]) == 0)
99 errx(2, "invalid '%s' command argument '%s'",
102 } else if (strcmp("ieee", argv
[i
]) == 0) {
103 if (strcmp("yes", argv
[i
+ 1]) == 0)
105 else if (strcmp("no", argv
[i
+ 1]) == 0)
108 errx(2, "invalid '%s' command argument '%s'",
111 } else if (strcmp("intr", argv
[i
]) == 0) {
112 if (strcmp("yes", argv
[i
+ 1]) == 0)
114 else if (strcmp("no", argv
[i
+ 1]) == 0)
117 errx(2, "invalid '%s' command argument '%s'",
120 } else if (strcmp("prime", argv
[i
]) == 0) {
121 if (strcmp("yes", argv
[i
+ 1]) == 0)
123 else if (strcmp("no", argv
[i
+ 1]) == 0)
126 errx(2, "invalid '%s' command argument '%s'",
129 } else if (strcmp("autolf", argv
[i
]) == 0) {
130 if (strcmp("yes", argv
[i
+ 1]) == 0)
132 else if (strcmp("no", argv
[i
+ 1]) == 0)
133 flags
&= ~LPT_AUTOLF
;
135 errx(2, "invalid '%s' command argument '%s'",
139 errx(2, "invalid command '%s'", argv
[i
]);
143 /* update mode and flags */
144 if (flags
!= oflags
) {
145 if (ioctl(fd
, LPTSFLAGS
, &flags
) == -1)
146 err(2, "ioctl(LPTSFLAGS)");
149 if (ioctl(fd
, LPTSMODE
, &mode
) == -1)
150 err(2, "ioctl(LPTSMODE)");
153 /* Print out information on device */
154 printf("%s status:\n\t", argv
[1]);
155 print_lpt_info(mode
, flags
);
162 print_lpt_info(int mode
, int flags
) {
184 printf("<unknown> ");
188 printf("dma=%s ", (flags
& LPT_DMA
) ? "yes" : "no");
189 printf("ieee=%s ", (flags
& LPT_IEEE
) ? "yes" : "no");
190 printf("intr=%s ", (flags
& LPT_INTR
) ? "yes" : "no");
191 printf("prime=%s ", (flags
& LPT_PRIME
) ? "yes" : "no");
192 printf("autolf=%s ", (flags
& LPT_AUTOLF
) ? "yes" : "no");
199 printf("usage:\t%s /dev/device [[command arg] ...]\n"
201 "\t\tmode [standard|ps2|nibble|fast|ecp|epp]\n"
203 "\t\tieee [yes|no]\n"
204 "\t\tintr [yes|no]\n"
205 "\t\tprime [yes|no]\n"
206 "\t\tautolf [yes|no]\n",