From owner-svn-src-all@FreeBSD.ORG Tue Jan 14 08:43:38 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id D439D283; Tue, 14 Jan 2014 08:43:38 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id BFF391DA7; Tue, 14 Jan 2014 08:43:38 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id s0E8hcEQ062831; Tue, 14 Jan 2014 08:43:38 GMT (envelope-from hselasky@svn.freebsd.org) Received: (from hselasky@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id s0E8hcpg062830; Tue, 14 Jan 2014 08:43:38 GMT (envelope-from hselasky@svn.freebsd.org) Message-Id: <201401140843.s0E8hcpg062830@svn.freebsd.org> From: Hans Petter Selasky Date: Tue, 14 Jan 2014 08:43:38 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r260622 - head/sys/dev/usb/input X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.17 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 14 Jan 2014 08:43:38 -0000 Author: hselasky Date: Tue Jan 14 08:43:38 2014 New Revision: 260622 URL: http://svnweb.freebsd.org/changeset/base/260622 Log: Don't output any modifier keys before we see a valid non-modifier key press. This prevents so-called "ghost keyboards" keeping modifier keys pressed while not actually seen as a real keyboard. MFC after: 2 weeks Modified: head/sys/dev/usb/input/ukbd.c Modified: head/sys/dev/usb/input/ukbd.c ============================================================================== --- head/sys/dev/usb/input/ukbd.c Tue Jan 14 04:28:41 2014 (r260621) +++ head/sys/dev/usb/input/ukbd.c Tue Jan 14 08:43:38 2014 (r260622) @@ -197,6 +197,7 @@ struct ukbd_softc { #define UKBD_FLAG_NUMLOCK 0x00080000 #define UKBD_FLAG_CAPSLOCK 0x00100000 #define UKBD_FLAG_SCROLLLOCK 0x00200000 +#define UKBD_FLAG_VALID_KEYS 0x00400000 int sc_mode; /* input mode (K_XLATE,K_RAW,K_CODE) */ int sc_state; /* shift/lock key state */ @@ -512,6 +513,41 @@ ukbd_interrupt(struct ukbd_softc *sc) n_mod = sc->sc_ndata.modifiers; o_mod = sc->sc_odata.modifiers; + + /* + * Don't output any modifier keys before we see a valid + * non-modifier key press. This prevents so-called "ghost + * keyboards" keeping modifier keys pressed while not actually + * seen as a real keyboard. + */ + if (sc->sc_flags & UKBD_FLAG_VALID_KEYS) + goto kfound; + + for (i = 0; i != UKBD_NKEYCODE; i++) { + key = sc->sc_ndata.keycode[i]; + switch (key) { + case 0xe0: + case 0xe4: + case 0xe1: + case 0xe5: + case 0xe2: + case 0xe6: + case 0xe3: + case 0xe7: + case 0x00: + case KEY_ERROR: + break; + default: + sc->sc_flags |= UKBD_FLAG_VALID_KEYS; + goto kfound; + } + } + DPRINTF("Keeping modifiers buffered\n"); + + /* keep modifiers in buffer */ + sc->sc_ndata.modifiers = n_mod = 0; + +kfound: if (n_mod != o_mod) { for (i = 0; i < UKBD_NMOD; i++) { if ((n_mod & ukbd_mods[i].mask) !=