diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2002-02-15 02:18:40 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2002-02-15 02:18:40 +0000 |
commit | 46ddc1639d097b34cc97bf53a5c69817c9bb95a9 (patch) | |
tree | 7b27cb1678df2796025f3c5d63d21e102b31fb61 /usr.sbin | |
parent | 08903593f9727964fc20ba6895625537cf0bf180 (diff) |
KNF
Diffstat (limited to 'usr.sbin')
-rw-r--r-- | usr.sbin/wsmoused/mouse_protocols.c | 1559 | ||||
-rw-r--r-- | usr.sbin/wsmoused/mouse_protocols.h | 26 | ||||
-rw-r--r-- | usr.sbin/wsmoused/wsmoused.c | 123 | ||||
-rw-r--r-- | usr.sbin/wsmoused/wsmoused.h | 16 |
4 files changed, 855 insertions, 869 deletions
diff --git a/usr.sbin/wsmoused/mouse_protocols.c b/usr.sbin/wsmoused/mouse_protocols.c index 5f706c0c569..5c3ca122eba 100644 --- a/usr.sbin/wsmoused/mouse_protocols.c +++ b/usr.sbin/wsmoused/mouse_protocols.c @@ -1,12 +1,12 @@ -/* $OpenBSD: mouse_protocols.c,v 1.4 2001/09/20 21:22:16 miod Exp $ */ +/* $OpenBSD: mouse_protocols.c,v 1.5 2002/02/15 02:18:39 deraadt Exp $ */ /* * Copyright (c) 2001 Jean-Baptiste Marchand, Julien Montagne and Jerome Verdon - * + * * Copyright (c) 1998 by Kazutaka Yokota * * Copyright (c) 1995 Michael Smith - * + * * Copyright (c) 1993 by David Dawes <dawes@xfree86.org> * * Copyright (c) 1990,91 by Thomas Roell, Dinkelscherben, Germany. @@ -14,12 +14,12 @@ * All rights reserved. * * Most of this code was taken from the FreeBSD moused daemon, written by - * Michael Smith. The FreeBSD moused daemon already contained code from the + * Michael Smith. The FreeBSD moused daemon already contained code from the * Xfree Project, written by David Dawes and Thomas Roell and Kazutaka Yokota. * * Adaptation to OpenBSD was done by Jean-Baptiste Marchand, Julien Montagne * and Jerome Verdon. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -52,14 +52,14 @@ /* Support for non-wsmouse (i.e. serial mice) mice */ -/* +/* * Most of this code comes from the Xfree Project and are derived from two files * of Xfree86 3.3.6 with the following CVS tags : - $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86_Mouse.c,v 3.21.2.24 - 1999/12/11 19:00:42 hohndel Exp $ + $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86_Mouse.c,v 3.21.2.24 + 1999/12/11 19:00:42 hohndel Exp $ and - $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86_PnPMouse.c,v 1.1.2.6 - 1999/07/29 09:22:51 hohndel Exp $ + $XFree86: xc/programs/Xserver/hw/xfree86/common/xf86_PnPMouse.c,v 1.1.2.6 + 1999/07/29 09:22:51 hohndel Exp $ */ #include <sys/ioctl.h> @@ -84,52 +84,53 @@ #include "wsmoused.h" #include "mouse_protocols.h" -extern int debug; -extern int nodaemon; -extern int background; -extern mouse_t mouse; - -/* Cflags of each mouse protocol, ordered by P_XXX */ -static unsigned short mousecflags[] = -{ - (CS7 | CREAD | CLOCAL | HUPCL ), /* MicroSoft */ - (CS8 | CSTOPB | CREAD | CLOCAL | HUPCL ), /* MouseSystems */ - (CS8 | CSTOPB | CREAD | CLOCAL | HUPCL ), /* Logitech */ - (CS8 | PARENB | PARODD | CREAD | CLOCAL | HUPCL ), /* MMSeries */ - (CS7 | CREAD | CLOCAL | HUPCL ), /* MouseMan */ - (CS8 | CREAD | CLOCAL | HUPCL ), /* MM HitTablet */ - (CS7 | CREAD | CLOCAL | HUPCL ), /* GlidePoint */ - (CS7 | CREAD | CLOCAL | HUPCL ), /* IntelliMouse */ - (CS7 | CREAD | CLOCAL | HUPCL ), /* Thinking Mouse */ +extern int debug; +extern int nodaemon; +extern int background; +extern mouse_t mouse; + +/* Cflags of each mouse protocol, ordered by P_XXX */ +static unsigned short mousecflags[] = { + (CS7 | CREAD | CLOCAL | HUPCL), /* MicroSoft */ + (CS8 | CSTOPB | CREAD | CLOCAL | HUPCL), /* MouseSystems */ + (CS8 | CSTOPB | CREAD | CLOCAL | HUPCL), /* Logitech */ + (CS8 | PARENB | PARODD | CREAD | CLOCAL | HUPCL), /* MMSeries */ + (CS7 | CREAD | CLOCAL | HUPCL), /* MouseMan */ + (CS8 | CREAD | CLOCAL | HUPCL), /* MM HitTablet */ + (CS7 | CREAD | CLOCAL | HUPCL), /* GlidePoint */ + (CS7 | CREAD | CLOCAL | HUPCL), /* IntelliMouse */ + (CS7 | CREAD | CLOCAL | HUPCL), /* Thinking Mouse */ }; /* array ordered by P_XXX giving protocol properties */ static unsigned char proto[][7] = { - /* hd_mask hd_id dp_mask dp_id bytes b4_mask b4_id */ - { 0x40, 0x40, 0x40, 0x00, 3, ~0x23, 0x00 }, /* MicroSoft */ - { 0xf8, 0x80, 0x00, 0x00, 5, 0x00, 0xff }, /* MouseSystems */ - { 0xe0, 0x80, 0x80, 0x00, 3, 0x00, 0xff }, /* Logitech */ - { 0xe0, 0x80, 0x80, 0x00, 3, 0x00, 0xff }, /* MMSeries */ - { 0x40, 0x40, 0x40, 0x00, 3, ~0x33, 0x00 }, /* MouseMan */ - { 0xe0, 0x80, 0x80, 0x00, 3, 0x00, 0xff }, /* MM HitTablet */ - { 0x40, 0x40, 0x40, 0x00, 3, ~0x33, 0x00 }, /* GlidePoint */ - { 0x40, 0x40, 0x40, 0x00, 3, ~0x3f, 0x00 }, /* IntelliMouse */ - { 0x40, 0x40, 0x40, 0x00, 3, ~0x33, 0x00 }, /* ThinkingMouse */ + /* mask hd_id dp_mask dp_id bytes b4_mask b4_id */ + {0x40, 0x40, 0x40, 0x00, 3, ~0x23, 0x00}, /* MicroSoft */ + {0xf8, 0x80, 0x00, 0x00, 5, 0x00, 0xff}, /* MouseSystems */ + {0xe0, 0x80, 0x80, 0x00, 3, 0x00, 0xff}, /* Logitech */ + {0xe0, 0x80, 0x80, 0x00, 3, 0x00, 0xff}, /* MMSeries */ + {0x40, 0x40, 0x40, 0x00, 3, ~0x33, 0x00}, /* MouseMan */ + {0xe0, 0x80, 0x80, 0x00, 3, 0x00, 0xff}, /* MM HitTablet */ + {0x40, 0x40, 0x40, 0x00, 3, ~0x33, 0x00}, /* GlidePoint */ + {0x40, 0x40, 0x40, 0x00, 3, ~0x3f, 0x00}, /* IntelliMouse */ + {0x40, 0x40, 0x40, 0x00, 3, ~0x33, 0x00}, /* ThinkingMouse */ }; -/* array ordered by P_XXX (mouse protocols) giving the protocol corresponding - to the name of a mouse */ +/* + * array ordered by P_XXX (mouse protocols) giving the protocol + * corresponding to the name of a mouse + */ char *mouse_names[] = { - "microsoft", - "mousesystems", - "logitech", - "mmseries", - "mouseman", - "mmhitab", - "glidepoint", - "intellimouse", - "thinkingmouse", - NULL + "microsoft", + "mousesystems", + "logitech", + "mmseries", + "mouseman", + "mmhitab", + "glidepoint", + "intellimouse", + "thinkingmouse", + NULL }; /* protocol currently used */ @@ -137,98 +138,93 @@ static unsigned char cur_proto[7]; /* PnP EISA/product IDs */ static symtab_t pnpprod[] = { - { "KML0001", P_THINKING}, /* Kensignton ThinkingMouse */ - { "MSH0001", P_IMSERIAL}, /* MS IntelliMouse */ - { "MSH0004", P_IMSERIAL}, /* MS IntelliMouse TrackBall */ - { "KYEEZ00", P_MS}, /* Genius EZScroll */ - { "KYE0001", P_MS}, /* Genius PnP Mouse */ - { "KYE0003", P_IMSERIAL}, /* Genius NetMouse */ - { "LGI800C", P_IMSERIAL}, /* Logitech MouseMan (4 button model) */ - { "LGI8050", P_IMSERIAL}, /* Logitech MouseMan+ */ - { "LGI8051", P_IMSERIAL}, /* Logitech FirstMouse+ */ - { "LGI8001", P_LOGIMAN}, /* Logitech serial */ - { "PNP0F01", P_MS}, /* MS serial */ - /* - * XXX EzScroll returns PNP0F04 in the compatible device field; but it - * doesn't look compatible... - */ - { "PNP0F04", P_MSC}, /* MouseSystems */ - { "PNP0F05", P_MSC}, /* MouseSystems */ - { "PNP0F08", P_LOGIMAN}, /* Logitech serial */ - { "PNP0F09", P_MS}, /* MS BallPoint serial */ - { "PNP0F0A", P_MS}, /* MS PnP serial */ - { "PNP0F0B", P_MS}, /* MS PnP BallPoint serial */ - { "PNP0F0C", P_MS}, /* MS serial comatible */ - { "PNP0F0F", P_MS}, /* MS BallPoint comatible */ - { "PNP0F17", P_LOGIMAN}, /* Logitech serial compat */ - { NULL, -1 }, + {"KML0001", P_THINKING},/* Kensignton ThinkingMouse */ + {"MSH0001", P_IMSERIAL},/* MS IntelliMouse */ + {"MSH0004", P_IMSERIAL},/* MS IntelliMouse TrackBall */ + {"KYEEZ00", P_MS}, /* Genius EZScroll */ + {"KYE0001", P_MS}, /* Genius PnP Mouse */ + {"KYE0003", P_IMSERIAL},/* Genius NetMouse */ + {"LGI800C", P_IMSERIAL},/* Logitech MouseMan (4 button model) */ + {"LGI8050", P_IMSERIAL},/* Logitech MouseMan+ */ + {"LGI8051", P_IMSERIAL},/* Logitech FirstMouse+ */ + {"LGI8001", P_LOGIMAN}, /* Logitech serial */ + {"PNP0F01", P_MS}, /* MS serial */ + /* + * XXX EzScroll returns PNP0F04 in the compatible device field; but it + * doesn't look compatible... + */ + {"PNP0F04", P_MSC}, /* MouseSystems */ + {"PNP0F05", P_MSC}, /* MouseSystems */ + {"PNP0F08", P_LOGIMAN}, /* Logitech serial */ + {"PNP0F09", P_MS}, /* MS BallPoint serial */ + {"PNP0F0A", P_MS}, /* MS PnP serial */ + {"PNP0F0B", P_MS}, /* MS PnP BallPoint serial */ + {"PNP0F0C", P_MS}, /* MS serial comatible */ + {"PNP0F0F", P_MS}, /* MS BallPoint comatible */ + {"PNP0F17", P_LOGIMAN}, /* Logitech serial compat */ + {NULL, -1}, }; - + static symtab_t * -gettoken(symtab_t *tab, char *s, int len) +gettoken(symtab_t * tab, char *s, int len) { - int i; + int i; - for (i = 0; tab[i].name != NULL; ++i) { - if (strncmp(tab[i].name, s, len) == 0) - break; - } - return &tab[i]; + for (i = 0; tab[i].name != NULL; ++i) { + if (strncmp(tab[i].name, s, len) == 0) + break; + } + return &tab[i]; } char * mouse_name(int type) { - return (type == P_UNKNOWN - || (type > sizeof(mouse_names)/sizeof(mouse_names[0]) - 1)) - ? "unknown" : mouse_names[type]; + return (type == P_UNKNOWN || + (type > sizeof(mouse_names) / sizeof(mouse_names[0]) - 1)) ? + "unknown" : mouse_names[type]; } void SetMouseSpeed(int old, int new, unsigned int cflag) { struct termios tty; - char *c; + char *c; if (!IS_SERIAL_DEV(mouse.portname)) return; - if (tcgetattr(mouse.mfd, &tty) < 0) - { + if (tcgetattr(mouse.mfd, &tty) < 0) { debug("Warning: %s unable to get status of mouse fd (%s)\n", - mouse.portname, strerror(errno)); + mouse.portname, strerror(errno)); return; } - /* this will query the initial baudrate only once */ - if (mouse.old_baudrate < 0) { - switch (cfgetispeed(&tty)) - { - case B9600: - mouse.old_baudrate = 9600; - break; - case B4800: - mouse.old_baudrate = 4800; - break; - case B2400: - mouse.old_baudrate = 2400; - break; - case B1200: - default: - mouse.old_baudrate = 1200; - break; - } + if (mouse.old_baudrate < 0) { + switch (cfgetispeed(&tty)) { + case B9600: + mouse.old_baudrate = 9600; + break; + case B4800: + mouse.old_baudrate = 4800; + break; + case B2400: + mouse.old_baudrate = 2400; + break; + case B1200: + default: + mouse.old_baudrate = 1200; + break; + } } - tty.c_iflag = IGNBRK | IGNPAR; tty.c_oflag = 0; tty.c_lflag = 0; - tty.c_cflag = (tcflag_t)cflag; + tty.c_cflag = (tcflag_t) cflag; tty.c_cc[VTIME] = 0; tty.c_cc[VMIN] = 1; - switch (old) - { + switch (old) { case 9600: cfsetispeed(&tty, B9600); cfsetospeed(&tty, B9600); @@ -247,12 +243,10 @@ SetMouseSpeed(int old, int new, unsigned int cflag) cfsetospeed(&tty, B1200); } - if (tcsetattr(mouse.mfd, TCSADRAIN, &tty) < 0) { + if (tcsetattr(mouse.mfd, TCSADRAIN, &tty) < 0) logerr(1, "unable to get mouse status. Exiting...\n"); - } - - switch (new) - { + + switch (new) { case 9600: c = "*q"; cfsetispeed(&tty, B9600); @@ -275,24 +269,21 @@ SetMouseSpeed(int old, int new, unsigned int cflag) cfsetospeed(&tty, B1200); } - if (mouse.proto == P_LOGIMAN || mouse.proto == P_LOGI) - { - if (write(mouse.mfd, c, 2) != 2) { + if (mouse.proto == P_LOGIMAN || mouse.proto == P_LOGI) { + if (write(mouse.mfd, c, 2) != 2) logerr(1, "unable to write to mouse. Exiting...\n"); - } } usleep(100000); - if (tcsetattr(mouse.mfd, TCSADRAIN, &tty) < 0) { + if (tcsetattr(mouse.mfd, TCSADRAIN, &tty) < 0) logerr(1, "unable to get mouse status. Exiting...\n"); - } } int FlushInput(int fd) { struct pollfd pfd[1]; - char c[4]; + char c[4]; if (tcflush(fd, TCIFLUSH) == 0) return 0; @@ -306,768 +297,770 @@ FlushInput(int fd) } /* - * Try to elicit a PnP ID as described in - * Microsoft, Hayes: "Plug and Play External COM Device Specification, + * Try to elicit a PnP ID as described in + * Microsoft, Hayes: "Plug and Play External COM Device Specification, * rev 1.00", 1995. * * The routine does not fully implement the COM Enumerator as par Section * 2.1 of the document. In particular, we don't have idle state in which - * the driver software monitors the com port for dynamic connection or - * removal of a device at the port, because `moused' simply quits if no + * the driver software monitors the com port for dynamic connection or + * removal of a device at the port, because `moused' simply quits if no * device is found. * - * In addition, as PnP COM device enumeration procedure slightly has + * In addition, as PnP COM device enumeration procedure slightly has * changed since its first publication, devices which follow earlier - * revisions of the above spec. may fail to respond if the rev 1.0 + * revisions of the above spec. may fail to respond if the rev 1.0 * procedure is used. XXX */ - static int pnpgets(int mouse_fd, char *buf) { - struct pollfd pfd[1]; - int i; - char c; + struct pollfd pfd[1]; + int i; + char c; - pfd[0].fd = mouse_fd; - pfd[0].events = POLLIN; + pfd[0].fd = mouse_fd; + pfd[0].events = POLLIN; #if 0 - /* - * This is the procedure described in rev 1.0 of PnP COM device spec. - * Unfortunately, some devices which comform to earlier revisions of - * the spec gets confused and do not return the ID string... - */ - - /* port initialization (2.1.2) */ - ioctl(mouse_fd, TIOCMGET, &i); - i |= TIOCM_DTR; /* DTR = 1 */ - i &= ~TIOCM_RTS; /* RTS = 0 */ - ioctl(mouse_fd, TIOCMSET, &i); - usleep(200000); - if ((ioctl(mouse_fd, TIOCMGET, &i) == -1) || ((i & TIOCM_DSR) == 0)) - goto disconnect_idle; - - /* port setup, 1st phase (2.1.3) */ - SetMouseSpeed(1200, 1200, (CS7 | CREAD | CLOCAL | HUPCL)); - i = TIOCM_DTR | TIOCM_RTS; /* DTR = 0, RTS = 0 */ - ioctl(mouse_fd, TIOCMBIC, &i); - usleep(200000); - i = TIOCM_DTR; /* DTR = 1, RTS = 0 */ - ioctl(mouse_fd, TIOCMBIS, &i); - usleep(200000); - - /* wait for response, 1st phase (2.1.4) */ - FlushInput(mouse_fd); - i = TIOCM_RTS; /* DTR = 1, RTS = 1 */ - ioctl(mouse_fd, TIOCMBIS, &i); - - /* try to read something */ - if (poll(pfd, 1, 200000/1000) <= 0) { - - /* port setup, 2nd phase (2.1.5) */ - i = TIOCM_DTR | TIOCM_RTS; /* DTR = 0, RTS = 0 */ - ioctl(mouse_fd, TIOCMBIC, &i); - usleep(200000); - - /* wait for respose, 2nd phase (2.1.6) */ - FlushInput(mouse_fd); - i = TIOCM_DTR | TIOCM_RTS; /* DTR = 1, RTS = 1 */ - ioctl(mouse_fd, TIOCMBIS, &i); + /* + * This is the procedure described in rev 1.0 of PnP COM device spec. + * Unfortunately, some devices which comform to earlier revisions of + * the spec gets confused and do not return the ID string... + */ + + /* port initialization (2.1.2) */ + ioctl(mouse_fd, TIOCMGET, &i); + i |= TIOCM_DTR; /* DTR = 1 */ + i &= ~TIOCM_RTS; /* RTS = 0 */ + ioctl(mouse_fd, TIOCMSET, &i); + usleep(200000); + if ((ioctl(mouse_fd, TIOCMGET, &i) == -1) || ((i & TIOCM_DSR) == 0)) + goto disconnect_idle; + + /* port setup, 1st phase (2.1.3) */ + SetMouseSpeed(1200, 1200, (CS7 | CREAD | CLOCAL | HUPCL)); + i = TIOCM_DTR | TIOCM_RTS; /* DTR = 0, RTS = 0 */ + ioctl(mouse_fd, TIOCMBIC, &i); + usleep(200000); + i = TIOCM_DTR; /* DTR = 1, RTS = 0 */ + ioctl(mouse_fd, TIOCMBIS, &i); + usleep(200000); - /* try to read something */ - if (poll(pfd, 1, 200000/1000) <= 0) - goto connect_idle; - } + /* wait for response, 1st phase (2.1.4) */ + FlushInput(mouse_fd); + i = TIOCM_RTS; /* DTR = 1, RTS = 1 */ + ioctl(mouse_fd, TIOCMBIS, &i); + + /* try to read something */ + if (poll(pfd, 1, 200000 / 1000) <= 0) { + /* port setup, 2nd phase (2.1.5) */ + i = TIOCM_DTR | TIOCM_RTS; /* DTR = 0, RTS = 0 */ + ioctl(mouse_fd, TIOCMBIC, &i); + usleep(200000); + + /* wait for respose, 2nd phase (2.1.6) */ + FlushInput(mouse_fd); + i = TIOCM_DTR | TIOCM_RTS; /* DTR = 1, RTS = 1 */ + ioctl(mouse_fd, TIOCMBIS, &i); + + /* try to read something */ + if (poll(pfd, 1, 200000 / 1000) <= 0) + goto connect_idle; + } #else - - /* - * This is a simplified procedure; it simply toggles RTS. - */ - SetMouseSpeed(1200, 1200, (CS7 | CREAD | CLOCAL | HUPCL)); - - ioctl(mouse_fd, TIOCMGET, &i); - i |= TIOCM_DTR; /* DTR = 1 */ - i &= ~TIOCM_RTS; /* RTS = 0 */ - ioctl(mouse_fd, TIOCMSET, &i); - usleep(200000); - - /* wait for response */ - FlushInput(mouse_fd); - i = TIOCM_DTR | TIOCM_RTS; /* DTR = 1, RTS = 1 */ - ioctl(mouse_fd, TIOCMBIS, &i); - - /* try to read something */ - if (poll(pfd, 1, 200000/1000) <= 0) - goto connect_idle; + + /* + * This is a simplified procedure; it simply toggles RTS. + */ + SetMouseSpeed(1200, 1200, (CS7 | CREAD | CLOCAL | HUPCL)); + + ioctl(mouse_fd, TIOCMGET, &i); + i |= TIOCM_DTR; /* DTR = 1 */ + i &= ~TIOCM_RTS; /* RTS = 0 */ + ioctl(mouse_fd, TIOCMSET, &i); + usleep(200000); + + /* wait for response */ + FlushInput(mouse_fd); + i = TIOCM_DTR | TIOCM_RTS; /* DTR = 1, RTS = 1 */ + ioctl(mouse_fd, TIOCMBIS, &i); + + /* try to read something */ + if (poll(pfd, 1, 200000 / 1000) <= 0) + goto connect_idle; #endif - /* collect PnP COM device ID (2.1.7) */ - i = 0; - usleep(200000); /* the mouse must send `Begin ID' within 200msec */ - while (read(mouse_fd, &c, 1) == 1) { - /* we may see "M", or "M3..." before `Begin ID' */ - if ((c == 0x08) || (c == 0x28)) { /* Begin ID */ - buf[i++] = c; - break; - } - } - if (i <= 0) { - /* we haven't seen `Begin ID' in time... */ - goto connect_idle; - } - - ++c; /* make it `End ID' */ - for (;;) { - if (poll(pfd, 1, 200000/1000) <= 0) - break; - - read(mouse_fd, &buf[i], 1); - if (buf[i++] == c) /* End ID */ - break; - if (i >= 256) - break; - } - if (buf[i - 1] != c) - goto connect_idle; - return i; - + /* collect PnP COM device ID (2.1.7) */ + i = 0; + usleep(200000); /* the mouse must send `Begin ID' within + * 200msec */ + while (read(mouse_fd, &c, 1) == 1) { + /* we may see "M", or "M3..." before `Begin ID' */ + if ((c == 0x08) || (c == 0x28)) { /* Begin ID */ + buf[i++] = c; + break; + } + } + if (i <= 0) { + /* we haven't seen `Begin ID' in time... */ + goto connect_idle; + } + ++c; /* make it `End ID' */ + for (;;) { + if (poll(pfd, 1, 200000 / 1000) <= 0) + break; + + read(mouse_fd, &buf[i], 1); + if (buf[i++] == c) /* End ID */ + break; + if (i >= 256) + break; + } + if (buf[i - 1] != c) + goto connect_idle; + return i; + #if 0 - /* - * According to PnP spec, we should set DTR = 1 and RTS = 0 while - * in idle state. But, `moused' shall set DTR = RTS = 1 and proceed, - * assuming there is something at the port even if it didn't - * respond to the PnP enumeration procedure. - */ + /* + * According to PnP spec, we should set DTR = 1 and RTS = 0 while + * in idle state. But, `moused' shall set DTR = RTS = 1 and proceed, + * assuming there is something at the port even if it didn't + * respond to the PnP enumeration procedure. + */ disconnect_idle: - i = TIOCM_DTR | TIOCM_RTS; /* DTR = 1, RTS = 1 */ - ioctl(mouse_fd, TIOCMBIS, &i); + i = TIOCM_DTR | TIOCM_RTS; /* DTR = 1, RTS = 1 */ + ioctl(mouse_fd, TIOCMBIS, &i); #endif connect_idle: - return 0; + return 0; } /* pnpparse : parse a PnP string ID */ static int -pnpparse(pnpid_t *id, char *buf, int len) +pnpparse(pnpid_t * id, char *buf, int len) { - char s[3]; - int offset; - int sum = 0; - int i, j; - - id->revision = 0; - id->eisaid = NULL; - id->serial = NULL; - id->class = NULL; - id->compat = NULL; - id->description = NULL; - id->neisaid = 0; - id->nserial = 0; - id->nclass = 0; - id->ncompat = 0; - id->ndescription = 0; - - offset = 0x28 - buf[0]; - - /* calculate checksum */ - for (i = 0; i < len - 3; ++i) { - sum += buf[i]; - buf[i] += offset; - } - sum += buf[len - 1]; - for (; i < len; ++i) - buf[i] += offset; - debug("Mouse: PnP ID string: '%*.*s'\n", len, len, buf); - - /* revision */ - buf[1] -= offset; - buf[2] -= offset; - id->revision = ((buf[1] & 0x3f) << 6) | (buf[2] & 0x3f); - debug("Mouse: PnP rev %d.%02d\n", id->revision / 100, id->revision % 100); - - /* EISA vender and product ID */ - id->eisaid = &buf[3]; - id->neisaid = 7; - - /* option strings */ - i = 10; - if (buf[i] == '\\') { - /* device serial # */ - for (j = ++i; i < len; ++i) { - if (buf[i] == '\\') - break; - } - if (i >= len) - i -= 3; - if (i - j == 8) { - id->serial = &buf[j]; - id->nserial = 8; + char s[3]; + int offset, sum = 0, i, j; + + id->revision = 0; + id->eisaid = NULL; + id->serial = NULL; + id->class = NULL; + id->compat = NULL; + id->description = NULL; + id->neisaid = 0; + id->nserial = 0; + id->nclass = 0; + id->ncompat = 0; + id->ndescription = 0; + + offset = 0x28 - buf[0]; + + /* calculate checksum */ + for (i = 0; i < len - 3; ++i) { + sum += buf[i]; + buf[i] += offset; } - } - if (buf[i] == '\\') { - /* PnP class */ - for (j = ++i; i < len; ++i) { - if (buf[i] == '\\') - break; - } - if (i >= len) - i -= 3; - if (i > j + 1) { - id->class = &buf[j]; - id->nclass = i - j; - } - } - if (buf[i] == '\\') { - /* compatible driver */ - for (j = ++i; i < len; ++i) { - if (buf[i] == '\\') - break; - } - /* - * PnP COM spec prior to v0.96 allowed '*' in this field, - * it's not allowed now; just ignore it. - */ - if (buf[j] == '*') - ++j; - if (i >= len) - i -= 3; - if (i > j + 1) { - id->compat = &buf[j]; - id->ncompat = i - j; - } - } - if (buf[i] == '\\') { - /* product description */ - for (j = ++i; i < len; ++i) { - if (buf[i] == ';') - break; - } - if (i >= len) - i -= 3; - if (i > j + 1) { - id->description = &buf[j]; - id->ndescription = i - j; - } - } - - /* checksum exists if there are any optional fields */ - if ((id->nserial > 0) || (id->nclass > 0) - || (id->ncompat > 0) || (id->ndescription > 0)) { + sum += buf[len - 1]; + for (; i < len; ++i) + buf[i] += offset; + debug("Mouse: PnP ID string: '%*.*s'\n", len, len, buf); + + /* revision */ + buf[1] -= offset; + buf[2] -= offset; + id->revision = ((buf[1] & 0x3f) << 6) | (buf[2] & 0x3f); + debug("Mouse: PnP rev %d.%02d\n", id->revision / 100, id->revision % 100); + + /* EISA vender and product ID */ + id->eisaid = &buf[3]; + id->neisaid = 7; + + /* option strings */ + i = 10; + if (buf[i] == '\\') { + /* device serial # */ + for (j = ++i; i < len; ++i) { + if (buf[i] == '\\') + break; + } + if (i >= len) + i -= 3; + if (i - j == 8) { + id->serial = &buf[j]; + id->nserial = 8; + } + } + if (buf[i] == '\\') { + /* PnP class */ + for (j = ++i; i < len; ++i) { + if (buf[i] == '\\') + break; + } + if (i >= len) + i -= 3; + if (i > j + 1) { + id->class = &buf[j]; + id->nclass = i - j; + } + } + if (buf[i] == '\\') { + /* compatible driver */ + for (j = ++i; i < len; ++i) { + if (buf[i] == '\\') + break; + } + /* + * PnP COM spec prior to v0.96 allowed '*' in this field, + * it's not allowed now; just ignore it. + */ + if (buf[j] == '*') + ++j; + if (i >= len) + i -= 3; + if (i > j + 1) { + id->compat = &buf[j]; + id->ncompat = i - j; + } + } + if (buf[i] == '\\') { + /* product description */ + for (j = ++i; i < len; ++i) { + if (buf[i] == ';') + break; + } + if (i >= len) + i -= 3; + if (i > j + 1) { + id->description = &buf[j]; + id->ndescription = i - j; + } + } + /* checksum exists if there are any optional fields */ + if ((id->nserial > 0) || (id->nclass > 0) || + (id->ncompat > 0) || (id->ndescription > 0)) { #if 0 - debug("Mouse: PnP checksum: 0x%02X\n", sum); + debug("Mouse: PnP checksum: 0x%02X\n", sum); #endif - sprintf(s, "%02X", sum & 0x0ff); - if (strncmp(s, &buf[len - 3], 2) != 0) { + sprintf(s, "%02X", sum & 0x0ff); + if (strncmp(s, &buf[len - 3], 2) != 0) { #if 0 - /* - * Checksum error!! - * I found some mice do not comply with the PnP COM device - * spec regarding checksum... XXX - */ - return FALSE; + /* + * Checksum error!! + * I found some mice do not comply with the PnP COM device + * spec regarding checksum... XXX + */ + return FALSE; #endif - } - } - - return 1; + } + } + return 1; } /* pnpproto : return the prototype used, based on the PnP ID string */ static symtab_t * -pnpproto(pnpid_t *id) +pnpproto(pnpid_t * id) { - symtab_t *t; - int i, j; - - if (id->nclass > 0) - if (strncmp(id->class, "MOUSE", id->nclass) != 0) - /* this is not a mouse! */ - return NULL; - - if (id->neisaid > 0) { - t = gettoken(pnpprod, id->eisaid, id->neisaid); - if (t->val != -1) - return t; - } - /* - * The 'Compatible drivers' field may contain more than one - * ID separated by ','. - */ - if (id->ncompat <= 0) - return NULL; - for (i = 0; i < id->ncompat; ++i) { - for (j = i; id->compat[i] != ','; ++i) - if (i >= id->ncompat) - break; - if (i > j) { - t = gettoken(pnpprod, id->compat + j, i - j); - if (t->val != -1) - return t; + symtab_t *t; + int i, j; + + if (id->nclass > 0) + if (strncmp(id->class, "MOUSE", id->nclass) != 0) + /* this is not a mouse! */ + return NULL; + + if (id->neisaid > 0) { + t = gettoken(pnpprod, id->eisaid, id->neisaid); + if (t->val != -1) + return t; + } + /* + * The 'Compatible drivers' field may contain more than one + * ID separated by ','. + */ + if (id->ncompat <= 0) + return NULL; + for (i = 0; i < id->ncompat; ++i) { + for (j = i; id->compat[i] != ','; ++i) + if (i >= id->ncompat) + break; + if (i > j) { + t = gettoken(pnpprod, id->compat + j, i - j); + if (t->val != -1) + return t; + } } - } - return NULL; + return NULL; } /* mouse_init : init the mouse by writing appropriate sequences */ void mouse_init(void) { - struct pollfd pfd[1]; - char *s; - char c; - int i; - - if (IS_WSMOUSE_DEV(mouse.portname)) { - wsmouse_init(); - return ; - } - - pfd[0].fd = mouse.mfd; - pfd[0].events = POLLIN; - - /** - ** This comment is a little out of context here, but it contains - ** some useful information... - ******************************************************************** - ** - ** The following lines take care of the Logitech MouseMan protocols. - ** - ** NOTE: There are diffrent versions of both MouseMan and TrackMan! - ** Hence I add another protocol P_LOGIMAN, which the user can - ** specify as MouseMan in his XF86Config file. This entry was - ** formerly handled as a special case of P_MS. However, people - ** who don't have the middle button problem, can still specify - ** Microsoft and use P_MS. - ** - ** By default, these mice should use a 3 byte Microsoft protocol - ** plus a 4th byte for the middle button. However, the mouse might - ** have switched to a different protocol before we use it, so I send - ** the proper sequence just in case. - ** - ** NOTE: - all commands to (at least the European) MouseMan have to - ** be sent at 1200 Baud. - ** - each command starts with a '*'. - ** - whenever the MouseMan receives a '*', it will switch back - ** to 1200 Baud. Hence I have to select the desired protocol - ** first, then select the baud rate. - ** - ** The protocols supported by the (European) MouseMan are: - ** - 5 byte packed binary protocol, as with the Mouse Systems - ** mouse. Selected by sequence "*U". - ** - 2 button 3 byte MicroSoft compatible protocol. Selected - ** by sequence "*V". - ** - 3 button 3+1 byte MicroSoft compatible protocol (default). - ** Selected by sequence "*X". - ** - ** The following baud rates are supported: - ** - 1200 Baud (default). Selected by sequence "*n". - ** - 9600 Baud. Selected by sequence "*q". - ** - ** Selecting a sample rate is no longer supported with the MouseMan! - ** Some additional lines in xf86Config.c take care of ill configured - ** baud rates and sample rates. (The user will get an error.) - */ - - switch (mouse.proto) { - - case P_LOGI: - /* - * The baud rate selection command must be sent at the current - * baud rate; try all likely settings - */ - SetMouseSpeed(9600, mouse.baudrate, mousecflags[mouse.proto]); - SetMouseSpeed(4800, mouse.baudrate, mousecflags[mouse.proto]); - SetMouseSpeed(2400, mouse.baudrate, mousecflags[mouse.proto]); - // SetMouseSpeed(1200, mouse.baudrate, mousecflags[mouse.proto]); - /* select MM series data format */ - write(mouse.mfd, "S", 1); - SetMouseSpeed(mouse.baudrate, mouse.baudrate, - mousecflags[P_MM]); - /* select report rate/frequency */ - if (mouse.rate <= 0) write(mouse.mfd, "O", 1); - else if (mouse.rate <= 15) write(mouse.mfd, "J", 1); - else if (mouse.rate <= 27) write(mouse.mfd, "K", 1); - else if (mouse.rate <= 42) write(mouse.mfd, "L", 1); - else if (mouse.rate <= 60) write(mouse.mfd, "R", 1); - else if (mouse.rate <= 85) write(mouse.mfd, "M", 1); - else if (mouse.rate <= 125) write(mouse.mfd, "Q", 1); - else write(mouse.mfd, "N", 1); - break; - - case P_LOGIMAN: - /* The command must always be sent at 1200 baud */ - SetMouseSpeed(1200, 1200, mousecflags[mouse.proto]); - write(mouse.mfd, "*X", 2); - SetMouseSpeed(1200, mouse.baudrate, mousecflags[mouse.proto]); - break; - - case P_MMHIT: - SetMouseSpeed(1200, mouse.baudrate, mousecflags[mouse.proto]); + struct pollfd pfd[1]; + char *s; + char c; + int i; - /* - * Initialize Hitachi PUMA Plus - Model 1212E to desired settings. - * The tablet must be configured to be in MM mode, NO parity, - * Binary Format. xf86Info.sampleRate controls the sensativity - * of the tablet. We only use this tablet for it's 4-button puck - * so we don't run in "Absolute Mode" + if (IS_WSMOUSE_DEV(mouse.portname)) { + wsmouse_init(); + return; + } + pfd[0].fd = mouse.mfd; + pfd[0].events = POLLIN; + + /** + ** This comment is a little out of context here, but it contains + ** some useful information... + ******************************************************************** + ** + ** The following lines take care of the Logitech MouseMan protocols. + ** + ** NOTE: There are diffrent versions of both MouseMan and TrackMan! + ** Hence I add another protocol P_LOGIMAN, which the user can + ** specify as MouseMan in his XF86Config file. This entry was + ** formerly handled as a special case of P_MS. However, people + ** who don't have the middle button problem, can still specify + ** Microsoft and use P_MS. + ** + ** By default, these mice should use a 3 byte Microsoft protocol + ** plus a 4th byte for the middle button. However, the mouse might + ** have switched to a different protocol before we use it, so I send + ** the proper sequence just in case. + ** + ** NOTE: - all commands to (at least the European) MouseMan have to + ** be sent at 1200 Baud. + ** - each command starts with a '*'. + ** - whenever the MouseMan receives a '*', it will switch back + ** to 1200 Baud. Hence I have to select the desired protocol + ** first, then select the baud rate. + ** + ** The protocols supported by the (European) MouseMan are: + ** - 5 byte packed binary protocol, as with the Mouse Systems + ** mouse. Selected by sequence "*U". + ** - 2 button 3 byte MicroSoft compatible protocol. Selected + ** by sequence "*V". + ** - 3 button 3+1 byte MicroSoft compatible protocol (default). + ** Selected by sequence "*X". + ** + ** The following baud rates are supported: + ** - 1200 Baud (default). Selected by sequence "*n". + ** - 9600 Baud. Selected by sequence "*q". + ** + ** Selecting a sample rate is no longer supported with the MouseMan! + ** Some additional lines in xf86Config.c take care of ill configured + ** baud rates and sample rates. (The user will get an error.) */ - write(mouse.mfd, "z8", 2); /* Set Parity = "NONE" */ - usleep(50000); - write(mouse.mfd, "zb", 2); /* Set Format = "Binary" */ - usleep(50000); - write(mouse.mfd, "@", 1); /* Set Report Mode = "Stream" */ - usleep(50000); - write(mouse.mfd, "R", 1); /* Set Output Rate = "45 rps" */ - usleep(50000); - write(mouse.mfd, "I\x20", 2); /* Set Incrememtal Mode "20" */ - usleep(50000); - write(mouse.mfd, "E", 1); /* Set Data Type = "Relative */ - usleep(50000); - - /* Resolution is in 'lines per inch' on the Hitachi tablet */ - if (mouse.resolution == MOUSE_RES_LOW) c = 'g'; - else if (mouse.resolution == MOUSE_RES_MEDIUMLOW) c = 'e'; - else if (mouse.resolution == MOUSE_RES_MEDIUMHIGH) c = 'h'; - else if (mouse.resolution == MOUSE_RES_HIGH) c = 'd'; - else if (mouse.resolution <= 40) c = 'g'; - else if (mouse.resolution <= 100) c = 'd'; - else if (mouse.resolution <= 200) c = 'e'; - else if (mouse.resolution <= 500) c = 'h'; - else if (mouse.resolution <= 1000) c = 'j'; - else c = 'd'; - write(mouse.mfd, &c, 1); - usleep(50000); - - write(mouse.mfd, "\021", 1); /* Resume DATA output */ - break; - - case P_THINKING: - SetMouseSpeed(1200, mouse.baudrate, mousecflags[mouse.proto]); - /* the PnP ID string may be sent again, discard it */ - usleep(200000); - i = FREAD; - ioctl(mouse.mfd, TIOCFLUSH, &i); - /* send the command to initialize the beast */ - for (s = "E5E5"; *s; ++s) { - write(mouse.mfd, s, 1); - if (poll(pfd, 1, INFTIM) <= 0) + switch (mouse.proto) { + + case P_LOGI: + /* + * The baud rate selection command must be sent at the current + * baud rate; try all likely settings + */ + SetMouseSpeed(9600, mouse.baudrate, mousecflags[mouse.proto]); + SetMouseSpeed(4800, mouse.baudrate, mousecflags[mouse.proto]); + SetMouseSpeed(2400, mouse.baudrate, mousecflags[mouse.proto]); + //SetMouseSpeed(1200, mouse.baudrate, mousecflags[mouse.proto]); + /* select MM series data format */ + write(mouse.mfd, "S", 1); + SetMouseSpeed(mouse.baudrate, mouse.baudrate, + mousecflags[P_MM]); + /* select report rate/frequency */ + if (mouse.rate <= 0) + write(mouse.mfd, "O", 1); + else if (mouse.rate <= 15) + write(mouse.mfd, "J", 1); + else if (mouse.rate <= 27) + write(mouse.mfd, "K", 1); + else if (mouse.rate <= 42) + write(mouse.mfd, "L", 1); + else if (mouse.rate <= 60) + write(mouse.mfd, "R", 1); + else if (mouse.rate <= 85) + write(mouse.mfd, "M", 1); + else if (mouse.rate <= 125) + write(mouse.mfd, "Q", 1); + else + write(mouse.mfd, "N", 1); + break; + + case P_LOGIMAN: + /* The command must always be sent at 1200 baud */ + SetMouseSpeed(1200, 1200, mousecflags[mouse.proto]); + write(mouse.mfd, "*X", 2); + SetMouseSpeed(1200, mouse.baudrate, mousecflags[mouse.proto]); + break; + + case P_MMHIT: + SetMouseSpeed(1200, mouse.baudrate, mousecflags[mouse.proto]); + + /* + * Initialize Hitachi PUMA Plus - Model 1212E to desired settings. + * The tablet must be configured to be in MM mode, NO parity, + * Binary Format. xf86Info.sampleRate controls the sensativity + * of the tablet. We only use this tablet for it's 4-button puck + * so we don't run in "Absolute Mode" + */ + write(mouse.mfd, "z8", 2); /* Set Parity = "NONE" */ + usleep(50000); + write(mouse.mfd, "zb", 2); /* Set Format = "Binary" */ + usleep(50000); + write(mouse.mfd, "@", 1); /* Set Report Mode = "Stream" */ + usleep(50000); + write(mouse.mfd, "R", 1); /* Set Output Rate = "45 rps" */ + usleep(50000); + write(mouse.mfd, "I\x20", 2); /* Set Incrememtal Mode "20" */ + usleep(50000); + write(mouse.mfd, "E", 1); /* Set Data Type = "Relative */ + usleep(50000); + + /* Resolution is in 'lines per inch' on the Hitachi tablet */ + if (mouse.resolution == MOUSE_RES_LOW) + c = 'g'; + else if (mouse.resolution == MOUSE_RES_MEDIUMLOW) + c = 'e'; + else if (mouse.resolution == MOUSE_RES_MEDIUMHIGH) + c = 'h'; + else if (mouse.resolution == MOUSE_RES_HIGH) + c = 'd'; + else if (mouse.resolution <= 40) + c = 'g'; + else if (mouse.resolution <= 100) + c = 'd'; + else if (mouse.resolution <= 200) + c = 'e'; + else if (mouse.resolution <= 500) + c = 'h'; + else if (mouse.resolution <= 1000) + c = 'j'; + else + c = 'd'; + write(mouse.mfd, &c, 1); + usleep(50000); + + write(mouse.mfd, "\021", 1); /* Resume DATA output */ break; - read(mouse.mfd, &c, 1); - debug("%c", c); - if (c != *s) - break; - } - break; - case P_MSC: - SetMouseSpeed(1200, mouse.baudrate, mousecflags[mouse.proto]); + case P_THINKING: + SetMouseSpeed(1200, mouse.baudrate, mousecflags[mouse.proto]); + /* the PnP ID string may be sent again, discard it */ + usleep(200000); + i = FREAD; + ioctl(mouse.mfd, TIOCFLUSH, &i); + /* send the command to initialize the beast */ + for (s = "E5E5"; *s; ++s) { + write(mouse.mfd, s, 1); + + if (poll(pfd, 1, INFTIM) <= 0) + break; + read(mouse.mfd, &c, 1); + debug("%c", c); + if (c != *s) + break; + } + break; + + case P_MSC: + SetMouseSpeed(1200, mouse.baudrate, mousecflags[mouse.proto]); #if 0 - if (mouse.flags & ClearDTR) { - i = TIOCM_DTR; - ioctl(mouse.mfd, TIOCMBIC, &i); - } - if (mouse.flags & ClearRTS) { - i = TIOCM_RTS; - ioctl(mouse.mfd, TIOCMBIC, &i); - } + if (mouse.flags & ClearDTR) { + i = TIOCM_DTR; + ioctl(mouse.mfd, TIOCMBIC, &i); + } + if (mouse.flags & ClearRTS) { + i = TIOCM_RTS; + ioctl(mouse.mfd, TIOCMBIC, &i); + } #endif - break; + break; - default: - SetMouseSpeed(1200, mouse.baudrate, mousecflags[mouse.proto]); - break; - } + default: + SetMouseSpeed(1200, mouse.baudrate, mousecflags[mouse.proto]); + break; + } } /* mouse_identify : identify the protocol used by the mouse */ int mouse_identify(void) { - char pnpbuf[256];/* PnP identifier string may be up to 256 bytes long */ - pnpid_t pnpid; - symtab_t *t; - int len; + char pnpbuf[256]; /* PnP identifier string may be up to + * 256 bytes long */ + pnpid_t pnpid; + symtab_t *t; + int len; /* protocol has been specified with '-t' */ if (mouse.proto != P_UNKNOWN) bcopy(proto[mouse.proto], cur_proto, sizeof(cur_proto)); - else { + else { /* maybe this is an PnP mouse... */ if (mouse.flags & NoPnP) return mouse.proto; - if (((len = pnpgets(mouse.mfd, pnpbuf)) <= 0) - || !pnpparse(&pnpid, pnpbuf, len)) + if (((len = pnpgets(mouse.mfd, pnpbuf)) <= 0) + || !pnpparse(&pnpid, pnpbuf, len)) return mouse.proto; debug("PnP serial mouse: '%*.*s' '%*.*s' '%*.*s'", - pnpid.neisaid, pnpid.neisaid, - pnpid.eisaid, pnpid.ncompat, - pnpid.ncompat, pnpid.compat, - pnpid.ndescription, pnpid.ndescription, - pnpid.description); + pnpid.neisaid, pnpid.neisaid, + pnpid.eisaid, pnpid.ncompat, + pnpid.ncompat, pnpid.compat, + pnpid.ndescription, pnpid.ndescription, + pnpid.description); /* we have a valid PnP serial device ID */ t = pnpproto(&pnpid); if (t != NULL) { mouse.proto = t->val; bcopy(proto[mouse.proto], cur_proto, sizeof(cur_proto)); - } - else + } else mouse.proto = P_UNKNOWN; } debug("proto params: %02x %02x %02x %02x %d %02x %02x", - cur_proto[0], cur_proto[1], cur_proto[2], cur_proto[3], - cur_proto[4], cur_proto[5], cur_proto[6]); + cur_proto[0], cur_proto[1], cur_proto[2], cur_proto[3], + cur_proto[4], cur_proto[5], cur_proto[6]); return mouse.proto; } /* mouse_protocol : decode bytes with the current mouse protocol */ int -mouse_protocol(u_char rBuf, mousestatus_t *act) +mouse_protocol(u_char rBuf, mousestatus_t * act) { /* MOUSE_MSS_BUTTON?DOWN -> MOUSE_BUTTON?DOWN */ - static int butmapmss[4] = { /* Microsoft, MouseMan, GlidePoint, - IntelliMouse, Thinking Mouse */ - 0, - MOUSE_BUTTON3DOWN, - MOUSE_BUTTON1DOWN, - MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, - }; - static int butmapmss2[4] = { /* Microsoft, MouseMan, GlidePoint, - Thinking Mouse */ - 0, - MOUSE_BUTTON4DOWN, - MOUSE_BUTTON2DOWN, - MOUSE_BUTTON2DOWN | MOUSE_BUTTON4DOWN, - }; - /* MOUSE_INTELLI_BUTTON?DOWN -> MOUSE_BUTTON?DOWN */ - static int butmapintelli[4] = { /* IntelliMouse, NetMouse, Mie Mouse, - MouseMan+ */ - 0, - MOUSE_BUTTON2DOWN, - MOUSE_BUTTON4DOWN, - MOUSE_BUTTON2DOWN | MOUSE_BUTTON4DOWN, - }; - /* MOUSE_MSC_BUTTON?UP -> MOUSE_BUTTON?DOWN */ - static int butmapmsc[8] = { /* MouseSystems, MMSeries, Logitech, - Bus, sysmouse */ - 0, - MOUSE_BUTTON3DOWN, - MOUSE_BUTTON2DOWN, - MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN, - MOUSE_BUTTON1DOWN, - MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, - MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN, - MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN - }; - /* for Hitachi tablet */ - static int butmaphit[8] = { /* MM HitTablet */ - 0, - MOUSE_BUTTON3DOWN, - MOUSE_BUTTON2DOWN, - MOUSE_BUTTON1DOWN, - MOUSE_BUTTON4DOWN, - MOUSE_BUTTON5DOWN, - MOUSE_BUTTON6DOWN, - MOUSE_BUTTON7DOWN, - }; - /* for PS/2 VersaPad */ - static int butmapversaps2[8] = { /* VersaPad */ - 0, - MOUSE_BUTTON3DOWN, - 0, - MOUSE_BUTTON3DOWN, - MOUSE_BUTTON1DOWN, - MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, - MOUSE_BUTTON1DOWN, - MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, - }; - static int pBufP = 0; - static unsigned char pBuf[8]; - - debug("received char 0x%x",(int)rBuf); - - /* - * Hack for resyncing: We check here for a package that is: - * a) illegal (detected by wrong data-package header) - * b) invalid (0x80 == -128 and that might be wrong for MouseSystems) - * c) bad header-package - * - * NOTE: b) is a voilation of the MouseSystems-Protocol, since values of - * -128 are allowed, but since they are very seldom we can easily - * use them as package-header with no button pressed. - * NOTE/2: On a PS/2 mouse any byte is valid as a data byte. Furthermore, - * 0x80 is not valid as a header byte. For a PS/2 mouse we skip - * checking data bytes. - * For resyncing a PS/2 mouse we require the two most significant - * bits in the header byte to be 0. These are the overflow bits, - * and in case of an overflow we actually lose sync. Overflows - * are very rare, however, and we quickly gain sync again after - * an overflow condition. This is the best we can do. (Actually, - * we could use bit 0x08 in the header byte for resyncing, since - * that bit is supposed to be always on, but nobody told - * Microsoft...) - */ - - if (pBufP != 0 && ((rBuf & cur_proto[2]) != cur_proto[3] || rBuf == 0x80)) - { - pBufP = 0; /* skip package */ - } - - if (pBufP == 0 && (rBuf & cur_proto[0]) != cur_proto[1]) - return 0; - - /* is there an extra data byte? */ - if (pBufP >= cur_proto[4] && (rBuf & cur_proto[0]) != cur_proto[1]) - { - /* - * Hack for Logitech MouseMan Mouse - Middle button - * - * Unfortunately this mouse has variable length packets: the standard - * Microsoft 3 byte packet plus an optional 4th byte whenever the - * middle button status changes. - * - * We have already processed the standard packet with the movement - * and button info. Now post an event message with the old status - * of the left and right buttons and the updated middle button. - */ + static int butmapmss[4] = { /* Microsoft, MouseMan, + * GlidePoint, IntelliMouse, + * Thinking Mouse */ + 0, + MOUSE_BUTTON3DOWN, + MOUSE_BUTTON1DOWN, + MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, + }; + static int butmapmss2[4] = { /* Microsoft, MouseMan, + * GlidePoint, Thinking Mouse */ + 0, + MOUSE_BUTTON4DOWN, + MOUSE_BUTTON2DOWN, + MOUSE_BUTTON2DOWN | MOUSE_BUTTON4DOWN, + }; + /* MOUSE_INTELLI_BUTTON?DOWN -> MOUSE_BUTTON?DOWN */ + static int butmapintelli[4] = { /* IntelliMouse, NetMouse, + * Mie Mouse, MouseMan+ */ + 0, + MOUSE_BUTTON2DOWN, + MOUSE_BUTTON4DOWN, + MOUSE_BUTTON2DOWN | MOUSE_BUTTON4DOWN, + }; + /* MOUSE_MSC_BUTTON?UP -> MOUSE_BUTTON?DOWN */ + static int butmapmsc[8] = { /* MouseSystems, MMSeries, + * Logitech, Bus, sysmouse */ + 0, + MOUSE_BUTTON3DOWN, + MOUSE_BUTTON2DOWN, + MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN, + MOUSE_BUTTON1DOWN, + MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, + MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN, + MOUSE_BUTTON1DOWN | MOUSE_BUTTON2DOWN | MOUSE_BUTTON3DOWN + }; + /* for Hitachi tablet */ + static int butmaphit[8] = { /* MM HitTablet */ + 0, + MOUSE_BUTTON3DOWN, + MOUSE_BUTTON2DOWN, + MOUSE_BUTTON1DOWN, + MOUSE_BUTTON4DOWN, + MOUSE_BUTTON5DOWN, + MOUSE_BUTTON6DOWN, + MOUSE_BUTTON7DOWN, + }; + /* for PS/2 VersaPad */ + static int butmapversaps2[8] = { /* VersaPad */ + 0, + MOUSE_BUTTON3DOWN, + 0, + MOUSE_BUTTON3DOWN, + MOUSE_BUTTON1DOWN, + MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, + MOUSE_BUTTON1DOWN, + MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN, + }; + static int pBufP = 0; + static unsigned char pBuf[8]; + + debug("received char 0x%x", (int) rBuf); /* - * Even worse, different MouseMen and TrackMen differ in the 4th - * byte: some will send 0x00/0x20, others 0x01/0x21, or even - * 0x02/0x22, so I have to strip off the lower bits. + * Hack for resyncing: We check here for a package that is: + * a) illegal (detected by wrong data-package header) + * b) invalid (0x80 == -128 and that might be wrong for MouseSystems) + * c) bad header-package * - * [JCH-96/01/21] - * HACK for ALPS "fourth button". (It's bit 0x10 of the "fourth byte" - * and it is activated by tapping the glidepad with the finger! 8^) - * We map it to bit bit3, and the reverse map in xf86Events just has - * to be extended so that it is identified as Button 4. The lower - * half of the reverse-map may remain unchanged. - */ + * NOTE: b) is a voilation of the MouseSystems-Protocol, since values of + * -128 are allowed, but since they are very seldom we can easily + * use them as package-header with no button pressed. + * NOTE/2: On a PS/2 mouse any byte is valid as a data byte. Furthermore, + * 0x80 is not valid as a header byte. For a PS/2 mouse we skip + * checking data bytes. + * For resyncing a PS/2 mouse we require the two most significant + * bits in the header byte to be 0. These are the overflow bits, + * and in case of an overflow we actually lose sync. Overflows + * are very rare, however, and we quickly gain sync again after + * an overflow condition. This is the best we can do. (Actually, + * we could use bit 0x08 in the header byte for resyncing, since + * that bit is supposed to be always on, but nobody told + * Microsoft...) + */ + + if (pBufP != 0 && ((rBuf & cur_proto[2]) != cur_proto[3] || rBuf == 0x80)) { + pBufP = 0; /* skip package */ + } + if (pBufP == 0 && (rBuf & cur_proto[0]) != cur_proto[1]) + return 0; - /* - * [KY-97/08/03] - * Receive the fourth byte only when preceeding three bytes have - * been detected (pBufP >= cur_proto[4]). In the previous - * versions, the test was pBufP == 0; thus, we may have mistakingly - * received a byte even if we didn't see anything preceeding - * the byte. - */ + /* is there an extra data byte? */ + if (pBufP >= cur_proto[4] && (rBuf & cur_proto[0]) != cur_proto[1]) { + /* + * Hack for Logitech MouseMan Mouse - Middle button + * + * Unfortunately this mouse has variable length packets: the standard + * Microsoft 3 byte packet plus an optional 4th byte whenever the + * middle button status changes. + * + * We have already processed the standard packet with the movement + * and button info. Now post an event message with the old status + * of the left and right buttons and the updated middle button. + */ + + /* + * Even worse, different MouseMen and TrackMen differ in the 4th + * byte: some will send 0x00/0x20, others 0x01/0x21, or even + * 0x02/0x22, so I have to strip off the lower bits. + * + * [JCH-96/01/21] + * HACK for ALPS "fourth button". (It's bit 0x10 of the "fourth byte" + * and it is activated by tapping the glidepad with the finger! 8^) + * We map it to bit bit3, and the reverse map in xf86Events just has + * to be extended so that it is identified as Button 4. The lower + * half of the reverse-map may remain unchanged. + */ + + /* + * [KY-97/08/03] + * Receive the fourth byte only when preceeding three bytes have + * been detected (pBufP >= cur_proto[4]). In the previous + * versions, the test was pBufP == 0; thus, we may have mistakingly + * received a byte even if we didn't see anything preceeding + * the byte. + */ + + if ((rBuf & cur_proto[5]) != cur_proto[6]) { + pBufP = 0; + return 0; + } + switch (mouse.proto) { + + /* + * IntelliMouse, NetMouse (including NetMouse Pro) and Mie Mouse + * always send the fourth byte, whereas the fourth byte is + * optional for GlidePoint and ThinkingMouse. The fourth byte + * is also optional for MouseMan+ and FirstMouse+ in their + * native mode. It is always sent if they are in the IntelliMouse + * compatible mode. + */ + case P_IMSERIAL: /* IntelliMouse, NetMouse, Mie Mouse, + * MouseMan+ */ + act->dx = act->dy = 0; + act->dz = (rBuf & 0x08) ? (rBuf & 0x0f) - 16 : (rBuf & 0x0f); + act->obutton = act->button; + act->button = butmapintelli[(rBuf & MOUSE_MSS_BUTTONS) >> 4] + | (act->obutton & (MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN)); + break; + + default: + act->dx = act->dy = act->dz = 0; + act->obutton = act->button; + act->button = butmapmss2[(rBuf & MOUSE_MSS_BUTTONS) >> 4] + | (act->obutton & (MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN)); + break; + } - if ((rBuf & cur_proto[5]) != cur_proto[6]) { - pBufP = 0; - return 0; + act->flags = ((act->dx || act->dy || act->dz) ? MOUSE_POSCHANGED : 0) + | (act->obutton ^ act->button); + pBufP = 0; + return act->flags; } - - switch (mouse.proto) { + if (pBufP >= cur_proto[4]) + pBufP = 0; + pBuf[pBufP++] = rBuf; + if (pBufP != cur_proto[4]) + return 0; /* - * IntelliMouse, NetMouse (including NetMouse Pro) and Mie Mouse - * always send the fourth byte, whereas the fourth byte is - * optional for GlidePoint and ThinkingMouse. The fourth byte - * is also optional for MouseMan+ and FirstMouse+ in their - * native mode. It is always sent if they are in the IntelliMouse - * compatible mode. - */ + * assembly full package + */ + + debug("assembled full packet (len %d) %x,%x,%x,%x,%x,%x,%x,%x", + cur_proto[4], + pBuf[0], pBuf[1], pBuf[2], pBuf[3], + pBuf[4], pBuf[5], pBuf[6], pBuf[7]); + + act->dz = 0; + act->obutton = act->button; + switch (mouse.proto) { + case P_MS: /* Microsoft */ + case P_LOGIMAN: /* MouseMan/TrackMan */ + case P_GLIDEPOINT: /* GlidePoint */ + case P_THINKING: /* ThinkingMouse */ case P_IMSERIAL: /* IntelliMouse, NetMouse, Mie Mouse, - MouseMan+ */ - act->dx = act->dy = 0; - act->dz = (rBuf & 0x08) ? (rBuf & 0x0f) - 16 : (rBuf & 0x0f); - act->obutton = act->button; - act->button = butmapintelli[(rBuf & MOUSE_MSS_BUTTONS) >> 4] - | (act->obutton & (MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN)); - break; + * MouseMan+ */ + act->button = (act->obutton & (MOUSE_BUTTON2DOWN | MOUSE_BUTTON4DOWN)) + | butmapmss[(pBuf[0] & MOUSE_MSS_BUTTONS) >> 4]; + act->dx = (char) (((pBuf[0] & 0x03) << 6) | (pBuf[1] & 0x3F)); + act->dy = (char) (((pBuf[0] & 0x0C) << 4) | (pBuf[2] & 0x3F)); + break; + + case P_MSC: /* MouseSystems Corp */ + act->button = butmapmsc[(~pBuf[0]) & MOUSE_MSC_BUTTONS]; + act->dx = (char) (pBuf[1]) + (char) (pBuf[3]); + act->dy = -((char) (pBuf[2]) + (char) (pBuf[4])); + break; + + case P_MMHIT: /* MM HitTablet */ + act->button = butmaphit[pBuf[0] & 0x07]; + act->dx = (pBuf[0] & MOUSE_MM_XPOSITIVE) ? pBuf[1] : -pBuf[1]; + act->dy = (pBuf[0] & MOUSE_MM_YPOSITIVE) ? -pBuf[2] : pBuf[2]; + break; + + case P_MM: /* MM Series */ + case P_LOGI: /* Logitech Mice */ + act->button = butmapmsc[pBuf[0] & MOUSE_MSC_BUTTONS]; + act->dx = (pBuf[0] & MOUSE_MM_XPOSITIVE) ? pBuf[1] : -pBuf[1]; + act->dy = (pBuf[0] & MOUSE_MM_YPOSITIVE) ? -pBuf[2] : pBuf[2]; + break; + + /* + * XXX removed the code for BusMouse and PS/2 protocols which + * are now handled by wsmouse compatible mouse drivers XXX + */ default: - act->dx = act->dy = act->dz = 0; - act->obutton = act->button; - act->button = butmapmss2[(rBuf & MOUSE_MSS_BUTTONS) >> 4] - | (act->obutton & (MOUSE_BUTTON1DOWN | MOUSE_BUTTON3DOWN)); - break; + return 0; } - act->flags = ((act->dx || act->dy || act->dz) ? MOUSE_POSCHANGED : 0) - | (act->obutton ^ act->button); - pBufP = 0; + /* + * We don't reset pBufP here yet, as there may be an additional data + * byte in some protocols. See above. + */ + /* has something changed? */ + act->flags = ((act->dx || act->dy || act->dz) ? MOUSE_POSCHANGED : 0) | + (act->obutton ^ act->button); return act->flags; - } - - if (pBufP >= cur_proto[4]) - pBufP = 0; - pBuf[pBufP++] = rBuf; - if (pBufP != cur_proto[4]) - return 0; - - /* - * assembly full package - */ - - debug("assembled full packet (len %d) %x,%x,%x,%x,%x,%x,%x,%x", - cur_proto[4], - pBuf[0], pBuf[1], pBuf[2], pBuf[3], - pBuf[4], pBuf[5], pBuf[6], pBuf[7]); - - act->dz = 0; - act->obutton = act->button; - switch (mouse.proto) - { - case P_MS: /* Microsoft */ - case P_LOGIMAN: /* MouseMan/TrackMan */ - case P_GLIDEPOINT: /* GlidePoint */ - case P_THINKING: /* ThinkingMouse */ - case P_IMSERIAL: /* IntelliMouse, NetMouse, Mie Mouse, - MouseMan+ */ - act->button = (act->obutton & (MOUSE_BUTTON2DOWN | MOUSE_BUTTON4DOWN)) - | butmapmss[(pBuf[0] & MOUSE_MSS_BUTTONS) >> 4]; - act->dx = (char)(((pBuf[0] & 0x03) << 6) | (pBuf[1] & 0x3F)); - act->dy = (char)(((pBuf[0] & 0x0C) << 4) | (pBuf[2] & 0x3F)); - break; - - case P_MSC: /* MouseSystems Corp */ - act->button = butmapmsc[(~pBuf[0]) & MOUSE_MSC_BUTTONS]; - act->dx = (char)(pBuf[1]) + (char)(pBuf[3]); - act->dy = - ((char)(pBuf[2]) + (char)(pBuf[4])); - break; - - case P_MMHIT: /* MM HitTablet */ - act->button = butmaphit[pBuf[0] & 0x07]; - act->dx = (pBuf[0] & MOUSE_MM_XPOSITIVE) ? pBuf[1] : - pBuf[1]; - act->dy = (pBuf[0] & MOUSE_MM_YPOSITIVE) ? - pBuf[2] : pBuf[2]; - break; - - case P_MM: /* MM Series */ - case P_LOGI: /* Logitech Mice */ - act->button = butmapmsc[pBuf[0] & MOUSE_MSC_BUTTONS]; - act->dx = (pBuf[0] & MOUSE_MM_XPOSITIVE) ? pBuf[1] : - pBuf[1]; - act->dy = (pBuf[0] & MOUSE_MM_YPOSITIVE) ? - pBuf[2] : pBuf[2]; - break; - - /* XXX - * removed the code for BusMouse and PS/2 protocols - * which are now handled by wsmouse compatible mouse drivers - * XXX - */ - - default: - return 0; - } - - /* - * We don't reset pBufP here yet, as there may be an additional data - * byte in some protocols. See above. - */ - - /* has something changed? */ - act->flags = ((act->dx || act->dy || act->dz) ? MOUSE_POSCHANGED : 0) - | (act->obutton ^ act->button); - - return act->flags; } - diff --git a/usr.sbin/wsmoused/mouse_protocols.h b/usr.sbin/wsmoused/mouse_protocols.h index 2ac9abe1158..df26194e32a 100644 --- a/usr.sbin/wsmoused/mouse_protocols.h +++ b/usr.sbin/wsmoused/mouse_protocols.h @@ -1,12 +1,12 @@ -/* $OpenBSD: mouse_protocols.h,v 1.1 2001/04/14 04:47:41 aaron Exp $ */ +/* $OpenBSD: mouse_protocols.h,v 1.2 2002/02/15 02:18:39 deraadt Exp $ */ /* * Copyright (c) 2001 Jean-Baptiste Marchand, Julien Montagne and Jerome Verdon - * + * * Copyright (c) 1998 by Kazutaka Yokota * * Copyright (c) 1995 Michael Smith - * + * * Copyright (c) 1993 by David Dawes <dawes@xfree86.org> * * Copyright (c) 1990,91 by Thomas Roell, Dinkelscherben, Germany. @@ -14,12 +14,12 @@ * All rights reserved. * * Most of this code was taken from the FreeBSD moused daemon, written by - * Michael Smith. The FreeBSD moused daemon already contained code from the + * Michael Smith. The FreeBSD moused daemon already contained code from the * Xfree Project, written by David Dawes and Thomas Roell and Kazutaka Yokota. * * Adaptation to OpenBSD was done by Jean-Baptiste Marchand, Julien Montagne * and Jerome Verdon. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -78,13 +78,13 @@ #define MOUSE_BUTTONS 0x00FF #define MOUSE_POSCHANGED 0x0100 -/* - * List of all the protocols parameters +/* + * List of all the protocols parameters * The parameters are : * - size of the packet - * - synchronization mask + * - synchronization mask * - synchronization value (must be equal to data ANDed with SYNCMASK) - * - mask of buttons + * - mask of buttons * - mask of each button separetely */ @@ -146,23 +146,23 @@ /* Mouse resolutions */ -#define MOUSE_RES_DEFAULT 254 +#define MOUSE_RES_DEFAULT 254 #define MOUSE_RES_UNKNOWN 255 -#define MOUSE_RES_LOW 0 +#define MOUSE_RES_LOW 0 #define MOUSE_RES_MEDIUMLOW 1 #define MOUSE_RES_MEDIUMHIGH 2 #define MOUSE_RES_HIGH 3 /* Mouse report rates */ -#define MOUSE_RATE_UNKNOWN 255 +#define MOUSE_RATE_UNKNOWN 255 #define MOUSE_RATE_DEFAULT 80 #define MOUSE_RATE_VERY_LOW 20 #define MOUSE_RATE_LOW 40 #define MOUSE_RATE_MEDIUM_LOW 60 #define MOUSE_RATE_MEDIUM_HIGH 80 #define MOUSE_RATE_HIGH 100 -#define MOUSE_RATE_VERY_HIGH 200 +#define MOUSE_RATE_VERY_HIGH 200 /* serial PnP ID string */ typedef struct { diff --git a/usr.sbin/wsmoused/wsmoused.c b/usr.sbin/wsmoused/wsmoused.c index e5b2691b44a..930c9e3003f 100644 --- a/usr.sbin/wsmoused/wsmoused.c +++ b/usr.sbin/wsmoused/wsmoused.c @@ -1,12 +1,12 @@ -/* $OpenBSD: wsmoused.c,v 1.8 2002/01/12 01:15:37 miod Exp $ */ +/* $OpenBSD: wsmoused.c,v 1.9 2002/02/15 02:18:39 deraadt Exp $ */ /* * Copyright (c) 2001 Jean-Baptiste Marchand, Julien Montagne and Jerome Verdon - * + * * Copyright (c) 1998 by Kazutaka Yokota * * Copyright (c) 1995 Michael Smith - * + * * Copyright (c) 1993 by David Dawes <dawes@xfree86.org> * * Copyright (c) 1990,91 by Thomas Roell, Dinkelscherben, Germany. @@ -14,12 +14,12 @@ * All rights reserved. * * Most of this code was taken from the FreeBSD moused daemon, written by - * Michael Smith. The FreeBSD moused daemon already contained code from the + * Michael Smith. The FreeBSD moused daemon already contained code from the * Xfree Project, written by David Dawes and Thomas Roell and Kazutaka Yokota. * * Adaptation to OpenBSD was done by Jean-Baptiste Marchand, Julien Montagne * and Jerome Verdon. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -55,7 +55,7 @@ #include <sys/time.h> #include <sys/tty.h> #include <dev/wscons/wsconsio.h> - + #include <ctype.h> #include <err.h> #include <errno.h> @@ -72,10 +72,10 @@ #include "mouse_protocols.h" #include "wsmoused.h" - + extern char *__progname; extern char *mouse_names[]; - + int debug = 0; int nodaemon = FALSE; int background = FALSE; @@ -83,29 +83,29 @@ int identify = FALSE; char *pidfile = "/var/run/wsmoused.pid"; mouse_t mouse = { - flags : 0, - portname : NULL, - proto : P_UNKNOWN, - baudrate : 1200, - old_baudrate : 1200, - rate : MOUSE_RATE_UNKNOWN, - resolution : MOUSE_RES_UNKNOWN, - zmap : 0, - wmode : 0, - mfd : -1, - clickthreshold : 500, /* 0.5 sec */ + flags : 0, + portname : NULL, + proto : P_UNKNOWN, + baudrate : 1200, + old_baudrate : 1200, + rate : MOUSE_RATE_UNKNOWN, + resolution : MOUSE_RES_UNKNOWN, + zmap : 0, + wmode : 0, + mfd : -1, + clickthreshold : 500, /* 0.5 sec */ }; /* identify the type of a wsmouse supported mouse */ -void +void wsmouse_identify(void) { unsigned int type; - + if (mouse.mfd != -1) { if (ioctl(mouse.mfd, WSMOUSEIO_GTYPE, &type) == -1) err(1, "can't detect mouse type"); - printf("wsmouse supported mouse: "); + printf("wsmouse supported mouse: "); switch (type) { case WSMOUSE_TYPE_VSXXX: printf("DEC serial\n"); @@ -138,20 +138,17 @@ wsmouse_identify(void) } else warnx("unable to open %s\n", mouse.portname); } - - /* wsmouse_init : init a wsmouse compatible mouse */ void wsmouse_init(void) { unsigned int res = WSMOUSE_RES_MIN; - unsigned int rate = WSMOUSE_RATE_DEFAULT; + unsigned int rate = WSMOUSE_RATE_DEFAULT; ioctl(mouse.mfd, WSMOUSEIO_SRES, &res); ioctl(mouse.mfd, WSMOUSEIO_SRATE, &rate); -} - +} /* * Buttons remapping @@ -162,11 +159,11 @@ static int p2l[MOUSE_MAXBUTTON] = { MOUSE_BUTTON1, MOUSE_BUTTON2, MOUSE_BUTTON3, MOUSE_BUTTON4, MOUSE_BUTTON5, MOUSE_BUTTON6, MOUSE_BUTTON7, MOUSE_BUTTON8, }; - + static char * skipspace(char *s) { - while(isspace(*s)) + while (isspace(*s)) ++s; return s; } @@ -203,7 +200,6 @@ mouse_installmap(char *arg) return FALSE; p2l[pbutton - 1] = lbutton - 1; } - return TRUE; } @@ -212,7 +208,7 @@ static void mouse_map(struct wscons_event *orig, struct wscons_event *mapped) { mapped->type = orig->type; - mapped->value = p2l[orig->value]; + mapped->value = p2l[orig->value]; } /* terminate signals handler */ @@ -240,9 +236,9 @@ static struct { struct timeval tv; /* timestamp on the last `up' event */ } buttonstate[MOUSE_MAXBUTTON]; -/* - * handle button click - * Note that an ioctl is sent for each button +/* + * handle button click + * Note that an ioctl is sent for each button */ static void mouse_click(struct wscons_event *event) @@ -252,12 +248,12 @@ mouse_click(struct wscons_event *event) struct timeval delay; struct timezone tz; int i = event->value; /* button number */ - - gettimeofday(&now, &tz); + + gettimeofday(&now, &tz); delay.tv_sec = mouse.clickthreshold / 1000; delay.tv_usec = (mouse.clickthreshold % 1000) * 1000; - timersub(&now, &delay, &max_date); - + timersub(&now, &delay, &max_date); + if (event->type == WSCONS_EVENT_MOUSE_DOWN) { if (timercmp(&max_date, &buttonstate[i].tv, >)) { buttonstate[i].tv.tv_sec = 0; @@ -271,10 +267,10 @@ mouse_click(struct wscons_event *event) buttonstate[i].tv.tv_sec = now.tv_sec; buttonstate[i].tv.tv_usec = now.tv_usec; } - - /* + + /* * we use the time field of wscons_event structure to put the number - * of multiple clicks + * of multiple clicks */ if (event->type == WSCONS_EVENT_MOUSE_DOWN) { event->time.tv_sec = buttonstate[i].count; @@ -287,7 +283,6 @@ mouse_click(struct wscons_event *event) ioctl(mouse.cfd, WSDISPLAYIO_WSMOUSED, event); } - /* workaround for cursor speed on serial mice */ static void normalize_event(struct wscons_event *event) @@ -302,7 +297,7 @@ normalize_event(struct wscons_event *event) case WSCONS_EVENT_MOUSE_DELTA_X: dx = abs(event->value); while (dx > 2) { - two_power++; + two_power++; dx = dx / 2; } event->value = event->value / (NORMALIZE_DIVISOR * two_power); @@ -311,7 +306,7 @@ normalize_event(struct wscons_event *event) two_power = 1; dy = abs(event->value); while (dy > 2) { - two_power++; + two_power++; dy = dy / 2; } event->value = event->value / (NORMALIZE_DIVISOR * two_power); @@ -320,7 +315,7 @@ normalize_event(struct wscons_event *event) } /* send a wscons_event to the kernel */ -static void +static void treat_event(struct wscons_event *event) { struct wscons_event mapped_event; @@ -333,9 +328,8 @@ treat_event(struct wscons_event *event) } } - /* split a full mouse event into multiples wscons events */ -static void +static void split_event(mousestatus_t *act) { struct wscons_event event; @@ -359,8 +353,8 @@ split_event(mousestatus_t *act) treat_event(&event); } - /* buttons state */ - mask = act->flags & MOUSE_BUTTONS; + /* buttons state */ + mask = act->flags & MOUSE_BUTTONS; if (mask == 0) /* no button modified */ return; @@ -376,7 +370,6 @@ split_event(mousestatus_t *act) button <<= 1; mask >>= 1; } - } /* main function */ @@ -407,18 +400,18 @@ wsmoused(void) logerr(1, "cannot open /dev/ttyCcfg"); /* initialization */ - + event.type = WSCONS_EVENT_WSMOUSED_ON; res = ioctl(mouse.cfd, WSDISPLAYIO_WSMOUSED, &event); if (res != 0) { /* the display driver has no getchar() method */ logerr(1, "this display driver has no support for wsmoused"); } - + bzero(&action, sizeof(action)); bzero(&event, sizeof(event)); bzero(&buttonstate, sizeof(buttonstate)); - + pfd[0].fd = mouse.mfd; pfd[0].events = POLLIN; @@ -429,11 +422,11 @@ wsmoused(void) if (IS_WSMOUSE_DEV(mouse.portname)) { /* wsmouse supported mouse */ read(mouse.mfd, &event, sizeof(event)); - treat_event(&event); + treat_event(&event); } else { /* serial mouse (not wsmouse supported) */ res = read(mouse.mfd, &b, 1); - + /* if we have a full mouse event */ if (mouse_protocol(b, &action)) /* split it as multiple wscons_event */ @@ -441,9 +434,9 @@ wsmoused(void) } } } - -static void + +static void usage(void) { fprintf(stderr, "usage: %s [-2df] [-t protocol] [-C threshold] [-I file] \ @@ -452,7 +445,7 @@ usage(void) exit(1); } -int +int main(int argc, char **argv) { int opt; @@ -500,7 +493,7 @@ main(int argc, char **argv) case 'C': #define MAX_CLICKTHRESHOLD 2000 /* max delay for double click */ mouse.clickthreshold = atoi(optarg); - if (mouse.clickthreshold < 0 || + if (mouse.clickthreshold < 0 || mouse.clickthreshold > MAX_CLICKTHRESHOLD) { warnx("invalid threshold `%s': max value is %d\n", optarg, MAX_CLICKTHRESHOLD); @@ -523,7 +516,7 @@ main(int argc, char **argv) if (mouse.portname == NULL) /* default is /dev/wsmouse */ mouse.portname = WSMOUSE_DEV; - + if (!nodaemon) openlog(__progname, LOG_PID, LOG_DAEMON); @@ -532,8 +525,8 @@ main(int argc, char **argv) signal(SIGQUIT, terminate); signal(SIGTERM, terminate); signal(SIGKILL, terminate); - if ((mouse.mfd = open(mouse.portname, - O_RDONLY | O_NONBLOCK, 0)) == -1) + if ((mouse.mfd = open(mouse.portname, + O_RDONLY | O_NONBLOCK, 0)) == -1) logerr(1, "unable to open %s", mouse.portname); if (IS_SERIAL_DEV(mouse.portname)) { if (mouse_identify() == P_UNKNOWN) { @@ -544,15 +537,15 @@ main(int argc, char **argv) } if (identify == TRUE) { - if (IS_WSMOUSE_DEV(mouse.portname)) + if (IS_WSMOUSE_DEV(mouse.portname)) wsmouse_identify(); - else + else printf("serial mouse: %s type\n", (char *)mouse_name(mouse.proto)); exit(0); } - mouse_init(); + mouse_init(); wsmoused(); } } diff --git a/usr.sbin/wsmoused/wsmoused.h b/usr.sbin/wsmoused/wsmoused.h index 412dd38d3a4..9f756c81bf3 100644 --- a/usr.sbin/wsmoused/wsmoused.h +++ b/usr.sbin/wsmoused/wsmoused.h @@ -1,12 +1,12 @@ -/* $OpenBSD: wsmoused.h,v 1.3 2002/01/12 01:15:37 miod Exp $ */ +/* $OpenBSD: wsmoused.h,v 1.4 2002/02/15 02:18:39 deraadt Exp $ */ /* * Copyright (c) 2001 Jean-Baptiste Marchand, Julien Montagne and Jerome Verdon - * + * * Copyright (c) 1998 by Kazutaka Yokota * * Copyright (c) 1995 Michael Smith - * + * * Copyright (c) 1993 by David Dawes <dawes@xfree86.org> * * Copyright (c) 1990,91 by Thomas Roell, Dinkelscherben, Germany. @@ -14,12 +14,12 @@ * All rights reserved. * * Most of this code was taken from the FreeBSD moused daemon, written by - * Michael Smith. The FreeBSD moused daemon already contained code from the + * Michael Smith. The FreeBSD moused daemon already contained code from the * Xfree Project, written by David Dawes and Thomas Roell and Kazutaka Yokota. * * Adaptation to OpenBSD was done by Jean-Baptiste Marchand, Julien Montagne * and Jerome Verdon. - * + * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions * are met: @@ -80,7 +80,7 @@ extern char *pidfile; /* Daemon flags */ -#define ChordMiddle 0x0001 /* avoid bug reporting middle button as down +#define ChordMiddle 0x0001 /* avoid bug reporting middle button as down when left and right are pressed */ #define Emulate3Button 0x0002 /* option to emulate a third button */ #define ClearDTR 0x0004 /* for mousesystems protocol (3 button mouse) */ @@ -94,7 +94,7 @@ extern char *pidfile; #define IS_WSMOUSE_DEV(dev) (!(strncmp((dev), WSMOUSE_DEV,12))) #define IS_SERIAL_DEV(dev) (!(strncmp((dev), SERIAL_DEV, 9))) - + /* mouse structure : main structure */ typedef struct mouse_s { int flags; @@ -121,5 +121,5 @@ typedef struct mouse_s { #define MOUSE_BUTTON6 5 #define MOUSE_BUTTON7 6 #define MOUSE_BUTTON8 7 -#define MOUSE_MAXBUTTON 8 +#define MOUSE_MAXBUTTON 8 |