2004-02-04 00:46:39 +03:00
|
|
|
/* $NetBSD: lptctl.c,v 1.10 2004/02/03 21:46:39 jdolecek Exp $ */
|
2004-01-28 20:54:03 +03:00
|
|
|
|
|
|
|
/*-
|
|
|
|
* Copyright (c) 2004 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
|
|
|
* by Gary Thorpe.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
|
|
|
|
* ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
|
|
|
|
* TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
|
|
|
|
* BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
|
|
|
|
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
|
|
|
|
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
|
|
|
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
|
|
|
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
|
|
|
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
2004-01-21 03:33:37 +03:00
|
|
|
|
2004-02-03 23:04:56 +03:00
|
|
|
#include <sys/cdefs.h>
|
2004-02-04 00:46:39 +03:00
|
|
|
__RCSID("$NetBSD: lptctl.c,v 1.10 2004/02/03 21:46:39 jdolecek Exp $");
|
2004-02-03 23:04:56 +03:00
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <fcntl.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <unistd.h>
|
2004-01-20 02:31:18 +03:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <err.h>
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
|
|
|
|
#include <dev/ppbus/lptio.h>
|
|
|
|
|
|
|
|
/* Prototypes */
|
2004-01-20 02:31:18 +03:00
|
|
|
static void usage(int status);
|
2004-02-03 23:00:22 +03:00
|
|
|
static void print_lpt_info(int, int);
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
int
|
|
|
|
main(const int argc, const char * const * argv) {
|
2004-02-03 23:00:22 +03:00
|
|
|
int fd, i;
|
|
|
|
int omode, mode, oflags, flags;
|
2004-01-20 02:22:23 +03:00
|
|
|
|
2004-01-20 02:31:18 +03:00
|
|
|
setprogname(argv[0]);
|
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* N = command name + device name + number of command-arg pairs */
|
|
|
|
/* Check number of arguments: at least 2, always even */
|
2004-01-20 02:31:18 +03:00
|
|
|
if((argc < 2) || (argc % 2 != 0))
|
|
|
|
usage(1);
|
2004-01-20 02:22:23 +03:00
|
|
|
|
2004-01-20 02:31:18 +03:00
|
|
|
if ((fd = open(argv[1], O_RDONLY, 0)) == -1)
|
|
|
|
err(2, "device open");
|
2004-01-20 02:22:23 +03:00
|
|
|
|
2004-02-03 23:00:22 +03:00
|
|
|
/* get current settings */
|
|
|
|
if (ioctl(fd, LPTGFLAGS, &flags) == -1)
|
|
|
|
err(2, "ioctl(LPTGFLAGS)");
|
|
|
|
oflags = flags;
|
|
|
|
|
|
|
|
if (ioctl(fd, LPTGMODE, &mode) == -1)
|
|
|
|
err(2, "ioctl(LPTGMODE)");
|
|
|
|
omode = mode;
|
|
|
|
|
2004-01-20 02:22:23 +03:00
|
|
|
/* Get command and arg pairs (if any) and do an ioctl for each */
|
|
|
|
for(i = 2; i < argc; i += 2) {
|
2004-01-20 02:31:18 +03:00
|
|
|
if (strcmp("dma", argv[i]) == 0) {
|
2004-02-04 00:46:39 +03:00
|
|
|
if (strcmp("yes", argv[i + 1]) == 0)
|
2004-02-03 23:00:22 +03:00
|
|
|
flags |= LPT_DMA;
|
2004-02-04 00:46:39 +03:00
|
|
|
else if (strcmp("no", argv[i + 1]) == 0)
|
2004-02-03 23:00:22 +03:00
|
|
|
flags &= ~LPT_DMA;
|
|
|
|
else {
|
2004-01-20 02:31:18 +03:00
|
|
|
errx(2, "invalid '%s' command argument '%s'",
|
|
|
|
argv[i], argv[i + 1]);
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
2004-01-20 02:31:18 +03:00
|
|
|
} else if (strcmp("mode", argv[i]) == 0) {
|
2004-02-03 23:00:22 +03:00
|
|
|
if (strcmp("standard", argv[i + 1]) == 0)
|
2004-02-03 23:04:10 +03:00
|
|
|
mode = mode_standard;
|
2004-02-03 23:00:22 +03:00
|
|
|
else if (strcmp("ps2", argv[i + 1]) == 0)
|
2004-02-03 23:04:10 +03:00
|
|
|
mode = mode_ps2;
|
2004-02-03 23:00:22 +03:00
|
|
|
else if (strcmp("nibble", argv[i + 1]) == 0)
|
2004-02-03 23:04:10 +03:00
|
|
|
mode = mode_nibble;
|
2004-02-03 23:00:22 +03:00
|
|
|
else if (strcmp("fast", argv[i + 1]) == 0)
|
2004-02-03 23:04:10 +03:00
|
|
|
mode = mode_fast;
|
2004-02-03 23:00:22 +03:00
|
|
|
else if (strcmp("ecp", argv[i + 1]) == 0)
|
2004-02-03 23:04:10 +03:00
|
|
|
mode = mode_ecp;
|
2004-02-03 23:00:22 +03:00
|
|
|
else if (strcmp("epp", argv[i + 1]) == 0)
|
2004-02-03 23:04:10 +03:00
|
|
|
mode = mode_epp;
|
2004-02-03 23:00:22 +03:00
|
|
|
else {
|
2004-01-20 02:31:18 +03:00
|
|
|
errx(2, "invalid '%s' command argument '%s'",
|
|
|
|
argv[i], argv[i+1]);
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
2004-01-20 02:31:18 +03:00
|
|
|
} else if (strcmp("ieee", argv[i]) == 0) {
|
2004-02-03 23:00:22 +03:00
|
|
|
if (strcmp("yes", argv[i + 1]) == 0)
|
|
|
|
flags |= LPT_IEEE;
|
|
|
|
else if (strcmp("no", argv[i + 1]) == 0)
|
|
|
|
flags &= ~LPT_IEEE;
|
|
|
|
else {
|
2004-01-20 02:31:18 +03:00
|
|
|
errx(2, "invalid '%s' command argument '%s'",
|
|
|
|
argv[i], argv[i+1]);
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
2004-02-04 00:32:02 +03:00
|
|
|
} else if (strcmp("intr", argv[i]) == 0) {
|
|
|
|
if (strcmp("yes", argv[i + 1]) == 0)
|
|
|
|
flags |= LPT_INTR;
|
|
|
|
else if (strcmp("no", argv[i + 1]) == 0)
|
|
|
|
flags &= ~LPT_INTR;
|
|
|
|
else {
|
|
|
|
errx(2, "invalid '%s' command argument '%s'",
|
|
|
|
argv[i], argv[i+1]);
|
|
|
|
}
|
|
|
|
} else if (strcmp("prime", argv[i]) == 0) {
|
|
|
|
if (strcmp("yes", argv[i + 1]) == 0)
|
|
|
|
flags |= LPT_PRIME;
|
|
|
|
else if (strcmp("no", argv[i + 1]) == 0)
|
|
|
|
flags &= ~LPT_PRIME;
|
|
|
|
else {
|
|
|
|
errx(2, "invalid '%s' command argument '%s'",
|
|
|
|
argv[i], argv[i+1]);
|
|
|
|
}
|
|
|
|
} else if (strcmp("autolf", argv[i]) == 0) {
|
|
|
|
if (strcmp("yes", argv[i + 1]) == 0)
|
|
|
|
flags |= LPT_AUTOLF;
|
|
|
|
else if (strcmp("no", argv[i + 1]) == 0)
|
|
|
|
flags &= ~LPT_AUTOLF;
|
|
|
|
else {
|
|
|
|
errx(2, "invalid '%s' command argument '%s'",
|
|
|
|
argv[i], argv[i+1]);
|
|
|
|
}
|
2004-01-20 02:31:18 +03:00
|
|
|
} else {
|
|
|
|
errx(2, "invalid command '%s'", argv[i]);
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
2004-02-03 23:00:22 +03:00
|
|
|
}
|
2004-01-20 02:22:23 +03:00
|
|
|
|
2004-02-03 23:00:22 +03:00
|
|
|
/* update mode and flags */
|
|
|
|
if (flags != oflags) {
|
|
|
|
if (ioctl(fd, LPTSFLAGS, &flags) == -1)
|
|
|
|
err(2, "ioctl(LPTSFLAGS)");
|
|
|
|
}
|
|
|
|
if (mode != omode) {
|
|
|
|
if (ioctl(fd, LPTSMODE, &mode) == -1)
|
|
|
|
err(2, "ioctl(LPTSMODE)");
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Print out information on device */
|
2004-02-04 00:32:02 +03:00
|
|
|
printf("%s status:\n\t", argv[1]);
|
2004-02-03 23:00:22 +03:00
|
|
|
print_lpt_info(mode, flags);
|
2004-01-20 02:22:23 +03:00
|
|
|
|
|
|
|
exit(0);
|
2004-01-20 02:31:18 +03:00
|
|
|
/* NOTREACHED */
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
|
|
|
|
2004-01-20 02:31:18 +03:00
|
|
|
static void
|
2004-02-03 23:00:22 +03:00
|
|
|
print_lpt_info(int mode, int flags) {
|
2004-01-28 12:21:55 +03:00
|
|
|
printf("mode=");
|
2004-02-03 23:00:22 +03:00
|
|
|
switch(mode) {
|
2004-02-03 23:04:10 +03:00
|
|
|
case mode_standard:
|
2004-01-28 12:21:55 +03:00
|
|
|
printf("standard ");
|
|
|
|
break;
|
2004-02-03 23:04:10 +03:00
|
|
|
case mode_nibble:
|
2004-01-28 12:21:55 +03:00
|
|
|
printf("nibble ");
|
|
|
|
break;
|
2004-02-03 23:04:10 +03:00
|
|
|
case mode_fast:
|
2004-01-28 12:21:55 +03:00
|
|
|
printf("fast ");
|
|
|
|
break;
|
2004-02-03 23:04:10 +03:00
|
|
|
case mode_ps2:
|
2004-01-28 12:21:55 +03:00
|
|
|
printf("ps2 ");
|
|
|
|
break;
|
2004-02-03 23:04:10 +03:00
|
|
|
case mode_ecp:
|
2004-01-28 12:21:55 +03:00
|
|
|
printf("ecp ");
|
|
|
|
break;
|
2004-02-03 23:04:10 +03:00
|
|
|
case mode_epp:
|
2004-01-28 12:21:55 +03:00
|
|
|
printf("epp ");
|
|
|
|
break;
|
2004-02-03 23:00:22 +03:00
|
|
|
default:
|
|
|
|
printf("<unknown> ");
|
|
|
|
break;
|
2004-01-28 12:21:55 +03:00
|
|
|
}
|
2004-02-04 00:46:39 +03:00
|
|
|
|
|
|
|
printf("dma=%s ", (flags & LPT_DMA) ? "yes" : "no");
|
2004-02-03 23:00:22 +03:00
|
|
|
printf("ieee=%s ", (flags & LPT_IEEE) ? "yes" : "no");
|
2004-02-04 00:32:02 +03:00
|
|
|
printf("intr=%s ", (flags & LPT_INTR) ? "yes" : "no");
|
|
|
|
printf("prime=%s ", (flags & LPT_PRIME) ? "yes" : "no");
|
|
|
|
printf("autolf=%s ", (flags & LPT_AUTOLF) ? "yes" : "no");
|
2004-02-03 23:00:22 +03:00
|
|
|
|
2004-01-28 12:21:55 +03:00
|
|
|
printf("\n");
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|
|
|
|
|
2004-01-20 02:31:18 +03:00
|
|
|
static void
|
|
|
|
usage(int status) {
|
2004-02-04 00:32:02 +03:00
|
|
|
printf("usage:\t%s /dev/device [[command arg] ...]\n"
|
|
|
|
"\tcommands are:\n"
|
|
|
|
"\t\tmode [standard|ps2|nibble|fast|ecp|epp]\n"
|
2004-02-04 00:46:39 +03:00
|
|
|
"\t\tdma [yes|no]\n"
|
|
|
|
"\t\tieee [yes|no]\n"
|
2004-02-04 00:32:02 +03:00
|
|
|
"\t\tintr [yes|no]\n"
|
|
|
|
"\t\tprime [yes|no]\n"
|
|
|
|
"\t\tautolf [yes|no]\n",
|
2004-01-20 02:31:18 +03:00
|
|
|
getprogname());
|
|
|
|
exit(status);
|
2004-01-20 02:22:23 +03:00
|
|
|
}
|