diff --git a/sys/dev/usb/ums.c b/sys/dev/usb/ums.c index ff9ab5a538ae..75b8c7c9dd49 100644 --- a/sys/dev/usb/ums.c +++ b/sys/dev/usb/ums.c @@ -1,826 +1,855 @@ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * 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. */ #include __FBSDID("$FreeBSD$"); /* * HID spec: http://www.usb.org/developers/devclass_docs/HID1_11.pdf */ #include #include #include #include #include #include #include #include #include #include #if __FreeBSD_version >= 500014 #include #else #include #endif #include #include #include #include #include #include #include #include "usbdevs.h" #include #include #if __FreeBSD_version >= 500000 #include #else #include #endif #ifdef USB_DEBUG #define DPRINTF(x) if (umsdebug) logprintf x #define DPRINTFN(n,x) if (umsdebug>(n)) logprintf x int umsdebug = 0; SYSCTL_NODE(_hw_usb, OID_AUTO, ums, CTLFLAG_RW, 0, "USB ums"); SYSCTL_INT(_hw_usb_ums, OID_AUTO, debug, CTLFLAG_RW, &umsdebug, 0, "ums debug level"); #else #define DPRINTF(x) #define DPRINTFN(n,x) #endif #define UMSUNIT(s) (minor(s)&0x1f) #define MS_TO_TICKS(ms) ((ms) * hz / 1000) #define QUEUE_BUFSIZE 400 /* MUST be divisible by 5 _and_ 8 */ struct ums_softc { device_t sc_dev; /* base device */ usbd_interface_handle sc_iface; /* interface */ usbd_pipe_handle sc_intrpipe; /* interrupt pipe */ int sc_ep_addr; u_char *sc_ibuf; u_int8_t sc_iid; int sc_isize; - struct hid_location sc_loc_x, sc_loc_y, sc_loc_z; + struct hid_location sc_loc_x, sc_loc_y, sc_loc_z, sc_loc_t; struct hid_location *sc_loc_btn; usb_callout_t callout_handle; /* for spurious button ups */ int sc_enabled; int sc_disconnected; /* device is gone */ int flags; /* device configuration */ #define UMS_Z 0x01 /* z direction available */ +#define UMS_T 0x02 /* aa direction available (tilt) */ #define UMS_SPUR_BUT_UP 0x02 /* spurious button up events */ int nbuttons; #define MAX_BUTTONS 7 /* chosen because sc_buttons is u_char */ u_char qbuf[QUEUE_BUFSIZE]; /* must be divisable by 3&4 */ u_char dummy[100]; /* XXX just for safety and for now */ int qcount, qhead, qtail; mousehw_t hw; mousemode_t mode; mousestatus_t status; int state; # define UMS_ASLEEP 0x01 /* readFromDevice is waiting */ # define UMS_SELECT 0x02 /* select is waiting */ struct selinfo rsel; /* process waiting in select */ struct cdev *dev; /* specfs */ }; #define MOUSE_FLAGS_MASK (HIO_CONST|HIO_RELATIVE) #define MOUSE_FLAGS (HIO_RELATIVE) Static void ums_intr(usbd_xfer_handle xfer, usbd_private_handle priv, usbd_status status); Static void ums_add_to_queue(struct ums_softc *sc, - int dx, int dy, int dz, int buttons); + int dx, int dy, int dz, int dt, int buttons); Static void ums_add_to_queue_timeout(void *priv); Static int ums_enable(void *); Static void ums_disable(void *); Static d_open_t ums_open; Static d_close_t ums_close; Static d_read_t ums_read; Static d_ioctl_t ums_ioctl; Static d_poll_t ums_poll; Static struct cdevsw ums_cdevsw = { .d_version = D_VERSION, .d_flags = D_NEEDGIANT, .d_open = ums_open, .d_close = ums_close, .d_read = ums_read, .d_ioctl = ums_ioctl, .d_poll = ums_poll, .d_name = "ums", #if __FreeBSD_version < 500014 .d_bmaj -1 #endif }; USB_DECLARE_DRIVER(ums); USB_MATCH(ums) { USB_MATCH_START(ums, uaa); usb_interface_descriptor_t *id; int size, ret; void *desc; usbd_status err; if (!uaa->iface) return (UMATCH_NONE); id = usbd_get_interface_descriptor(uaa->iface); if (!id || id->bInterfaceClass != UICLASS_HID) return (UMATCH_NONE); err = usbd_read_report_desc(uaa->iface, &desc, &size, M_TEMP); if (err) return (UMATCH_NONE); if (hid_is_collection(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_MOUSE))) ret = UMATCH_IFACECLASS; else ret = UMATCH_NONE; free(desc, M_TEMP); return (ret); } USB_ATTACH(ums) { USB_ATTACH_START(ums, sc, uaa); usbd_interface_handle iface = uaa->iface; usb_interface_descriptor_t *id; usb_endpoint_descriptor_t *ed; int size; void *desc; usbd_status err; char devinfo[1024]; u_int32_t flags; int i; struct hid_location loc_btn; sc->sc_disconnected = 1; sc->sc_iface = iface; id = usbd_get_interface_descriptor(iface); usbd_devinfo(uaa->device, USBD_SHOW_INTERFACE_CLASS, devinfo); USB_ATTACH_SETUP; ed = usbd_interface2endpoint_descriptor(iface, 0); if (!ed) { printf("%s: could not read endpoint descriptor\n", USBDEVNAME(sc->sc_dev)); USB_ATTACH_ERROR_RETURN; } DPRINTFN(10,("ums_attach: bLength=%d bDescriptorType=%d " "bEndpointAddress=%d-%s bmAttributes=%d wMaxPacketSize=%d" " bInterval=%d\n", ed->bLength, ed->bDescriptorType, UE_GET_ADDR(ed->bEndpointAddress), UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN ? "in":"out", UE_GET_XFERTYPE(ed->bmAttributes), UGETW(ed->wMaxPacketSize), ed->bInterval)); if (UE_GET_DIR(ed->bEndpointAddress) != UE_DIR_IN || UE_GET_XFERTYPE(ed->bmAttributes) != UE_INTERRUPT) { printf("%s: unexpected endpoint\n", USBDEVNAME(sc->sc_dev)); USB_ATTACH_ERROR_RETURN; } err = usbd_read_report_desc(uaa->iface, &desc, &size, M_TEMP); if (err) USB_ATTACH_ERROR_RETURN; if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_X), hid_input, &sc->sc_loc_x, &flags)) { printf("%s: mouse has no X report\n", USBDEVNAME(sc->sc_dev)); USB_ATTACH_ERROR_RETURN; } if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) { printf("%s: X report 0x%04x not supported\n", USBDEVNAME(sc->sc_dev), flags); USB_ATTACH_ERROR_RETURN; } if (!hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Y), hid_input, &sc->sc_loc_y, &flags)) { printf("%s: mouse has no Y report\n", USBDEVNAME(sc->sc_dev)); USB_ATTACH_ERROR_RETURN; } if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) { printf("%s: Y report 0x%04x not supported\n", USBDEVNAME(sc->sc_dev), flags); USB_ATTACH_ERROR_RETURN; } /* try to guess the Z activator: first check Z, then WHEEL */ if (hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_Z), hid_input, &sc->sc_loc_z, &flags) || hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_WHEEL), + hid_input, &sc->sc_loc_z, &flags) || + hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_TWHEEL), hid_input, &sc->sc_loc_z, &flags)) { if ((flags & MOUSE_FLAGS_MASK) != MOUSE_FLAGS) { sc->sc_loc_z.size = 0; /* Bad Z coord, ignore it */ } else { sc->flags |= UMS_Z; } } + /* The Microsoft Wireless Intellimouse 2.0 reports it's wheel + * using 0x0048 (i've called it HUG_TWHEEL) and seems to expect + * you to know that the byte after the wheel is the tilt axis. + * There are no other HID axis descriptors other than X,Y and + * TWHEEL */ + if (hid_locate(desc, size, HID_USAGE2(HUP_GENERIC_DESKTOP, HUG_TWHEEL), + hid_input, &sc->sc_loc_t, &flags)) { + sc->sc_loc_t.pos = sc->sc_loc_t.pos + 8; + sc->flags |= UMS_T; + } + /* figure out the number of buttons */ for (i = 1; i <= MAX_BUTTONS; i++) if (!hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i), hid_input, &loc_btn, 0)) break; sc->nbuttons = i - 1; sc->sc_loc_btn = malloc(sizeof(struct hid_location)*sc->nbuttons, M_USBDEV, M_NOWAIT); if (!sc->sc_loc_btn) { printf("%s: no memory\n", USBDEVNAME(sc->sc_dev)); USB_ATTACH_ERROR_RETURN; } - printf("%s: %d buttons%s\n", USBDEVNAME(sc->sc_dev), - sc->nbuttons, sc->flags & UMS_Z? " and Z dir." : ""); + printf("%s: %d buttons%s%s.\n", USBDEVNAME(sc->sc_dev), + sc->nbuttons, sc->flags & UMS_Z? " and Z dir" : "", + sc->flags & UMS_T?" and a TILT dir": ""); for (i = 1; i <= sc->nbuttons; i++) hid_locate(desc, size, HID_USAGE2(HUP_BUTTON, i), hid_input, &sc->sc_loc_btn[i-1], 0); sc->sc_isize = hid_report_size(desc, size, hid_input, &sc->sc_iid); sc->sc_ibuf = malloc(sc->sc_isize, M_USB, M_NOWAIT); if (!sc->sc_ibuf) { printf("%s: no memory\n", USBDEVNAME(sc->sc_dev)); free(sc->sc_loc_btn, M_USB); USB_ATTACH_ERROR_RETURN; } sc->sc_ep_addr = ed->bEndpointAddress; sc->sc_disconnected = 0; free(desc, M_TEMP); #ifdef USB_DEBUG DPRINTF(("ums_attach: sc=%p\n", sc)); DPRINTF(("ums_attach: X\t%d/%d\n", sc->sc_loc_x.pos, sc->sc_loc_x.size)); DPRINTF(("ums_attach: Y\t%d/%d\n", sc->sc_loc_y.pos, sc->sc_loc_y.size)); if (sc->flags & UMS_Z) DPRINTF(("ums_attach: Z\t%d/%d\n", sc->sc_loc_z.pos, sc->sc_loc_z.size)); for (i = 1; i <= sc->nbuttons; i++) { DPRINTF(("ums_attach: B%d\t%d/%d\n", i, sc->sc_loc_btn[i-1].pos,sc->sc_loc_btn[i-1].size)); } DPRINTF(("ums_attach: size=%d, id=%d\n", sc->sc_isize, sc->sc_iid)); #endif if (sc->nbuttons > MOUSE_MSC_MAXBUTTON) sc->hw.buttons = MOUSE_MSC_MAXBUTTON; else sc->hw.buttons = sc->nbuttons; sc->hw.iftype = MOUSE_IF_USB; sc->hw.type = MOUSE_MOUSE; sc->hw.model = MOUSE_MODEL_GENERIC; sc->hw.hwid = 0; sc->mode.protocol = MOUSE_PROTO_MSC; sc->mode.rate = -1; sc->mode.resolution = MOUSE_RES_UNKNOWN; sc->mode.accelfactor = 0; sc->mode.level = 0; sc->mode.packetsize = MOUSE_MSC_PACKETSIZE; sc->mode.syncmask[0] = MOUSE_MSC_SYNCMASK; sc->mode.syncmask[1] = MOUSE_MSC_SYNC; sc->status.flags = 0; sc->status.button = sc->status.obutton = 0; sc->status.dx = sc->status.dy = sc->status.dz = 0; #ifndef __FreeBSD__ sc->rsel.si_flags = 0; sc->rsel.si_pid = 0; #endif sc->dev = make_dev(&ums_cdevsw, device_get_unit(self), UID_ROOT, GID_OPERATOR, 0644, "ums%d", device_get_unit(self)); if (usbd_get_quirks(uaa->device)->uq_flags & UQ_SPUR_BUT_UP) { DPRINTF(("%s: Spurious button up events\n", USBDEVNAME(sc->sc_dev))); sc->flags |= UMS_SPUR_BUT_UP; } USB_ATTACH_SUCCESS_RETURN; } Static int ums_detach(device_t self) { struct ums_softc *sc = device_get_softc(self); if (sc->sc_enabled) ums_disable(sc); DPRINTF(("%s: disconnected\n", USBDEVNAME(self))); free(sc->sc_loc_btn, M_USB); free(sc->sc_ibuf, M_USB); /* someone waiting for data */ /* * XXX If we wakeup the process here, the device will be gone by * the time the process gets a chance to notice. *_close and friends * should be fixed to handle this case. * Or we should do a delayed detach for this. * Does this delay now force tsleep to exit with an error? */ if (sc->state & UMS_ASLEEP) { sc->state &= ~UMS_ASLEEP; wakeup(sc); } if (sc->state & UMS_SELECT) { sc->state &= ~UMS_SELECT; selwakeuppri(&sc->rsel, PZERO); } destroy_dev(sc->dev); return 0; } void ums_intr(xfer, addr, status) usbd_xfer_handle xfer; usbd_private_handle addr; usbd_status status; { struct ums_softc *sc = addr; u_char *ibuf; - int dx, dy, dz; + int dx, dy, dz, dt; u_char buttons = 0; int i; #define UMS_BUT(i) ((i) < 3 ? (((i) + 2) % 3) : (i)) DPRINTFN(5, ("ums_intr: sc=%p status=%d\n", sc, status)); - DPRINTFN(5, ("ums_intr: data = %02x %02x %02x\n", - sc->sc_ibuf[0], sc->sc_ibuf[1], sc->sc_ibuf[2])); + DPRINTFN(5, ("ums_intr: data = %02x %02x %02x %02x %02x %02x\n", + sc->sc_ibuf[0], sc->sc_ibuf[1], sc->sc_ibuf[2], sc->sc_ibuf[3], sc->sc_ibuf[4], sc->sc_ibuf[5])); if (status == USBD_CANCELLED) return; if (status != USBD_NORMAL_COMPLETION) { DPRINTF(("ums_intr: status=%d\n", status)); if (status == USBD_STALLED) usbd_clear_endpoint_stall_async(sc->sc_intrpipe); - return; + if(status != USBD_IOERROR) + return; } ibuf = sc->sc_ibuf; if (sc->sc_iid) { - if (*ibuf++ != sc->sc_iid) - return; + ibuf++; } + /* The M$ Wireless Intellimouse 2.0 sends 1 extra leading byte of + * data compared to most USB mice. This byte frequently switches + * from 0x01 (usual state) to 0x02. I assume it is to allow + * extra, non-standard, reporting (say battery-life). However + * at the same time it generates a left-click message on the button + * byte which causes spurious left-click's where there shouldn't be. + * This should sort that. */ + if ((sc->sc_ibuf != ibuf) && (sc->sc_ibuf[0] == 0x02)) + return; + dx = hid_get_data(ibuf, &sc->sc_loc_x); dy = -hid_get_data(ibuf, &sc->sc_loc_y); dz = -hid_get_data(ibuf, &sc->sc_loc_z); + dt = -hid_get_data(ibuf, &sc->sc_loc_t); for (i = 0; i < sc->nbuttons; i++) if (hid_get_data(ibuf, &sc->sc_loc_btn[i])) buttons |= (1 << UMS_BUT(i)); - if (dx || dy || dz || (sc->flags & UMS_Z) + if (dx || dy || dz || dt || (sc->flags & UMS_Z) || buttons != sc->status.button) { - DPRINTFN(5, ("ums_intr: x:%d y:%d z:%d buttons:0x%x\n", - dx, dy, dz, buttons)); + DPRINTFN(5, ("ums_intr: x:%d y:%d z:%d aa:%d buttons:0x%x\n", + dx, dy, dz, dt, buttons)); sc->status.button = buttons; sc->status.dx += dx; sc->status.dy += dy; sc->status.dz += dz; - + sc->status.dt += dt; + /* Discard data in case of full buffer */ if (sc->qcount == sizeof(sc->qbuf)) { DPRINTF(("Buffer full, discarded packet")); return; } /* * The Qtronix keyboard has a built in PS/2 port for a mouse. * The firmware once in a while posts a spurious button up * event. This event we ignore by doing a timeout for 50 msecs. * If we receive dx=dy=dz=buttons=0 before we add the event to * the queue. * In any other case we delete the timeout event. */ if (sc->flags & UMS_SPUR_BUT_UP && - dx == 0 && dy == 0 && dz == 0 && buttons == 0) { + dx == 0 && dy == 0 && dz == 0 && dt == 0 && buttons == 0) { usb_callout(sc->callout_handle, MS_TO_TICKS(50 /*msecs*/), ums_add_to_queue_timeout, (void *) sc); } else { usb_uncallout(sc->callout_handle, ums_add_to_queue_timeout, (void *) sc); - ums_add_to_queue(sc, dx, dy, dz, buttons); + ums_add_to_queue(sc, dx, dy, dz, dt, buttons); } } } Static void ums_add_to_queue_timeout(void *priv) { struct ums_softc *sc = priv; int s; s = splusb(); - ums_add_to_queue(sc, 0, 0, 0, 0); + ums_add_to_queue(sc, 0, 0, 0, 0, 0); splx(s); } Static void -ums_add_to_queue(struct ums_softc *sc, int dx, int dy, int dz, int buttons) +ums_add_to_queue(struct ums_softc *sc, int dx, int dy, int dz, int dt, int buttons) { /* Discard data in case of full buffer */ if (sc->qhead+sc->mode.packetsize > sizeof(sc->qbuf)) { DPRINTF(("Buffer full, discarded packet")); return; } if (dx > 254) dx = 254; if (dx < -256) dx = -256; if (dy > 254) dy = 254; if (dy < -256) dy = -256; if (dz > 126) dz = 126; if (dz < -128) dz = -128; + if (dt > 126) dt = 126; + if (dt < -128) dt = -128; sc->qbuf[sc->qhead] = sc->mode.syncmask[1]; sc->qbuf[sc->qhead] |= ~buttons & MOUSE_MSC_BUTTONS; sc->qbuf[sc->qhead+1] = dx >> 1; sc->qbuf[sc->qhead+2] = dy >> 1; sc->qbuf[sc->qhead+3] = dx - (dx >> 1); sc->qbuf[sc->qhead+4] = dy - (dy >> 1); if (sc->mode.level == 1) { sc->qbuf[sc->qhead+5] = dz >> 1; sc->qbuf[sc->qhead+6] = dz - (dz >> 1); sc->qbuf[sc->qhead+7] = ((~buttons >> 3) & MOUSE_SYS_EXTBUTTONS); } sc->qhead += sc->mode.packetsize; sc->qcount += sc->mode.packetsize; /* wrap round at end of buffer */ if (sc->qhead >= sizeof(sc->qbuf)) sc->qhead = 0; /* someone waiting for data */ if (sc->state & UMS_ASLEEP) { sc->state &= ~UMS_ASLEEP; wakeup(sc); } if (sc->state & UMS_SELECT) { sc->state &= ~UMS_SELECT; selwakeuppri(&sc->rsel, PZERO); } } Static int ums_enable(v) void *v; { struct ums_softc *sc = v; usbd_status err; if (sc->sc_enabled) return EBUSY; sc->sc_enabled = 1; sc->qcount = 0; sc->qhead = sc->qtail = 0; sc->status.flags = 0; sc->status.button = sc->status.obutton = 0; - sc->status.dx = sc->status.dy = sc->status.dz = 0; + sc->status.dx = sc->status.dy = sc->status.dz = sc->status.dt = 0; callout_handle_init((struct callout_handle *)&sc->callout_handle); /* Set up interrupt pipe. */ err = usbd_open_pipe_intr(sc->sc_iface, sc->sc_ep_addr, USBD_SHORT_XFER_OK, &sc->sc_intrpipe, sc, sc->sc_ibuf, sc->sc_isize, ums_intr, USBD_DEFAULT_INTERVAL); if (err) { DPRINTF(("ums_enable: usbd_open_pipe_intr failed, error=%d\n", err)); sc->sc_enabled = 0; return (EIO); } return (0); } Static void ums_disable(priv) void *priv; { struct ums_softc *sc = priv; usb_uncallout(sc->callout_handle, ums_add_to_queue_timeout, sc); /* Disable interrupts. */ usbd_abort_pipe(sc->sc_intrpipe); usbd_close_pipe(sc->sc_intrpipe); sc->sc_enabled = 0; if (sc->qcount != 0) DPRINTF(("Discarded %d bytes in queue\n", sc->qcount)); } Static int ums_open(struct cdev *dev, int flag, int fmt, usb_proc_ptr p) { struct ums_softc *sc; USB_GET_SC_OPEN(ums, UMSUNIT(dev), sc); return ums_enable(sc); } Static int ums_close(struct cdev *dev, int flag, int fmt, usb_proc_ptr p) { struct ums_softc *sc; USB_GET_SC(ums, UMSUNIT(dev), sc); if (!sc) return 0; if (sc->sc_enabled) ums_disable(sc); return 0; } Static int ums_read(struct cdev *dev, struct uio *uio, int flag) { struct ums_softc *sc; int s; char buf[sizeof(sc->qbuf)]; int l = 0; int error; USB_GET_SC(ums, UMSUNIT(dev), sc); s = splusb(); if (!sc) { splx(s); return EIO; } while (sc->qcount == 0 ) { if (flag & IO_NDELAY) { /* non-blocking I/O */ splx(s); return EWOULDBLOCK; } sc->state |= UMS_ASLEEP; /* blocking I/O */ error = tsleep(sc, PZERO | PCATCH, "umsrea", 0); if (error) { splx(s); return error; } else if (!sc->sc_enabled) { splx(s); return EINTR; } /* check whether the device is still there */ sc = devclass_get_softc(ums_devclass, UMSUNIT(dev)); if (!sc) { splx(s); return EIO; } } /* * XXX we could optimise the use of splx/splusb somewhat. The writer * process only extends qcount and qtail. We could copy them and use the copies * to do the copying out of the queue. */ while ((sc->qcount > 0) && (uio->uio_resid > 0)) { l = (sc->qcount < uio->uio_resid? sc->qcount:uio->uio_resid); if (l > sizeof(buf)) l = sizeof(buf); if (l > sizeof(sc->qbuf) - sc->qtail) /* transfer till end of buf */ l = sizeof(sc->qbuf) - sc->qtail; splx(s); uiomove(&sc->qbuf[sc->qtail], l, uio); s = splusb(); if ( sc->qcount - l < 0 ) { DPRINTF(("qcount below 0, count=%d l=%d\n", sc->qcount, l)); sc->qcount = l; } sc->qcount -= l; /* remove the bytes from the buffer */ sc->qtail = (sc->qtail + l) % sizeof(sc->qbuf); } splx(s); return 0; } Static int ums_poll(struct cdev *dev, int events, usb_proc_ptr p) { struct ums_softc *sc; int revents = 0; int s; USB_GET_SC(ums, UMSUNIT(dev), sc); if (!sc) return 0; s = splusb(); if (events & (POLLIN | POLLRDNORM)) { if (sc->qcount) { revents = events & (POLLIN | POLLRDNORM); } else { sc->state |= UMS_SELECT; selrecord(p, &sc->rsel); } } splx(s); return revents; } int ums_ioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, usb_proc_ptr p) { struct ums_softc *sc; int error = 0; int s; mousemode_t mode; USB_GET_SC(ums, UMSUNIT(dev), sc); if (!sc) return EIO; switch(cmd) { case MOUSE_GETHWINFO: *(mousehw_t *)addr = sc->hw; break; case MOUSE_GETMODE: *(mousemode_t *)addr = sc->mode; break; case MOUSE_SETMODE: mode = *(mousemode_t *)addr; if (mode.level == -1) /* don't change the current setting */ ; else if ((mode.level < 0) || (mode.level > 1)) return (EINVAL); s = splusb(); sc->mode.level = mode.level; if (sc->mode.level == 0) { if (sc->nbuttons > MOUSE_MSC_MAXBUTTON) sc->hw.buttons = MOUSE_MSC_MAXBUTTON; else sc->hw.buttons = sc->nbuttons; sc->mode.protocol = MOUSE_PROTO_MSC; sc->mode.packetsize = MOUSE_MSC_PACKETSIZE; sc->mode.syncmask[0] = MOUSE_MSC_SYNCMASK; sc->mode.syncmask[1] = MOUSE_MSC_SYNC; } else if (sc->mode.level == 1) { if (sc->nbuttons > MOUSE_SYS_MAXBUTTON) sc->hw.buttons = MOUSE_SYS_MAXBUTTON; else sc->hw.buttons = sc->nbuttons; sc->mode.protocol = MOUSE_PROTO_SYSMOUSE; sc->mode.packetsize = MOUSE_SYS_PACKETSIZE; sc->mode.syncmask[0] = MOUSE_SYS_SYNCMASK; sc->mode.syncmask[1] = MOUSE_SYS_SYNC; } bzero(sc->qbuf, sizeof(sc->qbuf)); sc->qhead = sc->qtail = sc->qcount = 0; splx(s); break; case MOUSE_GETLEVEL: *(int *)addr = sc->mode.level; break; case MOUSE_SETLEVEL: if (*(int *)addr < 0 || *(int *)addr > 1) return (EINVAL); s = splusb(); sc->mode.level = *(int *)addr; if (sc->mode.level == 0) { if (sc->nbuttons > MOUSE_MSC_MAXBUTTON) sc->hw.buttons = MOUSE_MSC_MAXBUTTON; else sc->hw.buttons = sc->nbuttons; sc->mode.protocol = MOUSE_PROTO_MSC; sc->mode.packetsize = MOUSE_MSC_PACKETSIZE; sc->mode.syncmask[0] = MOUSE_MSC_SYNCMASK; sc->mode.syncmask[1] = MOUSE_MSC_SYNC; } else if (sc->mode.level == 1) { if (sc->nbuttons > MOUSE_SYS_MAXBUTTON) sc->hw.buttons = MOUSE_SYS_MAXBUTTON; else sc->hw.buttons = sc->nbuttons; sc->mode.protocol = MOUSE_PROTO_SYSMOUSE; sc->mode.packetsize = MOUSE_SYS_PACKETSIZE; sc->mode.syncmask[0] = MOUSE_SYS_SYNCMASK; sc->mode.syncmask[1] = MOUSE_SYS_SYNC; } bzero(sc->qbuf, sizeof(sc->qbuf)); sc->qhead = sc->qtail = sc->qcount = 0; splx(s); break; case MOUSE_GETSTATUS: { mousestatus_t *status = (mousestatus_t *) addr; s = splusb(); *status = sc->status; sc->status.obutton = sc->status.button; sc->status.button = 0; - sc->status.dx = sc->status.dy = sc->status.dz = 0; + sc->status.dx = sc->status.dy = sc->status.dz = sc->status.dt = 0; splx(s); - if (status->dx || status->dy || status->dz) + if (status->dx || status->dy || status->dz || status->dt) status->flags |= MOUSE_POSCHANGED; if (status->button != status->obutton) status->flags |= MOUSE_BUTTONSCHANGED; break; } default: error = ENOTTY; } return error; } DRIVER_MODULE(ums, uhub, ums_driver, ums_devclass, usbd_driver_load, 0); diff --git a/sys/dev/usb/usbhid.h b/sys/dev/usb/usbhid.h index fbc17047e6a0..416aec3f2e56 100644 --- a/sys/dev/usb/usbhid.h +++ b/sys/dev/usb/usbhid.h @@ -1,184 +1,185 @@ /* $NetBSD: usbhid.h,v 1.9 2000/09/03 19:09:14 augustss Exp $ */ /* $FreeBSD$ */ /* * Copyright (c) 1998 The NetBSD Foundation, Inc. * All rights reserved. * * This code is derived from software contributed to The NetBSD Foundation * by Lennart Augustsson (lennart@augustsson.net) at * Carlstedt Research & Technology. * * 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. */ #ifndef _USBHID_H_ #define _USBHID_H_ #define UR_GET_HID_DESCRIPTOR 0x06 #define UDESC_HID 0x21 #define UDESC_REPORT 0x22 #define UDESC_PHYSICAL 0x23 #define UR_SET_HID_DESCRIPTOR 0x07 #define UR_GET_REPORT 0x01 #define UR_SET_REPORT 0x09 #define UR_GET_IDLE 0x02 #define UR_SET_IDLE 0x0a #define UR_GET_PROTOCOL 0x03 #define UR_SET_PROTOCOL 0x0b typedef struct usb_hid_descriptor { uByte bLength; uByte bDescriptorType; uWord bcdHID; uByte bCountryCode; uByte bNumDescriptors; struct { uByte bDescriptorType; uWord wDescriptorLength; } descrs[1]; } UPACKED usb_hid_descriptor_t; #define USB_HID_DESCRIPTOR_SIZE(n) (9+(n)*3) /* Usage pages */ #define HUP_UNDEFINED 0x0000 #define HUP_GENERIC_DESKTOP 0x0001 #define HUP_SIMULATION 0x0002 #define HUP_VR_CONTROLS 0x0003 #define HUP_SPORTS_CONTROLS 0x0004 #define HUP_GAMING_CONTROLS 0x0005 #define HUP_KEYBOARD 0x0007 #define HUP_LEDS 0x0008 #define HUP_BUTTON 0x0009 #define HUP_ORDINALS 0x000a #define HUP_TELEPHONY 0x000b #define HUP_CONSUMER 0x000c #define HUP_DIGITIZERS 0x000d #define HUP_PHYSICAL_IFACE 0x000e #define HUP_UNICODE 0x0010 #define HUP_ALPHANUM_DISPLAY 0x0014 #define HUP_MONITOR 0x0080 #define HUP_MONITOR_ENUM_VAL 0x0081 #define HUP_VESA_VC 0x0082 #define HUP_VESA_CMD 0x0083 #define HUP_POWER 0x0084 #define HUP_BATTERY_SYSTEM 0x0085 #define HUP_BARCODE_SCANNER 0x008b #define HUP_SCALE 0x008c #define HUP_CAMERA_CONTROL 0x0090 #define HUP_ARCADE 0x0091 #define HUP_MICROSOFT 0xff00 /* Usages, generic desktop */ #define HUG_POINTER 0x0001 #define HUG_MOUSE 0x0002 #define HUG_JOYSTICK 0x0004 #define HUG_GAME_PAD 0x0005 #define HUG_KEYBOARD 0x0006 #define HUG_KEYPAD 0x0007 #define HUG_X 0x0030 #define HUG_Y 0x0031 #define HUG_Z 0x0032 #define HUG_RX 0x0033 #define HUG_RY 0x0034 #define HUG_RZ 0x0035 #define HUG_SLIDER 0x0036 #define HUG_DIAL 0x0037 #define HUG_WHEEL 0x0038 #define HUG_HAT_SWITCH 0x0039 #define HUG_COUNTED_BUFFER 0x003a #define HUG_BYTE_COUNT 0x003b #define HUG_MOTION_WAKEUP 0x003c #define HUG_VX 0x0040 #define HUG_VY 0x0041 #define HUG_VZ 0x0042 #define HUG_VBRX 0x0043 #define HUG_VBRY 0x0044 #define HUG_VBRZ 0x0045 #define HUG_VNO 0x0046 +#define HUG_TWHEEL 0x0048 // M$ Wireless Intellimouse Wheel #define HUG_SYSTEM_CONTROL 0x0080 #define HUG_SYSTEM_POWER_DOWN 0x0081 #define HUG_SYSTEM_SLEEP 0x0082 #define HUG_SYSTEM_WAKEUP 0x0083 #define HUG_SYSTEM_CONTEXT_MENU 0x0084 #define HUG_SYSTEM_MAIN_MENU 0x0085 #define HUG_SYSTEM_APP_MENU 0x0086 #define HUG_SYSTEM_MENU_HELP 0x0087 #define HUG_SYSTEM_MENU_EXIT 0x0088 #define HUG_SYSTEM_MENU_SELECT 0x0089 #define HUG_SYSTEM_MENU_RIGHT 0x008a #define HUG_SYSTEM_MENU_LEFT 0x008b #define HUG_SYSTEM_MENU_UP 0x008c #define HUG_SYSTEM_MENU_DOWN 0x008d /* Usages Digitizers */ #define HUD_UNDEFINED 0x0000 #define HUD_TIP_PRESSURE 0x0030 #define HUD_BARREL_PRESSURE 0x0031 #define HUD_IN_RANGE 0x0032 #define HUD_TOUCH 0x0033 #define HUD_UNTOUCH 0x0034 #define HUD_TAP 0x0035 #define HUD_QUALITY 0x0036 #define HUD_DATA_VALID 0x0037 #define HUD_TRANSDUCER_INDEX 0x0038 #define HUD_TABLET_FKEYS 0x0039 #define HUD_PROGRAM_CHANGE_KEYS 0x003a #define HUD_BATTERY_STRENGTH 0x003b #define HUD_INVERT 0x003c #define HUD_X_TILT 0x003d #define HUD_Y_TILT 0x003e #define HUD_AZIMUTH 0x003f #define HUD_ALTITUDE 0x0040 #define HUD_TWIST 0x0041 #define HUD_TIP_SWITCH 0x0042 #define HUD_SEC_TIP_SWITCH 0x0043 #define HUD_BARREL_SWITCH 0x0044 #define HUD_ERASER 0x0045 #define HUD_TABLET_PICK 0x0046 #define HID_USAGE2(p,u) (((p) << 16) | u) #define UHID_INPUT_REPORT 0x01 #define UHID_OUTPUT_REPORT 0x02 #define UHID_FEATURE_REPORT 0x03 /* Bits in the input/output/feature items */ #define HIO_CONST 0x001 #define HIO_VARIABLE 0x002 #define HIO_RELATIVE 0x004 #define HIO_WRAP 0x008 #define HIO_NONLINEAR 0x010 #define HIO_NOPREF 0x020 #define HIO_NULLSTATE 0x040 #define HIO_VOLATILE 0x080 #define HIO_BUFBYTES 0x100 #endif /* _USBHID_H_ */ diff --git a/sys/sys/mouse.h b/sys/sys/mouse.h index 08e1a76f9fbb..e77761195ee4 100644 --- a/sys/sys/mouse.h +++ b/sys/sys/mouse.h @@ -1,361 +1,362 @@ /*- * Copyright (c) 1992, 1993 Erik Forsberg. * Copyright (c) 1996, 1997 Kazutaka YOKOTA * All rights reserved. * * 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. * * THIS SOFTWARE IS PROVIDED BY ``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 I 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. * * $FreeBSD$ */ #ifndef _SYS_MOUSE_H_ #define _SYS_MOUSE_H_ #include #include /* ioctls */ #define MOUSE_GETSTATUS _IOR('M', 0, mousestatus_t) #define MOUSE_GETHWINFO _IOR('M', 1, mousehw_t) #define MOUSE_GETMODE _IOR('M', 2, mousemode_t) #define MOUSE_SETMODE _IOW('M', 3, mousemode_t) #define MOUSE_GETLEVEL _IOR('M', 4, int) #define MOUSE_SETLEVEL _IOW('M', 5, int) #define MOUSE_GETVARS _IOR('M', 6, mousevar_t) #define MOUSE_SETVARS _IOW('M', 7, mousevar_t) #define MOUSE_READSTATE _IOWR('M', 8, mousedata_t) #define MOUSE_READDATA _IOWR('M', 9, mousedata_t) #if notyet #define MOUSE_SETRESOLUTION _IOW('M', 10, int) #define MOUSE_SETSCALING _IOW('M', 11, int) #define MOUSE_SETRATE _IOW('M', 12, int) #define MOUSE_GETHWID _IOR('M', 13, int) #endif #define MOUSE_SYN_GETHWINFO _IOR('M', 100, synapticshw_t) /* mouse status block */ typedef struct mousestatus { int flags; /* state change flags */ int button; /* button status */ int obutton; /* previous button status */ int dx; /* x movement */ int dy; /* y movement */ int dz; /* z movement */ + int dt; /* left right tilt axis */ } mousestatus_t; /* button */ #define MOUSE_BUTTON1DOWN 0x0001 /* left */ #define MOUSE_BUTTON2DOWN 0x0002 /* middle */ #define MOUSE_BUTTON3DOWN 0x0004 /* right */ #define MOUSE_BUTTON4DOWN 0x0008 #define MOUSE_BUTTON5DOWN 0x0010 #define MOUSE_BUTTON6DOWN 0x0020 #define MOUSE_BUTTON7DOWN 0x0040 #define MOUSE_BUTTON8DOWN 0x0080 #define MOUSE_MAXBUTTON 31 #define MOUSE_STDBUTTONS 0x0007 /* buttons 1-3 */ #define MOUSE_EXTBUTTONS 0x7ffffff8 /* the others (28 of them!) */ #define MOUSE_BUTTONS (MOUSE_STDBUTTONS | MOUSE_EXTBUTTONS) /* flags */ #define MOUSE_STDBUTTONSCHANGED MOUSE_STDBUTTONS #define MOUSE_EXTBUTTONSCHANGED MOUSE_EXTBUTTONS #define MOUSE_BUTTONSCHANGED MOUSE_BUTTONS #define MOUSE_POSCHANGED 0x80000000 typedef struct mousehw { int buttons; /* -1 if unknown */ int iftype; /* MOUSE_IF_XXX */ int type; /* mouse/track ball/pad... */ int model; /* I/F dependent model ID: MOUSE_MODEL_XXX */ int hwid; /* I/F dependent hardware ID * for the PS/2 mouse, it will be PSM_XXX_ID */ } mousehw_t; typedef struct synapticshw { int infoMajor; int infoMinor; int infoRot180; int infoPortrait; int infoSensor; int infoHardware; int infoNewAbs; int capPen; int infoSimplC; int infoGeometry; int capExtended; int capSleep; int capFourButtons; int capMultiFinger; int capPalmDetect; int capPassthrough; } synapticshw_t; /* iftype */ #define MOUSE_IF_UNKNOWN (-1) #define MOUSE_IF_SERIAL 0 #define MOUSE_IF_BUS 1 #define MOUSE_IF_INPORT 2 #define MOUSE_IF_PS2 3 #define MOUSE_IF_SYSMOUSE 4 #define MOUSE_IF_USB 5 /* type */ #define MOUSE_UNKNOWN (-1) /* should be treated as a mouse */ #define MOUSE_MOUSE 0 #define MOUSE_TRACKBALL 1 #define MOUSE_STICK 2 #define MOUSE_PAD 3 /* model */ #define MOUSE_MODEL_UNKNOWN (-1) #define MOUSE_MODEL_GENERIC 0 #define MOUSE_MODEL_GLIDEPOINT 1 #define MOUSE_MODEL_NETSCROLL 2 #define MOUSE_MODEL_NET 3 #define MOUSE_MODEL_INTELLI 4 #define MOUSE_MODEL_THINK 5 #define MOUSE_MODEL_EASYSCROLL 6 #define MOUSE_MODEL_MOUSEMANPLUS 7 #define MOUSE_MODEL_KIDSPAD 8 #define MOUSE_MODEL_VERSAPAD 9 #define MOUSE_MODEL_EXPLORER 10 #define MOUSE_MODEL_4D 11 #define MOUSE_MODEL_4DPLUS 12 #define MOUSE_MODEL_SYNAPTICS 13 typedef struct mousemode { int protocol; /* MOUSE_PROTO_XXX */ int rate; /* report rate (per sec), -1 if unknown */ int resolution; /* MOUSE_RES_XXX, -1 if unknown */ int accelfactor; /* accelation factor (must be 1 or greater) */ int level; /* driver operation level */ int packetsize; /* the length of the data packet */ unsigned char syncmask[2]; /* sync. data bits in the header byte */ } mousemode_t; /* protocol */ /* * Serial protocols: * Microsoft, MouseSystems, Logitech, MM series, MouseMan, Hitachi Tablet, * GlidePoint, IntelliMouse, Thinking Mouse, MouseRemote, Kidspad, * VersaPad * Bus mouse protocols: * bus, InPort * PS/2 mouse protocol: * PS/2 */ #define MOUSE_PROTO_UNKNOWN (-1) #define MOUSE_PROTO_MS 0 /* Microsoft Serial, 3 bytes */ #define MOUSE_PROTO_MSC 1 /* Mouse Systems, 5 bytes */ #define MOUSE_PROTO_LOGI 2 /* Logitech, 3 bytes */ #define MOUSE_PROTO_MM 3 /* MM series, 3 bytes */ #define MOUSE_PROTO_LOGIMOUSEMAN 4 /* Logitech MouseMan 3/4 bytes */ #define MOUSE_PROTO_BUS 5 /* MS/Logitech bus mouse */ #define MOUSE_PROTO_INPORT 6 /* MS/ATI InPort mouse */ #define MOUSE_PROTO_PS2 7 /* PS/2 mouse, 3 bytes */ #define MOUSE_PROTO_HITTAB 8 /* Hitachi Tablet 3 bytes */ #define MOUSE_PROTO_GLIDEPOINT 9 /* ALPS GlidePoint, 3/4 bytes */ #define MOUSE_PROTO_INTELLI 10 /* MS IntelliMouse, 4 bytes */ #define MOUSE_PROTO_THINK 11 /* Kensignton Thinking Mouse, 3/4 bytes */ #define MOUSE_PROTO_SYSMOUSE 12 /* /dev/sysmouse */ #define MOUSE_PROTO_X10MOUSEREM 13 /* X10 MouseRemote, 3 bytes */ #define MOUSE_PROTO_KIDSPAD 14 /* Genius Kidspad */ #define MOUSE_PROTO_VERSAPAD 15 /* Interlink VersaPad, 6 bytes */ #define MOUSE_PROTO_JOGDIAL 16 /* Vaio's JogDial */ #define MOUSE_RES_UNKNOWN (-1) #define MOUSE_RES_DEFAULT 0 #define MOUSE_RES_LOW (-2) #define MOUSE_RES_MEDIUMLOW (-3) #define MOUSE_RES_MEDIUMHIGH (-4) #define MOUSE_RES_HIGH (-5) typedef struct mousedata { int len; /* # of data in the buffer */ int buf[16]; /* data buffer */ } mousedata_t; #if (defined(MOUSE_GETVARS)) typedef struct mousevar { int var[16]; } mousevar_t; /* magic numbers in var[0] */ #define MOUSE_VARS_PS2_SIG 0x00325350 /* 'PS2' */ #define MOUSE_VARS_BUS_SIG 0x00535542 /* 'BUS' */ #define MOUSE_VARS_INPORT_SIG 0x00504e49 /* 'INP' */ #endif /* MOUSE_GETVARS */ /* Synaptics Touchpad */ #define MOUSE_SYNAPTICS_PACKETSIZE 6 /* '3' works better */ /* Microsoft Serial mouse data packet */ #define MOUSE_MSS_PACKETSIZE 3 #define MOUSE_MSS_SYNCMASK 0x40 #define MOUSE_MSS_SYNC 0x40 #define MOUSE_MSS_BUTTONS 0x30 #define MOUSE_MSS_BUTTON1DOWN 0x20 /* left */ #define MOUSE_MSS_BUTTON2DOWN 0x00 /* no middle button */ #define MOUSE_MSS_BUTTON3DOWN 0x10 /* right */ /* Logitech MouseMan data packet (M+ protocol) */ #define MOUSE_LMAN_BUTTON2DOWN 0x20 /* middle button, the 4th byte */ /* ALPS GlidePoint extension (variant of M+ protocol) */ #define MOUSE_ALPS_BUTTON2DOWN 0x20 /* middle button, the 4th byte */ #define MOUSE_ALPS_TAP 0x10 /* `tapping' action, the 4th byte */ /* Kinsington Thinking Mouse extension (variant of M+ protocol) */ #define MOUSE_THINK_BUTTON2DOWN 0x20 /* lower-left button, the 4th byte */ #define MOUSE_THINK_BUTTON4DOWN 0x10 /* lower-right button, the 4th byte */ /* MS IntelliMouse (variant of MS Serial) */ #define MOUSE_INTELLI_PACKETSIZE 4 #define MOUSE_INTELLI_BUTTON2DOWN 0x10 /* middle button in the 4th byte */ /* Mouse Systems Corp. mouse data packet */ #define MOUSE_MSC_PACKETSIZE 5 #define MOUSE_MSC_SYNCMASK 0xf8 #define MOUSE_MSC_SYNC 0x80 #define MOUSE_MSC_BUTTONS 0x07 #define MOUSE_MSC_BUTTON1UP 0x04 /* left */ #define MOUSE_MSC_BUTTON2UP 0x02 /* middle */ #define MOUSE_MSC_BUTTON3UP 0x01 /* right */ #define MOUSE_MSC_MAXBUTTON 3 /* MM series mouse data packet */ #define MOUSE_MM_PACKETSIZE 3 #define MOUSE_MM_SYNCMASK 0xe0 #define MOUSE_MM_SYNC 0x80 #define MOUSE_MM_BUTTONS 0x07 #define MOUSE_MM_BUTTON1DOWN 0x04 /* left */ #define MOUSE_MM_BUTTON2DOWN 0x02 /* middle */ #define MOUSE_MM_BUTTON3DOWN 0x01 /* right */ #define MOUSE_MM_XPOSITIVE 0x10 #define MOUSE_MM_YPOSITIVE 0x08 /* PS/2 mouse data packet */ #define MOUSE_PS2_PACKETSIZE 3 #define MOUSE_PS2_SYNCMASK 0xc8 #define MOUSE_PS2_SYNC 0x08 #define MOUSE_PS2_BUTTONS 0x07 /* 0x03 for 2 button mouse */ #define MOUSE_PS2_BUTTON1DOWN 0x01 /* left */ #define MOUSE_PS2_BUTTON2DOWN 0x04 /* middle */ #define MOUSE_PS2_BUTTON3DOWN 0x02 /* right */ #define MOUSE_PS2_TAP MOUSE_PS2_SYNC /* GlidePoint (PS/2) `tapping' * Yes! this is the same bit * as SYNC! */ #define MOUSE_PS2_XNEG 0x10 #define MOUSE_PS2_YNEG 0x20 #define MOUSE_PS2_XOVERFLOW 0x40 #define MOUSE_PS2_YOVERFLOW 0x80 /* Logitech MouseMan+ (PS/2) data packet (PS/2++ protocol) */ #define MOUSE_PS2PLUS_SYNCMASK 0x48 #define MOUSE_PS2PLUS_SYNC 0x48 #define MOUSE_PS2PLUS_ZNEG 0x08 /* sign bit */ #define MOUSE_PS2PLUS_BUTTON4DOWN 0x10 /* 4th button on MouseMan+ */ #define MOUSE_PS2PLUS_BUTTON5DOWN 0x20 /* IBM ScrollPoint (PS/2) also uses PS/2++ protocol */ #define MOUSE_SPOINT_ZNEG 0x80 /* sign bits */ #define MOUSE_SPOINT_WNEG 0x08 /* MS IntelliMouse (PS/2) data packet */ #define MOUSE_PS2INTELLI_PACKETSIZE 4 /* some compatible mice have additional buttons */ #define MOUSE_PS2INTELLI_BUTTON4DOWN 0x40 #define MOUSE_PS2INTELLI_BUTTON5DOWN 0x80 /* MS IntelliMouse Explorer (PS/2) data packet (variation of IntelliMouse) */ #define MOUSE_EXPLORER_ZNEG 0x08 /* sign bit */ /* IntelliMouse Explorer has additional button data in the fourth byte */ #define MOUSE_EXPLORER_BUTTON4DOWN 0x10 #define MOUSE_EXPLORER_BUTTON5DOWN 0x20 /* Interlink VersaPad (serial I/F) data packet */ #define MOUSE_VERSA_PACKETSIZE 6 #define MOUSE_VERSA_IN_USE 0x04 #define MOUSE_VERSA_SYNCMASK 0xc3 #define MOUSE_VERSA_SYNC 0xc0 #define MOUSE_VERSA_BUTTONS 0x30 #define MOUSE_VERSA_BUTTON1DOWN 0x20 /* left */ #define MOUSE_VERSA_BUTTON2DOWN 0x00 /* middle */ #define MOUSE_VERSA_BUTTON3DOWN 0x10 /* right */ #define MOUSE_VERSA_TAP 0x08 /* Interlink VersaPad (PS/2 I/F) data packet */ #define MOUSE_PS2VERSA_PACKETSIZE 6 #define MOUSE_PS2VERSA_IN_USE 0x10 #define MOUSE_PS2VERSA_SYNCMASK 0xe8 #define MOUSE_PS2VERSA_SYNC 0xc8 #define MOUSE_PS2VERSA_BUTTONS 0x05 #define MOUSE_PS2VERSA_BUTTON1DOWN 0x04 /* left */ #define MOUSE_PS2VERSA_BUTTON2DOWN 0x00 /* middle */ #define MOUSE_PS2VERSA_BUTTON3DOWN 0x01 /* right */ #define MOUSE_PS2VERSA_TAP 0x02 /* A4 Tech 4D Mouse (PS/2) data packet */ #define MOUSE_4D_PACKETSIZE 3 #define MOUSE_4D_WHEELBITS 0xf0 /* A4 Tech 4D+ Mouse (PS/2) data packet */ #define MOUSE_4DPLUS_PACKETSIZE 3 #define MOUSE_4DPLUS_ZNEG 0x04 /* sign bit */ #define MOUSE_4DPLUS_BUTTON4DOWN 0x08 /* sysmouse extended data packet */ /* * /dev/sysmouse sends data in two formats, depending on the protocol * level. At the level 0, format is exactly the same as MousSystems' * five byte packet. At the level 1, the first five bytes are the same * as at the level 0. There are additional three bytes which shows * `dz' and the states of additional buttons. `dz' is expressed as the * sum of the byte 5 and 6 which contain signed seven bit values. * The states of the button 4 though 10 are in the bit 0 though 6 in * the byte 7 respectively: 1 indicates the button is up. */ #define MOUSE_SYS_PACKETSIZE 8 #define MOUSE_SYS_SYNCMASK 0xf8 #define MOUSE_SYS_SYNC 0x80 #define MOUSE_SYS_BUTTON1UP 0x04 /* left, 1st byte */ #define MOUSE_SYS_BUTTON2UP 0x02 /* middle, 1st byte */ #define MOUSE_SYS_BUTTON3UP 0x01 /* right, 1st byte */ #define MOUSE_SYS_BUTTON4UP 0x0001 /* 7th byte */ #define MOUSE_SYS_BUTTON5UP 0x0002 #define MOUSE_SYS_BUTTON6UP 0x0004 #define MOUSE_SYS_BUTTON7UP 0x0008 #define MOUSE_SYS_BUTTON8UP 0x0010 #define MOUSE_SYS_BUTTON9UP 0x0020 #define MOUSE_SYS_BUTTON10UP 0x0040 #define MOUSE_SYS_MAXBUTTON 10 #define MOUSE_SYS_STDBUTTONS 0x07 #define MOUSE_SYS_EXTBUTTONS 0x7f /* the others */ /* Mouse remote socket */ #define _PATH_MOUSEREMOTE "/var/run/MouseRemote" #endif /* _SYS_MOUSE_H_ */