pnp.c revision 677833bc953b6cb418c701facbdcf4aa18d6c44e
2362N/A * Copyright 1998 by Kazutaka YOKOTA <yokota@zodiac.mech.utsunomiya-u.ac.jp> 1309N/A * Permission to use, copy, modify, distribute, and sell this software and its 1309N/A * documentation for any purpose is hereby granted without fee, provided that 1309N/A * the above copyright notice appear in all copies and that both that 1309N/A * copyright notice and this permission notice appear in supporting 1309N/A * documentation, and that the name of Kazutaka YOKOTA not be used in 1309N/A * advertising or publicity pertaining to distribution of the software without 1309N/A * specific, written prior permission. Kazutaka YOKOTA makes no representations 1309N/A * about the suitability of this software for any purpose. It is provided 1309N/A * "as is" without express or implied warranty. 1309N/A * KAZUTAKA YOKOTA DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, 1309N/A * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO 1309N/A * EVENT SHALL KAZUTAKA YOKOTA BE LIABLE FOR ANY SPECIAL, INDIRECT OR 1309N/A * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 1309N/A * DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 2362N/A * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 2362N/A * PERFORMANCE OF THIS SOFTWARE. 1309N/A char *
eisaid;
/* EISA ID including mfr ID and product ID */ {
"KYEEZ00",
PROT_MS },
/* Genius EZScroll */ {
"KYE0001",
PROT_MS },
/* Genius PnP Mouse */ {
"KYE0002",
PROT_MS },
/* MouseSystem (Genius?) SmartScroll */ {
"LGI800C",
PROT_IMSERIAL },
/* Logitech MouseMan (4 button model) */ {
"LGI8033",
PROT_IMSERIAL },
/* Logitech Cordless MouseMan Wheel */ {
"PNP0F00",
PROT_BM },
/* MS bus */ {
"PNP0F01",
PROT_MS },
/* MS serial */ {
"PNP0F02",
PROT_BM },
/* MS InPort */ * EzScroll returns PNP0F04 in the compatible device field; but it * doesn't look compatible... XXX {
"PNP0F04",
PROT_MSC },
/* MouseSystems */ {
"PNP0F05",
PROT_MSC },
/* MouseSystems */ {
"PNP0F06",
PROT_??? },
/* Genius Mouse */ {
"PNP0F07",
PROT_??? },
/* Genius Mouse */ {
"PNP0F09",
PROT_MS },
/* MS BallPoint serial */ {
"PNP0F0A",
PROT_MS },
/* MS PnP serial */ {
"PNP0F0B",
PROT_MS },
/* MS PnP BallPoint serial */ {
"PNP0F0C",
PROT_MS },
/* MS serial comatible */ {
"PNP0F0D",
PROT_BM },
/* MS InPort comatible */ {
"PNP0F0E",
PROT_PS2 },
/* MS PS/2 comatible */ {
"PNP0F0F",
PROT_MS },
/* MS BallPoint comatible */ {
"PNP0F10",
PROT_??? },
/* TI QuickPort */ {
"PNP0F11",
PROT_BM },
/* MS bus comatible */ {
"PNP0F12",
PROT_PS2 },
/* Logitech PS/2 */ {
"PNP0F14",
PROT_??? },
/* MS Kids Mouse */ {
"PNP0F15",
PROT_BM },
/* Logitech bus */ {
"PNP0F16",
PROT_??? },
/* Logitech SWIFT */ {
"PNP0F18",
PROT_BM },
/* Logitech bus compatible */ {
"PNP0F19",
PROT_PS2 },
/* Logitech PS/2 compatible */ {
"PNP0F1A",
PROT_??? },
/* Logitech SWIFT compatible */ {
"PNP0F1B",
PROT_??? },
/* HP Omnibook */ {
"PNP0F1C",
PROT_??? },
/* Compaq LTE TrackBall PS/2 */ {
"PNP0F1D",
PROT_??? },
/* Compaq LTE TrackBall serial */ {
"PNP0F1E",
PROT_??? },
/* MS Kids Trackball */ char buf[
256];
/* PnP ID string may be up to 256 bytes long */ * Try to elicit a PnP ID as described in * Microsoft, Hayes: "Plug and Play External COM Device Specification, * The routine does not fully implement the COM Enumerator as per 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 * 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 * 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) */ /* port setup, 1st phase (2.1.3) */ /* wait for response, 1st phase (2.1.4) */ /* try to read something */ /* port setup, 2nd phase (2.1.5) */ /* wait for respose, 2nd phase (2.1.6) */ /* try to read something */ * This is a simplified procedure; it simply toggles RTS. /* try to read something */ /* collect PnP COM device ID (2.1.7) */ usleep(
200000);
/* the mouse must send `Begin ID' within 200msec */ /* we may see "M", or "M3..." before `Begin ID' */ if ((c ==
0x08) || (c ==
0x28)) {
/* Begin ID */ /* we haven't seen `Begin ID' in time... */ ++c;
/* make it `End ID' */ if (
buf[i++] == c)
/* End ID */ * 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. for (i = 0; i <
len -
3; ++i) {
/* EISA vender and product ID */ for (j = ++i; i <
len; ++i) {
for (j = ++i; i <
len; ++i) {
for (j = ++i; i <
len; ++i) {
* PnP COM spec prior to v0.96 allowed '*' in this field, * it's not allowed now; just ignore it. /* product description */ for (j = ++i; i <
len; ++i) {
/* checksum exists if there are any optional fields */ * I found some mice do not comply with the PnP COM device * spec regarding checksum... XXX /* We can only identify MS at the moment */ if (
buf[0] ==
'M' &&
buf[
1] ==
'3')
/* this is not a mouse! */ * The 'Compatible drivers' field may contain more than one /******************* PS/2 PnP probing ****************/ for (i = 0; i <
len; i++)
for (i = 0; i <
len; i++) {
for (j = 0; j <
10; j++) {
if (c ==
0xFE)
/* resend */ if (c ==
0xFC)
/* error */ /* Some mice accidently enter wrap mode during init */ if (c == *(
bytes + i)
/* wrap mode */ && (*(
bytes + i) !=
0xEC))
/* avoid recursion */ unsigned char packet[] = {
0xF5 };
unsigned char packet[] = {
0xF4 };
unsigned char packet[] = {
0xf2 };
unsigned char packet[] = {
0xff };
unsigned char reply[] = {
0xaa,
0x00 };
/* we need a little delay here */ for (i = 0; i <
sizeof(
reply) ; i++) {
unsigned char seq[] = {
243,
200,
243,
100,
243,
80 };
/* Try to identify Intelli Mouse */ /* found IntelliMouse now try IntelliExplorer */ unsigned char seq[] = {
243,
200,
243,
200,
243,
80 };