1 /* $NetBSD: wsmuxctl.c,v 1.9 2004/10/30 15:55:28 dsl Exp $ */
4 * Copyright (c) 2001 The NetBSD Foundation, Inc.
7 * Author: Lennart Augustsson <augustss@carlstedt.se>
8 * Carlstedt Research & Technology
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.
37 #include <sys/types.h>
38 #include <sys/ioctl.h>
42 #include <dev/wscons/wsconsio.h>
44 static void usage(void);
45 int main(int, char**);
47 const char *ctlpath
= "/dev/wsmuxctl";
49 const char *devnames
[] = { "?", "wsmouse", "wskbd", "wsmux" };
55 fprintf(stderr
, "usage: %s [-a dev] -f wsmux [-l] [-L] [-r dev]\n",
61 parsedev(const char *dev
, struct wsmux_device
*mdev
)
63 if (sscanf(dev
, "wsmouse%d", &mdev
->idx
) == 1) {
64 mdev
->type
= WSMUX_MOUSE
;
67 if (sscanf(dev
, "wskbd%d", &mdev
->idx
) == 1) {
68 mdev
->type
= WSMUX_KBD
;
71 if (sscanf(dev
, "wsmux%d", &mdev
->idx
) == 1) {
72 mdev
->type
= WSMUX_MUX
;
75 errx(1, "bad device: `%s', use wsmouse, wskdb, or wsmux", dev
);
79 listdevs(int fd
, int rec
, int ind
)
83 struct wsmux_device_list devs
;
85 if (ioctl(fd
, WSMUXIO_LIST_DEVICES
, &devs
) < 0)
86 err(1, "WSMUXIO_LIST_DEVICES");
87 for (i
= 0; i
< devs
.ndevices
; i
++) {
88 printf("%*s%s%d\n", ind
, "", devnames
[devs
.devices
[i
].type
],
90 if (rec
&& devs
.devices
[i
].type
== WSMUX_MUX
) {
91 snprintf(buf
, sizeof(buf
), "%s%d", ctlpath
,
93 rfd
= open(buf
, O_WRONLY
, 0);
96 listdevs(rfd
, rec
, ind
+2);
103 main(int argc
, char **argv
)
106 int wsfd
, list
, c
, add
, rem
, recursive
;
107 struct wsmux_device mdev
;
117 while ((c
= getopt(argc
, argv
, "a:f:lLr:")) != -1) {
151 wsfd
= open(wsdev
, O_WRONLY
, 0);
153 if (isdigit((unsigned char)wsdev
[0])) {
154 snprintf(buf
, sizeof(buf
), "%s%s", ctlpath
, wsdev
);
156 wsfd
= open(wsdev
, O_WRONLY
, 0);
165 listdevs(wsfd
, recursive
, 0);
170 parsedev(dev
, &mdev
);
171 if (ioctl(wsfd
, WSMUXIO_ADD_DEVICE
, &mdev
) < 0)
172 err(1, "WSMUXIO_ADD_DEVICE");
176 parsedev(dev
, &mdev
);
177 if (ioctl(wsfd
, WSMUXIO_REMOVE_DEVICE
, &mdev
) < 0)
178 err(1, "WSMUXIO_REMOVE_DEVICE");