xref: /openbsd-src/usr.sbin/wsmoused/mouse_protocols.h (revision 3a50f0a93a2072911d0ba6ababa815fb04bf9a71)
1 /* $OpenBSD: mouse_protocols.h,v 1.7 2022/12/28 21:30:19 jmc Exp $ */
2 
3 /*
4  * Copyright (c) 2001 Jean-Baptiste Marchand, Julien Montagne and Jerome Verdon
5  *
6  * Copyright (c) 1998 by Kazutaka Yokota
7  *
8  * Copyright (c) 1995 Michael Smith
9  *
10  * Copyright (c) 1993 by David Dawes <dawes@xfree86.org>
11  *
12  * Copyright (c) 1990,91 by Thomas Roell, Dinkelscherben, Germany.
13  *
14  * All rights reserved.
15  *
16  * Most of this code was taken from the FreeBSD moused daemon, written by
17  * Michael Smith. The FreeBSD moused daemon already contained code from the
18  * Xfree Project, written by David Dawes and Thomas Roell and Kazutaka Yokota.
19  *
20  * Adaptation to OpenBSD was done by Jean-Baptiste Marchand, Julien Montagne
21  * and Jerome Verdon.
22  *
23  * Redistribution and use in source and binary forms, with or without
24  * modification, are permitted provided that the following conditions
25  * are met:
26  * 1. Redistributions of source code must retain the above copyright
27  *    notice, this list of conditions and the following disclaimer.
28  * 2. Redistributions in binary form must reproduce the above copyright
29  *    notice, this list of conditions and the following disclaimer in the
30  *    documentation and/or other materials provided with the distribution.
31  * 3. All advertising materials mentioning features or use of this software
32  *    must display the following acknowledgement:
33  *	This product includes software developed by
34  *      David Dawes, Jean-Baptiste Marchand, Julien Montagne, Thomas Roell,
35  *      Michael Smith, Jerome Verdon and Kazutaka Yokota.
36  * 4. The name authors may not be used to endorse or promote products
37  *    derived from this software without specific prior written permission.
38  *
39  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``AS IS'' AND ANY EXPRESS OR
40  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
41  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
42  * IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR ANY DIRECT, INDIRECT,
43  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
44  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
45  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
46  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
47  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
48  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
49  *
50  *
51  */
52 
53 
54 /* Mouse protocols */
55 
56 #define P_UNKNOWN 	-2
57 #define	P_WSCONS	-1	/* wsmouse */
58 #define P_MS 		0	/* Microsoft Serial, 3 bytes */
59 #define P_MSC 		1	/* Mouse Systems, 5 bytes */
60 #define P_LOGI 		2	/* Logitech, 3 bytes */
61 #define P_MM 		3	/* MM series, 3 bytes */
62 #define P_LOGIMAN	4	/* Logitech MouseMan 3/4 bytes */
63 #define P_MMHIT		5	/* Hitachi Tablet 3 bytes */
64 #define P_GLIDEPOINT	6	/* ALPS GlidePoint, 3/4 bytes */
65 #define P_IMSERIAL	7	/* MS IntelliMouse, 4 bytes */
66 #define P_THINKING	8	/* Kensignton Thinking Mouse, 3/4 bytes */
67 
68 /* flags */
69 
70 #define MOUSE_BUTTON1DOWN	0x0001	/* left */
71 #define MOUSE_BUTTON2DOWN	0x0002	/* middle */
72 #define MOUSE_BUTTON3DOWN	0x0004	/* right */
73 #define MOUSE_BUTTON4DOWN	0x0008
74 #define MOUSE_BUTTON5DOWN	0x0010
75 #define MOUSE_BUTTON6DOWN	0x0020
76 #define MOUSE_BUTTON7DOWN	0x0040
77 #define MOUSE_BUTTON8DOWN	0x0080
78 
79 #define MOUSE_BUTTONS		0x00FF
80 #define MOUSE_POSCHANGED	0x0100
81 
82 /*
83  * List of all the protocols parameters
84  * The parameters are :
85  * - size of the packet
86  * - synchronization mask
87  * - synchronization value (must be equal to data ANDed with SYNCMASK)
88  * - mask of buttons
89  * - mask of each button separately
90  */
91 
92 /* Microsoft Serial mouse data packet */
93 #define MOUSE_MSS_PACKETSIZE	3
94 #define MOUSE_MSS_SYNCMASK	0x40
95 #define MOUSE_MSS_SYNC		0x40
96 #define MOUSE_MSS_BUTTONS	0x30
97 #define MOUSE_MSS_BUTTON1DOWN	0x20	/* left */
98 #define MOUSE_MSS_BUTTON2DOWN	0x00	/* no middle button */
99 #define MOUSE_MSS_BUTTON3DOWN	0x10	/* right */
100 
101 /* Logitech MouseMan data packet (M+ protocol) */
102 #define MOUSE_LMAN_BUTTON2DOWN	0x20	/* middle button, the 4th byte */
103 
104 /* ALPS GlidePoint extension (variant of M+ protocol) */
105 #define MOUSE_ALPS_BUTTON2DOWN	0x20	/* middle button, the 4th byte */
106 #define MOUSE_ALPS_TAP		0x10	/* `tapping' action, the 4th byte */
107 
108 /* Kinsington Thinking Mouse extension (variant of M+ protocol) */
109 #define MOUSE_THINK_BUTTON2DOWN 0x20	/* lower-left button, the 4th byte */
110 #define MOUSE_THINK_BUTTON4DOWN 0x10	/* lower-right button, the 4th byte */
111 
112 /* MS IntelliMouse (variant of MS Serial) */
113 #define MOUSE_INTELLI_PACKETSIZE 4
114 #define MOUSE_INTELLI_BUTTON2DOWN 0x10	/* middle button the 4th byte */
115 
116 /* Mouse Systems Corp. mouse data packet */
117 #define MOUSE_MSC_PACKETSIZE	5
118 #define MOUSE_MSC_SYNCMASK	0xf8
119 #define MOUSE_MSC_SYNC		0x80
120 #define MOUSE_MSC_BUTTONS	0x07
121 #define MOUSE_MSC_BUTTON1UP	0x04	/* left */
122 #define MOUSE_MSC_BUTTON2UP	0x02	/* middle */
123 #define MOUSE_MSC_BUTTON3UP	0x01	/* right */
124 #define MOUSE_MSC_MAXBUTTON	3
125 
126 /* MM series mouse data packet */
127 #define MOUSE_MM_PACKETSIZE	3
128 #define MOUSE_MM_SYNCMASK	0xe0
129 #define MOUSE_MM_SYNC		0x80
130 #define MOUSE_MM_BUTTONS	0x07
131 #define MOUSE_MM_BUTTON1DOWN	0x04	/* left */
132 #define MOUSE_MM_BUTTON2DOWN	0x02	/* middle */
133 #define MOUSE_MM_BUTTON3DOWN	0x01	/* right */
134 #define MOUSE_MM_XPOSITIVE	0x10
135 #define MOUSE_MM_YPOSITIVE	0x08
136 
137 /* Interlink VersaPad (serial I/F) data packet */
138 #define MOUSE_VERSA_PACKETSIZE	6
139 #define MOUSE_VERSA_IN_USE	0x04
140 #define MOUSE_VERSA_SYNCMASK	0xc3
141 #define MOUSE_VERSA_SYNC	0xc0
142 #define MOUSE_VERSA_BUTTONS	0x30
143 #define MOUSE_VERSA_BUTTON1DOWN	0x20	/* left */
144 #define MOUSE_VERSA_BUTTON2DOWN	0x00	/* middle */
145 #define MOUSE_VERSA_BUTTON3DOWN	0x10	/* right */
146 #define MOUSE_VERSA_TAP		0x08
147 
148 /* Mouse resolutions */
149 
150 #define MOUSE_RES_DEFAULT	254
151 #define MOUSE_RES_UNKNOWN	255
152 #define MOUSE_RES_LOW		0
153 #define MOUSE_RES_MEDIUMLOW	1
154 #define MOUSE_RES_MEDIUMHIGH	2
155 #define MOUSE_RES_HIGH		3
156 
157 /* Mouse report rates */
158 
159 #define MOUSE_RATE_UNKNOWN	255
160 #define MOUSE_RATE_DEFAULT	80
161 #define MOUSE_RATE_VERY_LOW	20
162 #define MOUSE_RATE_LOW		40
163 #define MOUSE_RATE_MEDIUM_LOW	60
164 #define MOUSE_RATE_MEDIUM_HIGH	80
165 #define MOUSE_RATE_HIGH		100
166 #define MOUSE_RATE_VERY_HIGH	200
167 
168 /* serial PnP ID string */
169 typedef struct {
170     int revision;	/* PnP revision, 100 for 1.00 */
171     char *eisaid;	/* EISA ID including mfr ID and product ID */
172     char *serial;	/* serial No, optional */
173     char *class;	/* device class, optional */
174     char *compat;	/* list of compatible drivers, optional */
175     char *description;	/* product description, optional */
176     int neisaid;	/* length of the above fields... */
177     int nserial;
178     int nclass;
179     int ncompat;
180     int ndescription;
181 } pnpid_t;
182 
183 /* symbol table entry */
184 typedef struct {
185     char *name;
186     int val;
187 } symtab_t;
188 
189 /* current status of the mouse */
190 typedef struct mousestatus {
191     int     flags;		/* state change flags */
192     int     button;		/* button status */
193     int     obutton;		/* previous button status */
194     int     dx;			/* x movement */
195     int     dy;			/* y movement */
196     int     dz;			/* z movement */
197     int     dw;			/* w movement */
198 } mousestatus_t;
199 
200 /* Prototypes */
201 
202 void mouse_init(void);
203 int mouse_identify(void);
204 int mouse_protocol(unsigned char, mousestatus_t *);
205 const char *mouse_name(int type);
206 void wsmouse_init(void);
207 
208