xref: /freebsd/usr.sbin/lptcontrol/lptcontrol.c (revision b728350ee67c01f96c3c5121774536fee81ad176)
16dc3c6f7SGeoff Rehmet /*
26dc3c6f7SGeoff Rehmet  * Copyright (c) 1994 Geoffrey M. Rehmet
36dc3c6f7SGeoff Rehmet  * All rights reserved.
46dc3c6f7SGeoff Rehmet  *
56dc3c6f7SGeoff Rehmet  * Redistribution and use in source and binary forms, with or without
66dc3c6f7SGeoff Rehmet  * modification, are permitted provided that the following conditions
76dc3c6f7SGeoff Rehmet  * are met:
86dc3c6f7SGeoff Rehmet  * 1. Redistributions of source code must retain the above copyright
96dc3c6f7SGeoff Rehmet  *    notice, this list of conditions and the following disclaimer.
106dc3c6f7SGeoff Rehmet  * 2. Redistributions in binary form must reproduce the above copyright
116dc3c6f7SGeoff Rehmet  *    notice, this list of conditions and the following disclaimer in the
126dc3c6f7SGeoff Rehmet  *    documentation and/or other materials provided with the distribution.
136dc3c6f7SGeoff Rehmet  * 3. All advertising materials mentioning features or use of this software
146dc3c6f7SGeoff Rehmet  *    must display the following acknowledgement:
156dc3c6f7SGeoff Rehmet  *      This product includes software developed by Geoffrey M. Rehmet
166dc3c6f7SGeoff Rehmet  * 4. The name of the author may not be used to endorse or promote products
1721dc7d4fSJens Schweikhardt  *    derived from this software without specific prior written permission
186dc3c6f7SGeoff Rehmet  *
196dc3c6f7SGeoff Rehmet  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
206dc3c6f7SGeoff Rehmet  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
216dc3c6f7SGeoff Rehmet  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
226dc3c6f7SGeoff Rehmet  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
236dc3c6f7SGeoff Rehmet  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
246dc3c6f7SGeoff Rehmet  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
256dc3c6f7SGeoff Rehmet  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
266dc3c6f7SGeoff Rehmet  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
276dc3c6f7SGeoff Rehmet  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
286dc3c6f7SGeoff Rehmet  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
296dc3c6f7SGeoff Rehmet  */
306dc3c6f7SGeoff Rehmet 
31b728350eSDavid E. O'Brien #include <sys/cdefs.h>
32b728350eSDavid E. O'Brien __FBSDID("$FreeBSD$");
33fe577fe9SPhilippe Charnier 
3412365022SGeoff Rehmet #include <ctype.h>
35fe577fe9SPhilippe Charnier #include <err.h>
3612365022SGeoff Rehmet #include <limits.h>
3712365022SGeoff Rehmet #include <paths.h>
3812365022SGeoff Rehmet #include <stdio.h>
3912365022SGeoff Rehmet #include <stdlib.h>
4012365022SGeoff Rehmet #include <string.h>
4112365022SGeoff Rehmet #include <unistd.h>
4212365022SGeoff Rehmet 
43f8373524SPeter Wemm #include <dev/ppbus/lptio.h>
446dc3c6f7SGeoff Rehmet #include <sys/file.h>
456dc3c6f7SGeoff Rehmet #include <sys/ioctl.h>
4612365022SGeoff Rehmet #include <sys/types.h>
476dc3c6f7SGeoff Rehmet 
486dc3c6f7SGeoff Rehmet 
4912365022SGeoff Rehmet #define PATH_LPCTL	_PATH_DEV "lpctl"
502ae9a4a0SAlfred Perlstein #define DEFAULT_DEVICE	_PATH_DEV "lpt0"
516dc3c6f7SGeoff Rehmet #define IRQ_INVALID	-1
526dc3c6f7SGeoff Rehmet #define DO_POLL		0
536dc3c6f7SGeoff Rehmet #define USE_IRQ		1
54bc35c174SNicolas Souchu #define USE_EXT_MODE	2
55bc35c174SNicolas Souchu #define USE_STD_MODE	3
566dc3c6f7SGeoff Rehmet 
57167ce4fbSDima Dorfman static void usage(void)
586dc3c6f7SGeoff Rehmet {
593876b692SNicolas Souchu 	fprintf(stderr, "usage: lptcontrol -i | -p | -s | -e [-d device]\n");
606dc3c6f7SGeoff Rehmet 	exit(1);
616dc3c6f7SGeoff Rehmet }
626dc3c6f7SGeoff Rehmet 
636dc3c6f7SGeoff Rehmet static void set_interrupt_status(int irq_status, const char * file)
646dc3c6f7SGeoff Rehmet {
656dc3c6f7SGeoff Rehmet 	int	fd;
666dc3c6f7SGeoff Rehmet 
67fe577fe9SPhilippe Charnier 	if((fd = open(file, O_WRONLY, 0660)) < 0)
68fe577fe9SPhilippe Charnier 		err(1, "open");
69fe577fe9SPhilippe Charnier 	if(ioctl(fd, LPT_IRQ, &irq_status) < 0)
70fe577fe9SPhilippe Charnier 		err(1, "ioctl");
716dc3c6f7SGeoff Rehmet 	close(fd);
726dc3c6f7SGeoff Rehmet }
736dc3c6f7SGeoff Rehmet 
746dc3c6f7SGeoff Rehmet int main (int argc, char * argv[])
756dc3c6f7SGeoff Rehmet {
766dc3c6f7SGeoff Rehmet 	int		opt;
7712365022SGeoff Rehmet 	int		irq_status = IRQ_INVALID;
78167ce4fbSDima Dorfman 	const char	*device = DEFAULT_DEVICE;
796dc3c6f7SGeoff Rehmet 
803876b692SNicolas Souchu 	while((opt = getopt(argc, argv, "ipesd:")) != -1)
816dc3c6f7SGeoff Rehmet 		switch(opt) {
826dc3c6f7SGeoff Rehmet 		case 'i': irq_status = USE_IRQ; break;
836dc3c6f7SGeoff Rehmet 		case 'p': irq_status = DO_POLL; break;
84bc35c174SNicolas Souchu 		case 'e': irq_status = USE_EXT_MODE; break;
85bc35c174SNicolas Souchu 		case 's': irq_status = USE_STD_MODE; break;
863876b692SNicolas Souchu 		case 'd': device = optarg; break;
87fe577fe9SPhilippe Charnier 		default : usage();
886dc3c6f7SGeoff Rehmet 		}
8912365022SGeoff Rehmet 	if(irq_status == IRQ_INVALID)
90fe577fe9SPhilippe Charnier 		usage();
916dc3c6f7SGeoff Rehmet 
923876b692SNicolas Souchu 	set_interrupt_status(irq_status, device);
936dc3c6f7SGeoff Rehmet 
946dc3c6f7SGeoff Rehmet 	exit(0);
956dc3c6f7SGeoff Rehmet }
96